Search in sources :

Example 1 with CachedFile

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);
    }
}
Also used : CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) StateMachine(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.StateMachine) ResultReporter(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ResultReporter) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) Importer(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.Importer)

Example 2 with CachedFile

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();
    }
}
Also used : CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) File(java.io.File) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with CachedFile

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);
}
Also used : CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) RsLn(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsLn) UrlItem(nl.knaw.huygens.timbuctoo.remote.rs.xml.UrlItem) LogList(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList) Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) FileStorage(nl.knaw.huygens.timbuctoo.v5.filestorage.FileStorage) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) RsMd(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd) LogEntry(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogEntry)

Example 4 with CachedFile

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);
}
Also used : CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) FileSystemCachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileSystemCachedFile) FileSystemCachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileSystemCachedFile) FileInfo(nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileInfo) CachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile) File(java.io.File) FileSystemCachedFile(nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileSystemCachedFile)

Aggregations

CachedFile (nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile)4 File (java.io.File)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Importer (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.Importer)1 ResultReporter (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ResultReporter)1 StateMachine (nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.StateMachine)1 RsLn (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsLn)1 RsMd (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)1 UrlItem (nl.knaw.huygens.timbuctoo.remote.rs.xml.UrlItem)1 Urlset (nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)1 LogEntry (nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogEntry)1 LogList (nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList)1 FileStorage (nl.knaw.huygens.timbuctoo.v5.filestorage.FileStorage)1 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)1 FileInfo (nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileInfo)1 FileSystemCachedFile (nl.knaw.huygens.timbuctoo.v5.filestorage.implementations.filesystem.dto.FileSystemCachedFile)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1