use of nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile in project timbuctoo by HuygensING.
the class TabularRdfCreator method sendQuads.
@Override
public void sendQuads(RdfSerializer saver, DataSet dataSet, Consumer<String> statusConsumer) throws LogStorageFailedException {
try (CachedFile file = dataSet.getImportManager().getFile(fileToken)) {
final RawUploadRdfSaver rawUploadRdfSaver = new RawUploadRdfSaver(dataSet.getMetadata(), file.getFile().getName(), file.getMimeType(), saver, fileName, Clock.systemUTC());
loader.loadData(Lists.newArrayList(tuple(fileName, file.getFile())), new Importer(new StateMachine<>(rawUploadRdfSaver), new ResultReporter(statusConsumer)));
} catch (Exception e) {
throw new LogStorageFailedException(e);
}
}
use of nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile in project timbuctoo by HuygensING.
the class RsEndpoint method getFile.
@GET
@Path("{ownerId}/{dataSetName}/files/{fileId}")
public Response getFile(@HeaderParam("authorization") String authHeader, @PathParam("ownerId") String owner, @PathParam("dataSetName") String dataSetName, @PathParam("fileId") String fileId) throws IOException {
User user = getUser(authHeader);
Optional<CachedFile> maybeFile = rsDocumentBuilder.getCachedFile(user, owner, dataSetName, fileId);
if (maybeFile.isPresent()) {
CachedFile cachedFile = maybeFile.get();
File file = cachedFile.getFile();
if (file != null && file.exists()) {
return Response.ok(cachedFile.getFile(), cachedFile.getMimeType()).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} else if (user != null) {
return Response.status(Response.Status.FORBIDDEN).build();
} else {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
use of nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile in project timbuctoo by HuygensING.
the class RsDocumentBuilder method getResourceList.
/**
* Get the resource list for the dataSet denoted by <code>ownerId</code> and <code>dataSetId</code>.
* The {@link Optional} is empty if the dataSet is not published and the given <code>user</code> == <code>null</code>
* or has no read access for the dataSet or the dataSet does not exist.
*
* @param user User that requests the list, may be <code>null</code>
* @param ownerId ownerId
* @param dataSetId dataSetId
* @return the resource list for the dataSet denoted by <code>ownerId</code> and <code>dataSetId</code>
*/
public Optional<Urlset> getResourceList(@Nullable User user, String ownerId, String dataSetId) throws IOException {
Urlset resourceList = null;
Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId);
if (maybeDataSet.isPresent()) {
DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata();
LogList loglist = maybeDataSet.get().getImportManager().getLogList();
RsMd rsMd = new RsMd(Capability.RESOURCELIST.xmlValue).withAt(// lastImportDate set on server startup?
ZonedDateTime.parse(loglist.getLastImportDate()));
resourceList = new Urlset(rsMd).addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST)));
FileStorage fileStorage = maybeDataSet.get().getFileStorage();
List<LogEntry> entries = loglist.getEntries();
entries.sort((e1, e2) -> {
if (e1.getImportStatus().isPresent() && e2.getImportStatus().isPresent()) {
return e1.getImportStatus().get().getDate().compareTo(e2.getImportStatus().get().getDate());
} else if (e1.getImportStatus().isPresent()) {
return 1;
} else {
return -1;
}
});
for (LogEntry logEntry : entries) {
Optional<String> maybeToken = logEntry.getLogToken();
if (maybeToken.isPresent()) {
String loc = rsUriHelper.uriForToken(dataSetMetaData, maybeToken.get());
Optional<CachedFile> maybeCachedFile = fileStorage.getFile(maybeToken.get());
if (maybeCachedFile.isPresent()) {
UrlItem item = new UrlItem(loc).withMetadata(new RsMd().withType(maybeCachedFile.get().getMimeType().toString()));
resourceList.addItem(item);
}
}
}
rsMd.withCompleted(ZonedDateTime.now(ZoneOffset.UTC));
}
return Optional.ofNullable(resourceList);
}
use of nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile in project timbuctoo by HuygensING.
the class FileSystemFileStorage method getFile.
@Override
public Optional<CachedFile> getFile(String token) throws IOException {
CachedFile cachedFile = null;
FileInfo fileInfo = this.fileInfo.getData().getItems().get(token);
if (fileInfo != null) {
cachedFile = new FileSystemCachedFile(fileInfo.getMediaType(), fileInfo.getName(), new File(dir, token));
}
return Optional.ofNullable(cachedFile);
}
Aggregations