String ids = this.getAttributeAsString(SUBOBJECT_ID);
// ids contains the id of the subobjects to be deleted separated by ,
String[] idArray = ids.split(",");
for (int i = 0; i < idArray.length; i++) {
Integer id = new Integer(idArray[i]);
SubObject subObject = null;
try {
subObject = dao.getSubObject(id);
} catch (EMFUserError e) {
logger.error("SubObject with id = " + id + " not found", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Customized view not found", e);
}
if (subObject.getBiobjId().equals(obj.getId())) {
boolean canDeleteSubObject = false;
if (userProfile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)
|| subObject.getOwner().equals(userProfile.getUserId().toString())) {
canDeleteSubObject = true;
}
if (canDeleteSubObject) {
logger.info("User [id: " + userProfile.getUserUniqueIdentifier() + ", userId: " + userProfile.getUserId() + ", name: " + userProfile.getUserName() + "] " +
"is deleting customized view [id: " + subObject.getId() + ", name: " + subObject.getName() + "] ...");
try {
dao.deleteSubObject(id);
} catch (EMFUserError e) {
throw new SpagoBIServiceException(SERVICE_NAME, "Error while deleting customized view", e);
}
logger.debug("Customized view [id: " + subObject.getId() + ", name: " + subObject.getName() + "] deleted.");
} else {
logger.error("User [id: " + userProfile.getUserUniqueIdentifier() + ", userId: " + userProfile.getUserId() + ", name: " + userProfile.getUserName() + "] cannot delete customized view");
throw new SpagoBIServiceException(SERVICE_NAME, "User cannot delete customized view");
}
} else {
logger.error("Cannot delete customized view with id = " + subObject.getBiobjId() + ": " +
"it is not relevant to the current document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]");
throw new SpagoBIServiceException(SERVICE_NAME, "Cannot delete customized view: it is not relevant to the current document");
}
}