Example usage for org.springframework.data.mongodb.core.aggregation Fields and

List of usage examples for org.springframework.data.mongodb.core.aggregation Fields and

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.aggregation Fields and.

Prototype

public Fields and(String name, String target) 

Source Link

Usage

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * Helper that builds and runs the query. It creates a Match Operation, Group Operation and the Aggregation. The
 * GroupOperation groups by caller, callee, calleeMethod and method name.
 * /*from   ww  w.j  ava 2s.  c  o  m*/
 * @param matchCriteria
 *          {@link Criteria} which specifies the annotation and other filters
 * @return {@link ClientRequestCollector} a list of matching requests
 */
private List<ClientRequestCollector> getRequestsWithCriteria(Criteria matchCriteria) {

    // create match operation based on input
    final MatchOperation matchOperation = match(matchCriteria);

    // 1. group by caller
    Fields fields = Fields.from(Fields.field(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_FROM_ATTRIBUTE,
            "$" + ANNOTATION_FROM_ATTRIBUTE));

    // 2. group by callee
    fields = fields.and(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_TO_ATTRIBUTE, "$" + ANNOTATION_TO_ATTRIBUTE);

    // 3. group by callee method
    fields = fields.and(Ids.MICROSERVICE_CLIENT_REQUEST_ANNOTATION_TO_METHOD_ATTRIBUTE,
            "$" + ANNOTATION_TO_METHOD_ATTRIBUTE);

    // 4. group by name of method that contains the invocation
    fields = fields.and(METHOD_PROJECTION, "$" + METHOD_ATTRIBUTE);

    // create group operation
    final GroupOperation groupOperation = group(fields).push("$" + TIME_FIELD).as(TIME_AGGREGATION_ATTRIBUTE);
    final Aggregation microserviceClientAggregationSpec = newAggregation(matchOperation, groupOperation);

    return aggregateProcedureExecution(microserviceClientAggregationSpec, ClientRequestCollector.class)
            .getMappedResults();
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * Helper that builds and runs the query. It creates a Match Operation, Group Operation and the Aggregation. The
 * GroupOperation groups by caller, callee, calleeMethod and method name.
 * /*from   w  ww.  j a v  a2  s. co  m*/
 * @param matchCriteria
 *          {@link Criteria} which specifies the annotation and other filters
 * @return {@link IncomingRequestCollector} a list of matching requests
 */
private List<IncomingRequestCollector> getIncomingRequestsWithCriteria(Criteria matchCriteria,
        boolean groupByMethod) {
    // create match operation based on input
    final MatchOperation matchOperation = match(matchCriteria);

    // 1. group by service identifier
    Fields fields = Fields.from(Fields.field(Ids.MICROSERVICE_ENDPOINT_ANNOTATION_IDENTIFIER_ATTRIBUTE,
            "$" + ANNOTATION_IDENTIFIER_ATTRIBUTE));

    // 2. group by service method
    if (groupByMethod) {
        fields = fields.and(Ids.MICROSERVICE_DECLARATION_ANNOTATION_METHOD_ATTRIBUTE,
                "$" + ANNOTATION_METHOD_ATTRIBUTE);
    }

    // create group operation and push all timestamps into a list
    final GroupOperation groupOperation = group(fields).push("$" + TIME_FIELD).as(TIME_AGGREGATION_ATTRIBUTE);
    final Aggregation microserviceClientAggregationSpec = newAggregation(matchOperation, groupOperation);

    return aggregateProcedureExecution(microserviceClientAggregationSpec, IncomingRequestCollector.class)
            .getMappedResults();
}