Package com.jamonapi

Examples of com.jamonapi.Monitor


     * @throws EMFInternalError
     * @throws EMFUserError
     */
    private void checkRequestCorrectness(String user, BIObject biobj, HashMap parameters) throws SecurityException, EMFInternalError, EMFUserError {
      logger.debug("IN: user = [" + user + "], biobjectid = [" + biobj + "], parameters = [" + parameters + "]");
      Monitor monitor =MonitorFactory.start("spagobi.service.ContentSupplier.checkRequestCorrectness");
      try {
      if (biobj == null) {
        logger.error("No document specified");
        return;
      }
      logger.debug("Input document: id=[" + biobj.getId() + "], name=[" + biobj.getName() + "], label=[" + biobj.getLabel() + "]");
        // creates the user profile
      IEngUserProfile profile =null;
      try{
        profile = UserUtilities.getUserProfile(user);
        } catch (Exception e) {
          logger.error("An error occurred while creating the profile of user [" + user + "]");
          throw new SecurityException("An error occurred while creating the profile of user [" + user + "]", e);
        }       

        // Check if the user can execute the document
        boolean canSee = ObjectsAccessVerifier.canSee(biobj, profile);
        if (!canSee) {
          logger.error("Current user cannot execute the required document");
          throw new SecurityException("Current user cannot execute the required document");
        }
        Integer id = biobj.getId();
        // get the correct roles for execution
      List correctRoles = null;
      if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_DEV)
          || profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_USER)
          || profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN))
        correctRoles = DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(id, profile);
      else
        correctRoles = DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(id);
      logger.debug("correct roles for execution retrived " + correctRoles);
      if (correctRoles == null || correctRoles.size() == 0) {
        logger.error("Object cannot be executed by no role of the user");
        throw new SecurityException("Object cannot be executed by no role of the user");
      }
       
        if (parameters == null) {
          logger.debug("Input parameters map is null. It will be considered as an empty map");
          parameters = new HashMap();
        }
       
        boolean parametersAreCorrect = false;
       
        String roleName = (String) parameters.get("SBI_EXECUTION_ROLE");
        if (roleName != null) {
          // if a role is specified, check if it is a valid role for execution
          logger.debug("Execution role specified: " + roleName);
          if (!correctRoles.contains(roleName)) {
            if (correctRoles == null || correctRoles.size() == 0) {
              logger.error("Role [] is not a valid role for the execution of document with id = [" + biobj.getId()
                  + "], label = [" + biobj.getLabel() + "]");
              throw new SecurityException("Role [] is not a valid role for the execution of document with id = [" + biobj.getId()
                  + "], label = [" + biobj.getLabel() + "]");
            }
          }
          // check if parameter values are correct for the role
          parametersAreCorrect = checkParametersErrors(profile, biobj.getId(), roleName, parameters);
        } else {
          // if a role is not specified, iterate on valid roles
          logger.debug("Execution role not specified: iterating on all available roles...");
          Iterator it = correctRoles.iterator();
          while (it.hasNext()) {
            roleName = it.next().toString();
            // check if parameter values are correct for the role
            parametersAreCorrect = checkParametersErrors(profile, biobj.getId(), roleName, parameters);
            if (parametersAreCorrect) {
              break;
            } else {
              logger.debug("Role " + roleName + " is NOT compatible with input parameters");
            }
          }
         
        }
       
        if (!parametersAreCorrect) {
           logger.error("Document cannot be executed by the user with the input parameters.");
           throw new SecurityException("Document cannot be executed by the user with the input parameters.");
        } else {
          logger.debug("Role " + roleName + " is compatible with input parameters");
        }
    } finally {
        logger.debug("OUT");
        monitor.stop();
    }
    }
