Package it.eng.spagobi.kpi.threshold.dao

Examples of it.eng.spagobi.kpi.threshold.dao.IThresholdDAO


  @Override
  public void doService() {
    logger.debug("IN");
    IKpiDAO kpiDao;
    IDataSetDAO dsDao;
    IThresholdDAO thrDao;
    try {
      kpiDao = DAOFactory.getKpiDAO();
      dsDao = DAOFactory.getDataSetDAO();
      thrDao = DAOFactory.getThresholdDAO();
      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){
View Full Code Here


  //filters parameters
  public static String FILTERS = "FILTERS";
  @Override
  public void doService() {
    logger.debug("IN");
    IThresholdDAO thrDao;
    IThresholdValueDAO tDao;
    try {
      thrDao = DAOFactory.getThresholdDAO();
      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,
View Full Code Here

        hibKpiInst.setSbiKpi(sbiKpi);
      }

      // load threshold
      if (kpiInst.getThresholdId() != null) {
        IThresholdDAO thresholdDAO=DAOFactory.getThresholdDAO();
        Threshold th=thresholdDAO.loadThresholdById(kpiInst.getThresholdId());
        insertThreshold(th, session);
        SbiThreshold sbiTh= (SbiThreshold) session.load(SbiThreshold.class, th.getId());
        hibKpiInst.setSbiThreshold(sbiTh);
      }
View Full Code Here

    if (dsC != null) {
      dsId = dsC.getDsId();
      dsLabel = dsC.getLabel();
    }

    IThresholdDAO thresholdDAO=DAOFactory.getThresholdDAO();
    SbiThreshold thresh = kpi.getSbiThreshold();
    if(thresh!=null){
      Threshold threshold=thresholdDAO.toThreshold(thresh);
      toReturn.setThreshold(threshold);
      logger.debug("Kpi threshold setted");
    }

    Double standardWeight = kpi.getWeight();
View Full Code Here

        Set thresholdValues = t.getSbiThresholdValues();
        Iterator it = thresholdValues.iterator();
        while (it.hasNext()) {
          SbiThresholdValue val = (SbiThresholdValue) it.next();
          // TODO mettere a posto
          IThresholdDAO thDao=(IThresholdDAO)DAOFactory.getThresholdDAO();
          Threshold tr = thDao.toThreshold(null);
          logger.debug("Added threshold with label " + tr.getName());
          thresholds.add(tr);
        }
      }     
View Full Code Here

TOP

Related Classes of it.eng.spagobi.kpi.threshold.dao.IThresholdDAO

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.