From e553239b5b49760bcbdd864c89e00015c85be5ab Mon Sep 17 00:00:00 2001 From: Mihai Postelnicu Date: Tue, 27 Sep 2016 12:29:15 +0300 Subject: [PATCH] OCE-121 --- .../rest/controller/TenderPriceByTypeYearController.java | 8 ++++++-- .../controller/TenderPriceByTypeYearControllerTest.java | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/web/src/main/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearController.java b/web/src/main/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearController.java index 9914757d0..8cbed3422 100644 --- a/web/src/main/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearController.java +++ b/web/src/main/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearController.java @@ -10,6 +10,7 @@ import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.Fields; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -22,6 +23,7 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.match; import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; +import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; import static org.springframework.data.mongodb.core.query.Criteria.where; /** @@ -56,9 +58,11 @@ public List tenderPriceByProcurementMethod( match(where("awards").elemMatch(where("status").is("active")).and("tender.value").exists(true) .andOperator(getYearFilterCriteria("tender.tenderPeriod.startDate", filter))), getMatchDefaultFilterOperation(filter), - new CustomProjectionOperation(project), group("year", "tender." + Keys.PROCUREMENT_METHOD) + new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD) .sum("$tender.value.amount").as(Keys.TOTAL_TENDER_AMOUNT), - sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT)); + project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD).andInclude(Keys.TOTAL_TENDER_AMOUNT) + .andExclude(Fields.UNDERSCORE_ID), + sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT)); AggregationResults results = mongoTemplate.aggregate(agg, "release", DBObject.class); List tagCount = results.getMappedResults(); diff --git a/web/src/test/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearControllerTest.java b/web/src/test/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearControllerTest.java index 771a12dac..31740e10a 100644 --- a/web/src/test/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearControllerTest.java +++ b/web/src/test/java/org/devgateway/ocds/web/rest/controller/TenderPriceByTypeYearControllerTest.java @@ -25,15 +25,15 @@ public void tenderPriceByProcurementMethod() throws Exception { final DBObject first = tenderPriceByProcurementMethod.get(0); String procurementMethod = (String) first.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD); - double totalTenderAmount = (double) first.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); + Number totalTenderAmount = (Number) first.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("selective", procurementMethod); - Assert.assertEquals(600000.0, totalTenderAmount, 0); + Assert.assertEquals(600000.0, totalTenderAmount.doubleValue(), 0); final DBObject second = tenderPriceByProcurementMethod.get(1); procurementMethod = (String) second.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD); - totalTenderAmount = (double) second.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); + totalTenderAmount = (Number) second.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("open", procurementMethod); - Assert.assertEquals(9000.0, totalTenderAmount, 0); + Assert.assertEquals(9000.0, totalTenderAmount.doubleValue(), 0); } }