Search in sources :

Example 6 with Type

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;
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 7 with Type

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));
    }
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) LoggerFactory(org.slf4j.LoggerFactory) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) HAS_VIEW_CONFIG(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.HAS_VIEW_CONFIG) Map(java.util.Map) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) DataFetcher(graphql.schema.DataFetcher) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) IOException(java.io.IOException) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)

Example 8 with Type

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();
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 9 with Type

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;
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)

Example 10 with Type

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)))));
}
Also used : MergeSchemas(nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Type (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)17 Test (org.junit.Test)13 HashMap (java.util.HashMap)9 Map (java.util.Map)8 Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)8 MergeSchemas (nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas)8 IOException (java.io.IOException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 List (java.util.List)5 Optional (java.util.Optional)5 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)5 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)5 Logger (org.slf4j.Logger)5 ArrayList (java.util.ArrayList)4 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)4 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)4 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)4 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)3 Collectors (java.util.stream.Collectors)3 LoggerFactory (org.slf4j.LoggerFactory)3