Skip to content

Commit

Permalink
OCE-121
Browse files Browse the repository at this point in the history
  • Loading branch information
mpostelnicu committed Sep 27, 2016
1 parent 1911eb2 commit e553239
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -56,9 +58,11 @@ public List<DBObject> 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<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e553239

Please sign in to comment.