Search in sources :

Example 1 with Direction

use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction in project timbuctoo by HuygensING.

the class BdbSchemaStore method setPredicateOccurrence.

public void setPredicateOccurrence(Type type, String predicateUri, Direction direction, int listMutation, int subjectMutation) {
    final Predicate predicate = type.getOrCreatePredicate(predicateUri, direction);
    predicate.registerListOccurrence(listMutation);
    predicate.registerSubject(subjectMutation);
}
Also used : Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 2 with Direction

use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction in project timbuctoo by HuygensING.

the class BdbSchemaStore method updatePredicateOccurrence.

public void updatePredicateOccurrence(List<Type> addedTypes, List<Type> removedTypes, List<Type> unchangedTypes, int retractedCount, int unchangedCount, int assertedCount, String predicate, Direction direction) {
    if (!predicate.isEmpty()) {
        boolean wasList = (retractedCount + unchangedCount) > 1;
        boolean isList = (unchangedCount + assertedCount) > 1;
        boolean wasPresent = (retractedCount + unchangedCount) > 0;
        boolean isPresent = (unchangedCount + assertedCount) > 0;
        for (Type type : removedTypes) {
            setPredicateOccurrence(type, predicate, direction, wasList ? -1 : 0, wasPresent ? -1 : 0);
        }
        for (Type type : unchangedTypes) {
            setPredicateOccurrence(type, predicate, direction, wasList == isList ? 0 : isList ? 1 : -1, wasPresent == isPresent ? 0 : isPresent ? 1 : -1);
        }
        for (Type type : addedTypes) {
            setPredicateOccurrence(type, predicate, direction, isList ? 1 : 0, isPresent ? 1 : 0);
        }
    }
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ChangeType(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType)

Example 3 with Direction

use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction in project timbuctoo by HuygensING.

the class BdbTruePatchStore method makeCursorQuad.

public CursorQuad makeCursorQuad(String subject, boolean assertions, String value) {
    String[] parts = value.split("\n", 5);
    Direction direction = parts[1].charAt(0) == '1' ? OUT : IN;
    ChangeType changeType = assertions ? ChangeType.ASSERTED : ChangeType.RETRACTED;
    return CursorQuad.create(subject, parts[0], direction, changeType, parts[4], parts[2].isEmpty() ? null : parts[2], parts[3].isEmpty() ? null : parts[3], "");
}
Also used : ChangeType(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)

Example 4 with Direction

use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction in project timbuctoo by HuygensING.

the class RdfWiringFactory method getDataFetcher.

@Override
public DataFetcher getDataFetcher(FieldWiringEnvironment environment) {
    if (environment.getFieldDefinition().getDirective("passThrough") != null) {
        return DataFetchingEnvironment::getSource;
    } else if (environment.getFieldDefinition().getDirective("related") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("related");
        String source = ((StringValue) directive.getArgument("source").getValue()).getValue();
        String predicate = ((StringValue) directive.getArgument("predicate").getValue()).getValue();
        String direction = ((StringValue) directive.getArgument("direction").getValue()).getValue();
        return new CollectionFetcherWrapper(argumentsHelper, new RelationsOfSubjectDataFetcher(source, predicate, Direction.valueOf(direction)));
    } else if (environment.getFieldDefinition().getDirective("fromCollection") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("fromCollection");
        String uri = ((StringValue) directive.getArgument("uri").getValue()).getValue();
        boolean listAll = ((BooleanValue) directive.getArgument("listAll").getValue()).isValue();
        if (listAll) {
            return new CollectionFetcherWrapper(argumentsHelper, new CollectionDataFetcher(uri));
        } else {
            return lookupFetcher;
        }
    } else if (environment.getFieldDefinition().getDirective("rdf") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("rdf");
        String uri = ((StringValue) directive.getArgument("predicate").getValue()).getValue();
        Direction direction = valueOf(((StringValue) directive.getArgument("direction").getValue()).getValue());
        boolean isList = ((BooleanValue) directive.getArgument("isList").getValue()).isValue();
        boolean isObject = ((BooleanValue) directive.getArgument("isObject").getValue()).isValue();
        boolean isValue = ((BooleanValue) directive.getArgument("isValue").getValue()).isValue();
        if (isObject && isValue) {
            return new DataFetcherWrapper(argumentsHelper, isList, new UnionDataFetcher(uri, direction));
        } else {
            if (isObject) {
                return new DataFetcherWrapper(argumentsHelper, isList, new RelationDataFetcher(uri, direction));
            } else {
                return new DataFetcherWrapper(argumentsHelper, isList, new TypedLiteralDataFetcher(uri));
            }
        }
    } else if (environment.getFieldDefinition().getDirective("uri") != null) {
        return uriFetcher;
    } else if (environment.getFieldDefinition().getDirective("dataSet") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("dataSet");
        String userId = ((StringValue) directive.getArgument("userId").getValue()).getValue();
        String dataSetId = ((StringValue) directive.getArgument("dataSetId").getValue()).getValue();
        final DataSet dataSet = dataSetRepository.unsafeGetDataSetWithoutCheckingPermissions(userId, dataSetId).orElse(null);
        return dataFetchingEnvironment -> new DatabaseResult() {

            @Override
            public DataSet getDataSet() {
                return dataSet;
            }
        };
    } else if (environment.getFieldDefinition().getDirective("entityTitle") != null) {
        return entityTitleFetcher;
    } else if (environment.getFieldDefinition().getDirective("entityDescription") != null) {
        return entityDescriptionFetcher;
    } else if (environment.getFieldDefinition().getDirective("entityImage") != null) {
        return entityImageFetcher;
    }
    return null;
}
Also used : CollectionDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.CollectionDataFetcher) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DatabaseResult(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult) RelationsOfSubjectDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationsOfSubjectDataFetcher) TypedLiteralDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.TypedLiteralDataFetcher) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) BooleanValue(graphql.language.BooleanValue) UnionDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.UnionDataFetcher) StringValue(graphql.language.StringValue) Directive(graphql.language.Directive) RelationDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationDataFetcher)

Example 5 with Direction

use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction 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)

Aggregations

Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)5 Type (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)4 ChangeType (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType)3 StringValue (graphql.language.StringValue)2 Map (java.util.Map)2 DatabaseWriteException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)2 RdfProcessingFailedException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException)2 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)2 Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)2 DatabaseResult (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult)2 ExecutionResult (graphql.ExecutionResult)1 ExecutionResultImpl (graphql.ExecutionResultImpl)1 AsyncExecutionStrategy (graphql.execution.AsyncExecutionStrategy)1 ExecutionContext (graphql.execution.ExecutionContext)1 ExecutionStrategyParameters (graphql.execution.ExecutionStrategyParameters)1 NonNullableFieldWasNullException (graphql.execution.NonNullableFieldWasNullException)1 BooleanValue (graphql.language.BooleanValue)1 Directive (graphql.language.Directive)1 Field (graphql.language.Field)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1