use of bio.terra.model.FileDetailModel in project jade-data-repo by DataBiosphere.
the class FileService method fileModelFromFSItem.
public FileModel fileModelFromFSItem(FSItem fsItem) {
FileModel fileModel = new FileModel().fileId(fsItem.getFileId().toString()).collectionId(fsItem.getCollectionId().toString()).path(fsItem.getPath()).size(fsItem.getSize()).created(fsItem.getCreatedDate().toString()).description(fsItem.getDescription()).checksums(makeChecksums(fsItem));
if (fsItem instanceof FSFile) {
fileModel.fileType(FileModelType.FILE);
FSFile fsFile = (FSFile) fsItem;
fileModel.fileDetail(new FileDetailModel().datasetId(fsFile.getDatasetId().toString()).accessUrl(fsFile.getGspath()).mimeType(fsFile.getMimeType()).loadTag(fsFile.getLoadTag()));
} else if (fsItem instanceof FSDir) {
fileModel.fileType(FileModelType.DIRECTORY);
FSDir fsDir = (FSDir) fsItem;
DirectoryDetailModel directoryDetail = new DirectoryDetailModel().enumerated(fsDir.isEnumerated());
if (fsDir.isEnumerated()) {
directoryDetail.contents(new ArrayList<>());
for (FSItem fsContentsItem : fsDir.getContents()) {
FileModel itemModel = fileModelFromFSItem(fsContentsItem);
directoryDetail.addContentsItem(itemModel);
}
}
fileModel.directoryDetail(directoryDetail);
} else {
throw new FileSystemCorruptException("Entry type is totally wrong; we shouldn't be here");
}
return fileModel;
}
Aggregations