use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry in project OpenUnison by TremoloSecurity.
the class ModuleType method createUser.
@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
ModuleType mt = this.getModuleType(request);
int userID = 0;
int approvalID = 0;
int workflow = 0;
if (request.containsKey("TREMOLO_USER_ID")) {
userID = (Integer) request.get("TREMOLO_USER_ID");
}
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
if (request.containsKey("WORKFLOW_ID")) {
workflow = (Integer) request.get("WORKFLOW_ID");
}
try {
String sessionId = sugarLogin();
Gson gson = new Gson();
SugarEntry newContact = new SugarEntry();
newContact.setSession(sessionId);
newContact.setModule(mt.name);
Map<String, String> nvps = new HashMap<String, String>();
for (String attrName : user.getAttribs().keySet()) {
if (!attributes.contains(attrName) || attrName.equalsIgnoreCase("userName")) {
continue;
}
if (attrName.equalsIgnoreCase("account_name")) {
String id = this.getAccountId(user.getAttribs().get(attrName).getValues().get(0), sessionId);
nvps.put("account_id", id);
}
nvps.put(attrName, user.getAttribs().get(attrName).getValues().get(0));
}
newContact.setName_value_list(nvps);
String createUserJSON = gson.toJson(newContact);
execJson(createUserJSON, "set_entry");
} catch (Exception e) {
throw new ProvisioningException("Could not find user", e);
}
}
use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry 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.SugarEntry in project OpenUnison by TremoloSecurity.
the class ModuleType method syncUser.
@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
ModuleType mt = this.getModuleType(request);
int userID = 0;
int approvalID = 0;
int workflow = 0;
if (request.containsKey("TREMOLO_USER_ID")) {
userID = (Integer) request.get("TREMOLO_USER_ID");
}
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
if (request.containsKey("WORKFLOW_ID")) {
workflow = (Integer) request.get("WORKFLOW_ID");
}
try {
String sessionId = sugarLogin();
Map<String, String> toAdd = new HashMap<String, String>();
Map<String, String> toReplace = new HashMap<String, String>();
Map<String, String> toDelete = new HashMap<String, String>();
Gson gson = new Gson();
Set<String> nattribs = new HashSet<String>();
nattribs.addAll(attributes);
nattribs.add("id");
User foundUser = null;
try {
foundUser = this.findUser(user.getUserID(), nattribs, request);
} catch (Exception e) {
this.createUser(user, attributes, request);
return;
}
Map<String, String> nvps = new HashMap<String, String>();
nvps.put("id", foundUser.getAttribs().get("id").getValues().get(0));
for (String attrName : user.getAttribs().keySet()) {
if (!attributes.contains(attrName)) {
continue;
}
if (attrName.equalsIgnoreCase("account_name")) {
String id = this.getAccountId(user.getAttribs().get(attrName).getValues().get(0), sessionId);
nvps.put("account_id", id);
}
foundUser.getAttribs().put(attrName, new Attribute(attrName, user.getAttribs().get(attrName).getValues().get(0)));
}
if (!addOnly) {
for (String attrName : foundUser.getAttribs().keySet()) {
if (!user.getAttribs().containsKey(attrName) && !attributes.contains(attrName) && !attrName.equalsIgnoreCase("id")) {
foundUser.getAttribs().put(attrName, new Attribute(attrName, ""));
}
}
}
for (String attrName : foundUser.getAttribs().keySet()) {
nvps.put(attrName, foundUser.getAttribs().get(attrName).getValues().get(0));
}
SugarEntry newContact = new SugarEntry();
newContact.setSession(sessionId);
newContact.setModule(mt.name);
newContact.setName_value_list(nvps);
String createUserJSON = gson.toJson(newContact);
execJson(createUserJSON, "set_entry");
} catch (Exception e) {
throw new ProvisioningException("Could not sync user", e);
}
}
use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry in project OpenUnison by TremoloSecurity.
the class ModuleType method deleteAccount.
public void deleteAccount(String name) throws ProvisioningException {
try {
DefaultHttpClient http = new DefaultHttpClient();
String sessionId = sugarLogin();
Gson gson = new Gson();
String id = this.getAccountId(name, sessionId);
SugarEntry newContact = new SugarEntry();
newContact.setSession(sessionId);
newContact.setModule("Accounts");
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);
}
}
use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry 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