Package it.eng.spagobi.kpi.config.dao

Examples of it.eng.spagobi.kpi.config.dao.IKpiDAO


            value = getNewKpiValue(dataSet, kpiI, r,mI.getModelInstanceNodeId(), null);         
          }
        }
        logger.debug("New value calculated");
        // Insert new Value into the DB
        IKpiDAO dao=DAOFactory.getKpiDAO();
        dao.setUserProfile(profile);
        dao.insertKpiValue(value);
        logger.debug("New value inserted in the DB");   
        // Checks if the value is alarming (out of a certain range)
        // If the value is alarming a new line will be inserted in the sbi_alarm_event table and scheduled to be sent
        DAOFactory.getAlarmDAO().isAlarmingValue(value);    
      } catch (EMFInternalError e) {
View Full Code Here


          logger.debug("New value calculated");
          if(register_values && kpiValTemp.getR().getName()!=null){

            if(doSave){
              // Insert new Value into the DB
              IKpiDAO dao= DAOFactory.getKpiDAO();
              dao.setUserProfile(profile);
              Integer kpiValueId = dao.insertKpiValue(kpiValTemp);
              kVal.setKpiValueId(kpiValueId);
              logger.info("New value inserted in the DB. Resource="+kpiValTemp.getR().getName()+" KpiInstanceId="+kpiValTemp.getKpiInstanceId());
            }
            // Checks if the value is alarming (out of a certain range)
            // If the value is alarming a new line will be inserted in the
View Full Code Here

  public static String FILTERS = "FILTERS";

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

      List hibList = hibQuery.list();
      if(hibList!=null && !hibList.isEmpty()) {
        return;
      }
      // get the Kpi BO from id
      IKpiDAO kpiDao=DAOFactory.getKpiDAO();
      Kpi kpi=kpiDao.loadKpiById(kpiId);

      // main attributes     
      SbiKpi hibKpi = new SbiKpi();
      hibKpi.setKpiId(kpi.getKpiId());
      hibKpi.setCode(kpi.getCode());
      hibKpi.setDescription(kpi.getDescription());
      hibKpi.setInterpretation(kpi.getInterpretation());
      hibKpi.setName(kpi.getKpiName());
      hibKpi.setWeight(kpi.getStandardWeight());
      char isFather=kpi.getIsParent().equals(true)? 'T' : 'F';
      hibKpi.setFlgIsFather(new Character(isFather));
      hibKpi.setInterpretation(kpi.getInterpretation());
      hibKpi.setInputAttributes(kpi.getInputAttribute());
      hibKpi.setModelReference(kpi.getModelReference());
      hibKpi.setTargetAudience(kpi.getTargetAudience());
      hibKpi.setIsAdditive(kpi.getIsAdditive());

      if(kpi.getMeasureTypeId()!=null){
        SbiDomains measureType=(SbiDomains)session.load(SbiDomains.class, kpi.getMeasureTypeId());     
        hibKpi.setSbiDomainsByMeasureType(measureType);
      }
      if(kpi.getKpiTypeId()!=null){
        SbiDomains kpiType=(SbiDomains)session.load(SbiDomains.class, kpi.getKpiTypeId());     
        hibKpi.setSbiDomainsByKpiType(kpiType);
      }
      if(kpi.getMetricScaleId()!=null){
        SbiDomains metricScaleType=(SbiDomains)session.load(SbiDomains.class, kpi.getMetricScaleId());     
        hibKpi.setSbiDomainsByMetricScaleType(metricScaleType);
      }

      // load dataset
      if (kpi.getKpiDsId() != null) {   
        Integer dsID = kpi.getKpiDsId();       
        GuiGenericDataSet guiGenericDataSet = DAOFactory.getDataSetDAO().loadDataSetById(dsID);
        if(guiGenericDataSet!=null){
          insertDataSet(guiGenericDataSet, session);
          SbiDataSetConfig sbiDs= (SbiDataSetConfig) session.load(SbiDataSetConfig.class, guiGenericDataSet.getDsId());
          hibKpi.setSbiDataSet(sbiDs);
        }
      }

      // load threshold
      if (kpi.getThreshold() != null) {
        Threshold th=kpi.getThreshold();
        insertThreshold(th, session);
        SbiThreshold sbiTh= (SbiThreshold) session.load(SbiThreshold.class, th.getId());
        hibKpi.setSbiThreshold(sbiTh);
      }

      // Measure Unit   ???
      if(kpi.getScaleCode()!=null && !kpi.getScaleCode().equalsIgnoreCase("")){
        IMeasureUnitDAO muDao=DAOFactory.getMeasureUnitDAO();
        MeasureUnit mu=muDao.loadMeasureUnitByCd(kpi.getScaleCode());
        insertMeasureUnit(mu, session);
        SbiMeasureUnit sbiMu= (SbiMeasureUnit) session.load(SbiMeasureUnit.class, mu.getId());
        hibKpi.setSbiMeasureUnit(sbiMu);
      }

      Transaction tx = session.beginTransaction();
      Integer kpiIdReturned = (Integer)session.save(hibKpi);
      tx.commit();

      List kpiDocsList = kpi.getSbiKpiDocuments();
      Iterator i = kpiDocsList.iterator();
      while (i.hasNext()) {
        KpiDocuments doc = (KpiDocuments) i.next();
        String label = doc.getBiObjLabel();

        IBIObjectDAO biobjDAO = DAOFactory.getBIObjectDAO();
        BIObject biobj = biobjDAO.loadBIObjectByLabel(label);
        if(biobj!=null){
          insertBIObject(biobj, session, true);
          doc.setBiObjId(biobj.getId());       
        }

        Integer origDocId = doc.getBiObjId();
        Criterion labelCriterrion = Expression.eq("label",label);
        Criteria criteria = session.createCriteria(SbiObjects.class);
        criteria.add(labelCriterrion);
        SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();

        if(hibObject!=null){
          SbiKpiDocument temp = new SbiKpiDocument();
          temp.setSbiKpi(hibKpi);
          temp.setSbiObjects(hibObject);
          KpiDocuments docK = kpiDao.loadKpiDocByKpiIdAndDocId(kpiId, origDocId);
          if(docK!=null && docK.getKpiDocId()!=null){
            temp.setIdKpiDoc(docK.getKpiDocId());
            Transaction tx2 = session.beginTransaction();
            session.save(temp);
            tx2.commit();
View Full Code Here

      List hibList = hibQuery.list();
      if(!hibList.isEmpty()) {
        return null;
      }
      // get the Kpi BO from id
      IKpiDAO kpiDao=DAOFactory.getKpiDAO();
      Kpi kpi=kpiDao.loadKpiById(kpiId);

      // main attributes     
      hibKpi = new SbiKpi();
      hibKpi.setKpiId(kpi.getKpiId());
      hibKpi.setCode(kpi.getCode());
      hibKpi.setDescription(kpi.getDescription());
      hibKpi.setInterpretation(kpi.getInterpretation());
      hibKpi.setName(kpi.getKpiName());
      // Weight???  hibKpi.setWeight(kpi.get)
      hibKpi.setWeight(kpi.getStandardWeight());
      char isFather=kpi.getIsParent().equals(true)? 'T' : 'F';
      hibKpi.setFlgIsFather(new Character(isFather));
      hibKpi.setInterpretation(kpi.getInterpretation());
      hibKpi.setInputAttributes(kpi.getInputAttribute());
      hibKpi.setModelReference(kpi.getModelReference());
      hibKpi.setTargetAudience(kpi.getTargetAudience());
      hibKpi.setIsAdditive(kpi.getIsAdditive());

      if(kpi.getMeasureTypeId()!=null){
        SbiDomains measureType=(SbiDomains)session.load(SbiDomains.class, kpi.getMeasureTypeId());     
        hibKpi.setSbiDomainsByMeasureType(measureType);
      }
      if(kpi.getKpiTypeId()!=null){
        SbiDomains kpiType=(SbiDomains)session.load(SbiDomains.class, kpi.getKpiTypeId());     
        hibKpi.setSbiDomainsByKpiType(kpiType);
      }
      if(kpi.getMetricScaleId()!=null){
        SbiDomains metricScaleType=(SbiDomains)session.load(SbiDomains.class, kpi.getMetricScaleId());     
        hibKpi.setSbiDomainsByMetricScaleType(metricScaleType);
      }

      // load dataset
      if (kpi.getKpiDsId() != null) {   
        Integer dsID = kpi.getKpiDsId();       
        GuiGenericDataSet guiGenericDataSet = DAOFactory.getDataSetDAO().loadDataSetById(dsID);
        if(guiGenericDataSet!=null){
          insertDataSet(guiGenericDataSet, session);
          SbiDataSetConfig sbiDs= (SbiDataSetConfig) session.load(SbiDataSetConfig.class, guiGenericDataSet.getDsId());
          hibKpi.setSbiDataSet(sbiDs);
        }
      }

      // load threshold
      if (kpi.getThreshold() != null) {
        Threshold th=kpi.getThreshold();
        insertThreshold(th, session);
        SbiThreshold sbiTh= (SbiThreshold) session.load(SbiThreshold.class, th.getId());
        hibKpi.setSbiThreshold(sbiTh);
      }

      // Measure Unit   ???
      if(kpi.getScaleCode()!=null && !kpi.getScaleCode().equalsIgnoreCase("")){
        IMeasureUnitDAO muDao=DAOFactory.getMeasureUnitDAO();
        MeasureUnit mu=muDao.loadMeasureUnitByCd(kpi.getScaleCode());
        insertMeasureUnit(mu, session);
        SbiMeasureUnit sbiMu= (SbiMeasureUnit) session.load(SbiMeasureUnit.class, mu.getId());
        hibKpi.setSbiMeasureUnit(sbiMu);
      }

      Transaction tx = session.beginTransaction();
      Integer kpiIdReturned = (Integer)session.save(hibKpi);
      tx.commit();

      List kpiDocsList = kpi.getSbiKpiDocuments();
      Iterator i = kpiDocsList.iterator();
      while (i.hasNext()) {
        KpiDocuments doc = (KpiDocuments) i.next();
        String label = doc.getBiObjLabel();

        IBIObjectDAO biobjDAO = DAOFactory.getBIObjectDAO();
        BIObject biobj = biobjDAO.loadBIObjectByLabel(label);
        if(biobj!=null){
          insertBIObject(biobj, session, true);
          doc.setBiObjId(biobj.getId());       
        }

        Integer origDocId = doc.getBiObjId();
        Criterion labelCriterrion = Expression.eq("label",label);
        Criteria criteria = session.createCriteria(SbiObjects.class);
        criteria.add(labelCriterrion);
        SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();

        if(hibObject!=null){
          SbiKpiDocument temp = new SbiKpiDocument();
          temp.setSbiKpi(hibKpi);
          temp.setSbiObjects(hibObject);
          KpiDocuments docK = kpiDao.loadKpiDocByKpiIdAndDocId(kpiId, origDocId);
          if(docK!=null && docK.getKpiDocId()!=null){
            temp.setIdKpiDoc(docK.getKpiDocId());
            Transaction tx2 = session.beginTransaction();
            session.save(temp);
            tx2.commit();
View Full Code Here

TOP

Related Classes of it.eng.spagobi.kpi.config.dao.IKpiDAO

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.