Search in sources :

Example 1 with SugarID

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();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SugarEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry) Gson(com.google.gson.Gson) SugarID(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) SugarResult(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarResult) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Gson (com.google.gson.Gson)1 SugarEntry (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry)1 SugarGetEntryList (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList)1 SugarID (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID)1 SugarResult (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1