Search in sources :

Example 1 with FSFile

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

the class GcsPdao method fileAclOp.

private void fileAclOp(AclOp op, Dataset dataset, List<String> fileIds, String readersPolicyEmail) {
    Acl.Group readerGroup = new Acl.Group(readersPolicyEmail);
    Acl acl = Acl.newBuilder(readerGroup, Acl.Role.READER).build();
    for (String fileId : fileIds) {
        FSItem fsItem = fileDao.retrieveById(dataset, fileId, 0, true);
        if (fsItem instanceof FSFile) {
            FSFile fsFile = (FSFile) fsItem;
            GoogleBucketResource bucketForFile = dataLocationService.lookupBucket(fsFile.getBucketResourceId());
            Storage storage = storageForBucket(bucketForFile);
            URI gsUri = URI.create(fsFile.getGspath());
            String bucketPath = StringUtils.removeStart(gsUri.getPath(), "/");
            BlobId blobId = BlobId.of(bucketForFile.getName(), bucketPath);
            switch(op) {
                case ACL_OP_CREATE:
                    storage.createAcl(blobId, acl);
                    break;
                case ACL_OP_DELETE:
                    storage.deleteAcl(blobId, readerGroup);
                    break;
            }
        }
    }
}
Also used : GoogleBucketResource(bio.terra.service.resourcemanagement.google.GoogleBucketResource) Storage(com.google.cloud.storage.Storage) FSItem(bio.terra.service.filedata.FSItem) Acl(com.google.cloud.storage.Acl) URI(java.net.URI) BlobId(com.google.cloud.storage.BlobId) FSFile(bio.terra.service.filedata.FSFile)

Example 2 with FSFile

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

the class FireStoreDao method makeFSFile.

// Handle files - the fireStoreDirectoryEntry is a reference to a file in a dataset.
private FSItem makeFSFile(Firestore firestore, String collectionId, FireStoreDirectoryEntry fireStoreDirectoryEntry) {
    if (!fireStoreDirectoryEntry.getIsFileRef()) {
        throw new IllegalStateException("Expected file; got directory!");
    }
    String fullPath = fireStoreUtils.getFullPath(fireStoreDirectoryEntry.getPath(), fireStoreDirectoryEntry.getName());
    String fileId = fireStoreDirectoryEntry.getFileId();
    // Lookup the file in its owning dataset, not in the collection. The collection may be a snapshot directory
    // pointing to the files in one or more datasets.
    FireStoreFile fireStoreFile = fileDao.retrieveFileMetadata(firestore, fireStoreDirectoryEntry.getDatasetId(), fileId);
    if (fireStoreFile == null) {
        return null;
    }
    FSFile fsFile = new FSFile();
    fsFile.fileId(UUID.fromString(fileId)).collectionId(UUID.fromString(collectionId)).datasetId(UUID.fromString(fireStoreDirectoryEntry.getDatasetId())).createdDate(Instant.parse(fireStoreFile.getFileCreatedDate())).path(fullPath).checksumCrc32c(fireStoreFile.getChecksumCrc32c()).checksumMd5(fireStoreFile.getChecksumMd5()).size(fireStoreFile.getSize()).description(fireStoreFile.getDescription()).gspath(fireStoreFile.getGspath()).mimeType(fireStoreFile.getMimeType()).bucketResourceId(fireStoreFile.getBucketResourceId()).loadTag(fireStoreFile.getLoadTag());
    return fsFile;
}
Also used : FSFile(bio.terra.service.filedata.FSFile)

Aggregations

FSFile (bio.terra.service.filedata.FSFile)2 FSItem (bio.terra.service.filedata.FSItem)1 GoogleBucketResource (bio.terra.service.resourcemanagement.google.GoogleBucketResource)1 Acl (com.google.cloud.storage.Acl)1 BlobId (com.google.cloud.storage.BlobId)1 Storage (com.google.cloud.storage.Storage)1 URI (java.net.URI)1