Examples of ModelInstance


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

  public ModelInstance loadModelInstanceWithChildrenByLabel(String label)
  throws EMFUserError {
    logger.debug("IN");
    Session aSession = null;
    Transaction tx = null;
    ModelInstance toReturn = null;
    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      SbiKpiModelInst hibSbiKpiModelInst = (SbiKpiModelInst) aSession
      .load(SbiKpiModelInst.class, label);
View Full Code Here

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

  }

  private ModelInstance toModelInstanceWithChildren(Session session,
      SbiKpiModelInst value, Integer parentId) {
    logger.debug("IN");
    ModelInstance toReturn = new ModelInstance();
    String name = value.getName();
    String description = value.getDescription();
    String label = value.getLabel();
    Date startDate = value.getStartDate();
    Date endDate = value.getEndDate();
    Integer id = value.getKpiModelInst();
    SbiKpiModel sbiKpiModel = value.getSbiKpiModel();
    String modelUUID = value.getModelUUID();
    Model aModel = ModelDAOImpl
    .toModelWithoutChildren(sbiKpiModel, session);
    SbiKpiInstance sbiKpiInstance = value.getSbiKpiInstance();

    if (sbiKpiInstance != null) {
      // toKpiInstance
      KpiInstance aKpiInstance = new KpiInstance();
      aKpiInstance.setKpiInstanceId(sbiKpiInstance.getIdKpiInstance());
      aKpiInstance.setKpi(sbiKpiInstance.getSbiKpi().getKpiId());
      if (sbiKpiInstance.getSbiThreshold() != null) {
        aKpiInstance.setThresholdId(sbiKpiInstance.getSbiThreshold()
            .getThresholdId());
      }
      if (sbiKpiInstance.getChartType() != null) {
        aKpiInstance.setChartTypeId(sbiKpiInstance.getChartType()
            .getValueId());
      }
      // TODO
      if (sbiKpiInstance.getSbiKpiInstPeriods() != null
          && !(sbiKpiInstance.getSbiKpiInstPeriods().isEmpty())) {
        SbiKpiInstPeriod instPeriod = (SbiKpiInstPeriod) sbiKpiInstance
        .getSbiKpiInstPeriods().toArray()[0];

        aKpiInstance.setPeriodicityId(instPeriod.getSbiKpiPeriodicity()
            .getIdKpiPeriodicity());
      }
      aKpiInstance.setWeight(sbiKpiInstance.getWeight());
      aKpiInstance.setTarget(sbiKpiInstance.getTarget());
      aKpiInstance.setD(sbiKpiInstance.getBeginDt());
      //
      toReturn.setKpiInstance(aKpiInstance);
    }

    List childrenNodes = new ArrayList();

    Criteria critt = session.createCriteria(SbiKpiModelInst.class);
    critt.add(Expression.eq("sbiKpiModelInst", value));
    critt.createCriteria("sbiKpiModel").addOrder(Order.asc("kpiModelCd"));

    List children = critt.list();

    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
      SbiKpiModelInst sbiKpichild = (SbiKpiModelInst) iterator.next();
      ModelInstance child = toModelInstanceWithChildren(session,
          sbiKpichild, id);
      childrenNodes.add(child);
    }

    toReturn.setId(id);
View Full Code Here

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

      List sbiKpiModelInstanceList = crit.list();
      for (Iterator iterator = sbiKpiModelInstanceList.iterator(); iterator
      .hasNext();) {
        SbiKpiModelInst sbiKpiModelInst = (SbiKpiModelInst) iterator
        .next();
        ModelInstance aModelInst = toModelInstanceWithoutChildren(
            sbiKpiModelInst, aSession);
        toReturn.add(aModelInst);
      }
    } catch (HibernateException he) {
      logException(he);
View Full Code Here

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

    logger.debug("IN");
    if (mi.getParentId() == null) {
      logger.debug("OUT");
      return mi;
    } else {
      ModelInstance miPar = loadModelInstanceWithoutChildrenById(mi
          .getParentId());
      logger.debug("Searching model instance parent.");
      return loadModelInstanceRoot(miPar);
    }
  }
View Full Code Here

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

    biObjectToInsert=new ArrayList();

    //I want to insert the whole model instance tree, first of all I get the model instance root
    IModelInstanceDAO modInstDAO=DAOFactory.getModelInstanceDAO();
    ModelInstance miRoot=modInstDAO.loadModelInstanceRoot(mi);


    // insert the model (model instance root points to model root)
    logger.debug("Insert the model root and the tree");   

    // insert model tree starting from root.
    Model modelRoot=miRoot.getModel();
    insertModelTree(modelRoot, session);

    logger.debug("Insert the model Instance root and the tree");   

    //insert the Model Instanceroot
