private void processSearch(ObjectValue target, List<Selection> selection, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { for (Selection sel : selection) { if ((sel.getField() == null)) throw new EGraphQLException("Only field selections are allowed in this context"); checkNoDirectives(sel.getField().getDirectives()); if ((isResourceName(sel.getField().getName(), ""))) processSearchSingle(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "List"))) processSearchSimple(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "Connection"))) processSearchFull(target, sel.getField(), inheritedList, suffix); } }
Argument arg = null; ExpressionNode expression = null; if (sel.getField().hasDirective("slice")) { Directive dir = sel.getField().directive("slice"); String s = ((StringValue) dir.getArguments().get(0).getValues().get(0)).getValue(); if (s.equals("$index")) if (sel.getField().hasDirective("flatten")) // special: instruction to drop this node... il = prop.isList() && !sel.getField().hasDirective("first"); else if (sel.getField().hasDirective("first")) { if (expression != null) throw new FHIRException("You cannot mix @slice and @first"); arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), inheritedList)); } else if (expression == null) arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), prop.isList() || inheritedList)); else ss = suffix+'.'+fpe.evaluateToString(null, null, value, expression); if (!sel.getField().hasDirective("flatten")) arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), prop.isList() || inheritedList)); if (!sel.getField().getSelectionSet().isEmpty()) throw new EGraphQLException("Encountered a selection set on a scalar field type"); processPrimitive(arg, value); } else { if (sel.getField().getSelectionSet().isEmpty()) throw new EGraphQLException("No Fields selected on a complex object"); if (arg == null) processObject(context, value, target, sel.getField().getSelectionSet(), il, ss);
private void processObject(Resource context, Base source, ObjectValue target, List<Selection> selection, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { for (Selection sel : selection) { if (sel.getField() != null) { if (checkDirectives(sel.getField().getDirectives())) { Property prop = source.getNamedProperty(sel.getField().getName()); if ((prop == null) && sel.getField().getName().startsWith("_")) prop = source.getNamedProperty(sel.getField().getName().substring(1)); if (prop == null) { if ((sel.getField().getName().equals("resourceType") && source instanceof Resource)) target.addField("resourceType", listStatus(sel.getField(), false)).addValue(new StringValue(source.fhirType())); else if ((sel.getField().getName().equals("resource") && source.fhirType().equals("Reference"))) processReference(context, source, sel.getField(), target, inheritedList, suffix); else if ((sel.getField().getName().equals("resource") && source.fhirType().equals("canonical"))) processCanonicalReference(context, source, sel.getField(), target, inheritedList, suffix); else if (isResourceName(sel.getField().getName(), "List") && (source instanceof Resource)) processReverseReferenceList((Resource) source, sel.getField(), target, inheritedList, suffix); else if (isResourceName(sel.getField().getName(), "Connection") && (source instanceof Resource)) processReverseReferenceSearch((Resource) source, sel.getField(), target, inheritedList, suffix); else throw new EGraphQLException("Unknown property "+sel.getField().getName()+" on "+source.fhirType()); } else { if (!isPrimitive(prop.getTypeCode()) && sel.getField().getName().startsWith("_")) throw new EGraphQLException("Unknown property "+sel.getField().getName()+" on "+source.fhirType()); List<Base> vl = filter(context, prop, sel.getField().getArguments(), prop.getValues(), sel.getField().getName().startsWith("_")); if (!vl.isEmpty()) processValues(context, sel, prop, target, vl, sel.getField().getName().startsWith("_"), inheritedList, suffix);
private void processSearch(ObjectValue target, List<Selection> selection, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { for (Selection sel : selection) { if ((sel.getField() == null)) throw new EGraphQLException("Only field selections are allowed in this context"); checkNoDirectives(sel.getField().getDirectives()); if ((isResourceName(sel.getField().getName(), ""))) processSearchSingle(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "List"))) processSearchSimple(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "Connection"))) processSearchFull(target, sel.getField(), inheritedList, suffix); } }
Argument arg = null; ExpressionNode expression = null; if (sel.getField().hasDirective("slice")) { Directive dir = sel.getField().directive("slice"); String s = ((StringValue) dir.getArguments().get(0).getValues().get(0)).getValue(); if (s.equals("$index")) if (sel.getField().hasDirective("flatten")) // special: instruction to drop this node... il = prop.isList() && !sel.getField().hasDirective("first"); else if (sel.getField().hasDirective("first")) { if (expression != null) throw new FHIRException("You cannot mix @slice and @first"); arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), inheritedList)); } else if (expression == null) arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), prop.isList() || inheritedList)); else ss = suffix+'.'+fpe.evaluateToString(null, null, value, expression); if (!sel.getField().hasDirective("flatten")) arg = target.addField(sel.getField().getAlias()+suffix, listStatus(sel.getField(), prop.isList() || inheritedList)); if (!sel.getField().getSelectionSet().isEmpty()) throw new EGraphQLException("Encountered a selection set on a scalar field type"); processPrimitive(arg, value); } else { if (sel.getField().getSelectionSet().isEmpty()) throw new EGraphQLException("No Fields selected on a complex object"); if (arg == null) processObject(context, value, target, sel.getField().getSelectionSet(), il, ss);
private void processObject(Resource context, Base source, ObjectValue target, List<Selection> selection, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { for (Selection sel : selection) { if (sel.getField() != null) { if (checkDirectives(sel.getField().getDirectives())) { Property prop = source.getNamedProperty(sel.getField().getName()); if ((prop == null) && sel.getField().getName().startsWith("_")) prop = source.getNamedProperty(sel.getField().getName().substring(1)); if (prop == null) { if ((sel.getField().getName().equals("resourceType") && source instanceof Resource)) target.addField("resourceType", listStatus(sel.getField(), false)).addValue(new StringValue(source.fhirType())); else if ((sel.getField().getName().equals("resource") && source.fhirType().equals("Reference"))) processReference(context, source, sel.getField(), target, inheritedList, suffix); else if ((sel.getField().getName().equals("resource") && source.fhirType().equals("canonical"))) processCanonicalReference(context, source, sel.getField(), target, inheritedList, suffix); else if (isResourceName(sel.getField().getName(), "List") && (source instanceof Resource)) processReverseReferenceList((Resource) source, sel.getField(), target, inheritedList, suffix); else if (isResourceName(sel.getField().getName(), "Connection") && (source instanceof Resource)) processReverseReferenceSearch((Resource) source, sel.getField(), target, inheritedList, suffix); else throw new EGraphQLException("Unknown property "+sel.getField().getName()+" on "+source.fhirType()); } else { if (!isPrimitive(prop.getTypeCode()) && sel.getField().getName().startsWith("_")) throw new EGraphQLException("Unknown property "+sel.getField().getName()+" on "+source.fhirType()); List<Base> vl = filter(context, prop, sel.getField().getArguments(), prop.getValues(), sel.getField().getName().startsWith("_")); if (!vl.isEmpty()) processValues(context, sel, prop, target, vl, sel.getField().getName().startsWith("_"), inheritedList, suffix);