//ArrayList<Role> roles = (ArrayList<Role>)roleDao.loadAllRoles();
logger.debug("Loaded roles list");
JSONArray rolesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(roles, locale);
JSONObject rolesResponseJSON = createJSONResponseRoles(rolesJSON,totalResNum);
writeBackToClient(new JSONSuccess(rolesResponseJSON));
} catch (Throwable e) {
logger.error(e.getMessage(), e);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while retrieving roles", e);
}
} else if (serviceType != null && serviceType.equalsIgnoreCase(ROLE_INSERT)) {
String name = getAttributeAsString(NAME);
String roleTypeCD = getAttributeAsString(ROLE_TYPE_CD);
String code = getAttributeAsString(CODE);
String description = getAttributeAsString(DESCRIPTION);
Boolean saveSubobjects= getAttributeAsBoolean(SAVE_SUBOBJECTS);
Boolean seeSubobjects= getAttributeAsBoolean(SEE_SUBOBJECTS);
Boolean seeViewpoints= getAttributeAsBoolean(SEE_VIEWPOINTS);
Boolean seeSnapshots= getAttributeAsBoolean(SEE_SNAPSHOTS);
Boolean seeNotes= getAttributeAsBoolean(SEE_NOTES);
Boolean sendMail= getAttributeAsBoolean(SEND_MAIL);
Boolean saveIntoPersonalFolder= getAttributeAsBoolean(SAVE_INTO_PERSONAL_FOLDER);
Boolean saveRememberMe= getAttributeAsBoolean(SAVE_REMEMBER_ME);
Boolean seeMetadata= getAttributeAsBoolean(SEE_METADATA);
Boolean saveMetadata= getAttributeAsBoolean(SAVE_METADATA);
Boolean buildQbeQuery= getAttributeAsBoolean(BUILD_QBE_QUERY);
if (name != null) {
//checks for unique role name
try {
Role existentRole = DAOFactory.getRoleDAO().loadByName(name);
if(existentRole != null){
String id = getAttributeAsString(ID);
if(id == null || id.equals("") || id.equals("0")){
throw new SpagoBIServiceException(SERVICE_NAME, "Role Name already present.");
}
}
} catch (EMFUserError e1) {
logger.error(e1.getMessage(), e1);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while retrieving role by name", e1);
}
List<Domain> domains = (List<Domain>)getSessionContainer().getAttribute("roleTypes");
HashMap<String, Integer> domainIds = new HashMap<String, Integer> ();
for(int i=0; i< domains.size(); i++){
domainIds.put(domains.get(i).getValueCd(), domains.get(i).getValueId());
}
Integer roleTypeID = domainIds.get(roleTypeCD);
if(roleTypeID == null){
logger.error("Role type CD not existing");
throw new SpagoBIServiceException(SERVICE_NAME, "Role Type ID is undefined");
}
Role role = new Role();
role.setCode(code);
role.setDescription(description);
role.setName(name);
role.setRoleTypeCD(roleTypeCD);
role.setRoleTypeID(roleTypeID);
role.setIsAbleToBuildQbeQuery(buildQbeQuery);
role.setIsAbleToSaveIntoPersonalFolder(saveIntoPersonalFolder);
role.setIsAbleToSaveMetadata(saveMetadata);
role.setIsAbleToSaveRememberMe(saveRememberMe);
role.setIsAbleToSaveSubobjects(saveSubobjects);
role.setIsAbleToSeeMetadata(seeMetadata);
role.setIsAbleToSeeNotes(seeNotes);
role.setIsAbleToSeeSnapshots(seeSnapshots);
role.setIsAbleToSeeSubobjects(seeSubobjects);
role.setIsAbleToSeeViewpoints(seeViewpoints);
role.setIsAbleToSendMail(sendMail);
try {
String id = getAttributeAsString(ID);
if(id != null && !id.equals("") && !id.equals("0")){
role.setId(Integer.valueOf(id));
roleDao.modifyRole(role);
logger.debug("Role "+id+" updated");
JSONObject attributesResponseSuccessJSON = new JSONObject();
attributesResponseSuccessJSON.put("success", true);
attributesResponseSuccessJSON.put("responseText", "Operation succeded");
writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
}else{
Integer roleID = roleDao.insertRoleComplete(role);
logger.debug("New Role inserted");
JSONObject attributesResponseSuccessJSON = new JSONObject();
attributesResponseSuccessJSON.put("success", true);
attributesResponseSuccessJSON.put("responseText", "Operation succeded");
attributesResponseSuccessJSON.put("id", roleID);
writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while saving new role",
e);
}
}else{
logger.error("Missing role name");
throw new SpagoBIServiceException(SERVICE_NAME, "Please enter role name");
}
} else if (serviceType != null && serviceType.equalsIgnoreCase(ROLE_DELETE)) {
Integer id = getAttributeAsInteger(ID);
try {
Role aRole = roleDao.loadByID(id);
roleDao.eraseRole(aRole);
logger.debug("Role deleted");
writeBackToClient( new JSONAcknowledge("Operazion succeded") );
} catch (Throwable e) {
logger.error("Exception occurred while deleting role", e);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while deleting role",
e);
}
} else if (serviceType != null && serviceType.equalsIgnoreCase(ROLES_SYNCHRONIZATION)) {
try {
RoleSynchronizer roleSynch = new RoleSynchronizer();
roleSynch.synchronize();
logger.debug("Roles synchronized");
JSONObject attributesResponseSuccessJSON = new JSONObject();
attributesResponseSuccessJSON.put("success", true);
attributesResponseSuccessJSON.put("responseText", "Operation succeded");
writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
} catch (Throwable e) {
logger.error("Exception occurred while syncronize roles", e);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while syncronize role",