logger.debug("IN");
try {
// BIObject obj = executionInstance.getBIObject();
UserProfile userProfile = (UserProfile) this.getUserProfile();
IBIObjectDAO dao = null;
try {
dao = DAOFactory.getBIObjectDAO();
} catch (EMFUserError e) {
logger.error("Error while istantiating DAO", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Cannot access database", e);
}
String ids = this.getAttributeAsString(OBJECT_ID);
String func = this.getAttributeAsString(FUNCT_ID);
Integer iFunc = new Integer(func);
logger.debug("Input Folder:" + func);
logger.debug("Input Object:" + ids);
// ids contains the id of the object to be deleted separated by ,
String[] idArray = ids.split(",");
for (int i = 0; i < idArray.length; i++) {
Integer id = new Integer(idArray[i]);
BIObject biObject = null;
try {
biObject = dao.loadBIObjectById(id);
} catch (EMFUserError e) {
logger.error("BIObject with id = " + id + " not found", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Customized view not found", e);
}
if (userProfile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)) {
// delete document
try {
dao.eraseBIObject(biObject, iFunc);
logger.debug("Object deleted by administrator");
} catch (EMFUserError e) {
logger.error("Error to delete Document", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Error to delete Document", e);
}
} else {
String userId = ((UserProfile)userProfile).getUserId().toString();
ILowFunctionalityDAO functDAO = DAOFactory.getLowFunctionalityDAO();
LowFunctionality lowFunc = functDAO.loadLowFunctionalityByID(iFunc, false);
if(lowFunc==null){
logger.error("Functionality does not exist");
throw new Exception("Functionality does not exist");
}
if(lowFunc.getPath().equals("/"+userId)){ // folder is current user one
dao.eraseBIObject(biObject, iFunc);
logger.debug("Object deleted");
}
else{
logger.error("Functionality is not user's one");
throw new Exception("Functionality is not user's one");