use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type 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.Type in project timbuctoo by HuygensING.
the class ViewConfigFetcher method get.
@Override
public Object get(DataFetchingEnvironment env) {
SubjectReference source = env.getSource();
final DataSet dataSet = source.getDataSet();
final QuadStore qs = dataSet.getQuadStore();
final Map<String, Type> schema = dataSet.getSchemaStore().getStableTypes();
final TypeNameStore typeNameStore = dataSet.getTypeNameStore();
try (Stream<CursorQuad> quads = qs.getQuads(source.getSubjectUri(), HAS_VIEW_CONFIG, Direction.OUT, "")) {
return quads.findFirst().flatMap(q -> {
try {
return Optional.ofNullable(objectMapper.readValue(q.getObject(), List.class));
} catch (IOException e) {
LOG.error("view config is not a valid JSON object", e);
return Optional.empty();
}
}).orElseGet(() -> makeDefaultViewConfig(source.getSubjectUri(), schema, typeNameStore));
}
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type 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.Type in project timbuctoo by HuygensING.
the class MergeSchemasTest method createTypeWithPredicate.
private Type createTypeWithPredicate(String generated, Direction direction) {
Type generatedType = new Type("");
generatedType.getOrCreatePredicate(generated, direction);
generatedType.getPredicate(generated, direction).setIsExplicit(true);
return generatedType;
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.
the class MergeSchemasTest method mergeSchemaReturnsMergedSchemeWithAllPredicates.
@Test
public void mergeSchemaReturnsMergedSchemeWithAllPredicates() throws Exception {
MergeSchemas mergeSchemas = new MergeSchemas();
Map<String, Type> generatedSchema = new HashMap<>();
generatedSchema.put("Type", createTypeWithPredicate("generated", Direction.OUT));
Map<String, Type> customSchema = new HashMap<>();
customSchema.put("Type 2", createTypeWithPredicate("custom", Direction.IN));
Map<String, Type> mergedSchema = mergeSchemas.mergeSchema(generatedSchema, customSchema);
assertThat(mergedSchema, hasEntry(is("Type"), hasProperty("predicates", contains(predicateMatcher().withName("generated").withDirection(Direction.OUT)))));
assertThat(mergedSchema, hasEntry(is("Type 2"), hasProperty("predicates", contains(predicateMatcher().withName("custom").withDirection(Direction.IN)))));
}
Aggregations