public void doService() {
logger.debug("IN");
try {
// retrieving execution instance from session, no need to check if user is able to execute the current document
ExecutionInstance executionInstance = getContext().getExecutionInstance( ExecutionInstance.class.getName() );
BIObject obj = executionInstance.getBIObject();
BIObjectNotesManager objectNManager = new BIObjectNotesManager();
String execIdentifier = objectNManager.getExecutionIdentifier(obj);
String previousNotes = this.getAttributeAsString("PREVIOUS_NOTES");
logger.debug("Parameter [" + PREVIOUS_NOTES + "] is equal to [" + previousNotes + "]");
String notes = this.getAttributeAsString("NOTES");
logger.debug("Parameter [" + NOTES + "] is equal to [" + notes + "]");
String message = this.getAttributeAsString(MESSAGE);
logger.debug("Parameter [" + MESSAGE + "] is equal to [" + message + "]");
String visibility = this.getAttributeAsString(VISIBILITY);
logger.debug("Parameter [" + VISIBILITY + "] is equal to [" + visibility + "]");
String resultStr = null;
ObjNote objnote = null;
SessionContainer sessCont = getSessionContainer();
SessionContainer permCont = sessCont.getPermanentContainer();
IEngUserProfile profile = (IEngUserProfile)permCont.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
String owner = (String)((UserProfile)profile).getUserId();
try {
objnote = DAOFactory.getObjNoteDAO().getExecutionNotesByOwner(obj.getId(), execIdentifier, owner);
} catch (Exception e) {
logger.error("Cannot load notes for document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Cannot load notes", e);
}
String currentNotes = "";
if (objnote != null) {
logger.debug("Existing notes found with the same execution identifier");
byte[] content = objnote.getContent();
currentNotes = new String(content);
}
if (!"INSERT_NOTE".equalsIgnoreCase(MESSAGE) && !currentNotes.equals(previousNotes)) {
logger.debug("Notes have been created by another user");
resultStr = "conflict";
} else {
logger.debug("Saving notes...");
try {
saveNotes(execIdentifier, obj.getId(), notes, objnote, owner, visibility,profile);
logger.debug("Notes saved");
resultStr = "ok";
} catch (Exception e) {
throw new SpagoBIServiceException(SERVICE_NAME, "Error while saving notes", e);
}