Search in sources :

Example 6 with LogList

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList in project timbuctoo by HuygensING.

the class ImportManager method generateLog.

public Future<ImportStatus> generateLog(String baseUri, String defaultGraph, RdfCreator creator) throws LogStorageFailedException {
    importStatus.start(this.getClass().getSimpleName() + ".generateLog", baseUri);
    try {
        // add to the log structure
        int[] index = new int[1];
        logListStore.updateData(logList -> {
            index[0] = logList.addEntry(LogEntry.create(baseUri, defaultGraph, creator));
            return logList;
        });
        // schedule processing
        return executorService.submit(() -> processLogsUntil(index[0]));
    } catch (IOException e) {
        importStatus.addError("Could not update logList", e);
        throw new LogStorageFailedException(e);
    }
}
Also used : LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) IOException(java.io.IOException)

Example 7 with LogList

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList 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 8 with LogList

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList in project timbuctoo by HuygensING.

the class RdfDescriptionSaverTest method setUp.

@Before
public void setUp() throws Exception {
    descriptionFileName = "description.xml";
    descriptionFile = new File(descriptionFileName);
    logList = new LogList();
    importStatus = new ImportStatus(logList);
    testRdfDescriptionSaver = new RdfDescriptionSaver(descriptionFile, BASE_URI, importStatus);
    testRdfDescriptionSaver.start(0);
}
Also used : LogList(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) File(java.io.File) Before(org.junit.Before)

Example 9 with LogList

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList in project timbuctoo by HuygensING.

the class BdbSchemaStoreTest method generatesASchemaForAllAdded.

@Test
public void generatesASchemaForAllAdded() throws Exception {
    final DummyDataStorage dataStore = new DummyDataStorage();
    ChangeFetcher changeFetcher = new DummyChangeFetcher(CursorQuad.create("subj", "pred", Direction.OUT, ChangeType.ASSERTED, "obj", null, null, ""), CursorQuad.create("subj", RdfConstants.RDF_TYPE, Direction.OUT, ChangeType.ASSERTED, "type", null, null, ""), CursorQuad.create("obj", "pred", Direction.IN, ChangeType.ASSERTED, "subj", null, null, ""));
    BdbSchemaStore schemaStore = new BdbSchemaStore(dataStore, new ImportStatus(new LogList()));
    schemaStore.start();
    schemaStore.onChangedSubject("subj", changeFetcher);
    schemaStore.onChangedSubject("obj", changeFetcher);
    schemaStore.finish();
    assertThat(dataStore.getResult(), is("{\n" + "  \"http://timbuctoo.huygens.knaw.nl/static/v5/vocabulary#unknown\" : {\n" + "    \"name\" : \"http://timbuctoo.huygens.knaw.nl/static/v5/vocabulary#unknown\",\n" + "    \"predicates\" : [ {\n" + "      \"name\" : \"pred\",\n" + "      \"direction\" : \"IN\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"type\" : 1\n" + "      },\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    } ],\n" + "    \"subjectsWithThisType\" : 1\n" + "  },\n" + "  \"type\" : {\n" + "    \"name\" : \"type\",\n" + "    \"predicates\" : [ {\n" + "      \"name\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\",\n" + "      \"direction\" : \"OUT\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"http://timbuctoo.huygens.knaw.nl/static/v5/vocabulary#unknown\" : 1\n" + "      },\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    }, {\n" + "      \"name\" : \"pred\",\n" + "      \"direction\" : \"OUT\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"http://timbuctoo.huygens.knaw.nl/static/v5/vocabulary#unknown\" : 1\n" + "      },\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    } ],\n" + "    \"subjectsWithThisType\" : 1\n" + "  }\n" + "}"));
}
Also used : LogList(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) ChangeFetcher(nl.knaw.huygens.timbuctoo.v5.dataset.ChangeFetcher) Test(org.junit.Test)

Aggregations

LogList (nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList)6 IOException (java.io.IOException)3 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)3 LogEntry (nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogEntry)3 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)3 Test (org.junit.Test)3 File (java.io.File)2 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)2 CachedFile (nl.knaw.huygens.timbuctoo.v5.filestorage.dto.CachedFile)2 RdfSerializer (nl.knaw.huygens.timbuctoo.v5.rdfio.RdfSerializer)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Stopwatch (com.google.common.base.Stopwatch)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1