Search in sources :

Example 26 with YearFilterPagingRequest

use of org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest in project ocvn by devgateway.

the class TenderPercentagesControllerTest method avgTimeFromPlanToTenderPhase.

@Test
public void avgTimeFromPlanToTenderPhase() throws Exception {
    final List<DBObject> avgTimeFromPlanToTenderPhase = tenderPercentagesController.avgTimeFromPlanToTenderPhase(new YearFilterPagingRequest());
    final DBObject first = avgTimeFromPlanToTenderPhase.get(0);
    int year = (int) first.get(TenderPercentagesController.Keys.YEAR);
    double avgTimeFromPlanToTender = (double) first.get(TenderPercentagesController.Keys.AVG_TIME_FROM_PLAN_TO_TENDER_PHASE);
    Assert.assertEquals(2015, year);
    Assert.assertEquals(-315.00, avgTimeFromPlanToTender, 0);
}
Also used : YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 27 with YearFilterPagingRequest

use of org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest in project ocvn by devgateway.

the class TenderPercentagesControllerTest method percentTendersWithLinkedProcurementPlan.

@Test
public void percentTendersWithLinkedProcurementPlan() throws Exception {
    final List<DBObject> percentTendersWithLinkedProcurementPlan = tenderPercentagesController.percentTendersWithLinkedProcurementPlan(new YearFilterPagingRequest());
    final DBObject first = percentTendersWithLinkedProcurementPlan.get(0);
    int year = (int) first.get(TenderPercentagesController.Keys.YEAR);
    int totalTendersWithLinkedProcurementPlan = (int) first.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN);
    int totalTenders = (int) first.get(TenderPercentagesController.Keys.TOTAL_TENDERS);
    double percentTenders = (double) first.get(TenderPercentagesController.Keys.PERCENT_TENDERS);
    Assert.assertEquals(2014, year);
    Assert.assertEquals(1, totalTendersWithLinkedProcurementPlan);
    Assert.assertEquals(1, totalTenders);
    Assert.assertEquals(100.0, percentTenders, 0);
    final DBObject second = percentTendersWithLinkedProcurementPlan.get(1);
    year = (int) second.get(TenderPercentagesController.Keys.YEAR);
    totalTendersWithLinkedProcurementPlan = (int) second.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN);
    totalTenders = (int) second.get(TenderPercentagesController.Keys.TOTAL_TENDERS);
    percentTenders = (double) second.get(TenderPercentagesController.Keys.PERCENT_TENDERS);
    Assert.assertEquals(2015, year);
    Assert.assertEquals(2, totalTendersWithLinkedProcurementPlan);
    Assert.assertEquals(2, totalTenders);
    Assert.assertEquals(100.0, percentTenders, 0);
}
Also used : YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 28 with YearFilterPagingRequest

use of org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest in project ocvn by devgateway.

the class TenderPercentagesControllerTest method percentTendersAwarded.

@Test
public void percentTendersAwarded() throws Exception {
    final List<DBObject> percentTendersAwarded = tenderPercentagesController.percentTendersAwarded(new YearFilterPagingRequest());
    final DBObject first = percentTendersAwarded.get(0);
    int year = (int) first.get(TenderPercentagesController.Keys.YEAR);
    int totalTendersWithOneOrMoreTenderers = (int) first.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_ONE_OR_MORE_TENDERERS);
    int totalTendersWithTwoOrMoreTenderers = (int) first.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS);
    double percentTenders = (double) first.get(TenderPercentagesController.Keys.PERCENT_TENDERS);
    Assert.assertEquals(2014, year);
    Assert.assertEquals(1, totalTendersWithOneOrMoreTenderers);
    Assert.assertEquals(1, totalTendersWithTwoOrMoreTenderers);
    Assert.assertEquals(100.0, percentTenders, 0);
    final DBObject second = percentTendersAwarded.get(1);
    year = (int) second.get(TenderPercentagesController.Keys.YEAR);
    totalTendersWithOneOrMoreTenderers = (int) second.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_ONE_OR_MORE_TENDERERS);
    totalTendersWithTwoOrMoreTenderers = (int) second.get(TenderPercentagesController.Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS);
    percentTenders = (double) second.get(TenderPercentagesController.Keys.PERCENT_TENDERS);
    Assert.assertEquals(2015, year);
    Assert.assertEquals(2, totalTendersWithOneOrMoreTenderers);
    Assert.assertEquals(1, totalTendersWithTwoOrMoreTenderers);
    Assert.assertEquals(50.0, percentTenders, 0);
}
Also used : YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 29 with YearFilterPagingRequest

use of org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest in project oc-explorer by devgateway.

the class AwardsWonLostController method procurementsWonLost.

