private Argument parseArgument() throws EGraphQLException, IOException { Argument result = new Argument(); result.setName(consumeName()); consumePunctuation(":"); if (hasPunctuation("[")) { result.setListStatus(ArgumentListStatus.REPEATING); consumePunctuation("["); while (!hasPunctuation("]")) result.getValues().add(parseValue()); consumePunctuation("]"); } else result.getValues().add(parseValue()); return result; }
private void processReverseReferenceSearch(Resource source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { if (services == null) throw new EGraphQLException("Resource Referencing services not provided"); List<Argument> params = new ArrayList<Argument>(); Argument parg = null; for (Argument a : field.getArguments()) if (!(a.getName().equals("_reference"))) params.add(a); else if ((parg == null)) parg = a; else throw new EGraphQLException("Duplicate parameter _reference"); if (parg == null) throw new EGraphQLException("Missing parameter _reference"); Argument arg = new Argument(); params.add(arg); arg.setName(getSingleValue(parg)); arg.addValue(new StringValue(source.fhirType()+"/"+source.getId())); Bundle bnd = services.search(appInfo, field.getName().substring(0, field.getName().length()-10), params); Base bndWrapper = new SearchWrapper(field.getName(), bnd); arg = target.addField(field.getAlias()+suffix, listStatus(field, false)); ObjectValue obj = new ObjectValue(); arg.addValue(obj); processObject(null, bndWrapper, obj, field.getSelectionSet(), inheritedList, suffix); }
public Argument addField(String name, ArgumentListStatus listStatus) throws FHIRException { Argument result = null; for (Argument t : fields) if ((t.name.equals(name))) result = t; if (result == null) { result = new Argument(); result.setName(name); result.setListStatus(listStatus); fields.add(result); } else if (result.getListStatus() == ArgumentListStatus.SINGLETON) throw new FHIRException("Error: Attempt to make '+name+' into a repeating field when it is constrained by @singleton"); else result.setListStatus(ArgumentListStatus.REPEATING); return result; }
private List<Value> resolveValues(Argument arg, int max, String vars) throws EGraphQLException { List<Value> result = new ArrayList<Value>(); for (Value v : arg.getValues()) { if (! (v instanceof VariableValue)) result.add(v); else { if (vars.contains(":"+v.toString()+":")) throw new EGraphQLException("Recursive reference to variable "+v.toString()); Argument a = workingVariables.get(v.toString()); if (a == null) throw new EGraphQLException("No value found for variable \""+v.toString()+"\" in \""+arg.getName()+"\""); List<Value> vl = resolveValues(a, -1, vars+":"+v.toString()+":"); result.addAll(vl); } } if ((max != -1 && result.size() > max)) throw new EGraphQLException("Only "+Integer.toString(max)+" values are allowed for \""+arg.getName()+"\", but "+Integer.toString(result.size())+" enoucntered"); return result; }
private void processSearchFull(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { if (services == null) throw new EGraphQLException("Resource Referencing services not provided"); List<Argument> params = new ArrayList<Argument>(); Argument carg = null; for ( Argument arg : field.getArguments()) if (arg.getName().equals("cursor")) carg = arg; else params.add(arg); if ((carg != null)) { params.clear();; String[] parts = getSingleValue(carg).split(":"); params.add(new Argument("search-id", new StringValue(parts[0]))); params.add(new Argument("search-offset", new StringValue(parts[1]))); } Bundle bnd = services.search(appInfo, field.getName().substring(0, field.getName().length()-10), params); SearchWrapper bndWrapper = new SearchWrapper(field.getName(), bnd); Argument arg = target.addField(field.getAlias()+suffix, listStatus(field, false)); ObjectValue obj = new ObjectValue(); arg.addValue(obj); processObject(null, bndWrapper, obj, field.getSelectionSet(), inheritedList, suffix); }
private void processVariables(Operation op) throws EGraphQLException { for (Variable varRef : op.getVariables()) { Argument varDef = null; for (Argument v : graphQL.getVariables()) if (v.getName().equals(varRef.getName())) varDef = v; if (varDef != null) workingVariables.put(varRef.getName(), varDef); // todo: check type? else if (varRef.getDefaultValue() != null) workingVariables.put(varRef.getName(), new Argument(varRef.getName(), varRef.getDefaultValue())); else throw new EGraphQLException("No value found for variable "); } }
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")) expression = magicExpression; else { ObjectValue n = new ObjectValue(); arg.addValue(n); processObject(context, value, n, sel.getField().getSelectionSet(), il, ss);
private boolean targetTypeOk(List<Argument> arguments, Resource dest) throws EGraphQLException { List<String> list = new ArrayList<String>(); for (Argument arg : arguments) { if ((arg.getName().equals("type"))) { List<Value> vl = resolveValues(arg); for (Value v : vl) list.add(v.toString()); } } if (list.size() == 0) return true; else return list.indexOf(dest.fhirType()) > -1; }
private void processSearchSingle(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { if (services == null) throw new EGraphQLException("Resource Referencing services not provided"); String id = ""; for (Argument arg : field.getArguments()) if ((arg.getName().equals("id"))) id = getSingleValue(arg); else throw new EGraphQLException("Unknown/invalid parameter "+arg.getName()); if (Utilities.noString(id)) throw new EGraphQLException("No id found"); Resource res = services.lookup(appInfo, field.getName(), id); if (res == null) throw new EGraphQLException("Resource "+field.getName()+"/"+id+" not found"); Argument arg = target.addField(field.getAlias()+suffix, listStatus(field, false)); ObjectValue obj = new ObjectValue(); arg.addValue(obj); processObject(res, res, obj, field.getSelectionSet(), inheritedList, suffix); }
public ObjectValue(JsonObject json) throws EGraphQLException { super(); for (Entry<String, JsonElement> n : json.entrySet()) fields.add(new Argument(n.getKey(), n.getValue())); }
private void processPrimitive(Argument arg, Base value) { String s = value.fhirType(); if (s.equals("integer") || s.equals("decimal") || s.equals("unsignedInt") || s.equals("positiveInt")) arg.addValue(new NumberValue(value.primitiveValue())); else if (s.equals("boolean")) arg.addValue(new NameValue(value.primitiveValue())); else arg.addValue(new StringValue(value.primitiveValue())); }
public Argument(String name, JsonElement json) throws EGraphQLException { super(); this.name = name; valuesFromNode(json); } public String getName() {
private void processSearchFull(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { if (services == null) throw new EGraphQLException("Resource Referencing services not provided"); List<Argument> params = new ArrayList<Argument>(); Argument carg = null; for ( Argument arg : field.getArguments()) if (arg.getName().equals("cursor")) carg = arg; else params.add(arg); if ((carg != null)) { params.clear();; String[] parts = getSingleValue(carg).split(":"); params.add(new Argument("search-id", new StringValue(parts[0]))); params.add(new Argument("search-offset", new StringValue(parts[1]))); } Bundle bnd = services.search(appInfo, field.getName().substring(0, field.getName().length()-10), params); SearchWrapper bndWrapper = new SearchWrapper(field.getName(), bnd); Argument arg = target.addField(field.getAlias()+suffix, listStatus(field, false)); ObjectValue obj = new ObjectValue(); arg.addValue(obj); processObject(null, bndWrapper, obj, field.getSelectionSet(), inheritedList, suffix); }
private void processVariables(Operation op) throws EGraphQLException { for (Variable varRef : op.getVariables()) { Argument varDef = null; for (Argument v : graphQL.getVariables()) if (v.getName().equals(varRef.getName())) varDef = v; if (varDef != null) workingVariables.put(varRef.getName(), varDef); // todo: check type? else if (varRef.getDefaultValue() != null) workingVariables.put(varRef.getName(), new Argument(varRef.getName(), varRef.getDefaultValue())); else throw new EGraphQLException("No value found for variable "); } }
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")) expression = magicExpression; else { ObjectValue n = new ObjectValue(); arg.addValue(n); processObject(context, value, n, sel.getField().getSelectionSet(), il, ss);
private boolean checkBooleanDirective(Directive dir) throws EGraphQLException { if (dir.getArguments().size() != 1) throw new EGraphQLException("Unable to process @"+dir.getName()+": expected a single argument \"if\""); if (!dir.getArguments().get(0).getName().equals("if")) throw new EGraphQLException("Unable to process @"+dir.getName()+": expected a single argument \"if\""); List<Value> vl = resolveValues(dir.getArguments().get(0), 1); return vl.get(0).toString().equals("true"); }
private void processSearchSingle(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { if (services == null) throw new EGraphQLException("Resource Referencing services not provided"); String id = ""; for (Argument arg : field.getArguments()) if ((arg.getName().equals("id"))) id = getSingleValue(arg); else throw new EGraphQLException("Unknown/invalid parameter "+arg.getName()); if (Utilities.noString(id)) throw new EGraphQLException("No id found"); Resource res = services.lookup(appInfo, field.getName(), id); if (res == null) throw new EGraphQLException("Resource "+field.getName()+"/"+id+" not found"); Argument arg = target.addField(field.getAlias()+suffix, listStatus(field, false)); ObjectValue obj = new ObjectValue(); arg.addValue(obj); processObject(res, res, obj, field.getSelectionSet(), inheritedList, suffix); }