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;
}
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));
}
}
Aggregations