View Full Code Here


    IStatement statement;
   
    Integer resultNumber;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor;
         
    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.executeQueryAction.totalTime");
     
      start = getAttributeAsInteger( START )
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
     
      limit = getAttributeAsInteger( LIMIT );
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
     
      groupFields = getAttributeAsJSONArray( GROUPBY_FIELDS );
      logger.debug("Parameter [" + GROUPBY_FIELDS + "] is equals to [" + groupFields + "]");
      Assert.assertNotNull(groupFields, "Parameter [" + GROUPBY_FIELDS + "] cannot be null");
      Assert.assertTrue(groupFields.length() > 0, "GroupBy fileds list cannot be empty");
           
      maxSize = QbeEngineConfig.getInstance().getResultLimit();     
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.value" + "] is equals to [" + (maxSize != null? maxSize: "none") + "]");
      isMaxResultsLimitBlocking = QbeEngineConfig.getInstance().isMaxResultLimitBlocking();
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.isBlocking" + "] is equals to [" + isMaxResultsLimitBlocking + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
     
      // STEP 1: modify the query according to the input that come from the form
      query = getEngineInstance().getQueryCatalogue().getFirstQuery();
     
      // ... query transformation goes here 
      logger.debug("Making a deep copy of the original query...");
      String store = ((JSONObject)SerializerFactory.getSerializer("application/json").serialize(query, getEngineInstance().getDataSource(), getLocale())).toString();
      Query copy = SerializerFactory.getDeserializer("application/json").deserializeQuery(store, getEngineInstance().getDataSource());
      logger.debug("Deep copy of the original query produced");
     
      String jsonEncodedFormState = getAttributeAsString( FORM_STATE );
      logger.debug("Form state retrieved as a string: " + jsonEncodedFormState);
      JSONObject formState = new JSONObject(jsonEncodedFormState);
      logger.debug("Form state converted into a valid JSONObject: " + formState.toString(3));
      JSONObject template = (JSONObject) getEngineInstance().getFormState().getConf();
      logger.debug("Form viewer template retrieved.");
     
      FormViewerQueryTransformer formViewerQueryTransformer = new FormViewerQueryTransformer();
      formViewerQueryTransformer.setFormState(formState);
      formViewerQueryTransformer.setTemplate(template);
      logger.debug("Applying Form Viewer query transformation...");
      query = formViewerQueryTransformer.execTransformation(copy);
      logger.debug("Applying Form Viewer query transformation...");
     
      updatePromptableFiltersValue(query);
      getEngineInstance().setActiveQuery(query);
     
     
      // STEP 2: prepare statment and obtain the corresponding sql query
      statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
     
      //String jpaQueryStr = statement.getQueryString();
      String sqlQuery = statement.getSqlQueryString();
     
      UserProfile userProfile = (UserProfile)getEnv().get(EngineConstants.ENV_USER_PROFILE);
     
     
      // STEP 3: transform the sql query
      GroupByQueryTransformer transformer = new GroupByQueryTransformer();
      List selectFields = SqlUtils.getSelectFields(sqlQuery);
     
      for(int i = 0; i < groupFields.length(); i++) {
        String groupByField = groupFields.getString(i);
        int fieldIndex = query.getSelectFieldIndex(groupByField);   
        Assert.assertTrue(fieldIndex >= 0 && fieldIndex <selectFields.size(), "Impossible to group on field [" + groupByField + "]");
        String[] f = (String[])selectFields.get(fieldIndex);       
        transformer.addGrouByColumn(f[1]!=null? f[1]:f[0], query.getSelectFieldByIndex(fieldIndex).getAlias());
      }
     
      // count column
      transformer.addAggregateColumn("*"/*f[1]!=null? f[1]:f[0]*/, "COUNT", "Records");
     
      // aggregate measures
      List dataMartSelectFields = query.getDataMartSelectFields(true);
      Iterator it = dataMartSelectFields.iterator();
      while (it.hasNext()) {
        DataMartSelectField field = (DataMartSelectField) it.next();
        int fieldIndex = query.getSelectFieldIndex(field.getUniqueName());       
        String[] f = (String[])selectFields.get(fieldIndex);
        IAggregationFunction aggregationFunction = field.getFunction();
        if (aggregationFunction != null && aggregationFunction != AggregationFunctions.NONE_FUNCTION) {
          transformer.addAggregateColumn(f[1]!=null? f[1]:f[0], aggregationFunction.getName(), field.getAlias());
        }
      }
     
      sqlQuery = (String)transformer.transformQuery(sqlQuery);
     
      // STEP 4: execute the query
     
      try {
        logger.debug("Executing query: [" + sqlQuery + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
       
        dataSet = new JDBCDataSet();
        ConnectionDescriptor connection = (ConnectionDescriptor)getDataSource().getConfiguration().loadDataSourceProperties().get("connection");
        DataSource dataSource = new DataSource();
        dataSource.setJndi(connection.getJndiName());
        dataSource.setHibDialectName(connection.getDialect());
        dataSource.setUrlConnection(connection.getUrl());
        dataSource.setDriver(connection.getDriverClass());
        dataSource.setUser(connection.getUsername());
        dataSource.setPwd(connection.getPassword());
        dataSet.setDataSource(dataSource);
        dataSet.setQuery(sqlQuery);
        dataSet.loadData(start, limit, -1);
        dataStore = dataSet.getDataStore();
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
     
      //dataStore.getMetaData().setProperty("resultNumber", new Integer( (int)dataStore.getRecordsCount() ));
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
      if (overflow) {
        logger.warn("Query results number [" + resultNumber + "] exceeds max result limit that is [" + maxSize + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: max result limit [" + maxSize + "] exceeded with SQL: " + sqlQuery);
      }
           
      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);
      }
     
    } catch(Throwable t) {
      errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
      errorHitsMonitor.stop();
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      if(totalTimeMonitor != null) totalTimeMonitor.stop();
      logger.debug("OUT");
   
View Full Code Here

    IStatement statement;
   
    Integer resultNumber;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor;
         
    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.executeQueryAction.totalTime");
     
      start = getAttributeAsInteger( START )
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
     
      limit = getAttributeAsInteger( LIMIT );
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
     
      filters = getAttributeAsJSONArray( FILTERS );
      logger.debug("Parameter [" + FILTERS + "] is equals to [" + filters + "]");
      Assert.assertNotNull(filters, "Parameter [" + FILTERS + "] cannot be null");
      Assert.assertTrue(filters.length() > 0, "GroupBy fileds list cannot be empty");
           
      maxSize = QbeEngineConfig.getInstance().getResultLimit();     
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.value" + "] is equals to [" + (maxSize != null? maxSize: "none") + "]");
      isMaxResultsLimitBlocking = QbeEngineConfig.getInstance().isMaxResultLimitBlocking();
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.isBlocking" + "] is equals to [" + isMaxResultsLimitBlocking + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
     
      // STEP 1: modify the query according to the input that come from the form
      query = getEngineInstance().getQueryCatalogue().getFirstQuery();     
      // ... query transformation goes here 
     
      logger.debug("Making a deep copy of the original query...");
      String store = ((JSONObject)SerializerFactory.getSerializer("application/json").serialize(query, getEngineInstance().getDataSource(), getLocale())).toString();
      Query copy = SerializerFactory.getDeserializer("application/json").deserializeQuery(store, getEngineInstance().getDataSource());
      logger.debug("Deep copy of the original query produced");
     
      String jsonEncodedFormState = getAttributeAsString( FORM_STATE );
      logger.debug("Form state retrieved as a string: " + jsonEncodedFormState);
      JSONObject formState = new JSONObject(jsonEncodedFormState);
      logger.debug("Form state converted into a valid JSONObject: " + formState.toString(3));
      JSONObject template = (JSONObject) getEngineInstance().getFormState().getConf();
      logger.debug("Form viewer template retrieved.");
     
      FormViewerQueryTransformer formViewerQueryTransformer = new FormViewerQueryTransformer();
      formViewerQueryTransformer.setFormState(formState);
      formViewerQueryTransformer.setTemplate(template);
      logger.debug("Applying Form Viewer query transformation...");
      query = formViewerQueryTransformer.execTransformation(copy);
      logger.debug("Applying Form Viewer query transformation...");
     
      updatePromptableFiltersValue(query);
      getEngineInstance().setActiveQuery(query);
     
     
     
      // STEP 2: prepare statment and obtain the corresponding sql query
      statement = getEngineInstance().getStatment()
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
      String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
      //logger.debug("Executable query (SQL): [" + sqlQuery + "]");
      UserProfile userProfile = (UserProfile)getEnv().get(EngineConstants.ENV_USER_PROFILE);
      //auditlogger.info("[" + userProfile.getUserId() + "]:: HQL: " + hqlQuery);
      //auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
     
      // STEP 3: transform the sql query
      FilterQueryTransformer transformer = new FilterQueryTransformer();
      List selectFields = SqlUtils.getSelectFields(sqlQuery);
     
      List queryFields = query.getDataMartSelectFields(true);
      for(int i = 0; i < queryFields.size(); i++) {
        ISelectField queryField = (ISelectField)queryFields.get(i);
        String[] f = (String[])selectFields.get(i)
        transformer.addColumn(f[1]!=null? f[1]:f[0], f[1]!=null? f[1]:f[0]);       
      }
     
      for(int i = 0; i < filters.length(); i++) {
        JSONObject filter = filters.getJSONObject(i);
        String columnName = filter.getString("columnName");
        String value = filter.getString("value");
       
        int fieldIndex = query.getSelectFieldIndex(columnName);       
        String[] f = (String[])selectFields.get(fieldIndex);   
        transformer.addFilter(f[1]!=null? f[1]:f[0], value);
      }
     
      sqlQuery = (String)transformer.transformQuery(sqlQuery);
     
      // put the query into session
      this.setAttributeInSession(LAST_DETAIL_QUERY, sqlQuery);
     
      // STEP 4: execute the query
     
      try {
        logger.debug("Executing query: [" + sqlQuery + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: SQL: " + sqlQuery);
       
        dataSet = new JDBCDataSet();
        //Session session = getDatamartModel().getDataSource().getSessionFactory().openSession();
        ConnectionDescriptor connection = (ConnectionDescriptor)getDataSource().getConfiguration().loadDataSourceProperties().get("connection");
        DataSource dataSource = new DataSource();
        dataSource.setJndi(connection.getJndiName());
        dataSource.setHibDialectName(connection.getDialect());
        dataSource.setUrlConnection(connection.getUrl());
        dataSource.setDriver(connection.getDriverClass());
        dataSource.setUser(connection.getUsername());
        dataSource.setPwd(connection.getPassword());
        dataSet.setDataSource(dataSource);
        dataSet.setQuery(sqlQuery);
        dataSet.loadData(start, limit, -1);
        dataStore = dataSet.getDataStore();
        IDataStoreMetaData dataStoreMetadata = dataStore.getMetaData();
        for(int i = 0; i < dataStoreMetadata.getFieldCount(); i++) {
          ISelectField queryField = (ISelectField)queryFields.get(i);
          dataStoreMetadata.changeFieldAlias(i, queryField.getAlias());
        }
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
     
      //dataStore.getMetaData().setProperty("resultNumber", new Integer( (int)dataStore.getRecordsCount() ));
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
      if (overflow) {
        logger.warn("Query results number [" + resultNumber + "] exceeds max result limit that is [" + maxSize + "]");
        auditlogger.info("[" + userProfile.getUserId() + "]:: max result limit [" + maxSize + "] exceeded with SQL: " + sqlQuery);
      }
           
      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);
      }
     
    } catch(Throwable t) {
      errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
      errorHitsMonitor.stop();
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      if(totalTimeMonitor != null) totalTimeMonitor.stop();
      logger.debug("OUT");
   
View Full Code Here

    public static transient Logger logger = Logger.getLogger(InvokeExternalServiceAction.class);
   
 
  public void service(SourceBean request, SourceBean response)  {       
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
    Monitor extServiceMonitor = null;
   
    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.invokeExternalServiceAction.totalTime");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
      ExternalServiceConfiguration serviceConfig = this.getExternalServiceConfiguration();
      Assert.assertNotNull(serviceConfig, "Required service not found!!!");
     
      JSONArray records = this.getAttributeAsJSONArray(RECORDS);
      Assert.assertNotNull(records, "Parameter [" + RECORDS + "] cannot be null in oder to execute " + this.getActionName() + " service");

      // if no records are selected, send a message to the client
      if (records.length() == 0) {
        try {
          writeBackToClient( new JSONFailure(new SpagoBIEngineServiceException(getActionName(), "No records selected!!")) );
          return;
        } catch (IOException e) {
          String message = "Impossible to write back the responce to the client";
          throw new SpagoBIEngineServiceException(getActionName(), message, e);
        }
      }
     
      // if some columns are missing, send a message to the client
      List<String> missingColumns = getMissingColumns(serviceConfig, records);
      logger.debug("Missing columns : " + join(missingColumns, ","));
      if (missingColumns.size() > 0) {
        logger.debug("The following columns are required in order to invoke " +
            "the required service: " + join(missingColumns, ","));
        try {
          JSONObject obj = new JSONObject();
          obj.put("missingcolumns", join(missingColumns, ","));
          writeBackToClient( new JSONSuccess(obj) );
          return;
        } catch (IOException e) {
          String message = "Impossible to write back the responce to the client";
          throw new SpagoBIEngineServiceException(getActionName(), message, e);
        }
      }
     
      // invoke external service
      String serviceResponse = null;
      try {
        extServiceMonitor = MonitorFactory.start("QbeEngine.externalService");
        serviceResponse = invokeExternalService(serviceConfig, records);
      } finally {
        extServiceMonitor.stop();
      }
      logger.debug("Service has returned this message response:\n" + serviceResponse);
     
      try {
        JSONObject obj = new JSONObject();
View Full Code Here

   */
  public void execute(RequestContainer requestContainer, BIObject obj,
      SourceBean response) throws EMFUserError {
   
    logger.debug("IN");
    Monitor monitor =MonitorFactory.start("spagobi.engines.SpagoBIDocumentCompositionInternalEngine.execute");
    if (obj == null) {
      logger.error("The input object is null");
      throw new EMFUserError(EMFErrorSeverity.ERROR, "100", messageBundle);
    }

    if (!obj.getBiObjectTypeCode().equalsIgnoreCase("DOCUMENT_COMPOSITE") &&
      !obj.getBiObjectTypeCode().equalsIgnoreCase("COMPOSITE_DOCUMENT")) {
      logger.error("The input object is not a composite document");
      throw new EMFUserError(EMFErrorSeverity.ERROR, "1001", messageBundle);
    }
   
    try {
      byte[] contentBytes = null;
      try{
        ObjTemplate template = DAOFactory.getObjTemplateDAO().getBIObjectActiveTemplate(obj.getId());
              if(template==null) throw new Exception("Active Template null");
              contentBytes = template.getContent();
              if(contentBytes==null) throw new Exception("Content of the Active template null");
      } catch (Exception e) {
        logger.error("Error while recovering template content: \n" + e);
        throw new EMFUserError(EMFErrorSeverity.ERROR, "1002", messageBundle);
      }
      // get bytes of template and transform them into a SourceBean
      SourceBean content = null;
      try {
        String contentStr = new String(contentBytes);
        content = SourceBean.fromXMLString(contentStr);
      } catch (Exception e) {
        logger.error("Error while converting the Template bytes into a SourceBean object: ", e);
        throw new EMFUserError(EMFErrorSeverity.ERROR, "1011", messageBundle);
      }
     
      // read the configuration and set relative object into session
      DocumentCompositionConfiguration docConf = new DocumentCompositionConfiguration(content);
      SessionContainer session = requestContainer.getSessionContainer();
      ContextManager contextManager = new ContextManager(new SpagoBISessionContainer(session),
          new LightNavigatorContextRetrieverStrategy(requestContainer.getServiceRequest()));
      contextManager.set("docConfig", docConf);
        
      // set information into response
      response.setAttribute(ObjectsTreeConstants.SESSION_OBJ_ATTR, obj);
      response.setAttribute(content);
      response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "DOCUMENT_COMPOSITION");
    } catch (EMFUserError ue) {
      logger.error("Cannot exec the composite document", ue);
      throw new EMFUserError(EMFErrorSeverity.ERROR, ue.getErrorCode(), messageBundle);
    } catch (Exception e) {
      logger.error("Cannot exec the composite document", e);
      throw new EMFUserError(EMFErrorSeverity.ERROR, "100", messageBundle);
    }finally{
      monitor.stop();
    }
  }
View Full Code Here

    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
         

    logger.debug("IN");
   
    try {
   
      super.service(request, response)
     
      totalTimeMonitor = MonitorFactory.start("QbeEngine.executeQueryAction.totalTime");
           
      start = getAttributeAsInteger( START )
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
     
      limit = getAttributeAsInteger( LIMIT );
     

      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
           
      maxSize = QbeEngineConfig.getInstance().getResultLimit();     
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.value" + "] is equals to [" + (maxSize != null? maxSize: "none") + "]");
      isMaxResultsLimitBlocking = QbeEngineConfig.getInstance().isMaxResultLimitBlocking();
      logger.debug("Configuration setting  [" + "QBE.QBE-SQL-RESULT-LIMIT.isBlocking" + "] is equals to [" + isMaxResultsLimitBlocking + "]");
     
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
           
     
      // retrieving query specified by id on request
      query = getQuery();       
      Assert.assertNotNull(query, "Query object with id [" + query.getId() + "] does not exist in the catalogue");

      statement = getStatement(query);
     
      // promptable filters values may come with request (read-only user modality)
      updatePromptableFiltersValue(query, this);

      dataStore = executeQuery(statement, start, limit);
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");

      logger.debug("Total records: " + resultNumber);     
     
     
      boolean overflow = maxSize != null && resultNumber >= maxSize;
      if (overflow) {
        logger.warn("Query results number [" + resultNumber + "] exceeds max result limit that is [" + maxSize + "]");
    //    auditlogger.info("[" + userProfile.getUserId() + "]:: max result limit [" + maxSize + "] exceeded with SQL: " + sqlQuery);
      }
     
      //gridDataFeed = buildGridDataFeed(results, resultNumber.intValue()); 
     
      dataSetWriter = new JSONDataWriter();
      gridDataFeed = (JSONObject)dataSetWriter.write(dataStore);
      //logger.debug("Response object: " + gridDataFeed.toString(3));
     
      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);
      }
     
    } catch(Throwable t) {
      errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
      errorHitsMonitor.stop();
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      if(totalTimeMonitor != null) totalTimeMonitor.stop();
      logger.debug("OUT");
   
View Full Code Here

*
* @return the user profile
*/
public SpagoBIUserProfile getUserProfile(String token,String userId) {
        logger.debug("IN");
        Monitor monitor =MonitorFactory.start("spagobi.service.security.getUserProfile");
  try {
      validateTicket(token, userId);
      SpagoBIUserProfile user=supplier.createUserProfile(userId);
      user.setFunctions(UserUtilities.readFunctionality(user.getRoles()));
      return user;
  } catch (SecurityException e) {
      logger.error("SecurityException", e);
      return null;
  } finally {
      monitor.stop();
      logger.debug("OUT");
 

 
    }
View Full Code Here

    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
   
    logger.debug("IN");
   
    try {
     
      super.service(request, response)
   
      totalTimeMonitor = MonitorFactory.start("QbeEngine.getFilterValuesAction.totalTime");
     
      queryType = getAttributeAsString(QUERY_TYPE);
      logger.debug("Parameter [" + QUERY_TYPE + "] is equals to [" + queryType + "]");
      if(StringUtilities.isEmpty(queryType)) {
        queryType = "standard";
        logger.debug("Parameter [" + QUERY_TYPE + "] set up to default value [" + queryType + "]");
      }
     
      lookupQuery = getAttributeAsString(LOOKUP_QUERY);
      logger.debug("Parameter [" + LOOKUP_QUERY + "] is equals to [" + lookupQuery + "]");
     
      entityId = getAttributeAsString(ENTITY_ID);
      logger.debug("Parameter [" + ENTITY_ID + "] is equals to [" + entityId + "]");
     
      orderEntity = getAttributeAsString(ORDER_ENTITY);
      logger.debug("Parameter [" + ORDER_ENTITY + "] is equals to [" + orderEntity + "]");
 
      orderType = getAttributeAsString(ORDER_TYPE);
      logger.debug("Parameter [" + ORDER_TYPE + "] is equals to [" + orderType + "]");
     
      queryRootEntity = getAttributeAsBoolean(QUERY_ROOT_ENTITY);
      logger.debug("Parameter [" + QUERY_ROOT_ENTITY + "] is equals to [" + queryRootEntity + "]");
     
      if(queryType.equalsIgnoreCase("standard")) {
        query = buildQuery(entityId, orderEntity, orderType, queryRootEntity);
      } else {
        QbeEngineInstance engineInstance = this.getEngineInstance();
        QueryCatalogue queryCatalogue = engineInstance.getQueryCatalogue();
        query = queryCatalogue.getQuery(lookupQuery);
        if(query == null) {
          throw new SpagoBIEngineServiceException(getActionName(), "Impossible to retrive custom query [" + lookupQuery + "] from catalogue");
        }
       
      }
     
      statement = getDataSource().createStatement( query );
     
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
      //String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
      //logger.debug("Executable query (SQL): [" + sqlQuery + "]");
     
      try {
        logger.debug("Executing query ...");
        dataSet = QbeDatasetFactory.createDataSet(statement);
        dataSet.setAbortOnOverflow(true);
       
        Map userAttributes = new HashMap();
        UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
        Iterator it = profile.getUserAttributeNames().iterator();
        while(it.hasNext()) {
          String attributeName = (String)it.next();
          Object attributeValue = profile.getUserAttribute(attributeName);
          userAttributes.put(attributeName, attributeValue);
        }
        dataSet.addBinding("attributes", userAttributes);
        dataSet.addBinding("parameters", this.getEnv());
        dataSet.loadData();
       
        dataStore = dataSet.getDataStore();
        Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
      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);
      }
     
    } catch(Throwable t) {
      errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
      errorHitsMonitor.stop();
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      if (totalTimeMonitor != null) totalTimeMonitor.stop();
      logger.debug("OUT");
    }   
View Full Code Here

    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
   
    logger.debug("IN");
   
    try {
     
      super.service(request, response)
   
      totalTimeMonitor = MonitorFactory.start("QbeEngine.GetValuesForQbeFilterLookup.totalTime");
     
      entityId = getAttributeAsString( ENTITY_ID );
      if(this.requestContainsAttribute( FILTERS ) ) {
        filtersJSON = getAttributeAsJSONObject( FILTERS );
      }
      query = buildQuery(entityId, filtersJSON);
      statement = getDataSource().createStatement( query );
     
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
    //  String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
    //  logger.debug("Executable query (SQL): [" + sqlQuery + "]");
     
      start = getAttributeAsInteger( START );
      limit = getAttributeAsInteger( LIMIT );
     
      logger.debug("Parameter [" + ENTITY_ID + "] is equals to [" + entityId + "]");
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
     
      Assert.assertNotNull(entityId, "Parameter [" + ENTITY_ID + "] cannot be null" );
   
      try {
        logger.debug("Executing query ...");
        dataSet = QbeDatasetFactory.createDataSet(statement);
        dataSet.setAbortOnOverflow(true);
       
        Map userAttributes = new HashMap();
        UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
        Iterator it = profile.getUserAttributeNames().iterator();
        while(it.hasNext()) {
          String attributeName = (String)it.next();
          Object attributeValue = profile.getUserAttribute(attributeName);
          userAttributes.put(attributeName, attributeValue);
        }
        dataSet.addBinding("attributes", userAttributes);
        dataSet.addBinding("parameters", this.getEnv());
        dataSet.loadData(start, limit, (maxSize == null? -1: maxSize.intValue()));
       
        dataStore = dataSet.getDataStore();
        Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
      //serializer = new DataStoreJSONSerializer();
      //gridDataFeed = (JSONObject)serializer.serialize(dataStore);
     
      serializer2 = new LookupStoreJSONSerializer();
      gridDataFeed = (JSONObject)serializer2.serialize(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);
      }
     
    } catch(Throwable t) {
      errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
      errorHitsMonitor.stop();
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      if (totalTimeMonitor != null) totalTimeMonitor.stop();
      logger.debug("OUT");
    }   
View Full Code Here

     *
     * @return the content
     */
    public Content readTemplate(String token, String user, String document,HashMap attributes) {

  Monitor monitor =MonitorFactory.start("spagobi.service.content.readTemplate");
        logger.debug("IN");
        try {
            validateTicket(token,user);
            ContentServiceImplSupplier c=new ContentServiceImplSupplier();
      return c.readTemplate(user, document, attributes);
  } catch (Exception e) {
      logger.error("Exception",e);
      return null;
  }finally{
      monitor.stop();
      logger.debug("OUT");
  }       
    }
View Full Code Here

TOP

Related Classes of com.jamonapi.Monitor

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.