use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID 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();
}
}
Aggregations