protected Engine getEngineByDocumentType(String type) {
    Engine engine;
    List<Engine> engines;

    engine = null;
    try {
      Assert.assertNotNull(DAOFactory.getEngineDAO(), "EngineDao cannot be null");
      engines = DAOFactory.getEngineDAO().loadAllEnginesForBIObjectType(type);
      if (engines == null || engines.size() == 0) {
        throw new SpagoBIServiceException(
            SERVICE_NAME, "There are no engines for documents of type [" + type + "] available");
      } else {
        engine = engines.get(0);
        if (engines.size() > 1) {
          LogMF.warn(
              logger,
              "There are more than one engine for document of type [WORKSHEET]. We will use the one whose label is equal to [{0}]",
              engine.getLabel());
        } else {
          LogMF.debug(logger, "Using worksheet engine with label [{0}]", engine.getLabel());
        }
      }
    } catch (Throwable t) {
      throw new SpagoBIServiceException(
          SERVICE_NAME, "Impossible to load a valid engine for document of type [WORKSHEET]", t);
    } finally {
      logger.debug("OUT");
    }

    return engine;
  }
  public static Engine getEngineByDocumentType(String type) {
    Engine engine;
    List<Engine> engines;

    engine = null;
    try {
      Assert.assertNotNull(DAOFactory.getEngineDAO(), "EngineDao cannot be null");
      engines = DAOFactory.getEngineDAO().loadAllEnginesForBIObjectType(type);
      if (engines == null || engines.size() == 0) {
        throw new SpagoBIRuntimeException(
            "There are no engines for documents of type [" + type + "] available");
      } else {
        engine = (Engine) engines.get(0);
        LogMF.warn(
            logger,
            "There are more than one engine for document of type ["
                + type
                + "]. We will use the one whose label is equal to [{0}]",
            engine.getLabel());
      }
    } catch (Throwable t) {
      throw new SpagoBIRuntimeException(
          "Impossible to load a valid engine for document of type [" + type + "]", t);
    } finally {
      logger.debug("OUT");
    }

    return engine;
  }
  @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");
    }
  }