@ApiOperation(value = "Counts the won, lost procurements, flags and amounts. Receives any filters, " + "but most important here is the supplierId and bidderId. Requires bid extension. Use bidderId instead " + "of supplierId.")
@RequestMapping(value = "/api/procurementsWonLost", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<ProcurementsWonLost> procurementsWonLost(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Assert.notEmpty(filter.getBidderId(), "bidderId must not be empty!");
    Assert.isTrue(CollectionUtils.isEmpty(filter.getSupplierId()), "supplierId is not allowed here! Use bidderId to show results!");
    // supplier is the same thing as bidder for this particular query
    filter.setSupplierId(filter.getBidderId());
    Map<String, CriteriaDefinition> noSupplierCriteria = createDefaultFilterCriteriaMap(filter);
    noSupplierCriteria.remove(MongoConstants.Filters.SUPPLIER_ID);
    Aggregation agg1 = newAggregation(match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), unwind("bids.details"), unwind("bids.details.tenderers"), match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), group(BIDS_DETAILS_TENDERERS_ID).count().as("count").sum(BIDS_DETAILS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
    List<CountAmountFlags> applied = releaseAgg(agg1, CountAmountFlags.class);
    Aggregation agg2 = newAggregation(match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))), unwind("awards"), unwind("awards.suppliers"), match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter.awardFiltering(), TENDER_PERIOD_START_DATE))), group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("count").sum(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
    List<CountAmountFlags> won = releaseAgg(agg2, CountAmountFlags.class);
    ArrayList<ProcurementsWonLost> ret = new ArrayList<>();
    applied.forEach(a -> {
        ProcurementsWonLost r = new ProcurementsWonLost();
        r.setApplied(a);
        Optional<CountAmountFlags> optWon = won.stream().filter(w -> w.getId().equals(a.getId())).findFirst();
        if (optWon.isPresent()) {
            r.setWon(optWon.get());
            r.setLostAmount(r.getApplied().getTotalAmount().subtract(r.getWon().getTotalAmount()));
            r.setLostCount(r.getApplied().getCount() - r.getWon().getCount());
        } else {
            r.setLostAmount(r.getApplied().getTotalAmount());
            r.setLostCount(r.getLostCount());
        }
        ret.add(r);
    });
    return ret;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) Aggregation.group(org.springframework.data.mongodb.core.aggregation.Aggregation.group) Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) AWARDS_SUPPLIERS_NAME(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_SUPPLIERS_NAME) FLAGS_TOTAL_FLAGGED(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.FLAGS_TOTAL_FLAGGED) Cacheable(org.springframework.cache.annotation.Cacheable) TENDER_PROCURING_ENTITY_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID) Aggregation.sort(org.springframework.data.mongodb.core.aggregation.Aggregation.sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Award(org.devgateway.ocds.persistence.mongo.Award) Aggregation.match(org.springframework.data.mongodb.core.aggregation.Aggregation.match) AggregationOperation(org.springframework.data.mongodb.core.aggregation.AggregationOperation) TENDER_PERIOD_START_DATE(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) Fields(org.springframework.data.mongodb.core.aggregation.Fields) MongoConstants(org.devgateway.ocds.persistence.mongo.constants.MongoConstants) Fields.field(org.springframework.data.mongodb.core.aggregation.Fields.field) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) BigDecimal(java.math.BigDecimal) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) DBObject(com.mongodb.DBObject) BIDS_DETAILS_TENDERERS_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.BIDS_DETAILS_TENDERERS_ID) AWARDS_STATUS(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_STATUS) Map(java.util.Map) TENDER_PROCURING_ENTITY_NAME(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_NAME) Sort(org.springframework.data.domain.Sort) Aggregation.limit(org.springframework.data.mongodb.core.aggregation.Aggregation.limit) Criteria.where(org.springframework.data.mongodb.core.query.Criteria.where) Aggregation.skip(org.springframework.data.mongodb.core.aggregation.Aggregation.skip) AWARDS_SUPPLIERS_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Aggregation.unwind(org.springframework.data.mongodb.core.aggregation.Aggregation.unwind) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) RestController(org.springframework.web.bind.annotation.RestController) Serializable(java.io.Serializable) List(java.util.List) BIDS_DETAILS_VALUE_AMOUNT(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.BIDS_DETAILS_VALUE_AMOUNT) CriteriaDefinition(org.springframework.data.mongodb.core.query.CriteriaDefinition) CollectionUtils(org.springframework.util.CollectionUtils) Aggregation.project(org.springframework.data.mongodb.core.aggregation.Aggregation.project) CacheConfig(org.springframework.cache.annotation.CacheConfig) Optional(java.util.Optional) Assert(org.springframework.util.Assert) ArrayList(java.util.ArrayList) CriteriaDefinition(org.springframework.data.mongodb.core.query.CriteriaDefinition) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with YearFilterPagingRequest

use of org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest in project oc-explorer by devgateway.

the class CorruptionRiskDashboardIndicatorsStatsControllerTest method totalFlaggedIndicatorsByIndicatorTypeByYearTest.

@Test
public void totalFlaggedIndicatorsByIndicatorTypeByYearTest() throws Exception {
    final List<DBObject> result = corruptionRiskDashboardIndicatorsStatsController.totalFlaggedIndicatorsByIndicatorTypeByYear(new YearFilterPagingRequest());
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(FlagType.RIGGING.toString(), result.get(0).get(CorruptionRiskDashboardIndicatorsStatsController.Keys.TYPE));
    Assert.assertEquals(2, result.get(0).get(CorruptionRiskDashboardIndicatorsStatsController.Keys.INDICATOR_COUNT));
    Assert.assertEquals(2015, result.get(0).get(CorruptionRiskDashboardIndicatorsStatsController.Keys.YEAR));
}
Also used : YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

YearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest)100 Test (org.junit.Test)98 DBObject (com.mongodb.DBObject)96 BasicDBObject (com.mongodb.BasicDBObject)13 AbstractEndPointControllerTest (org.devgateway.ocds.web.rest.controller.AbstractEndPointControllerTest)10 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AbstractWebTest (org.devgateway.toolkit.web.AbstractWebTest)4 Collection (java.util.Collection)3 ApiOperation (io.swagger.annotations.ApiOperation)2 BigDecimal (java.math.BigDecimal)2 Valid (javax.validation.Valid)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 ReleasePackage (org.devgateway.ocds.persistence.mongo.ReleasePackage)2 MongoConstants (org.devgateway.ocds.persistence.mongo.constants.MongoConstants)2 CacheConfig (org.springframework.cache.annotation.CacheConfig)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)2 Aggregation.group (org.springframework.data.mongodb.core.aggregation.Aggregation.group)2 Aggregation.match (org.springframework.data.mongodb.core.aggregation.Aggregation.match)2