示例#1
0
  /**
   * Returns a map of parameters which will be send in the request to the engine application.
   *
   * @param analyticalDocumentSubObject SubObject to execute
   * @param profile Profile of the user
   * @param roleName the name of the execution role
   * @param analyticalDocument the object
   * @return Map The map of the execution call parameters
   */
  public Map getParameterMap(
      Object analyticalDocument,
      Object analyticalDocumentSubObject,
      IEngUserProfile profile,
      String roleName) {

    Map parameters;
    BIObject biObject;
    SubObject subObject;

    logger.debug("IN");

    try {
      Assert.assertNotNull(
          analyticalDocument, "Input parameter [analyticalDocument] cannot be null");
      Assert.assertTrue(
          (analyticalDocument instanceof BIObject),
          "Input parameter [analyticalDocument] cannot be an instance of ["
              + analyticalDocument.getClass().getName()
              + "]");
      biObject = (BIObject) analyticalDocument;

      if (analyticalDocumentSubObject == null) {
        logger.warn("Input parameter [subObject] is null");
        return getParameterMap(analyticalDocument, profile, roleName);
      }
      Assert.assertTrue(
          (analyticalDocumentSubObject instanceof SubObject),
          "Input parameter [subObjectDetail] cannot be an instance of ["
              + analyticalDocumentSubObject.getClass().getName()
              + "]");
      subObject = (SubObject) analyticalDocumentSubObject;

      parameters = getRequestParameters(biObject);

      parameters.put("nameSubObject", subObject.getName() != null ? subObject.getName() : "");
      parameters.put(
          "descriptionSubObject",
          subObject.getDescription() != null ? subObject.getDescription() : "");
      parameters.put(
          "visibilitySubObject", subObject.getIsPublic().booleanValue() ? "Public" : "Private");
      parameters.put("subobjectId", subObject.getId());

      parameters = applySecurity(parameters, profile);
      parameters = applyService(parameters, biObject, profile);
      parameters = applyDatasourceForWriting(parameters, biObject);
      parameters.put("isFromCross", "false");

    } finally {
      logger.debug("OUT");
    }
    return parameters;
  }
