Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.20 KB | None | 0 0
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5.  
  6. package com.trinity.utils;
  7.  
  8. import com.ibm.commons.util.io.json.JsonJavaArray;
  9. import com.ibm.commons.util.io.json.JsonJavaObject;
  10. import com.ibm.sbt.security.authentication.AuthenticationException;
  11. import com.ibm.sbt.services.client.connections.profiles.ProfileService;
  12. import com.ibm.sbt.services.client.connections.profiles.ProfileServiceException;
  13. import com.trinity.profiles.Profile;
  14. import java.util.Collections;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.Map;
  18. import java.util.Map.Entry;
  19. import lotus.domino.Database;
  20. import lotus.domino.Document;
  21. import lotus.domino.DocumentCollection;
  22. import lotus.domino.NotesException;
  23. import lotus.domino.View;
  24.  
  25. public class NotesStructJsonBuilder {
  26.     private final Document settings;
  27.     private ProfileService profileSvc;
  28.     private View structByRef;
  29.     private Database db;
  30.     private JsonJavaArray departments;
  31.     private JsonJavaArray employees;
  32.     private static final Map<String, String> DOMINO_FIELDS = new HashMap();
  33.  
  34.     public NotesStructJsonBuilder(Database db, Document settings) throws NotesException, AuthenticationException {
  35.         this.db = db;
  36.         this.structByRef = db.getView("(StructByRef)");
  37.         this.departments = new JsonJavaArray();
  38.         this.employees = new JsonJavaArray();
  39.         this.settings = settings;
  40.         String url = settings.getItemValueString(DominoSettingsFields.CONN_URL_FIELD.toString());
  41.         String user = settings.getItemValueString(DominoSettingsFields.CONN_USER_FIELD.toString());
  42.         String pass = settings.getItemValueString(DominoSettingsFields.CONN_PASSWORD_FIELD.toString());
  43.         IbmConnConnector connector = new IbmConnConnector(url, user, pass);
  44.         this.profileSvc = new ProfileService(connector.getEndpoint());
  45.     }
  46.  
  47.     private void putEmployee(Document doc) throws NotesException {
  48.         String email = doc.getItemValueString("email");
  49.  
  50.         Profile requiredProfile;
  51.         try {
  52.             com.ibm.sbt.services.client.connections.profiles.Profile lcProfile = this.profileSvc.getProfile(email);
  53.             if(lcProfile == null || lcProfile.getUserid() == null) {
  54.                 throw new ProfileServiceException((Throwable)null, "Profile not found");
  55.             }
  56.  
  57.             requiredProfile = ProfileUtils.getProfile(lcProfile);
  58.             requiredProfile.putEntry("services", ProfileUtils.getProfileServices(this.settings, requiredProfile));
  59.             requiredProfile.putEntry("profilePage", ProfileUtils.getProfilePage(this.settings, requiredProfile));
  60.         } catch (ProfileServiceException var7) {
  61.             requiredProfile = new Profile();
  62.             requiredProfile.putEntry("profilePage", "user/user-" + doc.getItemValueString("TabNumber"));
  63.             requiredProfile.putEntry("photo", this.settings.getItemValueString(DominoSettingsFields.DEFAULT_PHOTO.toString()));
  64.             var7.printStackTrace();
  65.         }
  66.  
  67.         Iterator var8 = DOMINO_FIELDS.entrySet().iterator();
  68.  
  69.         while(var8.hasNext()) {
  70.             Entry<String, String> dmnField = (Entry)var8.next();
  71.             String val = doc.getItemValueString((String)dmnField.getValue());
  72.             if(val != null && !val.equals("")) {
  73.                 requiredProfile.putEntry((String)dmnField.getKey(), val);
  74.             }
  75.         }
  76.  
  77.         this.employees.add(ProfileUtils.profileToJson(requiredProfile));
  78.     }
  79.  
  80.     private JsonJavaArray getParentDepartments(Document doc) throws NotesException {
  81.         JsonJavaArray jsonArr = new JsonJavaArray();
  82.  
  83.         Document childDoc;
  84.         for(String parentUnid = doc.getParentDocumentUNID(); !parentUnid.equals(""); parentUnid = childDoc.getParentDocumentUNID()) {
  85.             childDoc = this.db.getDocumentByUNID(parentUnid);
  86.             JsonJavaObject curJson = new JsonJavaObject();
  87.             curJson.put("href", "0/" + childDoc.getUniversalID());
  88.             curJson.put("name", childDoc.getItemValueString("StaffName"));
  89.             jsonArr.add(curJson);
  90.         }
  91.  
  92.         Collections.reverse(jsonArr);
  93.         return jsonArr;
  94.     }
  95.  
  96.     private JsonJavaObject getDepartment(Document doc, boolean includeParents) throws NotesException {
  97.         JsonJavaObject json = new JsonJavaObject();
  98.         String unid = doc.getUniversalID();
  99.         String staffName = doc.getItemValueString("StaffName");
  100.         DocumentCollection viewDocs = this.structByRef.getAllDocumentsByKey(unid);
  101.         json.put("unid", unid);
  102.         json.put("name", staffName);
  103.         json.put("href", "0/" + unid);
  104.         json.put("has-child", Boolean.valueOf(viewDocs.getCount() > 0));
  105.         if(includeParents) {
  106.             json.put("parent-departments", this.getParentDepartments(doc));
  107.         }
  108.  
  109.         return json;
  110.     }
  111.  
  112.     public JsonJavaObject getStructAsJson(String unid) throws NotesException {
  113.         JsonJavaObject rootJson = new JsonJavaObject();
  114.         Document rootDoc = this.db.getDocumentByUNID(unid);
  115.         DocumentCollection childDocs = rootDoc.getResponses();
  116.  
  117.         JsonJavaObject departmentJson;
  118.         for(Document curDoc = childDocs.getFirstDocument(); curDoc != null; curDoc = childDocs.getNextDocument()) {
  119.             String form = curDoc.getItemValueString("form");
  120.             if(form.equals("f2")) {
  121.                 departmentJson = this.getDepartment(curDoc, false);
  122.                 this.departments.add(departmentJson);
  123.             } else if(form.equals("Person")) {
  124.                 this.putEmployee(curDoc);
  125.             }
  126.         }
  127.  
  128.         departmentJson = this.getDepartment(rootDoc, true);
  129.         departmentJson.put("child-departments", this.departments);
  130.         rootJson.put("employees", this.employees);
  131.         rootJson.put("department", departmentJson);
  132.         return rootJson;
  133.     }
  134.  
  135.     static {
  136.         DOMINO_FIELDS.put("displayName", "fio");
  137.         DOMINO_FIELDS.put("internalPhone", "PhoneNumberIn");
  138.         DOMINO_FIELDS.put("jobResp", "StaffName");
  139.         DOMINO_FIELDS.put("internalPhone", "PhoneNumberIn");
  140.         DOMINO_FIELDS.put("externalPhone", "PhoneNumberOut");
  141.         DOMINO_FIELDS.put("actualLocation", "LocationReal");
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement