Search in sources :

Example 1 with InvalidDatasetException

use of bio.terra.service.dataset.exception.InvalidDatasetException in project jade-data-repo by DataBiosphere.

the class DatasetDao method createAndLock.

/**
 * Create a new dataset object and lock it. An exception is thrown if the dataset already exists.
 * The correct order to call the DatasetDao methods when creating a dataset is: createAndLock, unlock.
 * @param dataset the dataset object to create
 * @return the id of the new dataset
 * @throws SQLException
 * @throws IOException
 * @throws InvalidDatasetException if a row already exists with this dataset name
 */
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE)
public UUID createAndLock(Dataset dataset, String flightId) throws IOException, SQLException {
    logger.debug("createAndLock dataset " + dataset.getName());
    String sql = "INSERT INTO dataset " + "(name, default_profile_id, flightid, description, additional_profile_ids, sharedlock) " + "VALUES (:name, :default_profile_id, :flightid, :description, :additional_profile_ids, ARRAY[]::TEXT[]) ";
    Array additionalProfileIds = DaoUtils.createSqlUUIDArray(connection, dataset.getAdditionalProfileIds());
    MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", dataset.getName()).addValue("default_profile_id", dataset.getDefaultProfileId()).addValue("flightid", flightId).addValue("description", dataset.getDescription()).addValue("additional_profile_ids", additionalProfileIds);
    DaoKeyHolder keyHolder = new DaoKeyHolder();
    try {
        jdbcTemplate.update(sql, params, keyHolder);
    } catch (DuplicateKeyException dkEx) {
        throw new InvalidDatasetException("Dataset name already exists: " + dataset.getName(), dkEx);
    }
    UUID datasetId = keyHolder.getId();
    dataset.id(datasetId);
    dataset.createdDate(keyHolder.getCreatedDate());
    tableDao.createTables(dataset.getId(), dataset.getTables());
    relationshipDao.createDatasetRelationships(dataset);
    assetDao.createAssets(dataset);
    return datasetId;
}
Also used : Array(java.sql.Array) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) InvalidDatasetException(bio.terra.service.dataset.exception.InvalidDatasetException) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with InvalidDatasetException

use of bio.terra.service.dataset.exception.InvalidDatasetException in project jade-data-repo by DataBiosphere.

the class CreateDatasetMetadataStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    try {
        Dataset newDataset = DatasetUtils.convertRequestWithGeneratedNames(datasetRequest);
        UUID datasetId = datasetDao.createAndLock(newDataset, context.getFlightId());
        FlightMap workingMap = context.getWorkingMap();
        workingMap.put(DatasetWorkingMapKeys.DATASET_ID, datasetId);
        DatasetSummaryModel datasetSummary = DatasetJsonConversion.datasetSummaryModelFromDatasetSummary(newDataset.getDatasetSummary());
        workingMap.put(JobMapKeys.RESPONSE.getKeyName(), datasetSummary);
        return StepResult.getStepResultSuccess();
    } catch (InvalidDatasetException idEx) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, idEx);
    } catch (Exception ex) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new InvalidDatasetException("Cannot create dataset: " + datasetRequest.getName(), ex));
    }
}
Also used : Dataset(bio.terra.service.dataset.Dataset) InvalidDatasetException(bio.terra.service.dataset.exception.InvalidDatasetException) FlightMap(bio.terra.stairway.FlightMap) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult) InvalidDatasetException(bio.terra.service.dataset.exception.InvalidDatasetException)

Aggregations

InvalidDatasetException (bio.terra.service.dataset.exception.InvalidDatasetException)2 UUID (java.util.UUID)2 DaoKeyHolder (bio.terra.common.DaoKeyHolder)1 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)1 Dataset (bio.terra.service.dataset.Dataset)1 FlightMap (bio.terra.stairway.FlightMap)1 StepResult (bio.terra.stairway.StepResult)1 Array (java.sql.Array)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 Transactional (org.springframework.transaction.annotation.Transactional)1