Package it.eng.spagobi.kpi.model.bo

Examples of it.eng.spagobi.kpi.model.bo.ModelInstanceNode


      String dateForDataset = getDateForDataset(dateOfKPI)
      parametersObject.put("ParKpiDate", dateForDataset);
    }

    // gets the ModelInstanceNode
    ModelInstanceNode mI = DAOFactory.getModelInstanceDAO().loadModelInstanceByLabel(modelNodeInstance, this.dateOfKPI);
    logger.debug("ModelInstanceNode, ID=" + mI.getModelInstanceNodeId());
    modelInstanceRootId = mI.getModelInstanceNodeId();
    logger.debug("Loaded the modelInstanceNode with LABEL " + modelNodeInstance);

    if(dataset_multires){//if datasets return a value for each resource
      this.resources = mI.getResources(); //Set all the Resources for the Model Instance
      logger.info("Dataset multiresource");
      try {
        calculateAndInsertKpiValueWithResources(mI.getModelInstanceNodeId(),this.resources);   
      } catch (EMFInternalError e) {
        e.printStackTrace();
        logger.error("Error in calculateAndInsertKpiValueWithResources",e);
      }
      logger.info("Inserted all values!!");
      return;     
    }

    // I set the list of resources of that specific ModelInstance
    if (this.resources == null || this.resources.isEmpty()) {
      this.resources = mI.getResources();
    }
    logger.debug("Setted the List of Resources related to the specified Model Instance");

    KpiLineVisibilityOptions options = setVisibilityOptions();

    if (cascade!=null && cascade.equals("true")){//in case all the kpi children have to be calculated too

      try {
        if (this.resources == null || this.resources.isEmpty()) {
          logger.debug("There are no resources assigned to the Model Instance");

          KpiResourceBlock block = new KpiResourceBlock();
          block.setD(this.dateOfKPI);
          KpiLine line = getBlock(mI.getModelInstanceNodeId(), null);       
          block.setRoot(line);
          block.setOptions(options);
          logger.debug("Setted the tree Root.");
          kpiRBlocks.add(block);
        } else {
          Iterator resourcesIt = this.resources.iterator();
          while (resourcesIt.hasNext()) {
            Resource r = (Resource) resourcesIt.next();
            logger.info("-------Resource: " + r.getName());
            KpiResourceBlock block = new KpiResourceBlock();
            block.setR(r);

        block.setD(dateOfKPI);
            block.setOptions(options);
            KpiLine line = getBlock(mI.getModelInstanceNodeId(), r);
            block.setRoot(line);
            logger.debug("Setted the tree Root.");
            kpiRBlocks.add(block);
          }
        }
      } catch (EMFInternalError e) {
        e.printStackTrace();
      }
    }else{//in case all the kpi children don't have to be calculated
      try {
        KpiInstance kpiI = mI.getKpiInstanceAssociated();
        IDataSet dataSet = DAOFactory.getKpiDAO().getDsFromKpiId(kpiI.getKpi());
        KpiValue value = new KpiValue();
        if (this.resources == null || this.resources.isEmpty()) {
          logger.debug("There are no resources assigned to the Model Instance");
          logger.debug("Retrieved the Dataset to be calculated: " + dataSet.getId());
          value = getNewKpiValue(dataSet, kpiI, null,mI.getModelInstanceNodeId(), null);
          logger.debug("New value calculated");
        } else {
          Iterator resourcesIt = this.resources.iterator();
          while (resourcesIt.hasNext()) {
            Resource r = (Resource) resourcesIt.next();
            logger.debug("Resource: " + r.getName());
            logger.debug("Retrieved the Dataset to be calculated: " + dataSet.getId());
            value = getNewKpiValue(dataSet, kpiI, r,mI.getModelInstanceNodeId(), null);         
          }
        }
        logger.debug("New value calculated");
        // Insert new Value into the DB
        IKpiDAO dao=DAOFactory.getKpiDAO();
View Full Code Here


      userId=userIdField;
    }

    String documentId = obj.getId().toString();
    logger.debug("Loaded documentId:" + documentId);   
    ModelInstanceNode mI = null;
    try {
      // **************get the template*****************   
      SourceBean content = getTemplate(documentId);
      logger.debug("Got the template.");

      // Date for which we want to see the KpiValues
      this.dateOfKPI = new Date();
      this.parametersObject = readParameters(obj.getBiObjectParameters());
      addBIParameterDescriptions(obj, this.parametersObject);
     
      if(!parametersObject.containsKey("ParKpiDate")){
        String dateForDataset = getDateForDataset(dateOfKPI)
        parametersObject.put("ParKpiDate", dateForDataset);
      }
      logger.debug("Got the date for which the KpiValues have to be calculated. Date:" + this.dateOfKPI);

      // **************take informations on the modelInstance and its KpiValues*****************
      String modelNodeInstance = (String) content.getAttribute("model_node_instance");
      logger.info("ModelNodeInstance : " + modelNodeInstance);

      if (modelNodeInstance == null) {
        logger.error("The modelNodeInstance specified in the template is null");
        throw new EMFUserError(EMFErrorSeverity.ERROR, "10106", messageBundle);
      }
      String periodInstanceID = (String) content.getAttribute("periodicity_id");
      logger.debug("PeriodInstanceID : " + (periodInstanceID!=null ? periodInstanceID : "null"));

      if (periodInstanceID == null) {
        logger.debug("No periodInstID specified will use default one");
      }else{
        periodInstID = new Integer(periodInstanceID);
      }
      getSetConf(content);
      logger.debug("Setted the configuration of the template");

      List kpiRBlocks = new ArrayList();// List of KpiValues Trees for each Resource: it will be sent to the jsp

      // gets the ModelInstanceNode
      mI = DAOFactory.getModelInstanceDAO().loadModelInstanceByLabel(modelNodeInstance, this.dateOfKPI);
      if (mI==null) {
        logger.error("MODEL INSTANCE IS NULL, CHECK model_node_instance IN DOCUMENT TEMPLATE.!!!!!!!!!!!!!!");
      }else {
        logger.debug("ModelInstanceNode, ID=" + (mI.getModelInstanceNodeId()!=null ? mI.getModelInstanceNodeId().toString():"null"));
        modelInstanceRootId = (mI.getModelInstanceNodeId()!=null ? mI.getModelInstanceNodeId() : null );
        logger.debug("Loaded the modelInstanceNode with LABEL " + modelNodeInstance);
      }

      if(dataset_multires){//if datasets return a value for each resource
        this.resources = mI.getResources(); //Set all the Resources for the Model Instance
        logger.info("Dataset multiresource");

        calculateAndInsertKpiValueWithResources(mI.getModelInstanceNodeId(),this.resources);   
        logger.info("Inserted all values!!");
        return;     
      }

      // I set the list of resources of that specific ModelInstance
      if (this.resources == null || this.resources.isEmpty()) {
        this.resources = mI.getResources();
      }
      logger.debug("Setted the List of Resources related to the specified Model Instance");

      KpiLineVisibilityOptions options = setVisibilityOptions();

      //sets up register values
      ModelInstanceNode modI = DAOFactory.getModelInstanceDAO().loadModelInstanceById(mI.getModelInstanceNodeId(), dateOfKPI);

      logger.debug("Setted the List of Kpis that does not need to be persisted in db");
      if (this.resources == null || this.resources.isEmpty()) {
        logger.debug("There are no resources assigned to the Model Instance");
        KpiResourceBlock block = new KpiResourceBlock();
View Full Code Here

    return options;
  }

  public void calculateAndInsertKpiValueWithResources(Integer miId,List resources)throws EMFUserError, EMFInternalError, SourceBeanException {
    logger.debug("IN");
    ModelInstanceNode modI =  DAOFactory.getModelInstanceDAO().loadModelInstanceById(miId, dateOfKPI);
    if (modI != null) {
      logger.info("Loaded Model Instance Node with id: " + modI.getModelInstanceNodeId());
    }

    List childrenIds = modI.getChildrenIds();
    if (!childrenIds.isEmpty()) {
      Iterator childrenIt = childrenIds.iterator();
      while (childrenIt.hasNext()) {
        Integer id = (Integer) childrenIt.next()
        calculateAndInsertKpiValueWithResources(id, resources);
      }
    }
    KpiInstance kpiI = modI.getKpiInstanceAssociated();
    if (kpiI != null) {
      KpiValue kVal = new KpiValue();
      logger.info("Got KpiInstance with ID: " + kpiI.getKpiInstanceId().toString());

     
      IDataSet dataSet = DAOFactory.getKpiDAO().getDsFromKpiId(kpiI.getKpi())
      logger.info("Retrieved the Dataset to be calculated: " + (dataSet!=null ? dataSet.getId():"null"));
      Integer kpiInstanceID = kpiI.getKpiInstanceId();
      Date kpiInstBegDt = kpiI.getD();

      kVal = setTimeAttributes(kVal, kpiI);   
      kVal.setKpiInstanceId(kpiInstanceID);
      logger.debug("Setted the KpiValue Instance ID:"+kpiInstanceID)

      if ( (dateOfKPI.after(kpiInstBegDt)||dateOfKPI.equals(kpiInstBegDt))) {
        //kpiInstance doesn't change
      }else{
        KpiInstance tempKIn = DAOFactory.getKpiInstanceDAO().loadKpiInstanceByIdFromHistory(kpiInstanceID,dateOfKPI);
        if(tempKIn==null){//kpiInstance doesn't change
        }else{
          // in case older thresholds have to be retrieved
          kpiI = tempKIn;
        }
      }

      kVal = getFromKpiInstAndSetKpiValueAttributes(kpiI,kVal);

      // If it has to be calculated for a Resource. The resource will be set as parameter
      HashMap temp = (HashMap) this.parametersObject.clone();
      temp.put("ParModelInstance", miId)
      temp.put("ParKpiInstance", kpiInstanceID.toString());
      // If not, the dataset will be calculated without the parameter Resource
      // and the DataSet won't expect a parameter of type resource
      //if(dataSet.hasBehaviour( QuerableBehaviour.class.getName()) ) {
      if(dataSet!=null){
        Kpi kpi = DAOFactory.getKpiDAO().loadKpiById(kpiI.getKpi());
        //if parameter exists and OU is abilitaded for Model Instance, than calculate as dataset parameter
        String parKpiOuLabel = (String)this.parametersObject.get("ParKpiOU");
        logger.info("Got ParKpiOU: " + parKpiOuLabel);
       
        String paramLabelHierarchy = (String)this.parametersObject.get("ParKpiHierarchy");
        logger.info("Got ParKpiHierarchy: " + paramLabelHierarchy);
        setOUAbilitated(miId, parKpiOuLabel, paramLabelHierarchy);
       
        if(ouList != null && !ouList.isEmpty()){
          if(use_ou){
            for(int i = 0; i<ouList.size(); i++){
              OrganizationalUnitGrantNode grantNode = ouList.get(i);
              String ouLabel = grantNode.getOuNode().getOu().getLabel();
              String hierLabel = grantNode.getOuNode().getHierarchy().getLabel();
              if(parKpiOuLabel == null){
                this.parametersObject.put("ParKpiOU", ouLabel);
                this.parametersObject.put("ParKpiHierarchy", hierLabel);
              }

              kVal.setGrantNodeOU(grantNode);
              kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
              kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
              if(ouWarning != null && kVal.getValue() == null){
                kVal.setValueDescr(ouWarning);   
              }
              if(parKpiOuLabel == null){
                this.parametersObject.remove("ParKpiOU");
                this.parametersObject.remove("ParKpiHierarchy");
              }
            }
          }else{
            kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
            kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
          }
        }else{       
          if(use_ou){   
            kVal = new KpiValue();
            kVal.setValueDescr(ouWarning)
            kVal.setKpiInstanceId(kpiI.getKpiInstanceId());
                  if(dateIntervalFrom!=null && dateIntervalTo!=null){
                    kVal.setBeginDate(dateIntervalFrom);
                    kVal.setEndDate(dateIntervalTo);
                    } else{
                      kVal.setBeginDate(dateOfKPI);
                      kVal.setEndDate(dateOfKPI);           
                    }
            kVal.setValue(null);
          }else{
            kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
            kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
           
         

        }
/*        if(ouList != null && !ouList.isEmpty()){
View Full Code Here

    return line;
  }
  public KpiLine getBlock(Integer miId, Resource r) throws EMFUserError, EMFInternalError, SourceBeanException {
    logger.debug("IN");
    KpiLine line = new KpiLine();
    ModelInstanceNode modI = DAOFactory.getModelInstanceDAO().loadModelInstanceById(miId, dateOfKPI);
    if (modI != null) {
      logger.info("Loaded Model Instance Node with id: " + modI.getModelInstanceNodeId());
    }
    String modelNodeName = modI.getName();
    line.setModelNodeName(modelNodeName);
    line.setModelInstanceNodeId(miId);
    line.setModelInstanceCode(modI.getModelCode());

    List children = new ArrayList();
    List childrenIds = modI.getChildrenIds();
    if (!childrenIds.isEmpty()) {
      Iterator childrenIt = childrenIds.iterator();
      while (childrenIt.hasNext()) {
        Integer id = (Integer) childrenIt.next()
        KpiLine childrenLine = getBlock(id, r);
        if(childrenLine != null){
          children.add(childrenLine);
        }
      }
    }

    KpiInstance kpiI = modI.getKpiInstanceAssociated();
    //if true the kpi value will always use the display behaviour
    boolean alreadyExistent = false;

    if (kpiI == null && modI.getModelInstaceReferenceLabel() != null){
      ModelInstanceNode modelInstanceRefered = DAOFactory.getModelInstanceDAO().loadModelInstanceByLabel(modI.getModelInstaceReferenceLabel(), dateOfKPI);
      alreadyExistent = true;
      if (modelInstanceRefered != null && modelInstanceRefered.getKpiInstanceAssociated() != null){
        kpiI = modelInstanceRefered.getKpiInstanceAssociated();
        modI.setKpiInstanceAssociated(kpiI);
      }
    }   

    line.setChildren(children);
View Full Code Here

    }
    if (kpiModelInstanceId!=null){
      Integer id = new Integer(kpiModelInstanceId);
      Date d = new Date();
      IModelInstanceDAO modInstDAO=DAOFactory.getModelInstanceDAO();
      ModelInstanceNode n = modInstDAO.loadModelInstanceById(id, d);
      String name =n.getName();
      String descr = n.getDescr();
      if (name!=null){
        serviceResponse.setAttribute("MODEL_INST_NAME", name);
      }else{
        serviceResponse.setAttribute("MODEL_INST_NAME", "");
      }
View Full Code Here

 
 
  public OrganizationalUnitGrantNode toOrganizationalUnitGrantNode(
      SbiOrgUnitGrantNodes hibGrantNode, Session aSession) {
    OrganizationalUnitNode ouNode = toOrganizationalUnitNode(hibGrantNode.getSbiOrgUnitNodes());
    ModelInstanceNode modelInstanceNode;
    try {
      modelInstanceNode = ModelInstanceDAOImpl.toModelInstanceNode(hibGrantNode.getSbiKpiModelInst());
    } catch (EMFUserError e) {
      throw new RuntimeException(e);
    }
View Full Code Here

  public static ModelInstanceNode toModelInstanceNode(
      SbiKpiModelInst hibSbiKpiModelInst)
  throws EMFUserError {

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

    String modelCode = "";

    if (hibSbiKpiModelInst.getSbiKpiModel() != null) {
      modelCode = hibSbiKpiModelInst.getSbiKpiModel().getKpiModelCd();
    }

    Integer id = hibSbiKpiModelInst.getKpiModelInst();
    logger.debug("SbiKpiModelInstanceNode id: "
        + (id != null ? id : "id null"));
    String descr = hibSbiKpiModelInst.getDescription();
    logger.debug("SbiKpiModelInstanceNode description: "
        + (descr != null ? descr : "Description null"));
    String name = hibSbiKpiModelInst.getName();
    logger.debug("SbiKpiModelInstanceNode name: "
        + (name != null ? name : "name null"));
    SbiKpiInstance kpiInst = hibSbiKpiModelInst.getSbiKpiInstance();

    IKpiInstanceDAO kpiInstDAO = DAOFactory.getKpiInstanceDAO();
    KpiInstance kpiInstanceAssociated = null;
    if (kpiInst != null) {
      kpiInstanceAssociated = kpiInstDAO.toKpiInstance(kpiInst);
    }

    Set resources = hibSbiKpiModelInst.getSbiKpiModelResourceses();
    List res = new ArrayList();
    if (!resources.isEmpty()) {
      Iterator i = resources.iterator();
      IModelResourceDAO resDAO = DAOFactory.getModelResourcesDAO();
      while (i.hasNext()) {
        SbiKpiModelResources dls = (SbiKpiModelResources) i.next();
        Resource r = resDAO.toResource(dls);
        logger.debug("SbiKpiModelInstanceNode resource name: "
            + (r.getName() != null ? r.getName()
                : "Resource name null"));
        res.add(r);
      }
    }
    // gets father id
    SbiKpiModelInst father = hibSbiKpiModelInst.getSbiKpiModelInst();
    Integer fatherId = null;
    Boolean isRoot = false;
    if (father != null) {
      fatherId = father.getKpiModelInst();
      logger
      .debug("SbiKpiModelInstanceNode fatherId: "
          + (fatherId != null ? fatherId.toString()
              : "fatherId null"));
    } else {
      isRoot = true;
    }

    // gets list of children id
    Set children = hibSbiKpiModelInst.getSbiKpiModelInsts();
    List childrenIds = new ArrayList();
    Iterator iCI = children.iterator();
    logger.debug("Started list of children");
    while (iCI.hasNext()) {
      SbiKpiModelInst skml = (SbiKpiModelInst) iCI.next();
      Integer childId = skml.getKpiModelInst();
      logger.debug("SbiKpiModelInstanceNode childrenId: "
          + (childId != null ? childId.toString() : "childId null"));
      childrenIds.add(childId);
    }

    // gets ModelNode referenced
    Integer reference = hibSbiKpiModelInst.getSbiKpiModel().getKpiModelId();
    logger
    .debug("SbiKpiModelInstanceNode modelNodeReference: "
        + (reference != null ? reference.toString()
            : "reference null"));

    toReturn.setModelInstanceNodeId(id);
    logger.debug("KpiModelInstanceNode id setted");
    toReturn.setDescr(descr);
    logger.debug("KpiModelInstanceNode description setted");
    toReturn.setName(name);
    logger.debug("KpiModelInstanceNode name setted");
    toReturn.setKpiInstanceAssociated(kpiInstanceAssociated);
    logger.debug("KpiModelInstanceNode kpiInstanceAssociated setted");
    toReturn.setResources(res);
    logger.debug("KpiModelInstanceNode resources setted");
    toReturn.setFatherId(fatherId);
    logger.debug("KpiModelInstanceNode fatherId setted");
    toReturn.setModelReference(reference);
    logger.debug("KpiModelInstanceNode ModelNode reference setted");
    toReturn.setIsRoot(isRoot);
    logger.debug("KpiModelInstanceNode isRoot setted");
    toReturn.setChildrenIds(childrenIds);
    logger.debug("KpiModelInstanceNode childrenIds setted");
    toReturn.setModelCode(modelCode);
    logger.debug("KpiModelInstanceNode childrenIds setted");

    toReturn.setModelInstaceReferenceLabel(hibSbiKpiModelInst
        .getModelUUID());
    logger.debug("OUT");
    return toReturn;
  }
View Full Code Here

  }

  public ModelInstanceNode loadModelInstanceById(Integer id,
      Date requestedDate) throws EMFUserError {
    logger.debug("IN");
    ModelInstanceNode toReturn = null;
    Session aSession = null;
    Transaction tx = null;

    try {
      aSession = getSession();
View Full Code Here

  }

  public ModelInstanceNode loadModelInstanceByLabel(String label,
      Date requestedDate) throws EMFUserError {
    logger.debug("IN");
    ModelInstanceNode toReturn = null;
    Session aSession = null;
    Transaction tx = null;

    try {
      aSession = getSession();
View Full Code Here

    Integer hierarchyId = grant.getHierarchy().getId();
    List<OrganizationalUnitNode> ouNodes = orUnitDao.getOrganizationalUnitNodeList(hierarchyId);
    //get only once the list of model instance nodes
   
    List<ModelInstanceNode> miNodes = getModelInstList(grant.getModelInstance().getId());
    ModelInstanceNode modelInstNode = DAOFactory.getModelInstanceDAO().loadModelInstanceById(grant.getModelInstance().getId(), null);
    //adds root
    miNodes.add(modelInstNode);
   
    for(int i=0; i<ouNodes.size(); i++){
      //model inst children     
View Full Code Here

TOP

Related Classes of it.eng.spagobi.kpi.model.bo.ModelInstanceNode

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.