private void documentRating(SourceBean request, String mod, SourceBean response) throws EMFUserError, SourceBeanException { String objId = ""; String rating = ""; RequestContainer requestContainer = this.getRequestContainer(); SessionContainer session = requestContainer.getSessionContainer(); SessionContainer permanentSession = session.getPermanentContainer(); UserProfile profile = (UserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE); IEngUserProfile profile2 = (IEngUserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE); String userId = (profile.getUserUniqueIdentifier() != null ? profile.getUserUniqueIdentifier().toString() : ""); List params = request.getContainedAttributes(); ListIterator it = params.listIterator(); while (it.hasNext()) { Object par = it.next(); SourceBeanAttribute p = (SourceBeanAttribute) par; String parName = (String) p.getKey(); logger.debug("got parName=" + parName); if (parName.equals("OBJECT_ID")) { objId = (String) request.getAttribute("OBJECT_ID"); logger.debug("got OBJECT_ID from Request=" + objId); } else if (parName.equals("RATING")) { rating = (String) request.getAttribute("RATING"); } } boolean canSee = false; BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectById(new Integer(objId)); try { canSee = ObjectsAccessVerifier.canSee(obj, profile); } catch (EMFInternalError e1) { e1.printStackTrace(); } if (!canSee) { logger.error("Object with label = '" + obj.getLabel() + "' cannot be executed by the user!!"); Vector v = new Vector(); v.add(obj.getLabel()); throw new EMFUserError(EMFErrorSeverity.ERROR, "1075", v, null); } // get all correct execution roles List correctRoles = new ArrayList(); try { correctRoles = DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(new Integer(objId), profile2); } catch (NumberFormatException e2) { e2.printStackTrace(); } if (correctRoles == null || correctRoles.size() == 0) { logger.warn("Object cannot be executed by no role of the user"); throw new EMFUserError(EMFErrorSeverity.ERROR, 1006); } if (objId != null && !objId.equals("")) { if (rating != null && !rating.equals("")) { // VOTE! DAOFactory.getBIObjectRatingDAO().voteBIObject(obj, userId, rating); } } response.setAttribute("MESSAGEDET", mod); response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "ratingBIObjectPubJ"); response.setAttribute("OBJECT_ID", objId); }
public void doService() { ExecutionInstance instance; Integer documentId; String documentLabel; Integer documentVersion; String executionRole; String userProvidedParametersStr; BIObject obj; IEngUserProfile profile; List roles; logger.debug("IN"); try { profile = getUserProfile(); documentId = requestContainsAttribute(DOCUMENT_ID) ? getAttributeAsInteger(DOCUMENT_ID) : null; documentVersion = requestContainsAttribute(DOCUMENT_VERSION) ? getAttributeAsInteger(DOCUMENT_VERSION) : 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 [" + DOCUMENT_VERSION + "] is equals to [" + documentVersion + "]"); 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"); // if into the request is specified a version of the template to use it's signed into the // object. if (documentVersion != null) obj.setDocVersion(documentVersion); // 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. // instance = createExecutionInstance(obj.getId(), executionRole); UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuidObj = uuidGen.generateTimeBasedUUID(); String executionContextId = uuidObj.toString(); executionContextId = executionContextId.replaceAll("-", ""); CoreContextManager ccm = createContext(executionContextId); // so far so good: everything has been validated successfully. Let's create a new // ExecutionInstance. instance = createExecutionInstance( obj.getId(), obj.getDocVersion(), executionRole, executionContextId, getLocale()); createContext(executionContextId).set(ExecutionInstance.class.getName(), instance); // instance.refreshParametersValues(getSpagoBIRequestContainer().getRequest(), true); // instance.setParameterValues(userProvidedParametersStr, true); // refresh obj variable because createExecutionInstance load the BIObject in a different way // obj = instance.getBIObject(); // ExecutionInstance has been created it's time to prepare the response with the instance // unique id and flush it to the client JSONObject responseJSON = null; responseJSON = new JSONObject(); try { responseJSON.put("execContextId", executionContextId); } catch (JSONException e) { throw new SpagoBIServiceException("Impossible to serialize response", e); } try { writeBackToClient(new JSONSuccess(responseJSON)); } catch (IOException e) { throw new SpagoBIServiceException("Impossible to write back the responce to the client", e); } } finally { logger.debug("OUT"); } }