Package it.eng.spagobi.utilities.service

Examples of it.eng.spagobi.utilities.service.JSONSuccess


          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 dsID = dsDao.insertDataSet(ds);
          GuiGenericDataSet dsSaved = dsDao.loadDataSetById(dsID);
          logger.debug("New Resource inserted");
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("responseText", "Operation succeded");
          attributesResponseSuccessJSON.put("id", dsID);
          if(dsSaved!=null){
            GuiDataSetDetail dsDetailSaved = dsSaved.getActiveDetail();
            attributesResponseSuccessJSON.put("dateIn", dsDetailSaved.getTimeIn());
            attributesResponseSuccessJSON.put("userIn", dsDetailSaved.getUserIn());
            attributesResponseSuccessJSON.put("versId", dsDetailSaved.getDsHId());
            attributesResponseSuccessJSON.put("versNum", dsDetailSaved.getVersionNum());
          }
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
        }
      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.saveDsError", e);
      }
View Full Code Here


  private void datatsetTest(IDataSetDAO dsDao, Locale locale){
    try {
      JSONObject dataSetJSON = datasetTest();
      if(dataSetJSON!=null){
        try {
          writeBackToClient( new JSONSuccess( dataSetJSON ) );
        } catch (IOException e) {
          throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
        }
      }else{
        throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.testError");
View Full Code Here

      JSONObject version = itemJSON.getJSONObject(0);
      JSONObject attributesResponseSuccessJSON = new JSONObject();
      attributesResponseSuccessJSON.put("success", true);
      attributesResponseSuccessJSON.put("responseText", "Operation succeded");
      attributesResponseSuccessJSON.put("result", version);
      writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
    } catch (Throwable e) {
      logger.error("Exception occurred while retrieving dataset to restore", e);
      throw new SpagoBIServiceException(SERVICE_NAME,"sbi.ds.restoreVersionError", e);
    }
  }
View Full Code Here

      fieldsJSON = queryJSON.getJSONArray(QuerySerializationConstants.FIELDS);     
      resultsJSON = new JSONObject();
      resultsJSON.put("results", fieldsJSON);
     
      try {
        writeBackToClient( new JSONSuccess( resultsJSON ) );
      } catch (IOException e) {
        throw new SpagoBIEngineServiceException(getActionName(), "Impossible to write back the responce to the client [" + resultsJSON.toString(2)+ "]", e);
      }
     
    } catch(Throwable t) {
View Full Code Here

           
      dataSetWriter = new JSONDataWriter();
      gridDataFeed = (JSONObject)dataSetWriter.write(dataStore);
     
      try {
        writeBackToClient( new JSONSuccess(gridDataFeed) );
      } catch (IOException e) {
        String message = "Impossible to write back the responce to the client";
        throw new SpagoBIEngineServiceException(getActionName(), message, e);
      }
     
View Full Code Here

       
        nodes.put(node);
      }
     
      try {
        writeBackToClient( new JSONSuccess(nodes) );
      } catch (IOException e) {
        String message = "Impossible to write back the responce to the client";
        throw new SpagoBIEngineServiceException(getActionName(), message, e);
      }
     
View Full Code Here

      }
      */
     
     
      try {
        writeBackToClient( new JSONSuccess(toReturn) );
      } catch (IOException e) {
        String message = "Impossible to write back the responce to the client";
        throw new SpagoBIEngineServiceException(getActionName(), message, e);
      }
     
