Search in sources :

Example 1 with ConstructingObjectParser

use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.

the class ListTasksResponse method setupParser.

protected static <T> ConstructingObjectParser<T, Void> setupParser(String name, TriFunction<List<TaskInfo>, List<TaskOperationFailure>, List<OpenSearchException>, T> ctor) {
    ConstructingObjectParser<T, Void> parser = new ConstructingObjectParser<>(name, true, constructingObjects -> {
        int i = 0;
        @SuppressWarnings("unchecked") List<TaskInfo> tasks = (List<TaskInfo>) constructingObjects[i++];
        @SuppressWarnings("unchecked") List<TaskOperationFailure> tasksFailures = (List<TaskOperationFailure>) constructingObjects[i++];
        @SuppressWarnings("unchecked") List<OpenSearchException> nodeFailures = (List<OpenSearchException>) constructingObjects[i];
        return ctor.apply(tasks, tasksFailures, nodeFailures);
    });
    parser.declareObjectArray(optionalConstructorArg(), TaskInfo.PARSER, new ParseField(TASKS));
    parser.declareObjectArray(optionalConstructorArg(), (p, c) -> TaskOperationFailure.fromXContent(p), new ParseField(TASK_FAILURES));
    parser.declareObjectArray(optionalConstructorArg(), (p, c) -> OpenSearchException.fromXContent(p), new ParseField(NODE_FAILURES));
    return parser;
}
Also used : ConstructingObjectParser(org.opensearch.common.xcontent.ConstructingObjectParser) TaskInfo(org.opensearch.tasks.TaskInfo) TaskOperationFailure(org.opensearch.action.TaskOperationFailure) ArrayList(java.util.ArrayList) List(java.util.List) OpenSearchException(org.opensearch.OpenSearchException) ParseField(org.opensearch.common.ParseField)

Example 2 with ConstructingObjectParser

use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.

the class AcknowledgedResponse method generateParser.

protected static <T> ConstructingObjectParser<T, Void> generateParser(String name, Function<Boolean, T> ctor, String parseField) {
    ConstructingObjectParser<T, Void> p = new ConstructingObjectParser<>(name, true, args -> ctor.apply((boolean) args[0]));
    p.declareBoolean(constructorArg(), new ParseField(parseField));
    return p;
}
Also used : ConstructingObjectParser(org.opensearch.common.xcontent.ConstructingObjectParser) ParseField(org.opensearch.common.ParseField)

Example 3 with ConstructingObjectParser

use of org.opensearch.common.xcontent.ConstructingObjectParser in project OpenSearch by opensearch-project.

the class ShardsAcknowledgedResponse method buildParser.

private static ConstructingObjectParser<ShardsAcknowledgedResponse, Void> buildParser() {
    ConstructingObjectParser<ShardsAcknowledgedResponse, Void> p = new ConstructingObjectParser<>("freeze", true, args -> new ShardsAcknowledgedResponse((boolean) args[0], (boolean) args[1]));
    p.declareBoolean(constructorArg(), new ParseField(AcknowledgedResponse.PARSE_FIELD_NAME));
    p.declareBoolean(constructorArg(), new ParseField(SHARDS_PARSE_FIELD_NAME));
    return p;
}
Also used : ConstructingObjectParser(org.opensearch.common.xcontent.ConstructingObjectParser) ParseField(org.opensearch.common.ParseField)

Aggregations

ParseField (org.opensearch.common.ParseField)3 ConstructingObjectParser (org.opensearch.common.xcontent.ConstructingObjectParser)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OpenSearchException (org.opensearch.OpenSearchException)1 TaskOperationFailure (org.opensearch.action.TaskOperationFailure)1 TaskInfo (org.opensearch.tasks.TaskInfo)1