Example usage for org.springframework.data.mongodb.core.aggregation AggregationResults getMappedResults

List of usage examples for org.springframework.data.mongodb.core.aggregation AggregationResults getMappedResults

Introduction

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

Prototype

public List<T> getMappedResults() 

Source Link

Document

Returns the aggregation results.

Usage

From source file:org.devgateway.ocds.web.rest.controller.NumberOfTendersByItemClassification.java

@ApiOperation(value = "This should show the number of tenders per tender.items.classification."
        + "The tender date is taken from tender.tenderPeriod.startDate.")
@RequestMapping(value = "/api/numberOfTendersByItemClassification", method = { RequestMethod.POST,
        RequestMethod.GET }, produces = "application/json")
public List<DBObject> numberOfTendersByItemClassification(
        @ModelAttribute @Valid final YearFilterPagingRequest filter) {

    DBObject project = new BasicDBObject();
    project.put(Fields.UNDERSCORE_ID, 0);
    project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1);

    Aggregation agg = newAggregation(/*from   ww w .j  a  va 2s . c  om*/
            match(where("tender.tenderPeriod.startDate").exists(true)
                    .andOperator(getYearDefaultFilterCriteria(filter, "tender.tenderPeriod.startDate"))),
            new CustomProjectionOperation(project), unwind("tender.items"),
            group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS),
            sort(Direction.ASC, Fields.UNDERSCORE_ID));

    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}

From source file:org.devgateway.ocds.web.rest.controller.selector.BidSelectionMethodSearchController.java

/**
 * db.release.aggregate([ {$project : {"tender.procurementMethodDetails":1}
 * }, {$group: {_id: "$tender.procurementMethodDetails" }} ])
 *
 * @return/* ww  w.  j a v a  2  s.  c om*/
 */
@ApiOperation(value = "Display the available bid selection methods. "
        + "These are taken from tender.procurementMethodDetails")
@RequestMapping(value = "/api/ocds/bidSelectionMethod/all", method = { RequestMethod.POST,
        RequestMethod.GET }, produces = "application/json")
public List<DBObject> bidSelectionMethods() {

    DBObject project = new BasicDBObject("tender.procurementMethodDetails", 1);

    Aggregation agg = newAggregation(new CustomOperation(new BasicDBObject("$project", project)),
            group("$tender.procurementMethodDetails"), sort(Direction.ASC, Fields.UNDERSCORE_ID));

    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);

    List<DBObject> mappedResults = results.getMappedResults();

    return mappedResults;

}

From source file:com.epam.ta.reportportal.database.dao.LogRepositoryCustomImpl.java

@Override
public List<String> findLogIdsByItemRefs(List<String> ids) {
    Aggregation aggregation = newAggregation(match(where("testItemRef").in(ids)), group("id"));
    AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class);
    return results.getMappedResults().stream().map(it -> it.get("_id").toString()).collect(toList());
}

From source file:com.epam.ta.reportportal.database.dao.LogRepositoryCustomImpl.java

@Override
public List<String> findBinaryIdsByLogRefs(List<String> ids) {
    Aggregation aggregation = newAggregation(
            match(where("id").in(ids).andOperator(where("binaryContent").exists(true))),
            group("binaryContent.binaryDataId", "binaryContent.thumbnailId"));
    AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class);
    return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream())
            .collect(toList());//w w w .ja  va  2 s  . c om
}

From source file:com.epam.ta.reportportal.database.dao.LogRepositoryCustomImpl.java

@Override
public List<String> findBinaryIdsByItemRefs(List<String> ids) {
    Aggregation aggregation = newAggregation(
            match(where("testItemRef").in(ids).andOperator(where("binaryContent").exists(true))),
            group("binaryContent.binaryDataId", "binaryContent.thumbnailId"));
    AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class);
    return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream())
            .collect(toList());/*from ww  w  . jav a  2 s  .  co  m*/
}

From source file:io.smalldata.ohmageomh.data.repository.MongoDataPointRepositoryImpl.java

@Override
public List<LastDataPointDate> findLastDataPointDate(List<String> userIds,
        DataPointSearchCriteria searchCriteria, String dateField) {

    if (dateField == null) {
        dateField = "header.creation_date_time";
    }/*  ww w .j  a v  a  2s  .c  om*/

    Aggregation agg = Aggregation.newAggregation(
            Aggregation.match(Criteria.where("header.user_id").in(userIds).and("header.schema_id.namespace")
                    .is(searchCriteria.getSchemaNamespace()).and("header.schema_id.name")
                    .is(searchCriteria.getSchemaName()).and("header.schema_id.version.major")
                    .is(searchCriteria.getSchemaVersion().getMajor()).and("header.schema_id.version.minor")
                    .is(searchCriteria.getSchemaVersion().getMinor())),
            Aggregation.group("header.user_id").max(dateField).as("date").last("header.user_id").as("user_id"));

    //Convert the aggregation result into a List
    AggregationResults<LastDataPointDate> groupResults = mongoOperations.aggregate(agg, "dataPoint",
            LastDataPointDate.class);

    List<LastDataPointDate> result = groupResults.getMappedResults();

    return result;
}

From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java

@Override
public List<String> findLaunchIdsByProjectIds(List<String> ids) {
    Aggregation aggregation = newAggregation(match(where("projectRef").in(ids)), group("id"));
    AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Launch.class, Map.class);
    return results.getMappedResults().stream().map(it -> it.get("_id").toString()).collect(toList());
}

From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java

@SuppressWarnings({ "rawtypes" })
@Override//from   ww  w  .  j a  v  a2s .c om
public List<String> findValuesWithMode(String projectName, String containsValue, String distinctBy,
        String mode) {
    Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)),
            match(where(MODE).is(mode)),
            match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy),
            limit(AUTOCOMPLETE_LIMITATION));
    AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class);
    return result.getMappedResults().stream().map(entry -> entry.get("_id").toString()).collect(toList());
}

From source file:example.springdata.mongodb.aggregation.SpringBooksIntegrationTests.java

/**
 * Project Book titles./*  ww w .  j ava  2 s .c  o  m*/
 */
@Test
public void shouldRetrieveOrderedBookTitles() {

    Aggregation aggregation = newAggregation( //
            sort(Direction.ASC, "volumeInfo.title"), //
            project().and("volumeInfo.title").as("title"));

    AggregationResults<BookTitle> result = operations.aggregate(aggregation, "books", BookTitle.class);

    assertThat(result.getMappedResults())//
            .extracting("title")//
            .containsSequence("Aprende a Desarrollar con Spring Framework", "Beginning Spring",
                    "Beginning Spring 2");
}

From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/* w ww. j  a v  a  2s  . c  o m*/
public List<String> findDistinctValues(String projectName, String containsValue, String distinctBy) {
    Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)),
            unwind(distinctBy), match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")),
            group(distinctBy), limit(AUTOCOMPLETE_LIMITATION));
    AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class);
    List<String> tags = new ArrayList<>(result.getMappedResults().size());
    for (Map<String, String> entry : result.getMappedResults()) {
        tags.add(entry.get("_id"));
    }
    return tags;
}