use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList in project OpenUnison by TremoloSecurity.
the class ModuleType method getAccountId.
private String getAccountId(String name, String sessionId) throws UnsupportedEncodingException, ClientProtocolException, IOException, ProvisioningException {
Gson gson = new Gson();
SugarGetEntryList sgel = new SugarGetEntryList();
sgel.setSession(sessionId);
sgel.setModule_name("Accounts");
StringBuffer b = new StringBuffer();
b.append("accounts.name='").append(name).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 companyLookupJSON = gson.toJson(sgel);
String respJSON = execJson(companyLookupJSON, "get_entry_list");
SugarResult sr = gson.fromJson(respJSON, SugarResult.class);
if (sr.getResult_count() == 0) {
SugarEntry newContact = new SugarEntry();
newContact.setSession(sessionId);
newContact.setModule("Accounts");
Map<String, String> nvps = new HashMap<String, String>();
nvps.put("name", name);
newContact.setName_value_list(nvps);
String createUserJSON = gson.toJson(newContact);
respJSON = execJson(createUserJSON, "set_entry");
SugarID id = gson.fromJson(respJSON, SugarID.class);
return id.getId();
} else {
return sr.getEntry_list().get(0).getId();
}
}
use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList 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);
}
}
use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList in project OpenUnison by TremoloSecurity.
the class ModuleType method deleteUser.
@Override
public void deleteUser(User user, 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(user.getUserID()).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");
if (jsonArray.size() == 0) {
throw new Exception("User " + user.getUserID() + " not found");
}
String id = (String) ((JSONObject) jsonArray.get(0)).get("id");
SugarEntry newContact = new SugarEntry();
newContact.setSession(sessionId);
newContact.setModule(mt.name);
Map<String, String> nvps = new HashMap<String, String>();
nvps.put("id", id);
nvps.put("deleted", "1");
newContact.setName_value_list(nvps);
String createUserJSON = gson.toJson(newContact);
execJson(createUserJSON, "set_entry");
} catch (Exception e) {
throw new ProvisioningException("Could not delete user", e);
}
}
Aggregations