Search in sources :

Example 1 with MissingRequiredFieldException

use of bio.terra.common.exception.MissingRequiredFieldException in project terra-workspace-manager by DataBiosphere.

the class WorkspaceDao method getWorkspaceIfExists.

@ReadTransaction
public Optional<Workspace> getWorkspaceIfExists(UUID id) {
    if (id == null) {
        throw new MissingRequiredFieldException("Valid workspace id is required");
    }
    String sql = WORKSPACE_SELECT_SQL + " WHERE workspace_id = :id";
    MapSqlParameterSource params = new MapSqlParameterSource().addValue("id", id.toString());
    try {
        Workspace result = DataAccessUtils.requiredSingleResult(jdbcTemplate.query(sql, params, WORKSPACE_ROW_MAPPER));
        logger.info("Retrieved workspace record {}", result);
        return Optional.of(result);
    } catch (EmptyResultDataAccessException e) {
        return Optional.empty();
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) MissingRequiredFieldException(bio.terra.common.exception.MissingRequiredFieldException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ReadTransaction(bio.terra.common.db.ReadTransaction)

Aggregations

ReadTransaction (bio.terra.common.db.ReadTransaction)1 MissingRequiredFieldException (bio.terra.common.exception.MissingRequiredFieldException)1 Workspace (bio.terra.workspace.service.workspace.model.Workspace)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1