Search in sources :

Example 1 with DataProjectNotFoundException

use of bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException in project jade-data-repo by DataBiosphere.

the class DataLocationService method getProject.

/**
 * Fetch existing SnapshotDataProject for the Snapshot.
 * Delete it if it's invalid, that is, the referenced cloud resource doesn't exist.
 * @param snapshot
 * @return a populated SnapshotDataProject if one exists, empty if not
 */
public Optional<SnapshotDataProject> getProject(Snapshot snapshot) {
    SnapshotDataProjectSummary snapshotDataProjectSummary = null;
    try {
        // first, check if SnapshotDataProjectSummary (= mapping btw Snapshot ID and cloud Project ID) exists
        snapshotDataProjectSummary = dataProjectDao.retrieveSnapshotDataProject(snapshot.getId());
        // second, check if the referenced cloud resource exists
        GoogleProjectResource googleProjectResource = resourceService.getProjectResourceById(snapshotDataProjectSummary.getProjectResourceId());
        // if both exist, then create the DatasetDataProject object from the summary and return here
        return Optional.of(new SnapshotDataProject(snapshotDataProjectSummary).googleProjectResource(googleProjectResource));
    } catch (DataProjectNotFoundException projNfEx) {
    // suppress exception here, will create later
    } catch (GoogleResourceNotFoundException rsrcNfEx) {
        // I don't think this null check will ever be false, but just in case
        if (snapshotDataProjectSummary != null) {
            logger.warn("metadata has a project resource id it can't resolve for snapshot: " + snapshot.getName());
            dataProjectDao.deleteSnapshotDataProject(snapshotDataProjectSummary.getId());
        }
    }
    // did not find a valid SnapshotDataProject for the given Snapshot
    return Optional.empty();
}
Also used : SnapshotDataProjectSummary(bio.terra.service.snapshot.SnapshotDataProjectSummary) GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) SnapshotDataProject(bio.terra.service.snapshot.SnapshotDataProject)

Example 2 with DataProjectNotFoundException

use of bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException in project jade-data-repo by DataBiosphere.

the class DataProjectDao method retrieveDatasetDataProject.

public DatasetDataProjectSummary retrieveDatasetDataProject(UUID datasetId) {
    try {
        String sql = "SELECT id, dataset_id, project_resource_id FROM dataset_data_project " + " WHERE dataset_id = :dataset_id";
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("dataset_id", datasetId);
        return jdbcTemplate.queryForObject(sql, params, new DatasetDataProjectSummaryMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new DataProjectNotFoundException("Dataset data project not found for: " + datasetId);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 3 with DataProjectNotFoundException

use of bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException in project jade-data-repo by DataBiosphere.

the class DataLocationService method getProject.

/**
 * Fetch existing DatasetDataProject for the Dataset.
 * Delete it if it's invalid, that is, the referenced cloud resource doesn't exist.
 * @param dataset
 * @return a populated DatasetDataProject if one exists, empty if not
 */
public Optional<DatasetDataProject> getProject(Dataset dataset) {
    DatasetDataProjectSummary datasetDataProjectSummary = null;
    try {
        // first, check if DatasetDataProjectSummary (= mapping btw Dataset ID and cloud Project ID) exists
        datasetDataProjectSummary = dataProjectDao.retrieveDatasetDataProject(dataset.getId());
        // second, check if the referenced cloud resource exists
        GoogleProjectResource googleProjectResource = resourceService.getProjectResourceById(datasetDataProjectSummary.getProjectResourceId());
        // if both exist, then create the DatasetDataProject object from the summary and return here
        return Optional.of(new DatasetDataProject(datasetDataProjectSummary).googleProjectResource(googleProjectResource));
    } catch (DataProjectNotFoundException projNfEx) {
    // suppress exception here, will create later
    } catch (GoogleResourceNotFoundException rsrcNfEx) {
        // I don't think this null check will ever be false, but just in case
        if (datasetDataProjectSummary != null) {
            logger.warn("metadata has a project resource id it can't resolve for dataset: " + dataset.getName());
            dataProjectDao.deleteDatasetDataProject(datasetDataProjectSummary.getId());
        }
    }
    // did not find a valid DatasetDataProject for the given Dataset
    return Optional.empty();
}
Also used : GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) GoogleProjectResource(bio.terra.service.resourcemanagement.google.GoogleProjectResource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) DatasetDataProjectSummary(bio.terra.service.dataset.DatasetDataProjectSummary) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject)

Example 4 with DataProjectNotFoundException

use of bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException in project jade-data-repo by DataBiosphere.

the class DataProjectDao method retrieveSnapshotDataProject.

public SnapshotDataProjectSummary retrieveSnapshotDataProject(UUID snapshotId) {
    try {
        String sql = "SELECT id, snapshot_id, project_resource_id FROM snapshot_data_project " + "WHERE snapshot_id = :snapshot_id";
        MapSqlParameterSource params = new MapSqlParameterSource().addValue("snapshot_id", snapshotId);
        return jdbcTemplate.queryForObject(sql, params, new SnapshotDataProjectSummaryMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new DataProjectNotFoundException("Snapshot data project not found for: " + snapshotId);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DataProjectNotFoundException(bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

DataProjectNotFoundException (bio.terra.service.resourcemanagement.exception.DataProjectNotFoundException)4 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)2 GoogleProjectResource (bio.terra.service.resourcemanagement.google.GoogleProjectResource)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)1 DatasetDataProjectSummary (bio.terra.service.dataset.DatasetDataProjectSummary)1 SnapshotDataProject (bio.terra.service.snapshot.SnapshotDataProject)1 SnapshotDataProjectSummary (bio.terra.service.snapshot.SnapshotDataProjectSummary)1