Search in sources :

Example 1 with FileDetailModel

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;
}
Also used : FileModel(bio.terra.model.FileModel) FileSystemCorruptException(bio.terra.service.filedata.exception.FileSystemCorruptException) FileDetailModel(bio.terra.model.FileDetailModel) ArrayList(java.util.ArrayList) DirectoryDetailModel(bio.terra.model.DirectoryDetailModel)

Aggregations

DirectoryDetailModel (bio.terra.model.DirectoryDetailModel)1 FileDetailModel (bio.terra.model.FileDetailModel)1 FileModel (bio.terra.model.FileModel)1 FileSystemCorruptException (bio.terra.service.filedata.exception.FileSystemCorruptException)1 ArrayList (java.util.ArrayList)1