Search in sources :

Example 1 with InvalidDrsIdException

use of bio.terra.service.filedata.exception.InvalidDrsIdException in project jade-data-repo by DataBiosphere.

the class DrsService method makeHttpsFromGs.

private String makeHttpsFromGs(String gspath) {
    try {
        URI gsuri = URI.create(gspath);
        String gsBucket = gsuri.getAuthority();
        String gsPath = StringUtils.removeStart(gsuri.getPath(), "/");
        String encodedPath = URLEncoder.encode(gsPath, StandardCharsets.UTF_8.toString());
        return String.format("https://www.googleapis.com/storage/v1/b/%s/o/%s?alt=media", gsBucket, encodedPath);
    } catch (UnsupportedEncodingException ex) {
        throw new InvalidDrsIdException("Failed to urlencode file path", ex);
    }
}
Also used : InvalidDrsIdException(bio.terra.service.filedata.exception.InvalidDrsIdException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URI(java.net.URI)

Example 2 with InvalidDrsIdException

use of bio.terra.service.filedata.exception.InvalidDrsIdException in project jade-data-repo by DataBiosphere.

the class DrsService method parseAndValidateDrsId.

private DrsId parseAndValidateDrsId(String drsObjectId) {
    DrsId drsId = drsIdService.fromObjectId(drsObjectId);
    try {
        UUID snapshotId = UUID.fromString(drsId.getSnapshotId());
        snapshotDao.retrieveSummaryById(snapshotId);
        return drsId;
    } catch (IllegalArgumentException ex) {
        throw new InvalidDrsIdException("Invalid object id format '" + drsObjectId + "'", ex);
    } catch (SnapshotNotFoundException ex) {
        throw new DrsObjectNotFoundException("No snapshot found for DRS object id '" + drsObjectId + "'", ex);
    }
}
Also used : InvalidDrsIdException(bio.terra.service.filedata.exception.InvalidDrsIdException) SnapshotNotFoundException(bio.terra.service.snapshot.exception.SnapshotNotFoundException) DrsObjectNotFoundException(bio.terra.service.filedata.exception.DrsObjectNotFoundException) UUID(java.util.UUID)

Example 3 with InvalidDrsIdException

use of bio.terra.service.filedata.exception.InvalidDrsIdException in project jade-data-repo by DataBiosphere.

the class DrsIdService method fromUri.

public DrsId fromUri(String drsuri) {
    URI uri = URI.create(drsuri);
    if (!StringUtils.equals(uri.getScheme(), "drs") || uri.getAuthority() == null || !StringUtils.startsWith(uri.getPath(), "/")) {
        throw new InvalidDrsIdException("Invalid DRS URI '" + drsuri + "'");
    }
    String objectId = StringUtils.remove(uri.getPath(), '/');
    return parseObjectId(objectId).dnsname(uri.getAuthority()).build();
}
Also used : InvalidDrsIdException(bio.terra.service.filedata.exception.InvalidDrsIdException) URI(java.net.URI)

Aggregations

InvalidDrsIdException (bio.terra.service.filedata.exception.InvalidDrsIdException)3 URI (java.net.URI)2 DrsObjectNotFoundException (bio.terra.service.filedata.exception.DrsObjectNotFoundException)1 SnapshotNotFoundException (bio.terra.service.snapshot.exception.SnapshotNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UUID (java.util.UUID)1