Package it.eng.spagobi.utilities.exceptions

Examples of it.eng.spagobi.utilities.exceptions.SpagoBIServiceException


      response.put("VALUE_ID", valueId);
      writeBackToClient(new JSONSuccess(response));

    } catch (Throwable e) {
      logger.error("Exception occurred while retrieving domain data", e);
      throw new SpagoBIServiceException(SERVICE_NAME,
          "Impossible to delete domain", e);
    }
  }
View Full Code Here


      writeBackToClient(new JSONSuccess(response));

    } catch (Throwable e) {
      logger.error("Exception occurred while retrieving domain data", e);
      throw new SpagoBIServiceException(SERVICE_NAME,
          "Exception occurred while retrieving domain data", e);
    }
  }
View Full Code Here

      JSONObject results = new JSONObject();
      results.put("results", notesListJSON);
      results.put("totalCount", notesListJSON.length());
      writeBackToClient( new JSONSuccess( results ) );
    } catch (IOException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
    } catch (JSONException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects into a JSON object", e);
    }
  }
View Full Code Here

    List updatedNotesList = null; //final list with notes public or of user owner
    try {
      notesList = DAOFactory.getObjNoteDAO().getListExecutionNotes(obj.getId(), execIdentifier);
    } catch (Exception e) {
      logger.error("Cannot load notes for document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]", e);
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot load notes", e);
    }
    try {
      JSONArray notesListJSON = new JSONArray();
      if (notesList != null){
        updatedNotesList = new ArrayList();
        //define isDeletable flag if the user is equal owner
        for (int i=0; i<notesList.size(); i++){
          ObjNote objNote = (ObjNote)notesList.get(i);
          if (objNote.getOwner().equals(owner)){
            objNote.setIsDeletable(true);
            updatedNotesList.add(objNote);
          }
          else if (objNote.getIsPublic()){           
            objNote.setIsDeletable(false);
            updatedNotesList.add(objNote);
          }                 
        }
         
        notesListJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize( updatedNotesList,null );
      }
      JSONObject results = new JSONObject();
      results.put("results", notesListJSON);
      results.put("totalCount", notesListJSON.length());
      writeBackToClient( new JSONSuccess( results ) )
    } catch (IOException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
    } catch (SerializationException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects", e);
    } catch (JSONException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects into a JSON object", e);
    }
  }
View Full Code Here

   
    try {
      objnote = DAOFactory.getObjNoteDAO().getExecutionNotesByOwner(obj.getId(), execIdentifier, owner);
    } catch (Exception e) {
      logger.error("Cannot load notes for document [id: " + obj.getId() + ", label: " + obj.getLabel() + ", name: " + obj.getName() + "]", e);
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot load notes", e);
    }
   
    try {
      JSONObject noteJSON = new JSONObject();
      JSONObject results = new JSONObject();
      if (objnote != null)
        noteJSON = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( objnote,null );
      //results.put("results", noteJSON);
      writeBackToClient( new JSONSuccess( noteJSON ) );
    } catch (IOException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to write back the responce to the client", e);
    } catch (SerializationException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects", e);
    } /*catch (JSONException e) {
      throw new SpagoBIServiceException(SERVICE_NAME, "Cannot serialize objects into a JSON object", e);
    }*/
  }
 
