use of io.hdocdb.store.HQueryCondition in project kgiraffe by rayokota.
the class GraphQLQueryFactory method getArgumentsPredicate.
protected HQueryCondition getArgumentsPredicate(DataFetchingEnvironment env, Argument argument) {
ArrayValue whereValue = getValue(argument, env);
if (whereValue.getValues().isEmpty()) {
return new HQueryCondition().build();
}
Logical logical = extractLogical(argument);
List<HQueryCondition> predicates = new ArrayList<>();
List<Map<String, Object>> arguments = env.getArgument(logical.symbol());
List<ObjectValue> values = whereValue.getValues().stream().map(ObjectValue.class::cast).collect(Collectors.toList());
List<SimpleEntry<ObjectValue, Map<String, Object>>> tuples = IntStream.range(0, values.size()).mapToObj(i -> new SimpleEntry<>(values.get(i), arguments.get(i))).collect(Collectors.toList());
tuples.stream().flatMap(e -> e.getKey().getObjectFields().stream().filter(it -> Logical.symbols().contains(it.getName())).map(it -> {
Map<String, Object> args = e.getValue();
Argument arg = new Argument(it.getName(), it.getValue());
if (it.getValue() instanceof ArrayValue) {
return getArgumentsPredicate(argumentEnvironment(env, args), arg);
}
return getArgumentPredicate(argumentEnvironment(env, args), arg);
})).forEach(predicates::add);
tuples.stream().flatMap(e -> e.getKey().getObjectFields().stream().filter(it -> !Logical.symbols().contains(it.getName())).map(it -> {
Map<String, Object> args = e.getValue();
Argument arg = new Argument(it.getName(), it.getValue());
return getObjectFieldPredicate(env, logical, it, arg, args);
})).filter(Objects::nonNull).forEach(predicates::add);
return getCompoundPredicate(predicates, logical);
}
use of io.hdocdb.store.HQueryCondition in project kgiraffe by rayokota.
the class GraphQLQueryFactory method getLogicalPredicate.
private HQueryCondition getLogicalPredicate(String fieldName, ObjectField objectField, DataFetchingEnvironment env, Argument argument) {
ObjectValue expressionValue;
if (objectField.getValue() instanceof ObjectValue) {
expressionValue = (ObjectValue) objectField.getValue();
} else {
expressionValue = new ObjectValue(Collections.singletonList(objectField));
}
if (expressionValue.getChildren().isEmpty()) {
return new HQueryCondition().build();
}
Logical logical = extractLogical(argument);
List<HQueryCondition> predicates = new ArrayList<>();
// Let's parse relation criteria expressions if present, i.e. books, author, etc.
if (expressionValue.getObjectFields().stream().anyMatch(it -> !Criteria.symbols().contains(it.getName()))) {
GraphQLFieldDefinition fieldDefinition = getFieldDefinition(env.getGraphQLSchema(), this.getImplementingType(env), new Field(fieldName));
Map<String, Object> args = new LinkedHashMap<>();
Argument arg = new Argument(logical.symbol(), expressionValue);
if (Logical.symbols().contains(argument.getName())) {
args.put(logical.symbol(), env.getArgument(argument.getName()));
} else {
args.put(logical.symbol(), env.getArgument(fieldName));
}
HQueryCondition predicate = getArgumentPredicate(wherePredicateEnvironment(env, fieldDefinition, args), arg);
// Augment the FieldPath instances in the condition
if (objectField.getValue() instanceof ObjectValue) {
predicate = addNewParentToPaths(objectField.getName(), predicate);
}
return predicate;
}
// Let's parse simple Criteria expressions, i.e. EQ, LIKE, etc.
expressionValue.getObjectFields().stream().filter(it -> Criteria.symbols().contains(it.getName())).map(it -> getPredicateFilter(new ObjectField(fieldName, it.getValue()), argumentEnvironment(env, argument), new Argument(it.getName(), it.getValue()))).sorted().map(it -> it.toQueryCondition(env)).filter(Objects::nonNull).forEach(predicates::add);
return getCompoundPredicate(predicates, logical);
}
use of io.hdocdb.store.HQueryCondition in project kgiraffe by rayokota.
the class SubscriptionFetcher method get.
@Override
public Object get(DataFetchingEnvironment env) {
try {
HQueryCondition query = queryFactory.getCriteriaQuery(env, env.getField());
Flowable<Document> publisher = engine.getNotifier().consumer(topic).filter(doc -> query == null || query.isEmpty() || query.evaluate(doc));
return publisher;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.hdocdb.store.HQueryCondition in project kgiraffe by rayokota.
the class GraphQLQueryFactory method getWherePredicate.
protected HQueryCondition getWherePredicate(DataFetchingEnvironment env, Argument argument) {
ObjectValue whereValue = getValue(argument, env);
if (whereValue.getChildren().isEmpty()) {
return new HQueryCondition().build();
}
Logical logical = extractLogical(argument);
Map<String, Object> predicateArguments = new LinkedHashMap<>();
predicateArguments.put(logical.symbol(), env.getArguments());
DataFetchingEnvironment predicateDataFetchingEnv = DataFetchingEnvironmentBuilder.newDataFetchingEnvironment(env).arguments(predicateArguments).build();
Argument predicateArgument = new Argument(logical.symbol(), whereValue);
return getArgumentPredicate(predicateDataFetchingEnv, predicateArgument);
}
use of io.hdocdb.store.HQueryCondition in project kgiraffe by rayokota.
the class GraphQLQueryFactory method getArgumentPredicate.
protected HQueryCondition getArgumentPredicate(DataFetchingEnvironment env, Argument argument) {
ObjectValue whereValue = getValue(argument, env);
if (whereValue.getChildren().isEmpty()) {
return new HQueryCondition().build();
}
Logical logical = extractLogical(argument);
List<HQueryCondition> predicates = new ArrayList<>();
whereValue.getObjectFields().stream().filter(it -> Logical.symbols().contains(it.getName())).map(it -> {
Map<String, Object> arguments = getFieldArguments(env, it, argument);
if (it.getValue() instanceof ArrayValue) {
return getArgumentsPredicate(argumentEnvironment(env, arguments), new Argument(it.getName(), it.getValue()));
}
return getArgumentPredicate(argumentEnvironment(env, arguments), new Argument(it.getName(), it.getValue()));
}).forEach(predicates::add);
whereValue.getObjectFields().stream().filter(it -> !Logical.symbols().contains(it.getName())).map(it -> {
Map<String, Object> args = getFieldArguments(env, it, argument);
Argument arg = new Argument(it.getName(), it.getValue());
return getObjectFieldPredicate(env, logical, it, arg, args);
}).filter(Objects::nonNull).forEach(predicates::add);
return getCompoundPredicate(predicates, logical);
}
Aggregations