Search in sources :

Example 1 with Message

use of org.codice.ddf.admin.api.report.Message in project admin-console-beta by connexta.

the class BaseFunctionField method addArgumentMessage.

protected BaseFunctionField addArgumentMessage(Message msg) {
    Message copy = msg.copy();
    if (copy.getPath().isEmpty()) {
        copy.setPath(path());
    }
    report.addArgumentMessage(copy);
    return this;
}
Also used : Message(org.codice.ddf.admin.api.report.Message)

Example 2 with Message

use of org.codice.ddf.admin.api.report.Message in project admin-console-beta by connexta.

the class BaseFunctionField method addResultMessage.

protected BaseFunctionField addResultMessage(Message msg) {
    Message copy = msg.copy();
    List<String> copyMsgPath = copy.getPath();
    //Remove first element of path because the return object's name will be included in the path
    if (!copyMsgPath.isEmpty()) {
        copyMsgPath.remove(0);
    }
    List<String> fullPath = new ImmutableList.Builder<String>().addAll(path()).addAll(copyMsgPath).build();
    copy.setPath(fullPath);
    report.addResultMessage(copy);
    return this;
}
Also used : Message(org.codice.ddf.admin.api.report.Message) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with Message

use of org.codice.ddf.admin.api.report.Message in project admin-console-beta by connexta.

the class ExecutionStrategyImpl method resolveField.

@Override
protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, List<Field> fields) {
    GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
    Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
    DataFetchingEnvironment environment = new DataFetchingEnvironment(source, argumentValues, executionContext.getRoot(), fields, fieldDef.getType(), parentType, executionContext.getGraphQLSchema());
    Object resolvedValue = null;
    try {
        resolvedValue = fieldDef.getDataFetcher().get(environment);
        if (resolvedValue instanceof FunctionReport) {
            FunctionReport<DataType> report = ((FunctionReport) resolvedValue);
            resolvedValue = report.isResultPresent() ? report.result().getValue() : null;
            List<Message> msgs = report.messages();
            msgs.stream().map(GraphQLErrorMessageWrapper::new).forEach(executionContext::addError);
        }
    } catch (Exception e) {
        LOGGER.info("Exception while fetching data", e);
        executionContext.addError(new ExceptionWhileDataFetching(e));
    }
    return completeValue(executionContext, fieldDef.getType(), fields, resolvedValue);
}
Also used : Message(org.codice.ddf.admin.api.report.Message) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) FunctionReport(org.codice.ddf.admin.api.report.FunctionReport) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataType(org.codice.ddf.admin.api.DataType) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching)

Aggregations

Message (org.codice.ddf.admin.api.report.Message)3 ImmutableList (com.google.common.collect.ImmutableList)1 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 DataType (org.codice.ddf.admin.api.DataType)1 FunctionReport (org.codice.ddf.admin.api.report.FunctionReport)1