示例#2
0
  /**
   * Returns a map of parameters which will be send in the request to the engine application.
   *
   * @param profile Profile of the user
   * @param roleName the name of the execution role
   * @param analyticalDocument the biobject
   * @return Map The map of the execution call parameters
   */
  public Map getParameterMap(Object analyticalDocument, IEngUserProfile profile, String roleName) {
    Map parameters;
    BIObject biObject;

    logger.debug("IN");

    try {
      Assert.assertNotNull(
          analyticalDocument, "Input parameter [analyticalDocument] cannot be null");
      Assert.assertTrue(
          (analyticalDocument instanceof BIObject),
          "Input parameter [analyticalDocument] cannot be an instance of ["
              + analyticalDocument.getClass().getName()
              + "]");

      biObject = (BIObject) analyticalDocument;

      parameters = new Hashtable();
      parameters = getRequestParameters(biObject);
      parameters = applySecurity(parameters, profile);
      parameters = applyService(parameters, biObject, profile);
      parameters = applyDatasourceForWriting(parameters, biObject);
    } finally {
      logger.debug("OUT");
    }

    return parameters;
  }
  public static Trigger convertTriggerFromNativeObject(org.quartz.Trigger quartzTrigger) {
    Trigger spagobiTrigger;

    spagobiTrigger = new Trigger();
    spagobiTrigger.setName(quartzTrigger.getName());
    spagobiTrigger.setGroupName(quartzTrigger.getGroup());
    spagobiTrigger.setDescription(quartzTrigger.getDescription());

    // spagobiTrigger.setCalendarName( quartzTrigger.getCalendarName() );
    Assert.assertTrue(
        quartzTrigger.getCalendarName() == null,
        "quartz trigger calendar name is not null: " + quartzTrigger.getCalendarName());

    spagobiTrigger.setStartTime(quartzTrigger.getStartTime());
    spagobiTrigger.setEndTime(quartzTrigger.getEndTime());

    // triggers that run immediately have a generated name that starts with schedule_uuid_ (see
    // TriggerXMLDeserializer)
    // It would be better anyway to relay on a specific property to recognize if a trigger is
    // thinked to run immediately
    spagobiTrigger.setRunImmediately(spagobiTrigger.getName().startsWith("schedule_uuid_"));

    if (quartzTrigger instanceof org.quartz.CronTrigger) {
      org.quartz.CronTrigger quartzCronTrigger = (org.quartz.CronTrigger) quartzTrigger;
      // dirty trick
      String expression = (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION);
      if (expression != null) {
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION);
      } else {
        // for back compatibility
        expression =
            (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
      }
      spagobiTrigger.setCronExpression(new CronExpression(expression));
    }

    Job job = new Job();
    job.setName(quartzTrigger.getJobName());
    job.setGroupName(quartzTrigger.getJobGroup());
    job.setVolatile(quartzTrigger.isVolatile());
    Map<String, String> parameters =
        convertParametersFromNativeObject(quartzTrigger.getJobDataMap());
    job.addParameters(parameters);

    spagobiTrigger.setJob(job);

    return spagobiTrigger;
  }
  protected String buildParentFieldOperand(Operand operand, Query query, Map entityAliasesMaps) {
    String operandElement;

    String[] chunks;
    String parentQueryId;
    String fieldName;
    IModelField datamartField;
    IModelEntity rootEntity;
    String queryName;
    String rootEntityAlias;

    logger.debug("IN");

    try {

      // it comes directly from the client side GUI. It is a composition of the parent query id and
      // filed name,
      // separated by a space
      logger.debug("operand  is equals to [" + operand.values[0] + "]");

      chunks = operand.values[0].split(" ");
      Assert.assertTrue(
          chunks.length >= 2,
          "Operand ["
              + chunks.toString()
              + "] does not contains enougth informations in order to resolve the reference to parent field");

      parentQueryId = chunks[0];
      logger.debug("where right-hand field belonging query [" + parentQueryId + "]");
      fieldName = chunks[1];
      logger.debug("where right-hand field unique name [" + fieldName + "]");

      datamartField = parentStatement.getDataSource().getModelStructure().getField(fieldName);
      Assert.assertNotNull(
          datamartField, "DataMart does not cantain a field named [" + fieldName + "]");

      Couple queryNameAndRoot = datamartField.getQueryName();

      queryName = (String) queryNameAndRoot.getFirst();
      logger.debug("select field query name [" + queryName + "]");

      if (queryNameAndRoot.getSecond() != null) {
        rootEntity = (IModelEntity) queryNameAndRoot.getSecond();
      } else {
        rootEntity = datamartField.getParent().getRoot();
      }
      logger.debug("where right-hand field query name [" + queryName + "]");
      logger.debug(
          "where right-hand field root entity unique name [" + rootEntity.getUniqueName() + "]");

      Map parentEntityAliases = (Map) entityAliasesMaps.get(parentQueryId);
      if (parentEntityAliases != null) {
        if (!parentEntityAliases.containsKey(rootEntity.getUniqueName())) {
          Assert.assertUnreachable(
              "Filter of subquery ["
                  + query.getId()
                  + "] refers to a non "
                  + "existing parent query ["
                  + parentQueryId
                  + "] entity ["
                  + rootEntity.getUniqueName()
                  + "]");
        }
        rootEntityAlias = (String) parentEntityAliases.get(rootEntity.getUniqueName());
      } else {
        rootEntityAlias = "unresoved_alias";
        logger.warn(
            "Impossible to get aliases map for parent query ["
                + parentQueryId
                + "]. Probably the parent query ha not been compiled yet");
        logger.warn(
            "Query ["
                + query.getId()
                + "] refers entities of its parent query ["
                + parentQueryId
                + "] so the generated statement wont be executable until the parent query will be compiled");
      }
      logger.debug("where right-hand field root entity alias [" + rootEntityAlias + "]");

      operandElement = parentStatement.getFieldAlias(rootEntityAlias, queryName);
      logger.debug("where element right-hand field value [" + operandElement + "]");
    } finally {
      logger.debug("OUT");
    }

    return operandElement;
  }