View Full Code Here

    try {
      modelDao = DAOFactory.getModelDAO();
      modelDao.setUserProfile(getUserProfile());
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    Locale locale = getLocale();

    String serviceType = this.getAttributeAsString(MESSAGE_DET);
    logger.debug("Service type "+serviceType);
   
    if (serviceType != null && serviceType.equalsIgnoreCase(MODELS_LIST)) {
     
      try {       
        List modelRootsList = modelDao.loadModelsRoot();
       
        logger.debug("Loaded models list");
        JSONArray modelsListJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(modelRootsList,locale);
        JSONObject modelsResponseJSON = createJSONResponseModelsList(modelsListJSON, new Integer(6));

        writeBackToClient(new JSONSuccess(modelsResponseJSON));

      } 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)) {
     
      try
       
        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));

      } 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_SAVE)) {
      JSONArray nodesToSaveJSON = getAttributeAsJSONArray(NODES_TO_SAVE);
      List<Model> modelNodes = null;
      if(nodesToSaveJSON != null){
        try {
          modelNodes = deserializeNodesJSONArray(nodesToSaveJSON);
         
          //save them
          JSONObject response = saveModelNodes(modelNodes);
          writeBackToClient(new JSONSuccess(response));
         
        } catch (Exception e) {
          logger.error(e.getMessage(), e);
          writeErrorsBackToClient();
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception saving model nodes", e);
        }
      }
     
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(MODEL_NODE_DELETE)) {
     
      Integer modelId = getAttributeAsInteger("modelId");
      logger.warn("DELETING NODE WITH MODEL_ID:"+modelId);
      try {
        modelDao.deleteModel(modelId);
        logger.debug("Model deleted");
        writeBackToClient( new JSONSuccess("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving model to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving model to delete", e);
      }
     
     
    }else if(serviceType == null){
      try {
        List nodeTypesNodes = DAOFactory.getDomainDAO().loadListDomainsByType(MODEL_DOMAIN_TYPE_NODE);
        List nodeTypesRoot = DAOFactory.getDomainDAO().loadListDomainsByType(MODEL_DOMAIN_TYPE_ROOT);
        List nodeTypes = new ArrayList();
        nodeTypes.addAll(nodeTypesNodes);
        nodeTypes.addAll(nodeTypesRoot);
        getSessionContainer().setAttribute("nodeTypesList", nodeTypes);
        List kpiTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(KPI_DOMAIN_TYPE);
        getSessionContainer().setAttribute("kpiTypesList", kpiTypesList);
        List thrSeverityTypes = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_SEVERITY_TYPE);
        getSessionContainer().setAttribute("thrSeverityTypes", thrSeverityTypes);
        List measureTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(MEASURE_DOMAIN_TYPE);
        getSessionContainer().setAttribute("measureTypesList", measureTypesList);
        List metricScaleTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(METRIC_SCALE_DOMAIN_TYPE);
        getSessionContainer().setAttribute("metricScaleTypesList", metricScaleTypesList);
        List thrTypesList = DAOFactory.getDomainDAO().loadListDomainsByType(THRESHOLD_DOMAIN_TYPE);
        getSessionContainer().setAttribute("thrTypesList", thrTypesList);
        // Add Udp Values to sessionContainer
        List udpModelList = DAOFactory.getUdpDAO().loadAllByFamily("Model");
        getSessionContainer().setAttribute("udpModelList", udpModelList);
        List udpKpiList = DAOFactory.getUdpDAO().loadAllByFamily("Kpi");
        getSessionContainer().setAttribute("udpKpiList", udpKpiList);

      } catch (EMFUserError e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception retrieving model types", e);
      }
    }
    logger.debug("OUT");
