use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method filterResources.
private List<Resource> filterResources(Argument fhirpath, Bundle bnd) throws EGraphQLException, FHIRException {
List<Resource> result = new ArrayList<Resource>();
if (bnd.getEntry().size() > 0) {
if ((fhirpath == null))
for (BundleEntryComponent be : bnd.getEntry()) result.add(be.getResource());
else {
FHIRPathEngine fpe = new FHIRPathEngine(context);
ExpressionNode node = fpe.parse(getSingleValue(fhirpath));
for (BundleEntryComponent be : bnd.getEntry()) if (fpe.evaluateToBoolean(null, be.getResource(), be.getResource(), node))
result.add(be.getResource());
}
}
return result;
}
use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method processCanonicalReference.
private void processCanonicalReference(Resource context, Base source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
if (!(source instanceof CanonicalType))
throw new EGraphQLException("Not done yet");
if (services == null)
throw new EGraphQLException("Resource Referencing services not provided");
Reference ref = new Reference(source.primitiveValue());
ReferenceResolution res = services.lookup(appInfo, context, ref);
if (res != null) {
if (targetTypeOk(field.getArguments(), res.getTarget())) {
Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, inheritedList));
ObjectValue obj = new ObjectValue();
arg.addValue(obj);
processObject((Resource) res.getTargetContext(), (Base) res.getTarget(), obj, field.getSelectionSet(), inheritedList, suffix);
}
} else if (!hasArgument(field.getArguments(), "optional", "true"))
throw new EGraphQLException("Unable to resolve reference to " + ref.getReference());
}
use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertNotNull(doc);
}
use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertNotNull(doc);
}
use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngineTests method testResource.
private void testResource(Resource resource, String output, String source, String operation) throws IOException, EGraphEngine, EGraphQLException {
GraphQLEngine gql = new GraphQLEngine(TestingUtilities.getSharedWorkerContext());
gql.setServices(this);
if (resource != null)
gql.setFocus(resource);
gql.setGraphQL(Parser.parse(TestingUtilities.loadTestResource("r5", "graphql", source)));
gql.getGraphQL().setOperationName(operation);
gql.getGraphQL().getVariables().add(new Argument("var", new NameValue("true")));
boolean ok = false;
String msg = null;
try {
gql.execute();
ok = true;
} catch (Exception e) {
if (!output.equals("$error"))
e.printStackTrace();
ok = false;
msg = e.getMessage();
}
if (ok) {
Assertions.assertTrue(!output.equals("$error"), "Expected to fail, but didn't");
StringBuilder str = new StringBuilder();
gql.getOutput().setWriteWrapper(false);
gql.getOutput().write(str, 0);
IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", source), new FileOutputStream(CompareUtilities.tempFile("graphql", source)));
IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", output), new FileOutputStream(CompareUtilities.tempFile("graphql", output)));
TextFile.stringToFile(str.toString(), CompareUtilities.tempFile("graphql", output + ".out"));
msg = CompareUtilities.checkJsonIsSame(CompareUtilities.tempFile("graphql", output), CompareUtilities.tempFile("graphql", output + ".out"));
Assertions.assertTrue(Utilities.noString(msg), msg);
} else
Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
Aggregations