String documentLabel;
String executionRole;
String userProvidedParametersStr;
BIObject obj;
IEngUserProfile profile;
List roles;
logger.debug("IN");
try {
profile = getUserProfile();
documentId = requestContainsAttribute( DOCUMENT_ID )? getAttributeAsInteger( DOCUMENT_ID ): null;
documentLabel = getAttributeAsString( DOCUMENT_LABEL );
executionRole = getAttributeAsString( EXECUTION_ROLE );
userProvidedParametersStr = getAttributeAsString(ObjectsTreeConstants.PARAMETERS);
logger.debug("Parameter [" + DOCUMENT_ID + "] is equals to [" + documentId + "]");
logger.debug("Parameter [" + DOCUMENT_LABEL + "] is equals to [" + documentLabel + "]");
logger.debug("Parameter [" + EXECUTION_ROLE + "] is equals to [" + executionRole + "]");
Assert.assertTrue(!StringUtilities.isEmpty( documentLabel ) || documentId != null,
"At least one between [" + DOCUMENT_ID + "] and [" + DOCUMENT_LABEL + "] parameter must be specified on request");
Assert.assertTrue(!StringUtilities.isEmpty( executionRole ), "Parameter [" + EXECUTION_ROLE + "] cannot be null");
// load object to chek if it exists
obj = null;
if ( !StringUtilities.isEmpty( documentLabel ) ) {
logger.debug("Loading document with label = [" + documentLabel + "] ...");
try {
obj = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(documentLabel);
} catch (EMFUserError error) {
logger.error("Object with label equals to [" + documentLabel + "] not found");
throw new SpagoBIServiceException(SERVICE_NAME, "Object with label equals to [" + documentId + "] not found", error);
}
} else if ( documentId != null ) {
logger.info("Loading biobject with id = [" + documentId + "] ...");
try {
obj = DAOFactory.getBIObjectDAO().loadBIObjectById(documentId);
} catch (EMFUserError error) {
logger.error("Object with id equals to [" + documentId + "] not found");
throw new SpagoBIServiceException(SERVICE_NAME, "Object with id equals to [" + documentId + "] not found", error);
}
} else {
Assert.assertUnreachable("At least one between [" + DOCUMENT_ID + "] and [" + DOCUMENT_LABEL + "] parameter must be specified on request");
}
Assert.assertNotNull(obj, "Impossible to load document");
logger.debug("... docuemnt loaded succesfully");
// retrive roles for execution
try {
roles = ObjectsAccessVerifier.getCorrectRolesForExecution(obj.getId(), profile);
} catch (Throwable t) {
throw new SpagoBIServiceException(SERVICE_NAME, t);
}
if (roles != null && !roles.contains(executionRole)) {
logger.error("Document [id: " + obj.getId() +"; label: " + obj.getLabel() + " ] cannot be executed by any role of the user [" + profile.getUserUniqueIdentifier() + "]");
throw new SpagoBIServiceException(SERVICE_NAME, "Document [id: " + obj.getId() +"; label: " + obj.getLabel() + " ] cannot be executed by any role of the user [" + profile.getUserUniqueIdentifier() + "]");
}
// so far so good: everything has been validated successfully. Let's create a new ExecutionInstance.