View Full Code Here

      dataSetConfig = null;
      try {
        dataSetSupplier = new DataSetSupplier();           
        dataSetConfig = dataSetSupplier.getDataSetByLabel(dataSetLabel);
      } catch(Throwable t) {
        throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(dataSetConfig, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
     
      dataSet = DataSetFactory.getDataSet( dataSetConfig );
      dataSet.loadData();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
         
     
      dataSetJSON = null;
      try {
        dataSetJSON = (JSONObject)SerializerFactory.getSerializer("application/json").serialize( dataStore, null );
      } catch (SerializationException e) {
        throw new SpagoBIServiceException("Impossible to serialize datastore", e);
      }
     
      try {
        writeBackToClient( new JSONSuccess( dataSetJSON, callback ) );
      } catch (IOException e) {
        throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
      }
    } catch (Throwable t) {
      SpagoBIServiceExceptionHandler.getInstance().getWrappedException(SERVICE_NAME, t);
    } finally {
      logger.debug("OUT");
View Full Code Here

    try {
      daoGoal = DAOFactory.getGoalDAO();

    } catch (Exception e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
   
    String serviceType = this.getAttributeAsString(MESSAGE_DET);
   
    if (serviceType != null && serviceType.equalsIgnoreCase(GOAL_NODE_CHILD)) {
      logger.debug("Loading the children for the goal with id:");
      try{
        Integer nodeId =  getAttributeAsInteger("nodeId");
        logger.debug("nodeId:"+ nodeId);
        List<GoalNode> children = daoGoal.getChildrenNodes(nodeId);
        JSONArray ja = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(children,  getLocale());
        writeBackToClient(new JSONSuccess(ja));       
      } catch (NumberFormatException e) {
        logger.debug("The goal node "+ getAttribute("nodeId") +" is not saved yet ");
        try{
          writeBackToClient(new JSONSuccess(new JSONArray()));
        }catch (IOException io){
          logger.debug("Error getting the child of the goal node");
          throw new SpagoBIServiceException(SERVICE_NAME, "Error getting the child of the goal node",e);
        }
      } catch (Exception ee){
        logger.debug("Error getting the child of the goal node");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error getting the child of the goal node",ee);
      }
      logger.debug("Loaded children");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(OU_GOAL_ROOT)) {
      logger.debug("Loading the root node of the goal tree with:");
      JSONObject jo;
      Integer goalId =  getAttributeAsInteger("goalId");
      Integer ouId =  getAttributeAsInteger("ouId");
      logger.debug("goalId: "+goalId+" ,ouId "+ouId);
      GoalNode root = daoGoal.getRootNode(goalId, ouId);
      try{
        if(root!=null){
          jo = (JSONObject) SerializerFactory.getSerializer("application/json").serialize(root, getLocale());
        }else{
          jo = new JSONObject();
        }
        writeBackToClient(new JSONSuccess(jo))
      } catch (Exception e){
        logger.debug("Error getting the root of the goal");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error getting the root of the goal",e);
      }
      logger.debug("Goal root loaded");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(INSERT_GOAL_NODE)) {
      logger.debug("Adding the goal node: ");
      JSONObject JSONGoal =  getAttributeAsJSONObject("goalNode");
      Integer goalId =  getAttributeAsInteger("goalId");
      Integer ouId =  getAttributeAsInteger("ouId");
      logger.debug("JSONGoal: "+JSONGoal);
      try{
        GoalNode gn = insertGoalNode(JSONGoal, null, goalId, ouId);
        JSONObject jo = (JSONObject) SerializerFactory.getSerializer("application/json").serialize(gn, getLocale());
        writeBackToClient(new JSONSuccess(jo))
      } catch (Exception e){
        logger.debug("Error inserting the goal node");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error inserting the goal node",e);
      }
      logger.debug("Node added");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(INSERT_GOAL_DETAILS)) {
      logger.debug("Adding the details of the goal node: ");
      List<GoalKpi> kpisList = new ArrayList<GoalKpi>();
      JSONObject JSONGoalDetails =  getAttributeAsJSONObject("goalDetails");
      JSONObject goalNode =  JSONGoalDetails.optJSONObject("goalNode");
      Integer goalNodeId =  goalNode.optInt("id");
      String goalDesc =  goalNode.optString("goalDesc");
      String goalName =  goalNode.optString("name");
      logger.debug(goalNode);
      GoalNode gn = new GoalNode(goalName, "", goalDesc, null, null);
      gn.setId(goalNodeId);
     
      JSONArray kpis =  JSONGoalDetails.optJSONArray("kpis");
      try{
        for(int i=0; i<kpis.length(); i++){
          kpisList.add(deserializeKpiNode((JSONObject)kpis.get(i), goalNodeId));
        }
        daoGoal.ereseGoalKpis(goalNodeId);
        daoGoal.insertGoalKpis(kpisList, goalNodeId);
        daoGoal.updateGoalNode(gn);
        writeBackToClient(new JSONAcknowledge())
      } catch (Exception e){
        logger.debug("Error adding the details to the goal node");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error adding the details to the goal node",e);
      }
      logger.debug("Added the goal details");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(UPDATE_GOAL_NAME)) {
      logger.debug("Updating the name of the goal with id:");
      Integer goalNode =  getAttributeAsInteger("goalId");
      logger.debug("id:"+goalNode);
      String goalName =  getAttributeAsString("newName");
     
      daoGoal.updateGoalName(goalNode, goalName);
      try{
        writeBackToClient(new JSONAcknowledge());
      } catch (IOException e){
        logger.debug("Error sending the response after the erese of the goal node");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal node",e);
      }
      logger.debug("Goal name updated");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(ERESE_GOAL_NODE)) {
      logger.debug("Removing the goal node with id:");
      Integer goalNode =  getAttributeAsInteger("id");
      logger.debug("id:"+goalNode);
      daoGoal.ereseGoalNode(goalNode);
      try{
        writeBackToClient(new JSONAcknowledge());
      } catch (IOException e){
        logger.debug("Error sending the response after the erese of the goal node");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal node",e);
      }
      logger.debug("Goal removed");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(KPI_GOAL_ROOT_NODE)) {
      logger.debug("Loading the kpi model instances linked to the goal: ");
      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", "");
              }else{
                modelInstanceJSON.put("threshold1", ""+listGoalKpi.get(i).getThreshold1());
              }
              modelInstanceJSON.put("sign2", ""+listGoalKpi.get(i).getSign2());
              if(listGoalKpi.get(i).getSign2()==110){
                modelInstanceJSON.put("threshold2", "");
              }else{
                modelInstanceJSON.put("threshold2", ""+listGoalKpi.get(i).getThreshold2());
              }
              break;
            }
          }
        }
        writeBackToClient( new JSONSuccess( modelInstanceJSON ) );
      } catch (Exception e) {
        logger.debug("Impossible to serialize the responce to the client");
        throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to serialize the responce to the client", e);
      }
      logger.debug("kpi model instances loaded.");
    }
 
   
    if (serviceType != null && serviceType.equalsIgnoreCase(GOAL_ERESE)) {
      logger.debug("Removing the goal with id:");
      Integer goalId = getAttributeAsInteger("goalId");
      logger.debug(goalId);
      logger.debug(goalId);
      daoGoal.eraseGoal(goalId);
      try{
        writeBackToClient( new JSONAcknowledge() );
      } catch (IOException e){
        logger.debug("Error sending the response after the erese of the goal");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal",e);
      }
      logger.debug("Goal removed");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(GOAL_INSERT)) {
      logger.debug("Adding the goal: ");
      JSONObject goalJSON = getAttributeAsJSONObject(GOAL);
      logger.debug(goalJSON);
      try{
        Goal goal = deserializeGoal(goalJSON);
        daoGoal.insertGoal(goal);
        writeBackToClient( new JSONAcknowledge() );
      } catch (Exception e){
        logger.debug("Error inserting the goal");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error inserting the goal",e);
      }
      logger.debug("Goal added");
    }
    if (serviceType != null && serviceType.equalsIgnoreCase(GOALS_LIST)) {
      logger.debug("Getting the list of the goals");
      try{
      List<Goal> goals = daoGoal.getGoalsList();
      JSONArray jo = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(goals,  getLocale());
      JSONObject grantsJSONObject = new JSONObject();
      grantsJSONObject.put("rows",jo);
      writeBackToClient(new JSONSuccess(grantsJSONObject))
      } catch (Exception e){
        logger.debug("Error getting the goals list");
        throw new SpagoBIServiceException(SERVICE_NAME, "Error getting the goals list",e);
      }
      logger.debug("List loaded");
    }
   
  }
