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

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


    //loop over nodes and order them ascending
    TreeMap<Integer, ModelInstance> treeMap = new TreeMap<Integer, ModelInstance>();
    for(int i= 0; i<nodesToSave.size(); i++){

      ModelInstance modelInstance = (ModelInstance)nodesToSave.get(i);

      //loads all nodes guiid with type error

      respObj.put(modelInstance.getGuiId(), "OK");

      if(modelInstance.getParentId() != null){
        //look up for its id: if null --> newly created node
        Integer id = modelInstance.getId();
        if(id == null){
          treeMap.put(Integer.valueOf("-"+i+1), modelInstance);
        }else{
          //else to modify node
          treeMap.put(modelInstance.getId(), modelInstance);
        }

      }else{
        //root node --> save first
        try {
          if(modelInstance.getId()  != null){
            modelDao.modifyModelInstance(modelInstance);
            respObj.put(modelInstance.getGuiId(), modelInstance.getId());
          }else{
            if(modelInstance.getId() == null &&
                modelInstance.getParentId() == null &&
                modelInstance.getGuiId() == null){
              //new model instance root --> insert it first
              logger.debug("new model instance root");
            }
            Integer index = modelDao.insertModelInstance(modelInstance);
            respObj.put(modelInstance.getGuiId(), index);
          }
        } catch (Exception e) {
          //send error!!!   
          respObj.put(modelInstance.getGuiId(), "KO");

        }
      }
    }

    Set set = treeMap.entrySet();
    // Get an iterator
    Iterator it = set.iterator();
    //loop again over treemap
    while(it.hasNext()) {
      Map.Entry orderedEntry = (Map.Entry)it.next();
      //check that parent exists
      ModelInstance orderedNode = (ModelInstance)orderedEntry.getValue();

      //GET JSON OBJECT VALUE
      Integer parentId = orderedNode.getParentId();
      try {
        ModelInstance parent = modelDao.loadModelInstanceWithoutChildrenById(parentId);
        if(parent != null){           
          //if parent exists--> save         
          //if node id is negative --> insert
          if(orderedNode.getId() == null){
            Integer newId = modelDao.insertModelInstance(orderedNode);
View Full Code Here


      Integer grantId =  getAttributeAsInteger("grantId");
      Integer goalNodeId =  getAttributeAsInteger("goalNodeId");
      Integer ouNodeId =  getAttributeAsInteger("ouNodeId");
      logger.debug("grantId: "+grantId+", goalNodeId"+goalNodeId);
      OrganizationalUnitGrant grant = DAOFactory.getOrganizationalUnitDAO().getGrant(grantId);
      ModelInstance mi = grant.getModelInstance();
     
      List<OrganizationalUnitNodeWithGrant> ousWithGrants = DAOFactory.getOrganizationalUnitDAO().getGrantNodes(ouNodeId, grantId);
      List<OrganizationalUnitGrantNode> grants = new ArrayList<OrganizationalUnitGrantNode>();
      for(int i=0; i<ousWithGrants.size(); i++){
        grants.addAll(ousWithGrants.get(i).getGrants());
      }
      List<Integer> modelInstances = new ArrayList<Integer>();
     
      for(int i=0; i<grants.size(); i++){
        modelInstances.add(grants.get(i).getModelInstanceNode().getModelInstanceNodeId());
      }
     
      if(modelInstances.contains(mi.getId())){
        mi.setActive(true);
      }
     
      try {
        JSONObject modelInstanceJSON = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( mi, null);
       
        if(goalNodeId!=null){
          List<GoalKpi> listGoalKpi = daoGoal.getGoalKpi(goalNodeId);
          for(int i=0; i<listGoalKpi.size(); i++){
            if(listGoalKpi.get(i).getModelInstanceId().equals( mi.getId())){
              modelInstanceJSON.put("weight1", ""+listGoalKpi.get(i).getWeight1());
              modelInstanceJSON.put("weight2", ""+listGoalKpi.get(i).getWeight2());
              modelInstanceJSON.put("sign1", ""+listGoalKpi.get(i).getSign1());
              if(listGoalKpi.get(i).getSign1()==110){
                modelInstanceJSON.put("threshold1", "");
View Full Code Here

          logger.debug("Loading the ou root of the hierarchy with id"+hierarchyId+" and grant "+grantId+"...");
        }catch(Throwable e){
          grantId = null;
         
          try{
            ModelInstance aModel = DAOFactory.getModelInstanceDAO().loadModelInstanceWithChildrenById(modelInstanceId);
            modelInstances = getModelInstances(aModel.getId());
          }catch(Exception ee){

          }
          logger.debug("Loading the ou root of the hierarchy with id"+hierarchyId+"...");
        }

       
        getHierarchyRootNode(hierarchyId, grantId, modelInstances);
        logger.debug("Loaded the ou root of the hierarchy with id"+hierarchyId+"...");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_GRANT_ERESE)) {
        Integer grantId = getAttributeAsInteger("grantId");
        logger.debug("Eresing the grant with id "+grantId+"...");
        eraseGrant(grantId);
        logger.debug("Eresed the grant with id "+grantId+"...");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_GRANT_INSERT)) {
        JSONArray grantNodesJSON = getAttributeAsJSONArray(GRANTNODES);
        JSONObject grantJSON = getAttributeAsJSONObject(GRANT);
        logger.debug("Adding the grant "+grantNodesJSON+"..."+grantJSON);
        insertGrant(grantJSON, grantNodesJSON);
        logger.debug("Added the grant.");

      }else if (serviceType != null && serviceType.equalsIgnoreCase(KPI_ACTIVE_CHILDS_LIST)) {
        Integer ouNodeId =  getAttributeAsInteger("ouNodeId");
        Integer grantId =  getAttributeAsInteger("grantId");
        Integer goalNodeId =  null;
        try{
          goalNodeId = getAttributeAsInteger("goalNodeId");
        }catch (NumberFormatException e) {
          goalNodeId = null;
        }
        String parentId = (String)getAttributeAsString("modelInstId");
       
        List<OrganizationalUnitNodeWithGrant> ousWithGrants = orUnitDao.getGrantNodes(ouNodeId, grantId);
        List<OrganizationalUnitGrantNode> grants = new ArrayList<OrganizationalUnitGrantNode>();
        for(int i=0; i<ousWithGrants.size(); i++){
          grants.addAll(ousWithGrants.get(i).getGrants());
        }
        List<Integer> modelInstances = new ArrayList<Integer>();
       
        for(int i=0; i<grants.size(); i++){
          modelInstances.add(grants.get(i).getModelInstanceNode().getModelInstanceNodeId());
        }
       
        try{
          if(parentId == null || parentId.startsWith("xnode")){
            writeBackToClient( new JSONAcknowledge() );
            return;
          }
          ModelInstance aModel = DAOFactory.getModelInstanceDAO().loadModelInstanceWithChildrenById(Integer.parseInt(parentId));
          List<ModelInstance> children = aModel.getChildrenNodes();
         
          for(int i=0; i<children.size(); i++){
            if(modelInstances.contains(children.get(i).getId())){
              children.get(i).setActive(true);
            }
View Full Code Here

    try{
      organizationalUnitGrant.setId(JSONGrant.getInt("id"));
    }catch(JSONException e){}
    int hierarchyId = JSONGrant.getInt("hierarchy");
    int modelInstanceId = JSONGrant.getInt("modelinstance");
    ModelInstance modelInstance = DAOFactory.getModelInstanceDAO().loadModelInstanceWithChildrenById(modelInstanceId);
    OrganizationalUnitHierarchy organizationalUnitHierarchy = orUnitDao.getHierarchy(hierarchyId);
    organizationalUnitGrant.setModelInstance(modelInstance);
    organizationalUnitGrant.setHierarchy(organizationalUnitHierarchy);
   
    return organizationalUnitGrant;
View Full Code Here

    return nodes;
  }
 
  public List<Integer> getChildren(Integer modelInstanceId) throws Exception{
    List<Integer> list = new ArrayList<Integer>();
    ModelInstance mi = DAOFactory.getModelInstanceDAO().loadModelInstanceWithChildrenById(modelInstanceId);
    list.add(mi.getId());
    if(mi.getChildrenNodes()!=null){
      for(int i=0; i<mi.getChildrenNodes().size(); i++){
        list.addAll(getChildren(((ModelInstance)mi.getChildrenNodes().get(i)).getId()));
      }
    }
    return list;
  }
View Full Code Here

    if( !(o instanceof ModelInstance) ) {
      throw new SerializationException("ModelInstanceNodeJSONSerializer is unable to serialize object of type: " + o.getClass().getName());
    }
   
    try {
      ModelInstance res = (ModelInstance)o;
      result = new JSONObject();
     
      result.put(MODEL_INST_ID, res.getId() );
      result.put(PARENT_ID, res.getParentId() );
     
      if(res.getModel() != null){
        result.put(MODEL_ID, res.getModel().getId() );
        Model model = DAOFactory.getModelDAO().loadModelWithoutChildrenById(res.getModel().getId() );
        result.put(MODEL_TEXT, model.getCode() +" - "+model.getName() );
        result.put(MODEL_CODE, model.getCode());
        result.put(MODEL_NAME, model.getName() );
        result.put(MODEL_DESCR, model.getDescription() );
        result.put(MODEL_TYPE, model.getTypeName() );
        result.put(MODEL_TYPEDESCR, model.getTypeDescription() );       

     
      //if no kpi instance --> fill data with kpi properties           
      //else with kpi instance properties
      if(res.getKpiInstance() != null){
        result.put(KPI_INST_ID, res.getKpiInstance().getKpiInstanceId() );
        KpiInstance kpiInst = DAOFactory.getKpiInstanceDAO().loadKpiInstanceById(res.getKpiInstance().getKpiInstanceId());

        if(kpiInst != null){
          result.put(KPI_ID, kpiInst.getKpi());
          if(kpiInst.getKpi() != null){
            Kpi kpi = DAOFactory.getKpiDAO().loadKpiById(kpiInst.getKpi());
            result.put(KPI_NAME, kpi.getKpiName());
            result.put(KPI_CODE, kpi.getCode());
          }
          result.put(KPI_INST_CHART, kpiInst.getChartTypeId());
          result.put(KPI_INST_PERIODICITY, kpiInst.getPeriodicityId());
          result.put(KPI_INST_TARGET, kpiInst.getTarget());
          result.put(KPI_INST_THR_ID, kpiInst.getThresholdId());
          if(kpiInst.getThresholdId() != null){
            Threshold thr = DAOFactory.getThresholdDAO().loadThresholdById(kpiInst.getThresholdId());
            result.put(KPI_INST_THR_NAME, thr.getName());
          }
          result.put(KPI_INST_WEIGHT, kpiInst.getWeight());
          result.put(KPI_INST_SAVE_HISTORY, kpiInst.isSaveKpiHistory());

        }
      }
      result.put(NAME, res.getName() );
      String text = res.getName() ;
      if(text.length()>= 20){
        text = text.substring(0, 19)+"...";
      }
      text = res.getModel().getCode()+" - "+ text;
      result.put(TEXT, text );
      result.put(LABEL, res.getLabel());     
      result.put(DESCRIPTION, res.getDescription() );
      result.put(STARTDATE, res.getStartDate());
      result.put(ENDDATE, res.getEndDate());
      result.put(MODELUUID, res.getModelUUID() );
      result.put(KPI_INST_ACTIVE, res.isActive());
      if(res.getChildrenNodes() != null && !res.getChildrenNodes().isEmpty()){
        result.put(LEAF, false );
      }else{
        result.put(LEAF, true );
      }
View Full Code Here

TOP

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

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.