View Full Code Here

        //ArrayList<Role> roles = (ArrayList<Role>)roleDao.loadAllRoles();
        logger.debug("Loaded roles list");
        JSONArray rolesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(roles,  locale);
        JSONObject rolesResponseJSON = createJSONResponseRoles(rolesJSON,totalResNum);

        writeBackToClient(new JSONSuccess(rolesResponseJSON));

      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving roles", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(ROLE_INSERT)) {
      String name = getAttributeAsString(NAME);
      String roleTypeCD = getAttributeAsString(ROLE_TYPE_CD);
      String code = getAttributeAsString(CODE);
      String description = getAttributeAsString(DESCRIPTION);
     
      Boolean saveSubobjects= getAttributeAsBoolean(SAVE_SUBOBJECTS);
      Boolean seeSubobjects= getAttributeAsBoolean(SEE_SUBOBJECTS);
      Boolean seeViewpoints= getAttributeAsBoolean(SEE_VIEWPOINTS);
      Boolean seeSnapshots= getAttributeAsBoolean(SEE_SNAPSHOTS);
      Boolean seeNotes= getAttributeAsBoolean(SEE_NOTES);
      Boolean sendMail= getAttributeAsBoolean(SEND_MAIL);
      Boolean saveIntoPersonalFolder= getAttributeAsBoolean(SAVE_INTO_PERSONAL_FOLDER);
      Boolean saveRememberMe= getAttributeAsBoolean(SAVE_REMEMBER_ME);
      Boolean seeMetadata= getAttributeAsBoolean(SEE_METADATA);
      Boolean saveMetadata= getAttributeAsBoolean(SAVE_METADATA);
      Boolean buildQbeQuery= getAttributeAsBoolean(BUILD_QBE_QUERY);

      if (name != null) {
        //checks for unique role name
        try {
          Role existentRole = DAOFactory.getRoleDAO().loadByName(name);
          if(existentRole != null){
            String id = getAttributeAsString(ID);
            if(id == null || id.equals("") || id.equals("0")){
              throw new SpagoBIServiceException(SERVICE_NAME,  "Role Name already present.");
            }
          }
        } catch (EMFUserError e1) {
          logger.error(e1.getMessage(), e1);
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception occurred while retrieving role by name", e1);
        }

          List<Domain> domains = (List<Domain>)getSessionContainer().getAttribute("roleTypes");

          HashMap<String, Integer> domainIds = new HashMap<String, Integer> ();
          for(int i=0; i< domains.size(); i++){
            domainIds.put(domains.get(i).getValueCd(), domains.get(i).getValueId());
          }
         
          Integer roleTypeID = domainIds.get(roleTypeCD);
          if(roleTypeID == null){
            logger.error("Role type CD not existing");
            throw new SpagoBIServiceException(SERVICE_NAME,  "Role Type ID is undefined");
          }
         
        Role role = new Role();
        role.setCode(code);
        role.setDescription(description);
        role.setName(name);
        role.setRoleTypeCD(roleTypeCD);
        role.setRoleTypeID(roleTypeID);
        role.setIsAbleToBuildQbeQuery(buildQbeQuery);
        role.setIsAbleToSaveIntoPersonalFolder(saveIntoPersonalFolder);
        role.setIsAbleToSaveMetadata(saveMetadata);
        role.setIsAbleToSaveRememberMe(saveRememberMe);
        role.setIsAbleToSaveSubobjects(saveSubobjects);
        role.setIsAbleToSeeMetadata(seeMetadata);
        role.setIsAbleToSeeNotes(seeNotes);
        role.setIsAbleToSeeSnapshots(seeSnapshots);
        role.setIsAbleToSeeSubobjects(seeSubobjects);
        role.setIsAbleToSeeViewpoints(seeViewpoints);
        role.setIsAbleToSendMail(sendMail);
        try {
          String id = getAttributeAsString(ID);
          if(id != null && !id.equals("") && !id.equals("0")){             
            role.setId(Integer.valueOf(id));
            roleDao.modifyRole(role);
            logger.debug("Role "+id+" updated");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }else{
            Integer roleID = roleDao.insertRoleComplete(role);
            logger.debug("New Role inserted");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", roleID);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }

        } catch (Throwable e) {
          logger.error(e.getMessage(), e);
          throw new SpagoBIServiceException(SERVICE_NAME,
              "Exception occurred while saving new role",
              e);
        }

      }else{
        logger.error("Missing role name");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please enter role name");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(ROLE_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        Role aRole = roleDao.loadByID(id);
        roleDao.eraseRole(aRole);
        logger.debug("Role deleted");
        writeBackToClient( new JSONAcknowledge("Operazion succeded") );

      } catch (Throwable e) {
        logger.error("Exception occurred while deleting role", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while deleting role",
            e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(ROLES_SYNCHRONIZATION)) {
      try {
        RoleSynchronizer roleSynch = new RoleSynchronizer();
        roleSynch.synchronize();
        logger.debug("Roles synchronized");
        JSONObject attributesResponseSuccessJSON = new JSONObject();
        attributesResponseSuccessJSON.put("success", true);
        attributesResponseSuccessJSON.put("responseText", "Operation succeded");
        writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );

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

                  JSONObject attributesResponseSuccessJSON = new JSONObject();
                  attributesResponseSuccessJSON.put("success", false);
                  attributesResponseSuccessJSON.put("message", "Either the field name is blank or it exceeds maxlength or it is not alfanumeric");
                  attributesResponseSuccessJSON.put("data", "[]");
                 
                  writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );

                  return;
 
                }
              }
              if(!samples.isNull(DESCRIPTION)){
                description = samples.getString(DESCRIPTION);
 
                if (GenericValidator.isBlankOrNull(description) ||
                    !GenericValidator.matchRegexp(description, ALPHANUMERIC_STRING_REGEXP_NOSPACE) ||
                        !GenericValidator.maxLength(description, descriptionMaxLenght)){
                  logger.error("Either the field description is blank or it exceeds maxlength or it is not alfanumeric");
 
                  EMFValidationError e = new EMFValidationError(EMFErrorSeverity.ERROR, description, "9000","");
                  getHttpResponse().setStatus(404)
                  JSONObject attributesResponseSuccessJSON = new JSONObject();
                  attributesResponseSuccessJSON.put("success", false);
                  attributesResponseSuccessJSON.put("message", "Either the field description is blank or it exceeds maxlength or it is not alfanumeric");
                  attributesResponseSuccessJSON.put("data", "[]");
                  writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
                  return;
                }
              }
           
              SbiAttribute attribute = new SbiAttribute();
              if(description!=null){
                attribute.setDescription(description);
              }
              if(name!=null){
                attribute.setAttributeName(name);
              }
              boolean isNewAttrForRes = true;
              if(idStr!=null && !idStr.equals("")){
                Integer attributeId = new Integer(idStr);
                attribute.setAttributeId(attributeId.intValue());
                isNewAttrForRes = false;
              }
              Integer attrID = attrDao.saveOrUpdateSbiAttribute(attribute);
              logger.debug("Attribute updated");

              ArrayList<SbiAttribute> attributes = new ArrayList<SbiAttribute> ();
              attribute.setAttributeId(attrID);
              attributes.add(attribute);
             
              getAttributesListAdded(locale,attributes,isNewAttrForRes, attrID);

            }
            //else the List of attributes will be sent to the client
          }else{
            getAttributesList(locale,attrDao);
          }
        }else{
          getAttributesList(locale,attrDao);
        }

      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        getHttpResponse().setStatus(404);               
        try {
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("message", "Exception occurred while saving attribute");
          attributesResponseSuccessJSON.put("data", "[]");
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) )
        } catch (IOException e1) {
          logger.error(e1.getMessage(), e1);
        } catch (JSONException e2) {
          logger.error(e2.getMessage(), e2);
        }
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving attributes", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(ATTR_DELETE)) {
     
      String idStr = null;
      try {
        BufferedReader b =httpRequest.getReader();
        if(b!=null){
          String respJsonObject = b.readLine();
          if(respJsonObject!=null){
            JSONObject responseJSON = deserialize(respJsonObject);
            idStr = responseJSON.getString(SAMPLES);
          }
        }
       
      } catch (IOException e1) {
        logger.error("IO Exception",e1);
        e1.printStackTrace();
      } catch (SerializationException e) {
        logger.error("Deserialization Exception",e);
        e.printStackTrace();
      } catch (JSONException e) {
        logger.error("JSONException",e);
        e.printStackTrace();
      }
      if(idStr!=null && !idStr.equals("")){
        Integer id = new Integer(idStr);
        try {
          attrDao.deleteSbiAttributeById(id);
          logger.debug("Attribute deleted");
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("message", "");
          attributesResponseSuccessJSON.put("data", "[]");
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
 
        } catch (Throwable e) {
          logger.error("Exception occurred while deleting attribute", e);
          getHttpResponse().setStatus(404);               
          try {
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", false);
            attributesResponseSuccessJSON.put("message", "Exception occurred while deleting attribute");
            attributesResponseSuccessJSON.put("data", "[]");
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) )
          } catch (IOException e1) {
            logger.error(e1.getMessage(), e1);
          } catch (JSONException e2) {
            // TODO Auto-generated catch block
            logger.error(e2.getMessage(), e2);
View Full Code Here

    ArrayList<SbiAttribute> attributes = (ArrayList<SbiAttribute>)attrDao.loadSbiAttributes();
    logger.debug("Loaded attributes list");
    JSONArray attributesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(attributes,  locale);
    JSONObject attributesResponseJSON = createJSONResponseAttributes(attributesJSON);

    writeBackToClient(new JSONSuccess(attributesResponseJSON));

  }
View Full Code Here

TOP

Related Classes of it.eng.spagobi.utilities.service.JSONSuccess

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.