Package it.eng.spagobi.kpi.config.bo

Examples of it.eng.spagobi.kpi.config.bo.KpiValue


  public KpiValue getKpiValue(Integer kpiInstanceId, Date d, Resource r, OrganizationalUnitGrantNode grantNode)
  throws EMFUserError {

    logger.debug("IN");
    KpiValue toReturn = null;
    Session aSession = null;
    Transaction tx = null;

    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      Criteria finder = aSession.createCriteria(SbiKpiValue.class);
      finder.add(Expression.eq("sbiKpiInstance.idKpiInstance",
          kpiInstanceId));
      finder.add(Expression.le("beginDt", d));
      finder.add(Expression.ge("endDt", d));
      finder.addOrder(Order.desc("beginDt"));
      finder.addOrder(Order.desc("idKpiInstanceValue"));
      logger.debug("Order Date Criteria setted");
      finder.setMaxResults(1);
      logger.debug("Max result to 1 setted");

      if (r != null) {
        finder.add(Expression.eq("sbiResources.resourceId", r.getId()));
      }
      if (grantNode != null) {
        finder.add(Expression.eq("sbiOrgUnit.id", grantNode.getOuNode().getOu().getId()));
        finder.add(Expression.eq("sbiOrgUnitHierarchies.id", grantNode.getOuNode().getHierarchy().getId()));
        if(grantNode.getOuNode().getHierarchy().getCompany() != null){
          finder.add(Expression.eq("company", grantNode.getOuNode().getHierarchy().getCompany()));
        }
      }
      List l = finder.list();
      if (!l.isEmpty()) {
        KpiValue tem = null;
        Iterator it = l.iterator();
        while (it.hasNext()) {
          SbiKpiValue temp = (SbiKpiValue) it.next();
          toReturn = toKpiValue(temp, d);
        }
View Full Code Here


  }

  private KpiValue toKpiValue(SbiKpiValue value, Date d) throws EMFUserError {

    logger.debug("IN");
    KpiValue toReturn = new KpiValue();

    Date beginDate = value.getBeginDt();
    logger
    .debug("SbiKpiValue begin date: "
        + (beginDate != null ? beginDate.toString()
            : "Begin date null"));
    Date endDate = value.getEndDt();
    logger.debug("SbiKpiValue end date: "
        + (endDate != null ? endDate.toString() : "End date null"));
    String val = value.getValue();
    logger
    .debug("SbiKpiValue value: "
        + (val != null ? val : "Value null"));
    String valueDescr = value.getDescription();
    logger.debug("SbiKpiValue description: "
        + (valueDescr != null ? valueDescr : "Value description null"));
    Integer kpiInstanceID = null;
    Double weight = null;
    Double target = null;
    String scaleCode = null;
    String scaleName = null;

    SbiResources res = value.getSbiResources();
    Resource r = null;
    IResourceDAO resDao=DAOFactory.getResourceDAO();
    if (res != null) {
      r = resDao.toResource(res);
      logger.debug("SbiKpiValue resource: "
          + (r.getColumn_name() != null ? r.getColumn_name()
              : "resource name null"));
    }

    kpiInstanceID = value.getSbiKpiInstance().getIdKpiInstance();
    logger.debug("SbiKpiValue kpiInstanceID: "
        + (kpiInstanceID != null ? kpiInstanceID.toString()
            : "kpiInstanceID null"));
    SbiKpiInstance kpiInst = value.getSbiKpiInstance();

    List thresholdValues = new ArrayList();
    Date kpiInstBegDt = kpiInst.getBeginDt();
    logger.debug("kpiInstBegDt begin date: "
        + (kpiInstBegDt != null ? kpiInstBegDt.toString()
            : "Begin date null"));
    // in case the current threshold is correct
    if (((d.before(endDate) || d.equals(endDate))
        && (d.after(beginDate) || d.equals(beginDate))
        && (d.after(kpiInstBegDt) || d.equals(kpiInstBegDt)))|| kpiInst.getSbiKpiInstanceHistories().isEmpty()) {

      weight = kpiInst.getWeight();
      logger.debug("SbiKpiValue weight: "
          + (weight != null ? weight.toString() : "weight null"));
      target = kpiInst.getTarget();
      logger.debug("SbiKpiValue target: "
          + (target != null ? target.toString() : "target null"));

      if (kpiInst.getSbiMeasureUnit() != null) {
        scaleCode = kpiInst.getSbiMeasureUnit().getScaleCd();
        logger.debug("SbiKpiValue scaleCode: "
            + (scaleCode != null ? scaleCode : "scaleCode null"));
        scaleName = kpiInst.getSbiMeasureUnit().getScaleNm();
        logger.debug("SbiKpiValue scaleName: "
            + (scaleName != null ? scaleName : "scaleName null"));
      }
      logger.debug("Requested date d: " + d.toString()
          + " in between beginDate and EndDate");
      SbiThreshold t = kpiInst.getSbiThreshold();
      if(t!=null){

        Set ts = t.getSbiThresholdValues();
        Iterator i = ts.iterator();
        while (i.hasNext()) {
          SbiThresholdValue tls = (SbiThresholdValue) i.next();

          IThresholdValueDAO thDao=(IThresholdValueDAO)DAOFactory.getThresholdValueDAO();
          ThresholdValue tr = thDao.toThresholdValue(tls);
          thresholdValues.add(tr);
        }
      }     

    } else {// in case older thresholds have to be retrieved

      Set kpiInstHist = kpiInst.getSbiKpiInstanceHistories();
      Iterator i = kpiInstHist.iterator();
      while (i.hasNext()) {
        SbiKpiInstanceHistory ih = (SbiKpiInstanceHistory) i.next();
        Date ihBegDt = ih.getBeginDt();
        Date ihEndDt = ih.getEndDt();
        if ((d.after(ihBegDt) || d.equals(ihBegDt))
            && (d.before(ihEndDt) || d.equals(ihEndDt))) {

          weight = ih.getWeight();
          logger.debug("SbiKpiValue weight: "
              + (weight != null ? weight.toString()
                  : "weight null"));
          target = ih.getTarget();
          logger.debug("SbiKpiValue target: "
              + (target != null ? target.toString()
                  : "target null"));

          if (ih.getSbiMeasureUnit() != null) {
            scaleCode = ih.getSbiMeasureUnit().getScaleCd();
            logger.debug("SbiKpiValue scaleCode: "
                + (scaleCode != null ? scaleCode
                    : "scaleCode null"));
            scaleName = ih.getSbiMeasureUnit().getScaleNm();
            logger.debug("SbiKpiValue scaleName: "
                + (scaleName != null ? scaleName
                    : "scaleName null"));
          }
          SbiThreshold t = ih.getSbiThreshold();
          if(t!=null){
            Set ts = t.getSbiThresholdValues();
            Iterator it = ts.iterator();
            while (it.hasNext()) {
              SbiThresholdValue tls = (SbiThresholdValue) it.next();

              IThresholdValueDAO thDao=(IThresholdValueDAO)DAOFactory.getThresholdValueDAO();
              ThresholdValue tr = thDao.toThresholdValue(tls);
              thresholdValues.add(tr);
            }
          }   
        }
      }
    }
    toReturn.setValueDescr(valueDescr);
    logger.debug("Kpi value descritpion setted");
    toReturn.setTarget(target);
    logger.debug("Kpi value target setted");
    toReturn.setBeginDate(beginDate);
    logger.debug("Kpi value begin date setted");
    toReturn.setEndDate(endDate);
    logger.debug("Kpi value end date setted");
    toReturn.setValue(val);
    logger.debug("Kpi value setted");
    toReturn.setKpiInstanceId(kpiInstanceID);
    logger.debug("Kpi value Instance ID setted");
    toReturn.setWeight(weight);
    logger.debug("Kpi value weight setted");
    toReturn.setR(r);
    logger.debug("Kpi value resource setted");
    toReturn.setScaleCode(scaleCode);
    logger.debug("Kpi value scale Code setted");
    toReturn.setScaleName(scaleName);
    logger.debug("Kpi value scale Name setted");
    toReturn.setThresholdValues(thresholdValues);
    logger.debug("Kpi value Thresholds setted");
    toReturn.setKpiValueId(value.getIdKpiInstanceValue());
    logger.debug("Kpi value ID setted");
    toReturn.setValueXml(value.getXmlData());
    logger.debug("Kpi value XML setted");
    OrganizationalUnitGrantNode grantNode = new OrganizationalUnitGrantNode();
    OrganizationalUnitNode node = new OrganizationalUnitNode();
    if(value.getSbiOrgUnit() != null){
      OrganizationalUnit ou = DAOFactory.getOrganizationalUnitDAO().getOrganizationalUnit(value.getSbiOrgUnit().getId());
      node.setOu(ou);
    }
    if(value.getSbiOrgUnitHierarchies() != null){
      OrganizationalUnitHierarchy hierarchy = DAOFactory.getOrganizationalUnitDAO().getHierarchy(value.getSbiOrgUnitHierarchies().getId());
      node.setHierarchy(hierarchy);
    }
    if(value.getSbiOrgUnit() != null && value.getSbiOrgUnitHierarchies() != null){
      grantNode.setOuNode(node);
      toReturn.setGrantNodeOU(grantNode);
    }

    logger.debug("Kpi value organizational unit grant node setted");

    logger.debug("OUT");
View Full Code Here

    return true;
  }

  public KpiValue getKpiValueFromInterval(Integer kpiInstanceId, Date from, Date to, Resource r, OrganizationalUnitGrantNode grantNode) throws EMFUserError {
    logger.debug("IN");
    KpiValue toReturn = null;
    Session aSession = null;
    Transaction tx = null;

    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      Criteria finder = aSession.createCriteria(SbiKpiValue.class);
      finder.add(Expression.eq("sbiKpiInstance.idKpiInstance",
          kpiInstanceId));
      finder.add(Expression.eq("beginDt", from));
      finder.add(Expression.eq("endDt", to));
      finder.addOrder(Order.desc("beginDt"));
      finder.addOrder(Order.desc("idKpiInstanceValue"));
      logger.debug("Order Date Criteria setted");
      finder.setMaxResults(1);
      logger.debug("Max result to 1 setted");

      if (r != null) {
        finder.add(Expression.eq("sbiResources.resourceId", r.getId()));
      }
      if (grantNode != null) {
        finder.add(Expression.eq("sbiOrgUnit.id", grantNode.getOuNode().getOu().getId()));
        finder.add(Expression.eq("sbiOrgUnitHierarchies.id", grantNode.getOuNode().getHierarchy().getId()));
        if(grantNode.getOuNode().getHierarchy().getCompany() != null){
          finder.add(Expression.eq("company", grantNode.getOuNode().getHierarchy().getCompany()));
        }
      }
      List l = finder.list();
      if (!l.isEmpty()) {
        KpiValue tem = null;
        Iterator it = l.iterator();
        while (it.hasNext()) {
          SbiKpiValue temp = (SbiKpiValue) it.next();
          toReturn = toKpiValue(temp, from, to);
        }
View Full Code Here

  }
 
  private KpiValue toKpiValue(SbiKpiValue value, Date from, Date to) throws EMFUserError {

    logger.debug("IN");
    KpiValue toReturn = new KpiValue();

    Date beginDate = value.getBeginDt();
    logger.debug("SbiKpiValue begin date: "
        + (beginDate != null ? beginDate.toString() : "Begin date null"));
    Date endDate = value.getEndDt();
    logger.debug("SbiKpiValue end date: "
        + (endDate != null ? endDate.toString() : "End date null"));
    String val = value.getValue();
    logger.debug("SbiKpiValue value: "
        + (val != null ? val : "Value null"));
    String valueDescr = value.getDescription();
    logger.debug("SbiKpiValue description: "
        + (valueDescr != null ? valueDescr : "Value description null"));
   
    Integer kpiInstanceID = null;
    Double weight = null;
    Double target = null;
    String scaleCode = null;
    String scaleName = null;

    SbiResources res = value.getSbiResources();
    Resource r = null;
    IResourceDAO resDao=DAOFactory.getResourceDAO();
    if (res != null) {
      r = resDao.toResource(res);
      logger.debug("SbiKpiValue resource: "
          + (r.getColumn_name() != null ? r.getColumn_name() : "resource name null"));
    }
    SbiOrgUnit sbiOrgUnit = value.getSbiOrgUnit();
    OrganizationalUnit orgUnit = null;
    if(sbiOrgUnit != null){
      orgUnit = DAOFactory.getOrganizationalUnitDAO().getOrganizationalUnit(sbiOrgUnit.getId())
      logger.debug("SbiKpiValue ou: "
          + (orgUnit.getName() != null ? orgUnit.getName()
              : "ou name null"));
    }
    kpiInstanceID = value.getSbiKpiInstance().getIdKpiInstance();
    logger.debug("SbiKpiValue kpiInstanceID: "
        + (kpiInstanceID != null ? kpiInstanceID.toString() : "kpiInstanceID null"));
    SbiKpiInstance kpiInst = value.getSbiKpiInstance();

    List thresholdValues = new ArrayList();
    Date kpiInstBegDt = kpiInst.getBeginDt();
    logger.debug("kpiInstBegDt begin date: "
        + (kpiInstBegDt != null ? kpiInstBegDt.toString() : "Begin date null"));
   
    // TODO for the moment get actual values of weight/target etc check if it is correct
    weight = kpiInst.getWeight();
    logger.debug("SbiKpiValue weight: "
        + (weight != null ? weight.toString() : "weight null"));
    target = kpiInst.getTarget();
    logger.debug("SbiKpiValue target: "
        + (target != null ? target.toString() : "target null"));

    if (kpiInst.getSbiMeasureUnit() != null) {
      scaleCode = kpiInst.getSbiMeasureUnit().getScaleCd();
      logger.debug("SbiKpiValue scaleCode: "
          + (scaleCode != null ? scaleCode : "scaleCode null"));
      scaleName = kpiInst.getSbiMeasureUnit().getScaleNm();
      logger.debug("SbiKpiValue scaleName: "
          + (scaleName != null ? scaleName : "scaleName null"));
    }
    SbiThreshold t = kpiInst.getSbiThreshold();
    if(t!=null){

      Set ts = t.getSbiThresholdValues();
      Iterator i = ts.iterator();
      while (i.hasNext()) {
        SbiThresholdValue tls = (SbiThresholdValue) i.next();

        IThresholdValueDAO thDao=(IThresholdValueDAO)DAOFactory.getThresholdValueDAO();
        ThresholdValue tr = thDao.toThresholdValue(tls);
        thresholdValues.add(tr);
      }
    }     
    // TODO for the moment get actual values of weight/target etc check if it is correct
   
    toReturn.setValueDescr(valueDescr);
    logger.debug("Kpi value descritpion setted");
    toReturn.setTarget(target);
    logger.debug("Kpi value target setted");
    toReturn.setBeginDate(beginDate);
    logger.debug("Kpi value begin date setted");
    toReturn.setEndDate(endDate);
    logger.debug("Kpi value end date setted");
    toReturn.setValue(val);
    logger.debug("Kpi value setted");
    toReturn.setKpiInstanceId(kpiInstanceID);
    logger.debug("Kpi value Instance ID setted");
    toReturn.setWeight(weight);
    logger.debug("Kpi value weight setted");
    toReturn.setR(r);
    logger.debug("Kpi value resource setted");
    toReturn.setScaleCode(scaleCode);
    logger.debug("Kpi value scale Code setted");
    toReturn.setScaleName(scaleName);
    logger.debug("Kpi value scale Name setted");
    toReturn.setThresholdValues(thresholdValues);
    logger.debug("Kpi value Thresholds setted");
    toReturn.setKpiValueId(value.getIdKpiInstanceValue());
    logger.debug("Kpi value ID setted");
    toReturn.setValueXml(value.getXmlData());
    logger.debug("Kpi value XML setted");

    OrganizationalUnitGrantNode grantNode = new OrganizationalUnitGrantNode();
    OrganizationalUnitNode node = new OrganizationalUnitNode();
    if(value.getSbiOrgUnit() != null){
      OrganizationalUnit ou = DAOFactory.getOrganizationalUnitDAO().getOrganizationalUnit(value.getSbiOrgUnit().getId());
      node.setOu(ou);
    }
    if(value.getSbiOrgUnitHierarchies() != null){
      OrganizationalUnitHierarchy hierarchy = DAOFactory.getOrganizationalUnitDAO().getHierarchy(value.getSbiOrgUnitHierarchies().getId());
      node.setHierarchy(hierarchy);
    }
    if(value.getSbiOrgUnit() != null && value.getSbiOrgUnitHierarchies() != null){
      grantNode.setOuNode(node);
      toReturn.setGrantNodeOU(grantNode);
    }
    logger.debug("Kpi value orgnaizational unit grant node setted");

    logger.debug("OUT");
    return toReturn;
View Full Code Here

  }

  public void deleteKpiValueFromInterval(Integer kpiInstanceId, Date from,
      Date to, Resource r, OrganizationalUnitGrantNode grantNode) throws EMFUserError {
    logger.debug("IN");
    KpiValue toReturn = null;
    Session aSession = null;
    Transaction tx = null;

    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      Criteria finder = aSession.createCriteria(SbiKpiValue.class);
      finder.add(Expression.eq("sbiKpiInstance.idKpiInstance",
          kpiInstanceId));
      finder.add(Expression.eq("beginDt", from));
      finder.add(Expression.eq("endDt", to));
      finder.addOrder(Order.desc("beginDt"));
      finder.addOrder(Order.desc("idKpiInstanceValue"));
      logger.debug("Order Date Criteria setted");
      finder.setMaxResults(1);
      logger.debug("Max result to 1 setted");

      if (r != null) {
        finder.add(Expression.eq("sbiResources.resourceId", r.getId()));
      }
      if (grantNode != null) {
        finder.add(Expression.eq("sbiOrgUnit.id", grantNode.getOuNode().getOu().getId()));
        finder.add(Expression.eq("sbiOrgUnitHierarchies.id", grantNode.getOuNode().getHierarchy().getId()));
        if(grantNode.getOuNode().getHierarchy().getCompany() != null){
          finder.add(Expression.eq("company", grantNode.getOuNode().getHierarchy().getCompany()));
        }
      }
      List l = finder.list();
      if (!l.isEmpty()) {
        KpiValue tem = null;
        Iterator it = l.iterator();
        while (it.hasNext()) {         
          SbiKpiValue temp = (SbiKpiValue) it.next();
          aSession.delete(temp);
        }
View Full Code Here

  public KpiValue getDisplayKpiValue(Integer kpiInstanceId, Date d,
      Resource r, OrganizationalUnitGrantNode grantNode)
      throws EMFUserError {
    logger.debug("IN");
    KpiValue toReturn = null;
    Session aSession = null;
    Transaction tx = null;


    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      Criteria finder = aSession.createCriteria(SbiKpiValue.class);
      finder.add(Expression.eq("sbiKpiInstance.idKpiInstance",
          kpiInstanceId));
      finder.add(Expression.le("beginDt", d));
      finder.add(Expression.ge("endDt", d));
      finder.addOrder(Order.desc("beginDt"));
      finder.addOrder(Order.desc("idKpiInstanceValue"));
      logger.debug("Order Date Criteria setted");
      finder.setMaxResults(1);
      logger.debug("Max result to 1 setted");

      if (r != null) {
        finder.add(Expression.eq("sbiResources.resourceId", r.getId()));
      }
      if (grantNode != null) {
        Integer hierarchyId = grantNode.getOuNode().getHierarchy().getId();
        Integer ouId = grantNode.getOuNode().getOu().getId();
        finder.add(Expression.eq("sbiOrgUnit.id", ouId));
        finder.add(Expression.eq("sbiOrgUnitHierarchies.id", hierarchyId));
        if(grantNode.getOuNode().getHierarchy().getCompany() != null){
          finder.add(Expression.eq("company", grantNode.getOuNode().getHierarchy().getCompany()));
        }
      }
/*      if (company != null) {
        finder.add(Expression.eq("company", company));
      }*/
      List l = finder.list();
      if (!l.isEmpty()) {
        KpiValue tem = null;
        Iterator it = l.iterator();
        while (it.hasNext()) {
          SbiKpiValue temp = (SbiKpiValue) it.next();
          toReturn = toKpiValue(temp, d);
        }
      }else{
        Criteria finder2 = aSession.createCriteria(SbiKpiValue.class);
        finder2.add(Expression.eq("sbiKpiInstance.idKpiInstance",
            kpiInstanceId));
        finder2.add(Expression.le("beginDt", d));
        finder2.addOrder(Order.desc("beginDt"));
        logger.debug("Order Date Criteria setted");
        finder2.setMaxResults(1);
        logger.debug("Max result to 1 setted");

        if (r != null) {
          finder2.add(Expression.eq("sbiResources.resourceId", r.getId()));
        }

        List l2 = finder2.list();
        if (!l2.isEmpty()) {
          KpiValue tem = null;
          Iterator it = l2.iterator();
          while (it.hasNext()) {
            SbiKpiValue temp = (SbiKpiValue) it.next();
            toReturn = toKpiValue(temp, d);
          }
View Full Code Here

TOP

Related Classes of it.eng.spagobi.kpi.config.bo.KpiValue

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.