Package it.eng.spagobi.utilities.exceptions

Examples of it.eng.spagobi.utilities.exceptions.SpagoBIServiceException


    try {
      dsDao = DAOFactory.getDataSetDAO();
      dsDao.setUserProfile(profile);
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    Locale locale = getLocale();
    String serviceType = this.getAttributeAsString(DataSetConstants.MESSAGE_DET);
    logger.debug("Service type "+serviceType);
   
    if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_EXEC)) {     
      try {
        Integer dsId = getAttributeAsInteger(DataSetConstants.ID);
        JSONObject dataSetJSON =getJSONDatasetResult(dsId, profile);
        if(dataSetJSON!=null){
          try {
            writeBackToClient( new JSONSuccess( dataSetJSON ) );
          } catch (IOException e) {
            throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
          }
        }else{
          throw new SpagoBIServiceException(SERVICE_NAME,"No data found");
        }
      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.testError", e);
      }
    }
    logger.debug("OUT");
  }
View Full Code Here


           
     
      try {
        writeBackToClient( new JSONSuccess(meta) );
      } catch (IOException e) {
        throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
      }
     
    } catch(Throwable t) {
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
View Full Code Here

      kpiDao.setUserProfile(getUserProfile());
      dsDao.setUserProfile(getUserProfile());
      thrDao.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(KPIS_LIST)) {

      try {
        JSONObject filtersJSON = null;

        Integer start = getAttributeAsInteger( START );
        Integer limit = getAttributeAsInteger( LIMIT );

        if(start==null){
          start = START_DEFAULT;
        }
        if(limit==null){
          limit = LIMIT_DEFAULT;
        }

        Integer totalItemsNum = kpiDao.countKpis();
       
        List kpis = null;
        if(this.requestContainsAttribute( FILTERS ) ) {
          filtersJSON = getAttributeAsJSONObject( FILTERS );
          String hsql = filterList(filtersJSON);
          kpis = kpiDao.loadKpiListFiltered(hsql, start, limit);
        }else{//not filtered
          kpis = kpiDao.loadPagedKpiList(start,limit);
        }

        logger.debug("Loaded thresholds list");

        Integer kpiParent = this.getAttributeAsInteger("id");
        if(kpiParent != null){
          kpis =cleanKpiListForRelation((ArrayList<Kpi>)kpis, kpiParent);
        }
        JSONArray resourcesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(kpis, locale);
        JSONObject resourcesResponseJSON = createJSONResponseResources(resourcesJSON, totalItemsNum);

        writeBackToClient(new JSONSuccess(resourcesResponseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving thresholds", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving thresholds", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_INSERT)) {

      String id = getAttributeAsString(ID);
      String code = getAttributeAsString(CODE);
      String name = getAttributeAsString(NAME);
      String description = getAttributeAsString(DESCRIPTION);
      String weight = getAttributeAsString(WEIGHT);
      Boolean isAdditive = getAttributeAsBoolean(ISADDITIVE);
     
      String dsLabel = getAttributeAsString(DATASET);
      String thresholdCode = getAttributeAsString(THR);
      JSONArray docLabelsJSON = null;
      String docs = getAttributeAsString(DOCS);
      if(docs!=null && !docs.contains(",")){
        //Don't do anything
      }else{
        docLabelsJSON = getAttributeAsJSONArray(DOCS);
      }

      String interpretation = getAttributeAsString(INTERPRETATION);
      String algdesc = getAttributeAsString(ALGDESC);
      String inputAttr = getAttributeAsString(INPUT_ATTR);
      String modelReference = getAttributeAsString(MODEL_REFERENCE);
      String targetAudience = getAttributeAsString(TARGET_AUDIENCE);

      String kpiTypeCd = getAttributeAsString(KPI_TYPE_CD)
      String metricScaleCd = getAttributeAsString(METRIC_SCALE_TYPE_CD);
      String measureTypeCd = getAttributeAsString(MEASURE_TYPE_CD);       

      JSONArray udpValuesArrayJSon = getAttributeAsJSONArray(UDP_VALUE_LIST);

      List<Domain> domains = (List<Domain>)getSessionContainer().getAttribute("kpiTypesList");
      List<Domain> domains1 = (List<Domain>)getSessionContainer().getAttribute("measureTypesList");
      List<Domain> domains2 = (List<Domain>)getSessionContainer().getAttribute("metricScaleTypesList");
      domains.addAll(domains1);
      domains.addAll(domains2);

      HashMap<String, Integer> domainIds = new HashMap<String, Integer> ();
      if(domains != null){
        for(int i=0; i< domains.size(); i++){
          domainIds.put(domains.get(i).getValueCd(), domains.get(i).getValueId());
        }
      }

      Integer kpiTypeId = domainIds.get(kpiTypeCd);
      Integer metricScaleId = domainIds.get(metricScaleCd);
      Integer measureTypeId = domainIds.get(measureTypeCd);

      if (name != null && code != null) {
        Kpi k = new Kpi();

        try {

          k.setKpiName(name);
          k.setCode(code);

          if(description != null){
            k.setDescription(description);
          }
          if(weight != null && !weight.equalsIgnoreCase("")){
            k.setStandardWeight(Double.valueOf(weight));
         
          if(isAdditive != null && isAdditive.booleanValue()==true){
            k.setIsAdditive(new Boolean(true));
          }else{
            k.setIsAdditive(new Boolean(false));
          }
          if(dsLabel != null){
            k.setDsLabel(dsLabel);
            IDataSet ds = dsDao.loadActiveDataSetByLabel(dsLabel);

            if(ds!=null){
              int dsId = ds.getId();
              k.setKpiDsId(new Integer(dsId));
            }       
          }
          if(thresholdCode != null){
            Threshold t = thrDao.loadThresholdByCode(thresholdCode);
            k.setThreshold(t);
          }

          k.setKpiName(name);
          k.setCode(code);

          if(description != null){
            k.setDescription(description);
          }
          if(weight != null && !weight.equalsIgnoreCase("")){
            k.setStandardWeight(Double.valueOf(weight));
         
          if(dsLabel != null){
            k.setDsLabel(dsLabel);
            IDataSet ds = dsDao.loadActiveDataSetByLabel(dsLabel);

            if(ds!=null){
              int dsId = ds.getId();
              k.setKpiDsId(new Integer(dsId));
            }       
          }
          if(thresholdCode != null){
            Threshold t = thrDao.loadThresholdByCode(thresholdCode);
            k.setThreshold(t);
          }

          List docsList = null;
          if(docLabelsJSON != null){
            docsList = deserializeDocLabelsJSONArray(docLabelsJSON);
            k.setSbiKpiDocuments(docsList);
          }else if(docs!=null && !docs.equalsIgnoreCase("")){
            KpiDocuments d = new KpiDocuments();
            d.setBiObjLabel(docs);
            docsList = new ArrayList();
            docsList.add(d);
            k.setSbiKpiDocuments(docsList);
          }

          if(interpretation != null){
            k.setInterpretation(interpretation);
          }
          if(algdesc != null){
            k.setMetric(algdesc);
          }
          if(inputAttr != null){
            k.setInputAttribute(inputAttr);
          }
          if(modelReference != null){
            k.setModelReference(modelReference);
          }
          if(targetAudience != null){
            k.setTargetAudience(targetAudience);
          }
          if(kpiTypeCd != null){
            k.setKpiTypeCd(kpiTypeCd);
            k.setKpiTypeId(kpiTypeId);
          }
          if(metricScaleCd != null){
            k.setMetricScaleCd(metricScaleCd);
            k.setMetricScaleId(metricScaleId);
          }
          if(measureTypeCd != null){
            k.setMeasureTypeCd(measureTypeCd);
            k.setMeasureTypeId(measureTypeId);
          }   

          // add to Kpi Definition UDP Value list...
          //List udpValues = k.getUdpValues();
          List<UdpValue> udpValues = new ArrayList<UdpValue>()
          for(int i=0; i< udpValuesArrayJSon.length(); i++){
            JSONObject obj = (JSONObject)udpValuesArrayJSon.get(i);
            // only label and value information are retrieved by JSON object
            String label = obj.getString("name")
            String value = obj.getString("value")

            UdpValue udpValue = new UdpValue();

            // reference id is the kpi id
            Integer kpiId = k.getKpiId();

            //udpValue.setLabel(label);
            udpValue.setValue(value);
            udpValue.setReferenceId(kpiId);

            // get the UDP to get ID (otherwise could be taken in js page)
            Udp udp = DAOFactory.getUdpDAO().loadByLabelAndFamily(label, "KPI");
            Domain familyDomain = DAOFactory.getDomainDAO().loadDomainById(udp.getFamilyId());

            Integer idUdp = udp.getUdpId();

            udpValue.setLabel(udp.getLabel());
            udpValue.setName(udp.getName());
            udpValue.setFamily(familyDomain != null ? familyDomain.getValueCd() : null);
            udpValue.setUdpId(udp.getUdpId());

            udpValues.add(udpValue);
          }

          k.setUdpValues(udpValues);


          if(id != null && !id.equals("") && !id.equals("0")){             
            k.setKpiId(Integer.valueOf(id));
            kpiDao.modifyKpi(k);
            logger.debug("threshold "+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 kpiID = kpiDao.insertKpi(k);
            logger.debug("New threshold inserted");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", kpiID);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }

        } catch(EMFUserError e){
          logger.error("EMFUserError");
          e.printStackTrace();
        } catch (JSONException e) {
          logger.error("JSONException");
          e.printStackTrace();
        } catch (IOException e) {
          logger.error("IOException");
          e.printStackTrace();
        }

      }else{
        logger.error("Resource name, code or type are missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please fill threshold name, code and type");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        kpiDao.deleteKpi(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);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINKS)) {     
      try {
        Integer id =null;
        try{
          id = getAttributeAsInteger(ID);
        }catch (Exception e) {
          logger.debug("No Kpi Instance Id");
        }
        ArrayList <KpiRel> relations = new ArrayList<KpiRel>();
        //looks up for relations
        if(id != null){
          relations = (ArrayList <KpiRel>)kpiDao.loadKpiRelListByParentId(id);
          logger.debug("Kpi relations loaded");
 
          //looks up for dataset parameters       
          IDataSet dataSet = kpiDao.getDsFromKpiId(id);
          if(dataSet != null){
            String parametersString = dataSet.getParameters();
   
            ArrayList<String> parameters = new ArrayList<String>();
            logger.debug("Dataset Parameters loaded");
            if(parametersString != null){
              SourceBean source = SourceBean.fromXMLString(parametersString);
              if(source.getName().equals("PARAMETERSLIST")) {
                List<SourceBean> rows = source.getAttributeAsList("ROWS.ROW");
                for(int i=0; i< rows.size(); i++){
                  SourceBean row = rows.get(i);
                  String name = (String)row.getAttribute("name");
                  parameters.add(name);
                }
              }
              JSONArray paramsJSON = serializeParametersList(parameters, relations);
              JSONObject paramsResponseJSON = createJSONResponseResources(paramsJSON, parameters.size());
              writeBackToClient(new JSONSuccess(paramsResponseJSON));
            }else{
              writeBackToClient(new JSONSuccess(new JSONObject()));
            }
          }else{
            writeBackToClient(new JSONSuccess(new JSONObject()));
          }
        }else{
          writeBackToClient(new JSONSuccess(new JSONObject()));
        }

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving kpi links", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving kpi links", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINKS_BY_DS)) {     
      try {
        String labelDS = getAttributeAsString("label");
        //looks up for relations
        ArrayList <KpiRel> relations = new ArrayList <KpiRel>();

        //looks up for dataset parameters       
        IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(labelDS);
        String parametersString = dataSet.getParameters();

        ArrayList<String> parameters = new ArrayList<String>();
        logger.debug("Dataset Parameters loaded");
        if(parametersString != null){
          SourceBean source = SourceBean.fromXMLString(parametersString);
          if(source.getName().equals("PARAMETERSLIST")) {
            List<SourceBean> rows = source.getAttributeAsList("ROWS.ROW");
            for(int i=0; i< rows.size(); i++){
              SourceBean row = rows.get(i);
              String name = (String)row.getAttribute("name");
              parameters.add(name);
            }
          }
          JSONArray paramsJSON = serializeParametersList(parameters, relations);
          JSONObject paramsResponseJSON = createJSONResponseResources(paramsJSON, parameters.size());
          writeBackToClient(new JSONSuccess(paramsResponseJSON));
        }else{
          writeBackToClient(new JSONSuccess(new JSONObject()));
        }

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving kpi links", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving kpi links", e);
      }
    }
    else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINK_SAVE)) {

      Integer kpiParentId = getAttributeAsInteger("kpiParentId");
      Integer kpiLinked = getAttributeAsInteger("kpiLinked");
      String parameter = getAttributeAsString("parameter");


      try {
        try{
          Integer relId = getAttributeAsInteger("relId");
          if(relId != null){
            boolean res = kpiDao.deleteKpiRel(relId);
          }
        }catch(Throwable t){
          logger.debug("Insert new relation");
        }
        Integer idRel = kpiDao.setKpiRel(kpiParentId, kpiLinked, parameter);
        logger.debug("Resource deleted");
        writeBackToClient( new JSONSuccess(new JSONObject("{id: "+idRel.intValue()+"}")) );
      } catch (Throwable e) {
        logger.error("Exception occurred while saving kpis link", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while saving kpis link", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINK_DELETE)) {

      Integer kpiRelId = getAttributeAsInteger("relId");
      try {
        boolean res = kpiDao.deleteKpiRel(kpiRelId);
        logger.debug("Resource deleted");
        writeBackToClient( new JSONSuccess("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while deleting kpis link", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while saving kpis link", e);
      }
    }else if(serviceType == null){
      try {
        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 also UDPs
        List udpList = DAOFactory.getUdpDAO().loadAllByFamily("Kpi");
        getSessionContainer().setAttribute("udpKpiList", udpList);

      } catch (EMFUserError e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception retrieving resources types", e);
      }
    }
    logger.debug("OUT");
  }
View Full Code Here

      try {
        paramValue = (String) param.getValue();
      } catch (Exception e) {
        logger.debug("OUT");
        logger.error("Impossible read value for the parameter [" + paramName + "] into request's content", e);
        throw new SpagoBIServiceException("", "Impossible read value for the parameter [" + paramName + "] into request's content", e);
      }
      params.put(paramName, paramValue);
    }
   
    logger.debug("OUT");
View Full Code Here

      thrDao.setUserProfile(getUserProfile());
      tDao = DAOFactory.getThresholdValueDAO();
      tDao.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(THRESHOLDS_LIST)) {
     
      try {   
        JSONObject filtersJSON = null;
       
        Integer start = getAttributeAsInteger( START );
        Integer limit = getAttributeAsInteger( LIMIT );
       
        if(start==null){
          start = START_DEFAULT;
        }
        if(limit==null){
          limit = LIMIT_DEFAULT;
        }
 
        Integer totalItemsNum = thrDao.countThresholds();
       
       
        List thresholds = null;
        if(this.requestContainsAttribute( FILTERS ) ) {
          filtersJSON = getAttributeAsJSONObject( FILTERS );
          String hsql = filterList(filtersJSON);
          thresholds = thrDao.loadThresholdListFiltered(hsql, start, limit);
        }else{//not filtered
          thresholds = thrDao.loadPagedThresholdList(start,limit);
        }
       

        logger.debug("Loaded thresholds list");
        JSONArray resourcesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(thresholds, locale);
        JSONObject resourcesResponseJSON = createJSONResponseResources(resourcesJSON, totalItemsNum);
 
        writeBackToClient(new JSONSuccess(resourcesResponseJSON));
 
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving thresholds", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving thresholds", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(THRESHOLD_INSERT)) {
      String id = getAttributeAsString(ID);
      String code = getAttributeAsString(CODE);
      String name = getAttributeAsString(NAME);
      String description = getAttributeAsString(DESCRIPTION);
      String typeCD = getAttributeAsString(NODE_TYPE_CODE)
     
      JSONArray thrValuesJSON = null;
      Integer position = null;
      String thrValId = null;
      String label = null;     
      String colourString = null;
      Double value = null;
      String severityCd = null;
      Boolean minClosed = null;
      Double minValue = null;
      Boolean maxClosed = null;
      Double maxValue = null;
     
      if(typeCD!=null && typeCD.equals("RANGE")){
       
        thrValuesJSON = getAttributeAsJSONArray(THRESHOLD_VALUES);
       
      }else if(typeCD!=null && (typeCD.equals("MINIMUM") || typeCD.equals("MAXIMUM")) ){
       
        String pos = getAttributeAsString(THR_VAL_POSITION)
        if(pos!=null && !pos.equals("")){
          position = new Integer(pos);
        }       
        thrValId = getAttributeAsString(THR_VAL_ID);
        label = getAttributeAsString(THR_VAL_LABEL);
        colourString = getAttributeAsString(THR_VAL_COLOR);
        String valueS = getAttributeAsString(THR_VAL_VALUE);       
        if(valueS!=null && !valueS.equals("")){
          value = new Double(valueS);
        }
        severityCd = getAttributeAsString(THR_VAL_SEVERITY_CD);
        String minC = getAttributeAsString(THR_VAL_MIN_INCLUDED)
        if(minC!=null && !minC.equals("")){
          minClosed = new Boolean(minC);
        }else{
          minClosed = new Boolean("false");
        }
        String minValueS = getAttributeAsString(THR_VAL_MIN);
        if(minValueS!=null && !minValueS.equals("")){
          minValue = new Double(minValueS);
        }
       
        String maxValueS = getAttributeAsString(THR_VAL_MAX);       
        if(maxValueS!=null && !maxValueS.equals("")){
          maxValue = new Double(maxValueS);
        }
        String maxC = getAttributeAsString(THR_VAL_MAX_INCLUDED)
        if(maxC!=null && !maxC.equals("")){
          maxClosed = new Boolean(maxC);
        }else{
          maxClosed = new Boolean("false");
        }
      }

      List<Domain> domains = (List<Domain>)getSessionContainer().getAttribute("thrTypesList");
      List<Domain> domainsthrValues = (List<Domain>)getSessionContainer().getAttribute("thrSeverityTypes");
      domains.addAll(domainsthrValues);
     
        HashMap<String, Integer> domainIds = new HashMap<String, Integer> ();
        if(domains != null){
          for(int i=0; i< domains.size(); i++){
            domainIds.put(domains.get(i).getValueCd(), domains.get(i).getValueId());
          }
        }
       
        Integer typeID = domainIds.get(typeCD);
        if(typeID == null){
          logger.error("Threshold type CD does not exist");
          throw new SpagoBIServiceException(SERVICE_NAME,  "Threshold Type ID is undefined");
        }
 
      if (name != null && typeID != null && code != null) {
        Threshold thr = new Threshold();
        thr.setName(name);
        thr.setThresholdTypeCode(typeCD);
        thr.setThresholdTypeId(typeID);
        thr.setCode(code);
 
        if(description != null){
          thr.setDescription(description);
       
       
        List thrValuesList = new ArrayList();
        if(typeCD != null){
          if(typeCD.equals("MINIMUM") || typeCD.equals("MAXIMUM")){
            ThresholdValue tVal = new ThresholdValue();
            if(thrValId!= null && !thrValId.equals("") && !thrValId.equals("0")){
              tVal.setId(Integer.valueOf(thrValId));
            }
            tVal.setLabel(label);           
            tVal.setPosition(position);
            tVal.setColourString(colourString);
            tVal.setValue(value);
            tVal.setSeverityCd(severityCd);
            if(severityCd!=null && !severityCd.equals("")){
              Integer severityId = domainIds.get(severityCd);   
              tVal.setSeverityId(severityId);   
            }

            if(typeCD.equals("MINIMUM")){
              tVal.setMinClosed(minClosed);
              tVal.setMinValue(minValue);
            }else if(typeCD.equals("MAXIMUM")){
              tVal.setMaxClosed(maxClosed);
              tVal.setMaxValue(maxValue);
           
            thrValuesList.add(tVal);
                       
          }else if(typeCD.equals("RANGE")){
            if(thrValuesJSON!=null){
              try {
                thrValuesList = deserializeThresholdValuesJSONArray(thrValuesJSON, domainIds);
              } catch (JSONException e) {
                logger.error("JSON Exception");
                e.printStackTrace();
              }
            }
          }
          thr.setThresholdValues(thrValuesList);
        }
     
        try {

          Integer idToReturnToClient = null;
         
          if(id != null && !id.equals("") && !id.equals("0")){ 
            //modify
            thr.setId(Integer.valueOf(id));
            try{
              thrDao.modifyThreshold(thr);
            }catch(EMFUserError e){
              logger.error(e.getMessage(), e);
              throw e;
             
            }
            idToReturnToClient = Integer.valueOf(id);           
          }else{
            //insert new
            idToReturnToClient = thrDao.insertThreshold(thr);   
          }
         
          List thrValueIds = new ArrayList();
          if(thrValuesList!=null && !thrValuesList.isEmpty()){             
            Iterator it = thrValuesList.iterator();
            while(it.hasNext()){
              ThresholdValue tVal = (ThresholdValue)it.next();
              tVal.setThresholdId(Integer.valueOf(idToReturnToClient));             
              //insert or update all threshold values
              Integer thrValueId = null;
              thrValueId = tDao.saveOrUpdateThresholdValue(tVal);               
              tVal.setId(thrValueId);
              thrValueIds.add(thrValueId);
            }       
          }
         
          logger.debug("Threshold inserted or updated");
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("responseText", "Operation succeded");
          attributesResponseSuccessJSON.put("id", idToReturnToClient);
          if(thrValueIds!=null && !thrValueIds.isEmpty()){
            if(thrValueIds.size()==1){
              attributesResponseSuccessJSON.put("idThrVal", thrValueIds.get(0));
            }else{
              JSONArray thrValsJSONArray = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(thrValuesList, locale);     
              attributesResponseSuccessJSON.put("thrValues", thrValsJSONArray);
            }
          }
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
 
        } catch (Throwable e) {
          logger.error(e.getMessage(), e);
          if(e instanceof EMFUserError && ((EMFUserError)e).getCode() == 10119){
            String descr = e.getLocalizedMessage();
            String[] descrTokens = descr.split("[\\]\\[]");

            throw new SpagoBIServiceException(SERVICE_NAME,
                descrTokens[descrTokens.length-1], e);
          }
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception occurred while saving new threshold", e);
        }
               
      }else{
        logger.error("Resource name, code or type are missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please fill threshold name, code and type");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(THRESHOLD_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        thrDao.deleteThreshold(id);
        logger.debug("Threshold deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving Threshold to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving Threshold to delete", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(THR_VAL_DELETE)) {
      Integer id = getAttributeAsInteger(THR_VAL_ID_TO_DELETE);
      try {
        tDao.deleteThresholdValue(id);
       
        logger.debug("Threshold value deleted deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving Threshold value  to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving Threshold value  to delete", e);
      }
    }else if(serviceType == null){
      try {
        List nodeTypes = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_DOMAIN_TYPE);
        getSessionContainer().setAttribute("thrTypesList", nodeTypes);
        List thrSeverityTypes = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_SEVERITY_TYPE);
        getSessionContainer().setAttribute("thrSeverityTypes", thrSeverityTypes);
       
      } catch (EMFUserError e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception retrieving resources types", e);
      }
    }
    logger.debug("OUT");
  }
View Full Code Here

    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) {
View Full Code Here

      ISubObjectDAO dao = null;
      try {
        dao = DAOFactory.getSubObjectDAO();
      } catch (EMFUserError e) {
        logger.error("Error while istantiating DAO", e);
        throw new SpagoBIServiceException(SERVICE_NAME, "Cannot access database", e);
      }
      String ids = this.getAttributeAsString(SUBOBJECT_ID);
      // ids contains the id of the subobjects to be deleted separated by ,
      String[] idArray = ids.split(",");
      for (int i = 0; i < idArray.length; i++) {
        Integer id = new Integer(idArray[i]);
        SubObject subObject = null;
        try {
          subObject = dao.getSubObject(id);
        } catch (EMFUserError e) {
          logger.error("SubObject with id = " + id + " not found", e);
          throw new SpagoBIServiceException(SERVICE_NAME, "Customized view not found", e);
        }
        if (subObject.getBiobjId().equals(obj.getId())) {
          boolean canDeleteSubObject = false;
          if (userProfile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN)
              || subObject.getOwner().equals(userProfile.getUserId().toString())) {
            canDeleteSubObject = true;
          }
          if (canDeleteSubObject) {
            logger.info("User [id: " + userProfile.getUserUniqueIdentifier() + ", userId: " + userProfile.getUserId() + ", name: " + userProfile.getUserName() + "] " +
                "is deleting customized view [id: " + subObject.getId() + ", name: " + subObject.getName() + "] ...");
            try {
              dao.deleteSubObject(id);
            } catch (EMFUserError e) {
              throw new SpagoBIServiceException(SERVICE_NAME, "Error while deleting customized view", e);
            }
            logger.debug("Customized view [id: " + subObject.getId() + ", name: " + subObject.getName() + "] deleted.");
          } else {
            logger.error("User [id: " + userProfile.getUserUniqueIdentifier() + ", userId: " + userProfile.getUserId() + ", name: " + userProfile.getUserName() + "] cannot delete customized view");
            throw new SpagoBIServiceException(SERVICE_NAME, "User cannot delete customized view");
          }
        } else {
          logger.error("Cannot delete customized view with id = " + subObject.getBiobjId() + ": " +
              "it is not relevant to the current document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]");
          throw new SpagoBIServiceException(SERVICE_NAME, "Cannot delete customized view: it is not relevant to the current document");
        }
       
      }
      try {
        JSONObject results = new JSONObject();
        results.put("result", "OK");
        writeBackToClient( new JSONSuccess( results ) );
      } catch (IOException e) {
        throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
      } catch (JSONException e) {
        throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects into a JSON object", e);
      }

    } catch (EMFInternalError e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "An internal error has occured", e);
    } finally {
      logger.debug("OUT");
    }
  }
View Full Code Here

    try {
      boDao = DAOFactory.getBIObjectDAO();
      boDao.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(BIOBJECTS_LIST)) {
     
      try {   
       
        Integer start = getAttributeAsInteger( START );
        Integer limit = getAttributeAsInteger( LIMIT );
       
        if(start==null){
          start = START_DEFAULT;
        }
        if(limit==null){
          limit = LIMIT_DEFAULT;
        }

        Integer totalItemsNum = boDao.countBIObjects();
        List items = boDao.loadPagedObjectsList(start,limit);
        logger.debug("Loaded items list");
        JSONArray itemsJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(items, locale);
        JSONObject responseJSON = createJSONResponse(itemsJSON, totalItemsNum);

        writeBackToClient(new JSONSuccess(responseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving items", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving items", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(BIOBJECT_INSERT)) {
      //TODO
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(BIOBJECT_DELETE)) {
View Full Code Here

    try {
      dsDao = DAOFactory.getDataSetDAO();
      dsDao.setUserProfile(profile);
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    Locale locale = getLocale();
    String serviceType = this.getAttributeAsString(DataSetConstants.MESSAGE_DET);
    logger.debug("Service type "+serviceType);
   
    if (serviceType != null && serviceType.equalsIgnoreCase(DataSetConstants.DATASETS_FOR_KPI_LIST)) {     
      try
        Integer totalItemsNum = dsDao.countDatasets();
        List<SbiDataSetConfig> items = getListOfGenericDatasetsForKpi(dsDao);
        logger.debug("Loaded items list");
        JSONArray itemsJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(items, locale);
        JSONObject responseJSON = createJSONResponse(itemsJSON, totalItemsNum);
        writeBackToClient(new JSONSuccess(responseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving items", e);
        throw new SpagoBIServiceException(SERVICE_NAME, "sbi.general.retrieveItemsError", e);
      }
    } else if(serviceType != null && serviceType.equalsIgnoreCase(DataSetConstants.DATASETS_LIST)) {     
      try {   
        Integer totalItemsNum = dsDao.countDatasets();
        List<GuiGenericDataSet> items = getListOfGenericDatasets(dsDao);
        logger.debug("Loaded items list");
        JSONArray itemsJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(items, locale);
        JSONObject responseJSON = createJSONResponse(itemsJSON, totalItemsNum);
        writeBackToClient(new JSONSuccess(responseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving items", e);
        throw new SpagoBIServiceException(SERVICE_NAME,  "sbi.general.retrieveItemsError", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_INSERT)) {     
      GuiGenericDataSet ds = getGuiGenericDatasetToInsert();   
      if(ds!=null){
        String id = getAttributeAsString(DataSetConstants.ID);
        try {
          if(id != null && !id.equals("") && !id.equals("0")){             
            ds.setDsId(Integer.valueOf(id));
            dsDao.modifyDataSet(ds);
            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 dsID = dsDao.insertDataSet(ds);
            GuiGenericDataSet dsSaved = dsDao.loadDataSetById(dsID);
            logger.debug("New Resource inserted");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", dsID);
            if(dsSaved!=null){
              GuiDataSetDetail dsDetailSaved = dsSaved.getActiveDetail();
              attributesResponseSuccessJSON.put("dateIn", dsDetailSaved.getTimeIn());
              attributesResponseSuccessJSON.put("userIn", dsDetailSaved.getUserIn());
              attributesResponseSuccessJSON.put("versId", dsDetailSaved.getDsHId());
              attributesResponseSuccessJSON.put("versNum", dsDetailSaved.getVersionNum());
            }
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }
        } catch (Throwable e) {
          logger.error(e.getMessage(), e);
          throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.saveDsError", e);
        }
      }else{
        logger.error("DataSet name, label or type are missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "sbi.ds.fillFieldsError");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_TEST)) {     
      try {
        JSONObject dataSetJSON = datasetTest();
        if(dataSetJSON!=null){
          try {
            writeBackToClient( new JSONSuccess( dataSetJSON ) );
          } catch (IOException e) {
            throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
          }
        }else{
          throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.testError");
        }
      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.testError", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_DELETE)) {
      Integer dsID = getAttributeAsInteger(DataSetConstants.ID);
      try {
        dsDao.deleteDataSet(dsID);
        logger.debug("Dataset deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving dataset to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.deleteDsError", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_VERSION_DELETE)) {
      Integer dsVersionID = getAttributeAsInteger(DataSetConstants.VERSION_ID);
      try {
        boolean deleted = dsDao.deleteInactiveDataSetVersion(dsVersionID)
        if(deleted){
          logger.debug("Dataset Version deleted");
          writeBackToClient( new JSONAcknowledge("Operation succeded") );
        }else{
          throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.deleteVersion");
        }
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving dataset version to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.deleteVersion", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_ALL_VERSIONS_DELETE)) {
      Integer dsID = getAttributeAsInteger(DataSetConstants.DS_ID);
      try {
        dsDao.deleteAllInactiveDataSetVersions(dsID);
        logger.debug("All Older Dataset versions deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving dataset to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.deleteVersion", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(DataSetConstants.DATASET_VERSION_RESTORE)) {
      Integer dsID = getAttributeAsInteger(DataSetConstants.DS_ID);
      Integer dsVersionNum = getAttributeAsInteger(DataSetConstants.VERSION_NUM);
      try {
        GuiGenericDataSet dsNewDetail= dsDao.restoreOlderDataSetVersion(dsID, dsVersionNum);
        logger.debug("Dataset Version correctly Restored");
        List temp = new ArrayList();
        temp.add(dsNewDetail);
        JSONArray itemJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(temp, locale)
        JSONObject version = itemJSON.getJSONObject(0);
        JSONObject attributesResponseSuccessJSON = new JSONObject();
        attributesResponseSuccessJSON.put("success", true);
        attributesResponseSuccessJSON.put("responseText", "Operation succeded");
        attributesResponseSuccessJSON.put("result", version);
        writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving dataset to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.restoreVersionError", e);
      }
    }else if(serviceType == null){
      try {
        List dsTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(DataSetConstants.DATA_SET_TYPE);
        getSessionContainer().setAttribute("dsTypesList", dsTypesList);       
        List catTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(DataSetConstants.CATEGORY_DOMAIN_TYPE);
        getSessionContainer().setAttribute("catTypesList", catTypesList);
        List dataSourceList = DAOFactory.getDataSourceDAO().loadAllDataSources();     
        getSessionContainer().setAttribute("dataSourceList", dataSourceList);
        List scriptLanguageList = DAOFactory.getDomainDAO().loadListDomainsByType(DataSetConstants.SCRIPT_TYPE);
        getSessionContainer().setAttribute("scriptLanguageList", scriptLanguageList)
        List trasfTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(DataSetConstants.TRANSFORMER_TYPE);
        getSessionContainer().setAttribute("trasfTypesList", trasfTypesList)
        List sbiAttrs = DAOFactory.getSbiAttributeDAO().loadSbiAttributes();
        getSessionContainer().setAttribute("sbiAttrsList", sbiAttrs)
        SingletonConfig configSingleton = SingletonConfig.getInstance();
        String pathh = configSingleton.getConfigValue("SPAGOBI.RESOURCE_PATH_JNDI_NAME");
        String filePath= SpagoBIUtilities.readJndiResource(pathh);
        filePath += "/dataset/files";
        File dir = new File(filePath);
           String[] fileNames = dir.list();
           getSessionContainer().setAttribute("fileNames", fileNames)
      } catch (EMFUserError e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.dsTypesRetrieve", e);
      }
    }
    logger.debug("OUT");
  }
View Full Code Here

        }
        GuiDataSetDetail dsActiveDetail = constructDataSetDetail(dsType);
        ds.setActiveDetail(dsActiveDetail)
      }else{
        logger.error("DataSet type is not existent");
        throw new SpagoBIServiceException(SERVICE_NAME,  "sbi.ds.dsTypeError");
      }
    }   
    return ds;
  }
View Full Code Here

TOP

Related Classes of it.eng.spagobi.utilities.exceptions.SpagoBIServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.