private void persistValues(
      String businessUnitCode,
      String businessAreaCode,
      String cdc,
      String year,
      String closureCode,
      String userId,
      String ricavi,
      String primoMargine,
      String margineContribuzione,
      String ricaviVarPer,
      String ricaviVarAbs,
      String primoMargineVarPer,
      String primoMargineVarAbs,
      String margineContribuzioneVarPer,
      String margineContribuzioneVarAbs) {

    try {

      IDataSourceDAO dataSourceDAO = DAOFactory.getDataSourceDAO();
      IDataSource dataSource = dataSourceDAO.loadDataSourceByLabel("DWH BIENG");
      Connection connection = dataSource.getConnection();
      String insertQuery =
          "INSERT INTO SUPP_REP02_T8 (BUSINESS_UNIT, BUSINESS_AREA, CDC, YEAR, CLOSURE, INSERT_USER, FC_RICAVI, FC_PM, FC_MDC, "
              + "VAR_PERC_RICAVI,VAR_ABS_RICAVI,VAR_PERC_PM,VAR_ABS_PM,VAR_PERC_MDC,VAR_ABS_MDC ) "
              + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);

      preparedStatement.setString(1, businessUnitCode);
      preparedStatement.setString(2, businessAreaCode);
      preparedStatement.setString(3, cdc);
      preparedStatement.setInt(4, Integer.valueOf(year));
      preparedStatement.setInt(5, Integer.valueOf(closureCode));
      preparedStatement.setString(6, userId);
      preparedStatement.setDouble(7, Double.valueOf(ricavi));
      preparedStatement.setDouble(8, Double.valueOf(primoMargine));
      preparedStatement.setDouble(9, Double.valueOf(margineContribuzione));

      preparedStatement.setDouble(10, Double.valueOf(ricaviVarPer));
      preparedStatement.setDouble(11, Double.valueOf(ricaviVarAbs));
      preparedStatement.setDouble(12, Double.valueOf(primoMargineVarPer));
      preparedStatement.setDouble(13, Double.valueOf(primoMargineVarAbs));
      preparedStatement.setDouble(14, Double.valueOf(margineContribuzioneVarPer));
      preparedStatement.setDouble(15, Double.valueOf(margineContribuzioneVarAbs));

      preparedStatement.executeUpdate();
      preparedStatement.close();
    } catch (Exception e) {
      logger.error("An unexpected error occured while updating Forecast Edit");
      throw new SpagoBIServiceException(
          "An unexpected error occured while updating Forecast Edit", e);
    }
  }
  private String getDatasourceUnqualifiedName(List datamartNames, IDataSource connection) {
    String datasourceName = getDatamartName(datamartNames);
    if (connection != null) {
      if (connection.checkIsJndi()) {
        datasourceName += "@" + connection.getJndi();
      } else {
        datasourceName += "@" + connection.getUser() + "@" + connection.getUrlConnection();
      }
    }

    logger.info("Using " + datasourceName + " as datasource unqualified name");
    return datasourceName;
  }
Exemple #3
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");
    }
  }