示例#5
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void service(SourceBean request, SourceBean response) {

    String dataSetLabel;
    String callback;
    String locale;
    Integer start;
    Integer limit;
    Integer limitSS; // for pagination server side
    Integer rowsLimit;
    Boolean memoryPagination;

    IDataSet dataSet;
    IDataStore dataStore;

    logger.debug("IN");
    Monitor monitor = MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service");

    try {
      super.service(request, response);
      ConsoleEngineInstance consoleEngineInstance = getConsoleEngineInstance();

      dataSetLabel = getAttributeAsString(DATASET_LABEL);
      logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");
      Assert.assertTrue(
          !StringUtilities.isEmpty(dataSetLabel),
          "Parameter [" + DATASET_LABEL + "] cannot be null or empty");

      callback = getAttributeAsString(CALLBACK);
      logger.debug("Parameter [" + CALLBACK + "] is equals to [" + callback + "]");

      locale = getAttributeAsString(LOCALE);
      logger.debug("Parameter [" + LOCALE + "] is equals to [" + locale + "]");

      memoryPagination = getAttributeAsBoolean(MEMORY_PAGINATION);
      logger.debug("Parameter [" + MEMORY_PAGINATION + "] is equals to [" + memoryPagination + "]");

      limitSS = (getAttributeAsInteger(LIMIT_SS) == null) ? -1 : getAttributeAsInteger(LIMIT_SS);
      logger.debug("Parameter [" + LIMIT_SS + "] is equals to [" + LIMIT_SS + "]");

      rowsLimit =
          (getAttributeAsInteger(ROWS_LIMIT) == null) ? -1 : getAttributeAsInteger(ROWS_LIMIT);
      logger.debug("Parameter [" + ROWS_LIMIT + "] is equals to [" + rowsLimit + "]");

      start = (getAttributeAsInteger(START) == null) ? 0 : getAttributeAsInteger(START);
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");

      limit = (getAttributeAsInteger(LIMIT) == null) ? -1 : getAttributeAsInteger(LIMIT);
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");

      dataSet = null;
      try {
        dataSet = getDataSet(dataSetLabel);
      } catch (Throwable t) {
        throw new SpagoBIServiceException(
            "Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
      }
      Assert.assertNotNull(
          dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
      Map params = consoleEngineInstance.getAnalyticalDrivers();
      params.put(LOCALE, locale);
      dataSet.setParamsMap(params);

      UserProfile userProfile = (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
      dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(userProfile));
      if (dataSet instanceof AbstractDataSet) {
        AbstractDataSet ads = (AbstractDataSet) dataSet;
        ads.setUserProfile(userProfile);
      }

      // gets the max number of rows for the table
      // String strRowLimit =
      // ConsoleEngineConfig.getInstance().getProperty("CONSOLE-TABLE-ROWS-LIMIT");
      // rowsLimit = (strRowLimit == null)? -1 : Integer.parseInt(strRowLimit);
      Monitor monitorLD =
          MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service.LoadData");
      if (!memoryPagination) {
        rowsLimit = -1; // serverSide
        limit = limitSS;
      }
      int totalResults = this.getDataSetTotalResult(dataSet);
      if (totalResults != -1) {
        // total results was already loaded, no need to recalculate it
        dataSet.setCalculateResultNumberOnLoad(false);
      }

      dataSet.loadData(start, limit, rowsLimit);

      monitorLD.stop();
      dataStore = dataSet.getDataStore();
      Assert.assertNotNull(
          dataStore,
          "The dataStore returned by loadData method of the class ["
              + dataSet.getClass().getName()
              + "] cannot be null");

      Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
      if (resultNumber != null) {
        this.setDataSetTotalResult(dataSet, (Integer) resultNumber);
      }

      JSONObject results = new JSONObject();
      try {
        JSONDataWriter writer = new JSONDataWriter();
        // write id property only if is a NGSI rest dataset, to not broke previous logic
        if (dataSet instanceof RESTDataSet && ((RESTDataSet) dataSet).isNgsi()) {
          writer.setUseIdProperty(true);
          // writer.setAdjust(true);
        }

        if (totalResults != -1) {
          // if total result was previously loaded, set this information into dataStore
          dataStore.getMetaData().setProperty("resultNumber", totalResults);
        }

        resultNumber = dataStore.getMetaData().getProperty("resultNumber");
        if (resultNumber == null) {
          dataStore
              .getMetaData()
              .setProperty("resultNumber", new Integer((int) dataStore.getRecordsCount()));
        }
        JSONObject dataSetJSON = (JSONObject) writer.write(dataStore);
        results = dataSetJSON;
      } catch (Throwable e) {
        throw new SpagoBIServiceException("Impossible to serialize datastore", e);
      }

      try {
        writeBackToClient(new JSONSuccess(results, callback));
      } catch (IOException e) {
        throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
      }
    } catch (Throwable t) {
      throw SpagoBIEngineServiceExceptionHandler.getInstance()
          .getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
      monitor.stop();
      logger.debug("OUT");
    }
  }
  public void doService() {
    ExecutionInstance instance;

    Integer documentId;
    String documentLabel;
    Integer documentVersion;
    String executionRole;
    String userProvidedParametersStr;

    BIObject obj;
    IEngUserProfile profile;
    List roles;

    logger.debug("IN");

    try {

      profile = getUserProfile();
      documentId =
          requestContainsAttribute(DOCUMENT_ID) ? getAttributeAsInteger(DOCUMENT_ID) : null;
      documentVersion =
          requestContainsAttribute(DOCUMENT_VERSION)
              ? getAttributeAsInteger(DOCUMENT_VERSION)
              : null;
      documentLabel = getAttributeAsString(DOCUMENT_LABEL);
      executionRole = getAttributeAsString(EXECUTION_ROLE);
      userProvidedParametersStr = getAttributeAsString(ObjectsTreeConstants.PARAMETERS);

      logger.debug("Parameter [" + DOCUMENT_ID + "] is equals to [" + documentId + "]");
      logger.debug("Parameter [" + DOCUMENT_LABEL + "] is equals to [" + documentLabel + "]");
      logger.debug("Parameter [" + DOCUMENT_VERSION + "] is equals to [" + documentVersion + "]");
      logger.debug("Parameter [" + EXECUTION_ROLE + "] is equals to [" + executionRole + "]");

      Assert.assertTrue(
          !StringUtilities.isEmpty(documentLabel) || documentId != null,
          "At least one between ["
              + DOCUMENT_ID
              + "] and ["
              + DOCUMENT_LABEL
              + "] parameter must be specified on request");

      Assert.assertTrue(
          !StringUtilities.isEmpty(executionRole),
          "Parameter [" + EXECUTION_ROLE + "] cannot be null");

      // load object to chek if it exists
      obj = null;
      if (!StringUtilities.isEmpty(documentLabel)) {
        logger.debug("Loading document with label = [" + documentLabel + "] ...");
        try {
          obj = DAOFactory.getBIObjectDAO().loadBIObjectByLabel(documentLabel);
        } catch (EMFUserError error) {
          logger.error("Object with label equals to [" + documentLabel + "] not found");
          throw new SpagoBIServiceException(
              SERVICE_NAME, "Object with label equals to [" + documentId + "] not found", error);
        }
      } else if (documentId != null) {
        logger.info("Loading biobject with id = [" + documentId + "] ...");
        try {
          obj = DAOFactory.getBIObjectDAO().loadBIObjectById(documentId);
        } catch (EMFUserError error) {
          logger.error("Object with id equals to [" + documentId + "] not found");
          throw new SpagoBIServiceException(
              SERVICE_NAME, "Object with id equals to [" + documentId + "] not found", error);
        }
      } else {
        Assert.assertUnreachable(
            "At least one between ["
                + DOCUMENT_ID
                + "] and ["
                + DOCUMENT_LABEL
                + "] parameter must be specified on request");
      }
      Assert.assertNotNull(obj, "Impossible to load document");
      logger.debug("... docuemnt loaded succesfully");
      // if into the request is specified a version of the template to use it's signed into the
      // object.
      if (documentVersion != null) obj.setDocVersion(documentVersion);

      // retrive roles for execution
      try {
        roles = ObjectsAccessVerifier.getCorrectRolesForExecution(obj.getId(), profile);
      } catch (Throwable t) {
        throw new SpagoBIServiceException(SERVICE_NAME, t);
      }

      if (roles != null && !roles.contains(executionRole)) {
        logger.error(
            "Document [id: "
                + obj.getId()
                + "; label: "
                + obj.getLabel()
                + " ] cannot be executed by any role of the user ["
                + profile.getUserUniqueIdentifier()
                + "]");
        throw new SpagoBIServiceException(
            SERVICE_NAME,
            "Document [id: "
                + obj.getId()
                + "; label: "
                + obj.getLabel()
                + " ] cannot be executed by any role of the user ["
                + profile.getUserUniqueIdentifier()
                + "]");
      }

      // so far so good: everything has been validated successfully. Let's create a new
      // ExecutionInstance.
      // instance = createExecutionInstance(obj.getId(), executionRole);

      UUIDGenerator uuidGen = UUIDGenerator.getInstance();
      UUID uuidObj = uuidGen.generateTimeBasedUUID();
      String executionContextId = uuidObj.toString();
      executionContextId = executionContextId.replaceAll("-", "");

      CoreContextManager ccm = createContext(executionContextId);
      // so far so good: everything has been validated successfully. Let's create a new
      // ExecutionInstance.
      instance =
          createExecutionInstance(
              obj.getId(), obj.getDocVersion(), executionRole, executionContextId, getLocale());

      createContext(executionContextId).set(ExecutionInstance.class.getName(), instance);

      // instance.refreshParametersValues(getSpagoBIRequestContainer().getRequest(), true);
      // instance.setParameterValues(userProvidedParametersStr, true);

      // refresh obj variable because createExecutionInstance load the BIObject in a different way
      // obj = instance.getBIObject();

      // ExecutionInstance has been created it's time to prepare the response with the instance
      // unique id and flush it to the client
      JSONObject responseJSON = null;
      responseJSON = new JSONObject();
      try {
        responseJSON.put("execContextId", executionContextId);
      } catch (JSONException e) {
        throw new SpagoBIServiceException("Impossible to serialize response", e);
      }

      try {
        writeBackToClient(new JSONSuccess(responseJSON));
      } catch (IOException e) {
        throw new SpagoBIServiceException("Impossible to write back the responce to the client", e);
      }

    } finally {
      logger.debug("OUT");
    }
  }