use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class JsonProvenanceToRdfPatchTest method retractsPreviousRevision.
@Test
public void retractsPreviousRevision() throws Exception {
String testRetractsRevision = "{\n" + " \"@type\":\"prov:Activity\",\n" + " \"http://www.w3.org/ns/prov#generates\":[\n" + " {\n" + " \"@type\":\"prov:Entity\",\n" + " \"@id\":\"_:b2\",\n" + " \"specializationOf\":{\n" + " \"@id\":\"http://example.com/the/actual/entitys\"\n" + " },\n" + " \"wasRevisionOf\":{\n" + " \"@id\":\"http://example.org/revision1\"\n" + " },\n" + " \"replacements\":[\n" + " {\n" + " \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + " \"predicate\":\"http://example.org/pred1\",\n" + " \"value\":\"value1\"\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + context + "}";
QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/revision1", PROV_SPECIALIZATION_OF, "http://example.com/the/actual/entitys", null).with("http://example.com/the/actual/entitys", TIM_LATEST_REVISION, "http://example.org/revision1");
JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testRetractsRevision, testQuadStore, EDITOR_URI, "test", CLOCK);
creator.sendQuads(basicRdfPatchSerializer, s -> {
}, null);
List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("latestRevision")));
assertThat(filteredResult, containsInAnyOrder("-<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://example.org/revision1" + "> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://timbuctoo.huygens.knaw.nl/static/v5/skolemized/test/b1> <" + defaultGraph + "> .\n"));
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class TypeTest method isSerializable.
@Test
public void isSerializable() throws IOException {
Type type = new Type("http://example.org/myType");
type.getOrCreatePredicate("http://example.org/myPredicate", Direction.OUT);
type.getOrCreatePredicate("http://example.org/myPredicate", Direction.IN);
ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()).registerModule(new GuavaModule()).registerModule(new TimbuctooCustomSerializers()).enable(SerializationFeature.INDENT_OUTPUT);
String result = mapper.writeValueAsString(type);
Type loadedType = mapper.readValue(result, Type.class);
assertThat(loadedType, is(type));
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class RawUploadRdfSaverTest method usageTest.
@Test
public void usageTest() throws LogStorageFailedException {
RdfToStringFaker rdfSerializer = new RdfToStringFaker();
RawUploadRdfSaver instance = instanceWithRdfSerializer(rdfSerializer, dataSetMetadata);
final String collection1 = instance.addCollection("collection1");
ImportPropertyDescriptions importPropertyDescriptions = new ImportPropertyDescriptions();
importPropertyDescriptions.getOrCreate(1).setPropertyName("propName1");
importPropertyDescriptions.getOrCreate(2).setPropertyName("propName2");
instance.addPropertyDescriptions(collection1, importPropertyDescriptions);
instance.addEntity(collection1, ImmutableMap.of("propName1", "value1", "propName2", "val2"));
instance.addEntity(collection1, ImmutableMap.of("propName1", "entVal1", "propName2", "entVal2"));
final String collection2 = instance.addCollection("collection2");
ImportPropertyDescriptions importPropertyDescriptions1 = new ImportPropertyDescriptions();
importPropertyDescriptions1.getOrCreate(1).setPropertyName("prop3");
importPropertyDescriptions1.getOrCreate(2).setPropertyName("prop4");
instance.addPropertyDescriptions(collection2, importPropertyDescriptions1);
instance.addEntity(collection2, ImmutableMap.of("prop3", "value1", "prop4", "val2"));
instance.addEntity(collection2, ImmutableMap.of("prop3", "entVal1", "prop4", "entVal2"));
String generatedRdf = rdfSerializer.toString();
// Use assertEquals because the failing Hamcrest output is hard to compare
String graphName = dataSetMetadata.getBaseUri();
String fileUri = dataSetMetadata.getUriPrefix() + "rawData/fileName/";
String prop = fileUri + "props/";
String rowData = fileUri + "entities/";
assertEquals(fileUri + " " + RDF_TYPE + " " + TIM_TABULAR_FILE + " " + graphName + "\n" + graphName + " " + PROV_DERIVED_FROM + " " + fileUri + " " + graphName + "\n" + fileUri + " " + TIM_MIMETYPE + " " + "application/octet-stream" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + RDFS_LABEL + " " + FILE_NAME + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + PROV_ATTIME + " " + DATE + "^^" + XSD_DATETIMESTAMP + " " + graphName + "\n" + collection1 + " " + RDF_TYPE + " " + collection1 + "type " + graphName + "\n" + collection1 + " " + RDF_TYPE + " " + TIM_TABULAR_COLLECTION + " " + graphName + "\n" + collection1 + " " + RDFS_LABEL + " collection1" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + TIM_HASCOLLECTION + " " + collection1 + " " + graphName + "\n" + fileUri + " " + TIMBUCTOO_NEXT + " " + collection1 + " " + graphName + "\n" + prop + "tim_id " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "tim_id " + graphName + "\n" + prop + "tim_id " + TIM_PROP_ID + " -1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "tim_id " + RDFS_LABEL + " tim_id" + "^^" + STRING + " " + graphName + "\n" + prop + "propName1 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "propName1 " + graphName + "\n" + prop + "propName1 " + TIM_PROP_ID + " 1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "propName1 " + RDFS_LABEL + " propName1" + "^^" + STRING + " " + graphName + "\n" + prop + "tim_id " + TIMBUCTOO_NEXT + " " + prop + "propName1 " + graphName + "\n" + prop + "propName2 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "propName2 " + graphName + "\n" + prop + "propName2 " + TIM_PROP_ID + " 2" + "^^" + INTEGER + " " + graphName + "\n" + prop + "propName2 " + RDFS_LABEL + " propName2" + "^^" + STRING + " " + graphName + "\n" + prop + "propName1 " + TIMBUCTOO_NEXT + " " + prop + "propName2 " + graphName + "\n" + rowData + "1 " + RDF_TYPE + " " + collection1 + " " + graphName + "\n" + collection1 + " " + TIM_HAS_ROW + " " + rowData + "1 " + graphName + "\n" + rowData + "1 " + prop + "propName1" + " value1" + "^^" + STRING + " " + graphName + "\n" + rowData + "1 " + prop + "propName2" + " val2" + "^^" + STRING + " " + graphName + "\n" + rowData + "1 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + RDF_TYPE + " " + collection1 + " " + graphName + "\n" + collection1 + " " + TIM_HAS_ROW + " " + rowData + "2 " + graphName + "\n" + rowData + "2 " + prop + "propName1" + " entVal1" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + prop + "propName2" + " entVal2" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + collection2 + " " + RDF_TYPE + " " + collection2 + "type " + graphName + "\n" + collection2 + " " + RDF_TYPE + " " + TIM_TABULAR_COLLECTION + " " + graphName + "\n" + collection2 + " " + RDFS_LABEL + " collection2" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + TIM_HASCOLLECTION + " " + collection2 + " " + graphName + "\n" + collection1 + " " + TIMBUCTOO_NEXT + " " + collection2 + " " + graphName + "\n" + prop + "tim_id " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "tim_id " + graphName + "\n" + prop + "tim_id " + TIM_PROP_ID + " -1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "tim_id " + RDFS_LABEL + " tim_id" + "^^" + STRING + " " + graphName + "\n" + prop + "prop3 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "prop3 " + graphName + "\n" + prop + "prop3 " + TIM_PROP_ID + " 1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "prop3 " + RDFS_LABEL + " prop3" + "^^" + STRING + " " + graphName + "\n" + prop + "tim_id " + TIMBUCTOO_NEXT + " " + prop + "prop3 " + graphName + "\n" + prop + "prop4 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "prop4 " + graphName + "\n" + prop + "prop4 " + TIM_PROP_ID + " 2" + "^^" + INTEGER + " " + graphName + "\n" + prop + "prop4 " + RDFS_LABEL + " prop4" + "^^" + STRING + " " + graphName + "\n" + prop + "prop3 " + TIMBUCTOO_NEXT + " " + prop + "prop4 " + graphName + "\n" + rowData + "3 " + RDF_TYPE + " " + collection2 + " " + graphName + "\n" + collection2 + " " + TIM_HAS_ROW + " " + rowData + "3 " + graphName + "\n" + rowData + "3 " + prop + "prop3" + " value1" + "^^" + STRING + " " + graphName + "\n" + rowData + "3 " + prop + "prop4" + " val2" + "^^" + STRING + " " + graphName + "\n" + rowData + "3 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + RDF_TYPE + " " + collection2 + " " + graphName + "\n" + collection2 + " " + TIM_HAS_ROW + " " + rowData + "4 " + graphName + "\n" + rowData + "4 " + prop + "prop3" + " entVal1" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + prop + "prop4" + " entVal2" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n", generatedRdf.replaceAll("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", "{UUID}"));
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class BdbSchemaStore method finish.
@Override
public void finish() {
LOG.info("Finished processing entities");
importStatus.setStatus("Finished processing entities");
// Step 3: Add type information to inverse predicates
for (Map.Entry<String, Type> typeEntry : types.entrySet()) {
Type type = typeEntry.getValue();
String typeName = typeEntry.getKey();
for (Predicate predicate : type.getPredicates()) {
predicate.finish();
if (predicate.getDirection() == Direction.IN) {
continue;
}
for (String referenceType : predicate.getReferenceTypes().keySet()) {
try {
types.get(referenceType).getPredicate(predicate.getName(), // There must be an inverse for each outward predicate
Direction.IN).incReferenceType(type.getName(), 1);
} catch (Exception e) {
String cause = "Referenced type " + referenceType + " not found";
try {
if (types.containsKey(referenceType)) {
cause = "type does not have the inverse predicate " + predicate.getName();
if (types.get(referenceType).getPredicate(predicate.getName(), Direction.IN) != null) {
cause = "Something failed during addreferencetype(" + typeName + ")";
}
}
LOG.error("Error during inverse generation (ignored): " + cause, e);
importStatus.addError("Error during inverse generation (ignored): " + cause, e);
} catch (Exception e2) {
LOG.error("Error during inverse generation " + cause, e);
importStatus.addError("Error during inverse generation " + cause, e);
LOG.error("Error during recovery generation ", e2);
importStatus.addError("Error during recovery generation ", e2);
}
}
}
}
}
try {
try {
String serializedValue = objectMapper.writeValueAsString(types);
dataStore.setValue(serializedValue);
dataStore.commit();
stableTypes = readTypes(serializedValue);
} catch (IOException | DatabaseWriteException e) {
throw new SchemaUpdateException(e);
}
} catch (SchemaUpdateException e) {
e.printStackTrace();
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class BdbSchemaStore method updatePredicateType.
public void updatePredicateType(Type type, CursorQuad quad, boolean inc, ChangeFetcher changeFetcher) {
final Predicate predicate = type.getOrCreatePredicate(quad.getPredicate(), quad.getDirection());
if (quad.getValuetype().isPresent()) {
predicate.incValueType(quad.getValuetype().get(), inc ? 1 : -1);
} else {
try (Stream<CursorQuad> typeQs = changeFetcher.getPredicates(quad.getObject(), RDF_TYPE, OUT, !inc, true, inc)) {
boolean[] hadType = new boolean[] { false };
typeQs.forEach(typeQ -> {
hadType[0] = true;
predicate.incReferenceType(typeQ.getObject(), inc ? 1 : -1);
});
if (!hadType[0]) {
predicate.incReferenceType(UNKNOWN, inc ? 1 : -1);
}
}
}
}
Aggregations