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

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


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


      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);
       
View Full Code Here

  }
  private JSONObject recurseOverModelTree(Integer id, JSONObject response, Integer parentId) throws JSONException{

    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");
        }

        List <Model> children = model.getChildrenNodes();
        if(children == null){
          try {
            DAOFactory.getModelDAO().loadModelWithChildrenById(parentId);
          } catch (EMFUserError e) {
            // TODO Auto-generated catch block
View Full Code Here

        modelUuid = null;

      }
      Integer modelId = obj.getInt("modelId");
      try{
        Model model = DAOFactory.getModelDAO().loadModelWithoutChildrenById(modelId);
        modelInst.setModel(model);
      }catch(Throwable t){
        //nothing
        logger.error("no model!");
        modelInst.setModel(null);
View Full Code Here

        String parentId = (String)getAttributeAsString("modelId");
        if(parentId == null || parentId.startsWith("xnode")){
          writeBackToClient(new JSONSuccess("OK"));
          return;
        }
        Model aModel = modelDao.loadModelWithChildrenById(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(MODEL_NODES_LIST_WITH_KPI)) {
     
      try
       
        String parentId = (String)getAttributeAsString("modelId");
        if(parentId == null || parentId.startsWith("xnode")){
          writeBackToClient(new JSONSuccess("OK"));
          return;
        }
        Model dbModel = modelDao.loadModelWithChildrenById(Integer.parseInt(parentId));
       
        ModelExtended aModel = new ModelExtended(dbModel);
       
        aModel.setExtendedChildrenNodes(dbModel.getChildrenNodes());
       
        logger.debug("Loaded model tree");
        JSONArray modelChildrenJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(aModel.getExtendedChildrenNodes(),  locale);
        writeBackToClient(new JSONSuccess(modelChildrenJSON));
View Full Code Here

    HashMap<String, Model> labels = new HashMap<String, Model>();
    for(int i=0; i< rows.length(); i++){
     
      JSONObject obj = (JSONObject)rows.get(i);

      Model model = new Model();
      //always present guiId
      String guiId = obj.getString("id");
      model.setGuiId(guiId);

      try{
        model.setId(obj.getInt("modelId"));
      }catch(Throwable t){
        //nothing
        model.setId(null);
      }
     
      try{
        model.setParentId(obj.getInt("parentId"));
      }catch(Throwable t){
        //nothing
        model.setParentId(null);
      }
      try{
        model.setCode(obj.getString("code"));
        try{
          model.setDescription(obj.getString("description"));
        }catch(Throwable t){
          //nothing
          model.setDescription(null);
        }
     
       
        String labelKey ;
        try{
          labelKey = obj.getString("label");
        }catch(Throwable t){
          labelKey = java.util.UUID.randomUUID().toString();
        }
        model.setLabel(labelKey);
        if(!labels.containsKey(labelKey)){
          labels.put(labelKey, model);
        }else{
          //skip it
          continue;
        }
        model.setName(obj.getString("name"));
        model.setTypeCd(obj.getString("type"));
        model.setTypeId(obj.getInt("typeId"));
        try{
          model.setTypeDescription(obj.getString("typeDescr"));
        }catch(Throwable t){
          //nothing
          model.setTypeDescription(null);
        }
        try{
          model.setKpiId(obj.getInt("kpiId"));
        }catch(Throwable t){
          //nothing
          model.setKpiId(null);
        }
        // add the udpValues to Model Instance Definition, that will be serialized
        List<UdpValue> udpValues = new ArrayList<UdpValue>();
        JSONArray jsonArray = null;
        try{
          jsonArray = obj.getJSONArray("udpValues");
        }catch(Throwable t){
          jsonArray = new JSONArray();
        }
        logger.debug("found udpValues Array containing number of Udp "+jsonArray.length());
        for(int j=0; j< jsonArray.length(); j++){
          JSONObject objJS = (JSONObject)jsonArray.get(j);
          // only label and value information are retrieved by JSON object
          String labelJ = objJS.getString("name")
          String value = objJS.getString("value")

          UdpValue udpValue = new UdpValue();

          // reference id is the kpi id
          udpValue.setLabel(obj.getString("label"));
          udpValue.setValue(value);
          udpValue.setReferenceId(model.getId());

          // get the UDP to get ID (otherwise could be taken in js page)
          Udp udp = DAOFactory.getUdpDAO().loadByLabelAndFamily(labelJ, "MODEL");
          Domain familyDomain = DAOFactory.getDomainDAO().loadDomainById(udp.getFamilyId());
          logger.debug("Udp value assigning value "+value+" to UDP with label "+udp.getLabel()+ " and Model Instance with label "+ model.getLabel());
          udpValue.setLabel(udp.getLabel());
          udpValue.setName(udp.getName());
          udpValue.setFamily(familyDomain != null ? familyDomain.getValueCd() : null);
          udpValue.setUdpId(udp.getUdpId());

          udpValues.add(udpValue);
        }
        model.setUdpValues(udpValues);
       
        String value = obj.getString("toSave");
      }catch(Throwable t){
        logger.debug("Deserialization error on node: "+guiId);
      }
View Full Code Here

   
    //loop over nodes and order them ascending
    TreeMap<Integer, Model> treeMap = new TreeMap<Integer, Model>();
    for(int i= 0; i<nodesToSave.size(); i++){
     
      Model model = (Model)nodesToSave.get(i);
      //loads all nodes guiid with type error
     
      respObj.put(model.getGuiId(), "OK");
      respObj.put("label", model.getLabel());
     
      if(model.getParentId() != null){
        //look up for its id: if null --> newly created node
        Integer id = model.getId();
        if(id == null){
          treeMap.put(Integer.valueOf("-"+i+1), model);
        }else{
        //else to modify node
          treeMap.put(model.getId(), model);
        }
       
      }else{
        //root node --> save first
        try {
          if(model.getId()  != null){
            modelDao.modifyModel(model);
            respObj.put(model.getGuiId(), model.getId());
            respObj.put(model.getId()+"", model.getLabel());
          }else{
            Integer index = modelDao.insertModel(model);
            respObj.put(model.getGuiId(), index);
            respObj.put(index+"", model.getLabel());
          }
        } catch (Exception e) {
          //send error!!!   
          respObj.put(model.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
      Model orderedNode = (Model)orderedEntry.getValue();
     
      //GET JSON OBJECT VALUE
      Integer parentId = orderedNode.getParentId();
      try {
        Model parent = modelDao.loadModelWithoutChildrenById(parentId);
        if(parent != null){           
          //if parent exists--> save         
          //if node id is negative --> insert
          if(orderedNode.getId() == null){
            Integer newId = modelDao.insertModel(orderedNode);
View Full Code Here

  static private Logger logger = Logger.getLogger(ModelDAOImpl.class);

  public Model loadModelWithoutChildrenById(Integer id) throws EMFUserError {
    logger.debug("IN");
    Model toReturn = null;
    Session aSession = null;
    Transaction tx = null;
    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
View Full Code Here

  public Model loadModelWithChildrenById(Integer id) throws EMFUserError {
    logger.debug("IN");
    Session aSession = null;
    Transaction tx = null;
    Model toReturn = null;
    try {
      aSession = getSession();
      tx = aSession.beginTransaction();
      SbiKpiModel hibSbiKpiModel = (SbiKpiModel) aSession.load(
          SbiKpiModel.class, id);
View Full Code Here

   * @return the Model create from the SbiKpiModel.
   */
  private Model toModelWithChildren(Session session, SbiKpiModel value,
      Integer rootId) {
    logger.debug("IN");
    Model toReturn = new Model();
    String name = value.getKpiModelNm();
    String description = value.getKpiModelDesc();
    String code = value.getKpiModelCd();
    String label = value.getKpiModelLabel();
    Integer id = value.getKpiModelId();
    SbiKpi sbiKpi = value.getSbiKpi();
    Integer kpiId = null;
    if (sbiKpi != null) {
      kpiId = sbiKpi.getKpiId();
    }

    Integer typeId = value.getModelType().getValueId();
    String typeCd = value.getModelType().getValueCd();
    String typeName = value.getModelType().getValueNm();
    String typeDescription = value.getModelType().getValueDs();
    List childrenNodes = new ArrayList();

    // Set children = value.getSbiKpiModels();

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

    List children = critt.list();

    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
      SbiKpiModel sbiKpichild = (SbiKpiModel) iterator.next();
      Model child = toModelWithChildren(session, sbiKpichild, id);
      childrenNodes.add(child);
    }
   
    // Put
    // add also associated UDP
View Full Code Here

TOP

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

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.