private static JSONObject createResponseContent(EMFInternalError error) throws JSONException { JSONObject content = new JSONObject(); content.put("severity", error.getSeverity()); content.put("message", error.getMessage()); content.put("localizedMessage", error.getDescription()); return content; }
private static JSONObject createResponseContent(EMFAbstractError error) throws JSONException { JSONObject jsonObject = new JSONObject(); if (error instanceof EMFInternalError) { EMFInternalError internalError = (EMFInternalError) error; Exception e = internalError.getNativeException(); if (e != null && e instanceof SpagoBIServiceException) { SpagoBIServiceException serviceError = (SpagoBIServiceException) e; jsonObject = createResponseContent(serviceError); } else { jsonObject = createResponseContent(internalError); } } else if (error instanceof EMFUserError) { EMFUserError userError = (EMFUserError) error; if (userError instanceof EMFValidationError) { EMFValidationError validationError = (EMFValidationError) error; jsonObject = createResponseContent(validationError); } else { jsonObject = createResponseContent(userError); } } else { jsonObject = new JSONObject(); jsonObject.put("severity", error.getSeverity()); jsonObject.put("message", error.getMessage()); jsonObject.put("localizedMessage", error.getDescription()); } return jsonObject; }
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); }