View Full Code Here

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

      Set modelInstanceChildren=new HashSet();
      logger.debug("insert current model instance children");
      // get the Model Instance children
      IModelInstanceDAO modelInstDao=DAOFactory.getModelInstanceDAO();
      ModelInstance modInstWithChildren=modelInstDao.loadModelInstanceWithChildrenById(mi.getId());
      List childrenList=modInstWithChildren.getChildrenNodes();
      if(childrenList!=null){
        for (Iterator iterator = childrenList.iterator(); iterator.hasNext();) {
          ModelInstance childNode = (ModelInstance) iterator.next();
          logger.debug("insert child "+childNode.getLabel());
          insertModelInstanceTree(childNode,session);       
          SbiKpiModelInst hibKpiModelInst = (SbiKpiModelInst) session.load(SbiKpiModelInst.class, childNode.getId());
          modelInstanceChildren.add(hibKpiModelInst);
        }
      }
      hibMi.setSbiKpiModelInsts(modelInstanceChildren)// serve?
View Full Code Here

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

        // biObjectToInsert keeps track of objects that have to be inserted beacuse related to Kpi

        if (modelInstanceLabel != null) {
          IModelInstanceDAO modelInstanceDao = DAOFactory.getModelInstanceDAO();
          ModelInstance modelInstance = modelInstanceDao.loadModelInstanceWithoutChildrenByLabel(modelInstanceLabel);
          if (modelInstance == null) {
            logger.warn("Error while exporting kpi with id " + biobj.getId() + " and label " + biobj.getLabel() + " : " +
                "the template refers to a Model Instance with label " + modelInstanceLabel + " that does not exist!");
          } else {
            objsToInsert=exporter.insertAllFromModelInstance(modelInstance, session);
View Full Code Here

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

        String parentId = (String)getAttributeAsString("modelInstId");
        if(parentId == null || parentId.startsWith("xnode")){
          writeBackToClient(new JSONSuccess("OK"));
          return;
        }
        ModelInstance aModel = modelDao.loadModelInstanceWithChildrenById(Integer.parseInt(parentId));

        logger.debug("Loaded model tree");
        JSONArray modelChildrenJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(aModel.getChildrenNodes(),  locale);
        writeBackToClient(new JSONSuccess(modelChildrenJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving model tree", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving model tree", e);
      }
    }else if (serviceType != null && serviceType.equalsIgnoreCase(MODELINSTS_NODE_DETAILS)) {

      try

        String node = (String)getAttributeAsString("modelInstId");

        ModelInstance aModel = modelDao.loadModelInstanceWithChildrenById(Integer.parseInt(node));

        logger.debug("Loaded model tree");
        JSONObject modelChildrenJSON = (JSONObject) SerializerFactory.getSerializer("application/json").serialize(aModel, locale);
        writeBackToClient(new JSONSuccess(modelChildrenJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving model tree", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving model tree", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(MODELINSTS_NODES_SAVE)) {

      JSONArray nodesToSaveJSON = getAttributeAsJSONArray(NODES_TO_SAVE);
      JSONArray droppedNodesToSaveJSON = getAttributeAsJSONArray(DROPPED_NODES_TO_SAVE);
      JSONObject rootObj = getAttributeAsJSONObject(ROOT_TO_SAVE);

      List<ModelInstance> modelNodes = null;
      List<ModelInstance> modelNodesDD = null;
      ModelInstance root = null;
      Vector idsToRemove = new Vector();
      if(nodesToSaveJSON != null || droppedNodesToSaveJSON != null){
        JSONObject response = new JSONObject();

        try {
          modelNodesDD = deserializeNodesJSONArrayDD(droppedNodesToSaveJSON);

          //clean nodes modified from DD ones
          for(int i=0; i<modelNodesDD.size(); i++){
            ModelInstance mi = modelNodesDD.get(i);
            String guidToSkip = mi.getGuiId();
            //if already present in modified nodes...
            for(int k =0; k< nodesToSaveJSON.length(); k++){
              JSONObject objMod = nodesToSaveJSON.getJSONObject(k);
              String guiId = "";
              try{
                guiId = objMod.getString("id");
              }catch(Throwable t){
                logger.debug("Dropped node guiid doesn't exist");
              }
              if(guiId.equals(guidToSkip)){
                idsToRemove.add(guidToSkip);
              }
            }
           
          }
          modelNodes = deserializeJSONArray(nodesToSaveJSON, idsToRemove);


          //save DD nodes
          if(rootObj != null){           
            root = deserializeJSONObjectDD(rootObj, new ArrayList<ModelInstance>())
            modelNodesDD.add(root);
          }
          if(modelNodesDD != null && !modelNodesDD.isEmpty()){
            if(!isTreeStructureOfDDNodes(droppedNodesToSaveJSON)){
              response = saveModelNodeInstances(modelNodesDD);
            }else{
              response = recursiveStart(modelNodesDD, root, response);
            }
           
          }
          try{
            if( rootObj.getBoolean("toSave")){
              //root node has been modified
              modelNodes.add(root);
            }
          }catch(Throwable e){
            logger.debug("Root node is not modified");
          }
          response = saveModelNodeInstances(modelNodes);
          writeBackToClient(new JSONSuccess(response));

        } catch (Exception e) {
          logger.error(e.getMessage(), e);
          try {
            writeBackToClient(new JSONSuccess(response));
          } catch (IOException e1) {
            logger.error("Exception occurred while sending response", e);
            throw new SpagoBIServiceException(SERVICE_NAME,
                "Exception occurred while sending response", e);
          }
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception saving model instance nodes", e);
        }

      }

    } else if (serviceType != null  && serviceType.equalsIgnoreCase(MODELINSTS_NODE_DELETE)) {

      Integer modelInstId = getAttributeAsInteger("modelInstId");
      try {
        boolean result = modelDao.deleteModelInstance(modelInstId);
        logger.debug("Model instance node deleted");
        writeBackToClient( new JSONSuccess("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving model instance to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving model instance to delete", e);
      }


    }else if (serviceType != null  && serviceType.equalsIgnoreCase(MODELINSTS_KPI_RESTORE)) {

      Integer kpiId = getAttributeAsInteger("kpiId");
      try {
        Kpi kpiToRestore = DAOFactory.getKpiDAO().loadKpiById(kpiId);

        logger.debug("Found kpi to restore");
        JSONObject kpiJson = (JSONObject) SerializerFactory.getSerializer("application/json").serialize(kpiToRestore,  locale);
        writeBackToClient(new JSONSuccess(kpiJson));
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving kpi to restore", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving kpi to restore", e);
      }


    }else if (serviceType != null  && serviceType.equalsIgnoreCase(MODELINST_RESOURCE_LIST)) {

      try {
        Integer modelInstId = null;
        try{
          modelInstId = getAttributeAsInteger("modelInstId");
        }catch (Exception e) {
          // TODO: handle exception
          logger.debug("No model Instance Id");
        }
        Integer start = getAttributeAsInteger( START );
        Integer limit = getAttributeAsInteger( LIMIT );

        if(start==null){
          start = START_DEFAULT;
        }
        if(limit==null){
          limit = LIMIT_DEFAULT;
        }
        List<ModelResourcesExtended> modelResourcesExtenList = new ArrayList<ModelResourcesExtended>();
        //extract resources
        List<ModelResources> modelResources = new ArrayList<ModelResources>();
        if(modelInstId != null){
          modelResources = modelResourcesDao.loadModelResourceByModelId(modelInstId);
        }
        HashMap<Integer, ModelResources> modResourcesIds = new HashMap<Integer, ModelResources>();
        if(modelResources != null){
          for(int i =0;i<modelResources.size(); i++){
            ModelResources mr = modelResources.get(i);
            modResourcesIds.put(mr.getResourceId(), mr);
          }
        }
        //extract all resources
        Vector resourcesIds = new Vector<Integer>();

        List<Resource> allResources = (List<Resource>)getSessionContainer().getAttribute("ALL_RESOURCES_LIST");

        //if null than extract
        if(allResources == null){
          allResources = DAOFactory.getResourceDAO().loadPagedResourcesList(start,limit);
        }
        modelResourcesExtendedListCreate(modelResourcesExtenList, allResources, modResourcesIds);

        logger.debug("Loaded model resources");
        JSONArray modelsResourcesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(modelResourcesExtenList,locale);
        JSONObject modelsResourcesResponseJSON = createJSONResponsemodelsResourcesList(modelsResourcesJSON, modelResourcesExtenList.size());

        writeBackToClient(new JSONSuccess(modelsResourcesResponseJSON));


      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving model tree", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving model tree", e);
      }

    }else if(serviceType != null  && serviceType.equalsIgnoreCase(MODELINST_RESOURCE_SAVE)){
      JSONArray resToSaveJSON = getAttributeAsJSONArray("ids");
      Integer modelId = getAttributeAsInteger("modelInstId");

      try {

        List ids = deserializeResourceJSONArray(resToSaveJSON);
        List toAddIds = ids;
        //loops over all model resources
        List<ModelResources> mrs = modelResourcesDao.loadModelResourceByModelId(modelId);
        for(int i=0; i< mrs.size(); i++){
          ModelResources modelres = mrs.get(i);
          if(!ids.contains(modelres.getResourceId())){
            //to remove
            modelResourcesDao.removeModelResource(modelId, modelres.getResourceId());
          }else {
            //already present so remove it from the list
            toAddIds.remove(modelres.getResourceId());
          }


        }
        //now adds new ones         
        for(int i=0; i< toAddIds.size(); i++){
          Integer resourceId = (Integer)toAddIds.get(i);
          modelResourcesDao.addModelResource(modelId, resourceId);           
        }

        writeBackToClient(new JSONSuccess("Operation succeded"));


      } catch (EMFUserError e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception saving resources", e);
      } catch (JSONException e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception deserializing resources", e);
      } catch (IOException e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception in response", e);
      }

    }else if (serviceType != null && serviceType.equalsIgnoreCase(MODELINSTS_COPY_MODEL)) {

      try
        //saves all model nodes hierarchy as model instance
        JSONObject response = new JSONObject();
        Integer modelId = (Integer)getAttributeAsInteger("modelId");

        response = recurseOverModelTree(modelId, response, null);

        logger.debug("Loaded model tree");   

        writeBackToClient(new JSONSuccess(response));

      } catch (Throwable e) {
        logger.error("Exception occurred while copying model tree", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while copying model tree", e);
      }
    }else if (serviceType != null && serviceType.equalsIgnoreCase(MODELINSTS_SAVE_ROOT)) {

      try
        //saves all model nodes hierarchy as model instance
        JSONObject response = new JSONObject();
        Integer modelId = (Integer)getAttributeAsInteger("modelId");
        Model model = DAOFactory.getModelDAO().loadModelWithoutChildrenById(modelId);
        ModelInstance modelInstNode = new ModelInstance();
        modelInstNode = fillModelInstanceByModel(model, modelInstNode, null);
       
        modelInstNode = setProgressiveOnDuplicate(modelInstNode);
       
        Integer miId = modelDao.insertModelInstanceWithKpi(modelInstNode);
       
        response.append("root", miId);
        response.append("rootlabel", modelInstNode.getLabel());
        response.append("rootname", modelInstNode.getName());
       
        String text = modelInstNode.getName() ;
        if(text.length()>= 20){
          text = text.substring(0, 19)+"...";
        }
        text = modelInstNode.getModel().getCode()+" - "+ text;
        response.append("roottext", text);

        logger.debug("Loaded model tree");   

        writeBackToClient(new JSONSuccess(response));
View Full Code Here

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

    try {
      Model model =DAOFactory.getModelDAO().loadModelWithChildrenById(id);
      Integer modelInstId = null;
      if(id != null){
        ModelInstance modelInstNode = new ModelInstance();

        //save root first
        try {
          modelInstNode = fillModelInstanceByModel(model, modelInstNode, parentId);
          modelInstNode = setProgressiveOnDuplicate(modelInstNode);
          //save node as ModelInstance node
          modelInstId = modelDao.insertModelInstanceWithKpi(modelInstNode);
          modelInstNode.setId(modelInstId);

          if(parentId == null){
            response.append("root",modelInstId.intValue()+"");
            response.append("rootlabel", modelInstNode.getLabel());
            response.append("rootname", modelInstNode.getName());
            String text = modelInstNode.getName() ;
            if(text.length()>= 20){
              text = text.substring(0, 19)+"...";
            }
            text = modelInstNode.getModel().getCode()+" - "+ text;
            response.append("roottext", text);
          }
        } catch (EMFUserError e) {
          response.append("tree", "KO");
        }
View Full Code Here

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

    return response;
  }
  private JSONObject recurseOverTree(List<ModelInstance> modelInstList, ModelInstance modelInstance, Integer parentId, JSONObject response, boolean isToSave) throws JSONException{

    ModelInstance modInstToSave = modelInstance;
    //found  root child
    Integer oldId = null;
    if(modInstToSave.getGuiId() != null){
      try{
        oldId =Integer.valueOf(modInstToSave.getGuiId());//incorrect
      }catch(Throwable t){
        if(!isToSave && modInstToSave.getId() != null){
          oldId = modInstToSave.getId();
        }else
          oldId = null;
      }
    }
    modInstToSave.setParentId(parentId);       
    //save it
    try {
      Integer genId = modInstToSave.getId();
      if(isToSave){

        genId = modelDao.insertModelInstanceWithKpi(modInstToSave);
        modInstToSave.setId(genId);
      }

      response.append(modInstToSave.getGuiId(), "OK");

      List<ModelInstance> nodes = findNextNodes(modelInstList, oldId);

      if(nodes == null || nodes.isEmpty()){
        //try another way
        nodes = modInstToSave.getChildrenNodes();

      }
      if(nodes != null && !nodes.isEmpty()){
        for (int i=0; i< nodes.size(); i++){
          ModelInstance modInst = (ModelInstance)nodes.get(i);
          recurseOverTree(modelInstList, modInst, genId, response, true);
        }
      }

    } catch (EMFUserError e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.