private static JSONObject createResponseContent(EMFUserError error) throws JSONException { JSONObject content = new JSONObject(); content.put("code", error.getErrorCode()); content.put("severity", error.getSeverity()); content.put("message", error.getMessage()); content.put("localizedMessage", error.getDescription()); return content; }
@Override public void doService() { logger.debug("IN"); IPeriodicityDAO perDao; try { perDao = DAOFactory.getPeriodicityDAO(); perDao.setUserProfile(getUserProfile()); } catch (EMFUserError e1) { logger.error(e1.getMessage(), e1); throw new SpagoBIServiceException(SERVICE_NAME, "Error occurred"); } Locale locale = getLocale(); String serviceType = this.getAttributeAsString(MESSAGE_DET); logger.debug("Service type " + serviceType); if (serviceType != null && serviceType.equalsIgnoreCase(PERIODICTIES_LIST)) { try { List periodicities = perDao.loadPeriodicityList(); logger.debug("Loaded periodicities list"); JSONArray periodicitiesJSON = (JSONArray) SerializerFactory.getSerializer("application/json") .serialize(periodicities, locale); JSONObject periodicitiesResponseJSON = createJSONResponsePeriodicities(periodicitiesJSON); writeBackToClient(new JSONSuccess(periodicitiesResponseJSON)); } catch (Throwable e) { logger.error("Exception occurred while retrieving users", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving users", e); } } else if (serviceType != null && serviceType.equalsIgnoreCase(PERIODICITY_INSERT)) { String id = getAttributeAsString(ID); String name = getAttributeAsString(NAME); String months = getAttributeAsString(MONTHS); String days = getAttributeAsString(DAYS); String hours = getAttributeAsString(HOURS); String minutes = getAttributeAsString(MINUTES); if (name != null) { Periodicity per = new Periodicity(); per.setName(name); if (months != null && !months.equals("")) { per.setMonths(new Integer(months)); } else { per.setMonths(new Integer("0")); } if (days != null && !days.equals("")) { per.setDays(new Integer(days)); } else { per.setDays(new Integer("0")); } if (hours != null && !hours.equals("")) { per.setHours(new Integer(hours)); } else { per.setHours(new Integer("0")); } if (minutes != null && !minutes.equals("")) { per.setMinutes(new Integer(minutes)); } else { per.setMinutes(new Integer("0")); } try { if (id != null && !id.equals("") && !id.equals("0")) { per.setIdKpiPeriodicity(Integer.valueOf(id)); perDao.modifyPeriodicity(per); logger.debug("Resource " + id + " updated"); JSONObject attributesResponseSuccessJSON = new JSONObject(); attributesResponseSuccessJSON.put("success", true); attributesResponseSuccessJSON.put("responseText", "Operation succeded"); attributesResponseSuccessJSON.put("id", id); writeBackToClient(new JSONSuccess(attributesResponseSuccessJSON)); } else { Integer perID = perDao.insertPeriodicity(per); logger.debug("New Resource inserted"); JSONObject attributesResponseSuccessJSON = new JSONObject(); attributesResponseSuccessJSON.put("success", true); attributesResponseSuccessJSON.put("responseText", "Operation succeded"); attributesResponseSuccessJSON.put("id", perID); writeBackToClient(new JSONSuccess(attributesResponseSuccessJSON)); } } catch (Throwable e) { logger.error(e.getMessage(), e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while saving new resource", e); } } else { logger.error("Resource name, code or type are missing"); throw new SpagoBIServiceException(SERVICE_NAME, "Please fill resource name, code and type"); } } else if (serviceType != null && serviceType.equalsIgnoreCase(PERIODICITY_DELETE)) { Integer id = getAttributeAsInteger(ID); try { perDao.deletePeriodicity(id); logger.debug("Resource deleted"); writeBackToClient(new JSONAcknowledge("Operation succeded")); } catch (Throwable e) { logger.error("Exception occurred while retrieving resource to delete", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving resource to delete", e); } } logger.debug("OUT"); }
@Override public void doService() { logger.debug("IN"); try { modelDao = DAOFactory.getModelDAO(); modelDao.setUserProfile(getUserProfile()); } catch (EMFUserError e1) { logger.error(e1.getMessage(), e1); throw new SpagoBIServiceException(SERVICE_NAME, "Error occurred"); } Locale locale = getLocale(); String serviceType = this.getAttributeAsString(MESSAGE_DET); logger.debug("Service type " + serviceType); if (serviceType != null && serviceType.equalsIgnoreCase(MODELS_LIST)) { try { List modelRootsList = modelDao.loadModelsRoot(); logger.debug("Loaded models list"); JSONArray modelsListJSON = (JSONArray) SerializerFactory.getSerializer("application/json") .serialize(modelRootsList, locale); JSONObject modelsResponseJSON = createJSONResponseModelsList(modelsListJSON, new Integer(6)); writeBackToClient(new JSONSuccess(modelsResponseJSON)); } catch (Throwable e) { logger.error("Exception occurred while retrieving model tree", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving model tree", e); } } else if (serviceType != null && serviceType.equalsIgnoreCase(MODEL_NODES_LIST)) { try { String parentId = (String) getAttributeAsString("modelId"); if (parentId == null || parentId.startsWith("xnode")) { writeBackToClient(new JSONSuccess("'OK'")); return; } Model aModel = modelDao.loadModelWithChildrenById(Integer.parseInt(parentId)); logger.debug("Loaded model tree"); JSONArray modelChildrenJSON = (JSONArray) SerializerFactory.getSerializer("application/json") .serialize(aModel.getChildrenNodes(), locale); writeBackToClient(new JSONSuccess(modelChildrenJSON)); } catch (Throwable e) { logger.error("Exception occurred while retrieving model tree", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving model tree", e); } } else if (serviceType != null && serviceType.equalsIgnoreCase(MODEL_NODES_LIST_WITH_KPI)) { try { String parentId = (String) getAttributeAsString("modelId"); if (parentId == null || parentId.startsWith("xnode")) { writeBackToClient(new JSONSuccess("'OK'")); return; } Model dbModel = modelDao.loadModelWithChildrenById(Integer.parseInt(parentId)); ModelExtended aModel = new ModelExtended(dbModel); aModel.setExtendedChildrenNodes(dbModel.getChildrenNodes()); logger.debug("Loaded model tree"); JSONArray modelChildrenJSON = (JSONArray) SerializerFactory.getSerializer("application/json") .serialize(aModel.getExtendedChildrenNodes(), locale); writeBackToClient(new JSONSuccess(modelChildrenJSON)); } catch (Throwable e) { logger.error("Exception occurred while retrieving model tree", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving model tree", e); } } else if (serviceType != null && serviceType.equalsIgnoreCase(MODEL_NODES_SAVE)) { JSONArray nodesToSaveJSON = getAttributeAsJSONArray(NODES_TO_SAVE); List<Model> modelNodes = null; if (nodesToSaveJSON != null) { try { modelNodes = deserializeNodesJSONArray(nodesToSaveJSON); // save them JSONObject response = saveModelNodes(modelNodes); writeBackToClient(new JSONSuccess(response)); } catch (Exception e) { logger.error(e.getMessage(), e); writeErrorsBackToClient(); throw new SpagoBIServiceException(SERVICE_NAME, "Exception saving model nodes", e); } } } else if (serviceType != null && serviceType.equalsIgnoreCase(MODEL_NODE_DELETE)) { Integer modelId = getAttributeAsInteger("modelId"); logger.warn("DELETING NODE WITH MODEL_ID:" + modelId); try { modelDao.deleteModel(modelId); logger.debug("Model deleted"); writeBackToClient(new JSONSuccess("'Operation succeded'")); } catch (Throwable e) { logger.error("Exception occurred while retrieving model to delete", e); throw new SpagoBIServiceException( SERVICE_NAME, "Exception occurred while retrieving model to delete", e); } } else if (serviceType == null) { try { List nodeTypesNodes = DAOFactory.getDomainDAO().loadListDomainsByType(MODEL_DOMAIN_TYPE_NODE); List nodeTypesRoot = DAOFactory.getDomainDAO().loadListDomainsByType(MODEL_DOMAIN_TYPE_ROOT); List nodeTypes = new ArrayList(); nodeTypes.addAll(nodeTypesNodes); nodeTypes.addAll(nodeTypesRoot); getSessionContainer().setAttribute("nodeTypesList", nodeTypes); List kpiTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(KPI_DOMAIN_TYPE); getSessionContainer().setAttribute("kpiTypesList", kpiTypesList); List thrSeverityTypes = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_SEVERITY_TYPE); getSessionContainer().setAttribute("thrSeverityTypes", thrSeverityTypes); List measureTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(MEASURE_DOMAIN_TYPE); getSessionContainer().setAttribute("measureTypesList", measureTypesList); List metricScaleTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(METRIC_SCALE_DOMAIN_TYPE); getSessionContainer().setAttribute("metricScaleTypesList", metricScaleTypesList); List thrTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_DOMAIN_TYPE); getSessionContainer().setAttribute("thrTypesList", thrTypesList); // Add Udp Values to sessionContainer List udpModelList = DAOFactory.getUdpDAO().loadAllByFamily("Model"); getSessionContainer().setAttribute("udpModelList", udpModelList); List udpKpiList = DAOFactory.getUdpDAO().loadAllByFamily("Kpi"); getSessionContainer().setAttribute("udpKpiList", udpKpiList); } catch (EMFUserError e) { logger.error(e.getMessage(), e); throw new SpagoBIServiceException(SERVICE_NAME, "Exception retrieving model types", e); } } logger.debug("OUT"); }