View Full Code Here

    try {
      perDao = DAOFactory.getPeriodicityDAO();
      perDao.setUserProfile(getUserProfile());
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    Locale locale = getLocale();

    String serviceType = this.getAttributeAsString(MESSAGE_DET);
    logger.debug("Service type "+serviceType);
    if (serviceType != null && serviceType.equalsIgnoreCase(PERIODICTIES_LIST)) {
     
      try
        List periodicities = perDao.loadPeriodicityList();
        logger.debug("Loaded periodicities list");
        JSONArray periodicitiesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(periodicities, locale);
        JSONObject periodicitiesResponseJSON = createJSONResponsePeriodicities(periodicitiesJSON);

        writeBackToClient(new JSONSuccess(periodicitiesResponseJSON));

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving users", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving users", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(PERIODICITY_INSERT)) {
     
      String id = getAttributeAsString(ID);
      String name = getAttributeAsString(NAME);
      String months = getAttributeAsString(MONTHS);
      String days = getAttributeAsString(DAYS);
      String hours = getAttributeAsString(HOURS);
      String minutes = getAttributeAsString(MINUTES);   

      if (name != null) {
        Periodicity per = new Periodicity();
        per.setName(name);
       
        if(months!=null && !months.equals("")){
          per.setMonths(new Integer(months));
        }else{
          per.setMonths(new Integer("0"));
        }
        if(days!=null && !days.equals("")){
          per.setDays(new Integer(days));
        }else{
          per.setDays(new Integer("0"));
        }
        if(hours!=null && !hours.equals("")){
          per.setHours(new Integer(hours));
        }else{
          per.setHours(new Integer("0"));
        }
        if(minutes!=null && !minutes.equals("")){
          per.setMinutes(new Integer(minutes));
        }else{
          per.setMinutes(new Integer("0"));
        }     
       
        try {
          if(id != null && !id.equals("") && !id.equals("0")){             
            per.setIdKpiPeriodicity(Integer.valueOf(id));
            perDao.modifyPeriodicity(per);
            logger.debug("Resource "+id+" updated");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", id);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }else{
            Integer perID = perDao.insertPeriodicity(per);
            logger.debug("New Resource inserted");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", perID);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }

        } catch (Throwable e) {
          logger.error(e.getMessage(), e);
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception occurred while saving new resource", e);
        }
               
      }else{
        logger.error("Resource name, code or type are missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please fill resource name, code and type");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(PERIODICITY_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        perDao.deletePeriodicity(id);
        logger.debug("Resource deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving resource to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving resource to delete", e);
      }
    }
    logger.debug("OUT");
  }
View Full Code Here

    try {
      orUnitDao = DAOFactory.getOrganizationalUnitDAO();
      orUnitDao.setUserProfile(getUserProfile());
    } catch (Exception e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
   
    try {
      String serviceType = this.getAttributeAsString(MESSAGE_DET);
      if (serviceType != null && serviceType.equalsIgnoreCase(GRANT_DEF)) {
        logger.debug("Loading the grant..");
        Integer grantId =  getAttributeAsInteger("grantId");
        getGrant(grantId);
        logger.debug("Grant loaded.");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(GRANT_LIST)) {
        logger.debug("Loading the list of grants..");
        getGrantsList();
        logger.debug("List of grant loaded.");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_LIST)) {
        logger.debug("Loading the list of ous..");
        getHierarchiesList();
        logger.debug("List of ous loaded.");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_CHILDS_LIST)) {
        Integer grantId;
        Integer nodeId =  getAttributeAsInteger("nodeId");
       
        try{
          if(getAttribute("grantId").equals("")){
            grantId = null;
            logger.debug("Loading the list of ous childs of the node with id"+nodeId+"...");
          }
          grantId =  getAttributeAsInteger("grantId");
          logger.debug("Loading the list of ous childs of the node with id"+nodeId+" and grant "+grantId+"...");
        }catch(Throwable e){
          grantId = null;
          logger.debug("Loading the list of ous childs of the node with id"+nodeId+"...");
        }
        getOUChildrenNodes(nodeId, grantId);
        logger.debug("Loaded the list of ous childs of the node with id"+nodeId+".");
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_HIERARCHY_AND_ROOT)) {
       
        logger.debug("Loading the grant..");
        Integer grantId =  getAttributeAsInteger("grantId");
        OrganizationalUnitGrant grant = orUnitDao.getGrant(grantId);
        logger.debug("Grant loaded.");

        Integer hierarchyId = grant.getHierarchy().getId();
        OrganizationalUnitNode ou = orUnitDao.getRootNode(hierarchyId);
       
        try {
          JSONObject hierarchyWithRoot = new JSONObject();
          hierarchyWithRoot.put("ouRootName",ou.getOu().getName());
          hierarchyWithRoot.put("ouRootId",ou.getNodeId());
          writeBackToClient( new JSONSuccess( hierarchyWithRoot ) );
        } catch (Exception e) {
          throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to serialize the responce to the client", e);
        }

        logger.debug("Loaded ou root of grant with id"+grantId);
      }else if (serviceType != null && serviceType.equalsIgnoreCase(OU_HIERARCHY_ROOT)) {
        Integer hierarchyId = getAttributeAsInteger("hierarchyId");
        Integer modelInstanceId = getAttributeAsInteger("modelInstanceId");
        List<Integer> modelInstances = new ArrayList<Integer>();

        Integer grantId;
        try{
          grantId =  getAttributeAsInteger("grantId");
          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);
            }
          }

          JSONArray modelChildrenJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(children,  getLocale());
         
         
          if(goalNodeId!=null){
            List<GoalKpi> listGoalKpi = DAOFactory.getGoalDAO().getGoalKpi(goalNodeId);
            for(int i=0; i<modelChildrenJSON.length(); i++){
              for(int j=0; j<listGoalKpi.size(); j++){
                if(listGoalKpi.get(j).getModelInstanceId().equals( children.get(i).getId())){
                  ((JSONObject)modelChildrenJSON.get(i)).put("weight1", ""+listGoalKpi.get(j).getWeight1());
                  ((JSONObject)modelChildrenJSON.get(i)).put("weight2", ""+listGoalKpi.get(j).getWeight2());
                  ((JSONObject)modelChildrenJSON.get(i)).put("threshold1", ""+listGoalKpi.get(j).getThreshold1());
                  ((JSONObject)modelChildrenJSON.get(i)).put("threshold2", ""+listGoalKpi.get(j).getThreshold2());
                  ((JSONObject)modelChildrenJSON.get(i)).put("sign1", ""+listGoalKpi.get(j).getSign1());
                  ((JSONObject)modelChildrenJSON.get(i)).put("sign2", ""+listGoalKpi.get(j).getSign2());
                  break;
                }
              }
            }
          }
          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);
        }


        logger.debug("Loaded the list of ous childs of the node with id"+ouNodeId+".");
View Full Code Here

TOP

Related Classes of it.eng.spagobi.utilities.exceptions.SpagoBIServiceException

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.