Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package com.trinity.utils;
- import com.ibm.commons.util.io.json.JsonJavaArray;
- import com.ibm.commons.util.io.json.JsonJavaObject;
- import com.ibm.sbt.security.authentication.AuthenticationException;
- import com.ibm.sbt.services.client.connections.profiles.ProfileService;
- import com.ibm.sbt.services.client.connections.profiles.ProfileServiceException;
- import com.trinity.profiles.Profile;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Map.Entry;
- import lotus.domino.Database;
- import lotus.domino.Document;
- import lotus.domino.DocumentCollection;
- import lotus.domino.NotesException;
- import lotus.domino.View;
- public class NotesStructJsonBuilder {
- private final Document settings;
- private ProfileService profileSvc;
- private View structByRef;
- private Database db;
- private JsonJavaArray departments;
- private JsonJavaArray employees;
- private static final Map<String, String> DOMINO_FIELDS = new HashMap();
- public NotesStructJsonBuilder(Database db, Document settings) throws NotesException, AuthenticationException {
- this.db = db;
- this.structByRef = db.getView("(StructByRef)");
- this.departments = new JsonJavaArray();
- this.employees = new JsonJavaArray();
- this.settings = settings;
- String url = settings.getItemValueString(DominoSettingsFields.CONN_URL_FIELD.toString());
- String user = settings.getItemValueString(DominoSettingsFields.CONN_USER_FIELD.toString());
- String pass = settings.getItemValueString(DominoSettingsFields.CONN_PASSWORD_FIELD.toString());
- IbmConnConnector connector = new IbmConnConnector(url, user, pass);
- this.profileSvc = new ProfileService(connector.getEndpoint());
- }
- private void putEmployee(Document doc) throws NotesException {
- String email = doc.getItemValueString("email");
- Profile requiredProfile;
- try {
- com.ibm.sbt.services.client.connections.profiles.Profile lcProfile = this.profileSvc.getProfile(email);
- if(lcProfile == null || lcProfile.getUserid() == null) {
- throw new ProfileServiceException((Throwable)null, "Profile not found");
- }
- requiredProfile = ProfileUtils.getProfile(lcProfile);
- requiredProfile.putEntry("services", ProfileUtils.getProfileServices(this.settings, requiredProfile));
- requiredProfile.putEntry("profilePage", ProfileUtils.getProfilePage(this.settings, requiredProfile));
- } catch (ProfileServiceException var7) {
- requiredProfile = new Profile();
- requiredProfile.putEntry("profilePage", "user/user-" + doc.getItemValueString("TabNumber"));
- requiredProfile.putEntry("photo", this.settings.getItemValueString(DominoSettingsFields.DEFAULT_PHOTO.toString()));
- var7.printStackTrace();
- }
- Iterator var8 = DOMINO_FIELDS.entrySet().iterator();
- while(var8.hasNext()) {
- Entry<String, String> dmnField = (Entry)var8.next();
- String val = doc.getItemValueString((String)dmnField.getValue());
- if(val != null && !val.equals("")) {
- requiredProfile.putEntry((String)dmnField.getKey(), val);
- }
- }
- this.employees.add(ProfileUtils.profileToJson(requiredProfile));
- }
- private JsonJavaArray getParentDepartments(Document doc) throws NotesException {
- JsonJavaArray jsonArr = new JsonJavaArray();
- Document childDoc;
- for(String parentUnid = doc.getParentDocumentUNID(); !parentUnid.equals(""); parentUnid = childDoc.getParentDocumentUNID()) {
- childDoc = this.db.getDocumentByUNID(parentUnid);
- JsonJavaObject curJson = new JsonJavaObject();
- curJson.put("href", "0/" + childDoc.getUniversalID());
- curJson.put("name", childDoc.getItemValueString("StaffName"));
- jsonArr.add(curJson);
- }
- Collections.reverse(jsonArr);
- return jsonArr;
- }
- private JsonJavaObject getDepartment(Document doc, boolean includeParents) throws NotesException {
- JsonJavaObject json = new JsonJavaObject();
- String unid = doc.getUniversalID();
- String staffName = doc.getItemValueString("StaffName");
- DocumentCollection viewDocs = this.structByRef.getAllDocumentsByKey(unid);
- json.put("unid", unid);
- json.put("name", staffName);
- json.put("href", "0/" + unid);
- json.put("has-child", Boolean.valueOf(viewDocs.getCount() > 0));
- if(includeParents) {
- json.put("parent-departments", this.getParentDepartments(doc));
- }
- return json;
- }
- public JsonJavaObject getStructAsJson(String unid) throws NotesException {
- JsonJavaObject rootJson = new JsonJavaObject();
- Document rootDoc = this.db.getDocumentByUNID(unid);
- DocumentCollection childDocs = rootDoc.getResponses();
- JsonJavaObject departmentJson;
- for(Document curDoc = childDocs.getFirstDocument(); curDoc != null; curDoc = childDocs.getNextDocument()) {
- String form = curDoc.getItemValueString("form");
- if(form.equals("f2")) {
- departmentJson = this.getDepartment(curDoc, false);
- this.departments.add(departmentJson);
- } else if(form.equals("Person")) {
- this.putEmployee(curDoc);
- }
- }
- departmentJson = this.getDepartment(rootDoc, true);
- departmentJson.put("child-departments", this.departments);
- rootJson.put("employees", this.employees);
- rootJson.put("department", departmentJson);
- return rootJson;
- }
- static {
- DOMINO_FIELDS.put("displayName", "fio");
- DOMINO_FIELDS.put("internalPhone", "PhoneNumberIn");
- DOMINO_FIELDS.put("jobResp", "StaffName");
- DOMINO_FIELDS.put("internalPhone", "PhoneNumberIn");
- DOMINO_FIELDS.put("externalPhone", "PhoneNumberOut");
- DOMINO_FIELDS.put("actualLocation", "LocationReal");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement