use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class JsonProvenanceToRdfPatch method collectReplacements.
public static Map<String, List<CursorQuad>> collectReplacements(JsonNode activity, QuadStore quadStore) {
Map<String, List<CursorQuad>> toReplace = new HashMap<>();
for (JsonNode revision : activity.get(PROV_GENERATES)) {
final JsonNode replacements = revision.get(TIM_REPLACEMENTS);
if (replacements != null) {
String entity = revision.get(PROV_SPECIALIZATION_OF).get(0).get("@id").asText();
List<CursorQuad> quads = new ArrayList<>();
toReplace.put(revision.get("@id").asText(), quads);
for (JsonNode replacement : replacements) {
if (replacement.has(TIM_PREDICATE)) {
final String predicate = replacement.get(TIM_PREDICATE).get(0).get("@value").asText();
try (Stream<CursorQuad> source = quadStore.getQuads(entity, predicate, Direction.OUT, "")) {
source.forEach(quads::add);
}
}
}
}
}
return toReplace;
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class ViewConfigFetcher method makeDefaultViewConfig.
private ArrayList<Map> makeDefaultViewConfig(String collectionUri, Map<String, Type> schema, TypeNameStore typeNameStore) {
ArrayList<Map> result = new ArrayList<>();
Type collectionType = schema.get(collectionUri);
if (collectionType == null) {
LOG.error("The collectionUri " + collectionUri + " does not exist in the schema! (it does contain: [ " + schema.keySet().stream().collect(Collectors.joining(", ")) + " ]");
} else {
result.add(title(path(jsnA(jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value"))))));
final String collectionGraphqlTypeWithoutDataSet = typeNameStore.makeGraphQlname(collectionUri);
for (Predicate predicate : collectionType.getPredicates()) {
final String predicateAsGraphqlProp = typeNameStore.makeGraphQlnameForPredicate(predicate.getName(), predicate.getDirection(), predicate.isList());
ArrayNode predicateReference = jsnA(jsnA(jsn(collectionGraphqlTypeWithoutDataSet), jsn(predicateAsGraphqlProp)));
if (predicate.isList()) {
predicateReference.add(jsnA(jsn("items"), jsn("items")));
}
String title = "";
if (predicate.getDirection() == Direction.IN) {
title = "⬅︎ ";
}
title += typeNameStore.shorten(predicate.getName());
if (predicate.getReferenceTypes().values().stream().anyMatch(x -> x > 0)) {
// it's at least sometimes a link
result.add(keyValue(title, internalLink(path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("uri")))), path(pushImm(predicateReference, jsnA(jsn("Entity"), jsn("title")), jsnA(jsn("Value"), jsn("value")))))));
}
if (predicate.getValueTypes().values().stream().anyMatch(x -> x > 0)) {
// it's at least sometimes a normal value
result.add(keyValue(title, path(pushImm(predicateReference, jsnA(jsn("Value"), jsn("value"))))));
}
}
}
return result;
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate in project timbuctoo by HuygensING.
the class DerivedSchemaTypeGenerator method makeGraphQlTypes.
public String makeGraphQlTypes(String rootType, Map<String, Type> types, TypeNameStore nameStore) {
DerivedSchemaContainer typesContainer = new DerivedSchemaContainer(rootType, nameStore, this.argumentsHelper);
// FIXME find a better way to register standard types to the schema of a data set
typesContainer.valueType(RdfConstants.MARKDOWN);
typesContainer.valueType(RdfConstants.STRING);
typesContainer.valueType(RdfConstants.URI);
for (Type type : types.values()) {
typesContainer.openObjectType(type.getName());
for (Predicate predicate : type.getPredicates()) {
fieldForDerivedType(predicate, typesContainer);
}
typesContainer.closeObjectType(type.getName());
}
return typesContainer.getSchema();
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate 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.Predicate in project timbuctoo by HuygensING.
the class PredicateTest method mergeMaintainsHasBeenListProperty.
@Test
public void mergeMaintainsHasBeenListProperty() throws Exception {
Predicate predicate1 = createPredicate("predicate", Direction.OUT, "testOwner");
predicate1.setHasBeenList(true);
Predicate predicate2 = createPredicate("predicate", Direction.OUT, "testOwner");
predicate2.setHasBeenList(false);
Predicate mergedPredicate = predicate1.merge(predicate2);
assertThat(mergedPredicate.hasBeenList(), Matchers.is(true));
}
Aggregations