use of bio.terra.service.filedata.FSItem in project jade-data-repo by DataBiosphere.
the class FireStoreDao method makeFSDir.
private FSItem makeFSDir(Firestore firestore, String collectionId, int level, FireStoreDirectoryEntry fireStoreDirectoryEntry) {
if (fireStoreDirectoryEntry.getIsFileRef()) {
throw new IllegalStateException("Expected directory; got file!");
}
String fullPath = fireStoreUtils.getFullPath(fireStoreDirectoryEntry.getPath(), fireStoreDirectoryEntry.getName());
FSDir fsDir = new FSDir();
fsDir.fileId(UUID.fromString(fireStoreDirectoryEntry.getFileId())).collectionId(UUID.fromString(collectionId)).createdDate(Instant.parse(fireStoreDirectoryEntry.getFileCreatedDate())).path(fullPath).checksumCrc32c(fireStoreDirectoryEntry.getChecksumCrc32c()).checksumMd5(fireStoreDirectoryEntry.getChecksumMd5()).size(fireStoreDirectoryEntry.getSize()).description(StringUtils.EMPTY);
if (level != 0) {
List<FSItem> fsContents = new ArrayList<>();
List<FireStoreDirectoryEntry> dirContents = directoryDao.enumerateDirectory(firestore, collectionId, fullPath);
for (FireStoreDirectoryEntry fso : dirContents) {
if (fso.getIsFileRef()) {
// Files that are in the middle of being ingested can have a directory entry, but not yet have
// a file entry. We do not return files that do not yet have a file entry.
FSItem fsFile = makeFSFile(firestore, collectionId, fso);
if (fsFile != null) {
fsContents.add(fsFile);
}
} else {
fsContents.add(makeFSDir(firestore, collectionId, level - 1, fso));
}
}
fsDir.contents(fsContents);
}
return fsDir;
}
use of bio.terra.service.filedata.FSItem 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;
}
}
}
}
use of bio.terra.service.filedata.FSItem in project jade-data-repo by DataBiosphere.
the class IngestFileFileStep method doStep.
@Override
public StepResult doStep(FlightContext context) {
FlightMap workingMap = context.getWorkingMap();
Boolean loadComplete = workingMap.get(FileMapKeys.LOAD_COMPLETED, Boolean.class);
if (loadComplete == null || !loadComplete) {
FlightMap inputParameters = context.getInputParameters();
FileLoadModel fileLoadModel = inputParameters.get(JobMapKeys.REQUEST.getKeyName(), FileLoadModel.class);
FSFileInfo fsFileInfo = workingMap.get(FileMapKeys.FILE_INFO, FSFileInfo.class);
String fileId = workingMap.get(FileMapKeys.FILE_ID, String.class);
FireStoreFile newFile = new FireStoreFile().fileId(fileId).mimeType(fileLoadModel.getMimeType()).description(fileLoadModel.getDescription()).bucketResourceId(fsFileInfo.getBucketResourceId()).fileCreatedDate(fsFileInfo.getCreatedDate()).gspath(fsFileInfo.getGspath()).checksumCrc32c(fsFileInfo.getChecksumCrc32c()).checksumMd5(fsFileInfo.getChecksumMd5()).size(fsFileInfo.getSize()).loadTag(fileLoadModel.getLoadTag());
try {
fileDao.createFileMetadata(dataset, newFile);
// Retrieve to build the complete FSItem
FSItem fsItem = fileDao.retrieveById(dataset, fileId, 1, true);
workingMap.put(JobMapKeys.RESPONSE.getKeyName(), fileService.fileModelFromFSItem(fsItem));
} catch (FileSystemAbortTransactionException rex) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, rex);
}
}
return StepResult.getStepResultSuccess();
}
Aggregations