use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntry in project OpenUnison by TremoloSecurity.
the class ModuleType method findUser.
@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
try {
ModuleType mt = this.getModuleType(request);
String sessionId = sugarLogin();
Gson gson = new Gson();
SugarGetEntryList sgel = new SugarGetEntryList();
sgel.setSession(sessionId);
sgel.setModule_name(mt.name);
StringBuffer b = new StringBuffer();
b.append(mt.lookupByEmail).append(userID).append("')");
sgel.setQuery(b.toString());
sgel.setOrder_by("");
sgel.setOffset(0);
ArrayList<String> reqFields = new ArrayList<String>();
reqFields.add("id");
sgel.setSelect_fields(reqFields);
sgel.setMax_results(-1);
sgel.setDeleted(false);
sgel.setLink_name_to_fields_array(new HashMap<String, List<String>>());
String searchJson = gson.toJson(sgel);
String respJSON = execJson(searchJson, "get_entry_list");
JSONObject jsonObj = (JSONObject) JSONValue.parse(respJSON);
JSONArray jsonArray = (JSONArray) jsonObj.get("entry_list");
String id = (String) ((JSONObject) jsonArray.get(0)).get("id");
SugarGetEntry sge = new SugarGetEntry();
sge.setId(id);
sge.setSession(sessionId);
sge.setSelect_fields(new ArrayList<String>());
sge.setModule_name(mt.name);
sge.setLink_name_to_fields_array(new HashMap<String, List<String>>());
searchJson = gson.toJson(sge);
respJSON = execJson(searchJson, "get_entry");
// System.out.println(respJSON);
SugarEntrySet res = gson.fromJson(respJSON, SugarEntrySet.class);
User user = new User(userID);
SugarContactEntry sce = res.getEntry_list().get(0);
for (String attrName : sce.getName_value_list().keySet()) {
NVP nvp = sce.getName_value_list().get(attrName);
if (attributes.size() > 0 && !attributes.contains(nvp.getName())) {
continue;
}
if (nvp.getValue() != null && !nvp.getValue().isEmpty()) {
Attribute attr = new Attribute(nvp.getName(), nvp.getValue());
user.getAttribs().put(nvp.getName(), attr);
}
}
return user;
} catch (Exception e) {
throw new ProvisioningException("Could not find user", e);
}
}
Aggregations