Example #1
0
 private Map applyDatasourceForWriting(Map parameters, BIObject biObject) {
   IDataSource datasource;
   try {
     datasource = DAOFactory.getDataSourceDAO().loadDataSourceWriteDefault();
   } catch (EMFUserError e) {
     throw new SpagoBIRuntimeException("Error while loading default datasource for writing", e);
   }
   if (datasource != null) {
     parameters.put(EngineConstants.DEFAULT_DATASOURCE_FOR_WRITING_LABEL, datasource.getLabel());
   } else {
     logger.debug("There is no default datasource for writing");
   }
   return parameters;
 }
  @Override
  public void doService() {

    DatasetManagementAPI creationUtilities;
    IDataSet datasetBean;

    logger.debug("IN");

    try {

      // create the input parameters to pass to the WorkSheet Edit Service
      Map worksheetEditActionParameters = buildWorksheetEditServiceBaseParametersMap();

      String executionId = ExecuteAdHocUtility.createNewExecutionId();
      worksheetEditActionParameters.put("SBI_EXECUTION_ID", executionId);

      Engine worksheetEngine = getWorksheetEngine();
      LogMF.debug(logger, "Engine label is equal to [{0}]", worksheetEngine.getLabel());

      IDataSource datasource;
      try {
        datasource = DAOFactory.getDataSourceDAO().loadDataSourceWriteDefault();
      } catch (EMFUserError e) {
        throw new SpagoBIRuntimeException("Error while loading default datasource for writing", e);
      }
      if (datasource != null) {
        LogMF.debug(logger, "Datasource label is equal to [{0}]", datasource.getLabel());
        worksheetEditActionParameters.put(
            EngineConstants.DEFAULT_DATASOURCE_FOR_WRITING_LABEL, datasource.getLabel());
      } else {
        logger.debug("There is no default datasource for writing");
      }

      datasetBean = getDatasetAttributesFromRequest();
      worksheetEditActionParameters.put("dataset_label", datasetBean.getLabel());

      Map<String, String> datasetParameterValuesMap = getDatasetParameterValuesMapFromRequest();
      worksheetEditActionParameters.putAll(datasetParameterValuesMap);

      // create the WorkSheet Edit Service's URL
      String worksheetEditActionUrl =
          GeneralUtilities.getUrl(worksheetEngine.getUrl(), worksheetEditActionParameters);
      LogMF.debug(
          logger, "Worksheet edit service invocation url is equal to [{}]", worksheetEditActionUrl);

      // create the dataset
      logger.trace("Creating the dataset...");
      Integer datasetId = null;
      try {
        creationUtilities = new DatasetManagementAPI();
        datasetId = creationUtilities.creatDataSet(datasetBean);
        Assert.assertNotNull(datasetId, "Dataset Id cannot be null");
      } catch (Throwable t) {
        throw new SpagoBIServiceException(
            SERVICE_NAME,
            "An error occurred while creating dataset from bean [" + datasetBean + "]",
            t);
      }
      LogMF.debug(logger, "Datset [{0}]succesfully created with id [{1}]", datasetBean, datasetId);

      logger.trace("Copying output parameters to response...");
      try {
        getServiceResponse().setAttribute(OUTPUT_PARAMETER_EXECUTION_ID, executionId);
        getServiceResponse()
            .setAttribute(OUTPUT_PARAMETER_WORKSHEET_EDIT_SERVICE_URL, worksheetEditActionUrl);
        getServiceResponse().setAttribute(OUTPUT_PARAMETER_DATASET_LABEL, datasetBean.getLabel());
        getServiceResponse()
            .setAttribute(OUTPUT_PARAMETER_DATASET_PARAMETERS, datasetParameterValuesMap);

        // business metadata
        JSONObject businessMetadata = getBusinessMetadataFromRequest();
        if (businessMetadata != null) {
          getServiceResponse()
              .setAttribute(OUTPUT_PARAMETER_BUSINESS_METADATA, businessMetadata.toString());
        }
      } catch (Throwable t) {
        throw new SpagoBIServiceException(
            SERVICE_NAME,
            "An error occurred while creating dataset from bean [" + datasetBean + "]",
            t);
      }
      logger.trace("Output parameter succesfully copied to response");

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