test_class.declarator: costEffectivenessVisualsController
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private CostEffectivenessVisualsController costEffectivenessVisualsController;
test_class.type: CostEffectivenessVisualsController
test_class.var_name: costEffectivenessVisualsController
test_class.file: web/src/test/java/org/devgateway/ocds/web/rest/controller/CostEffectivenessVisualsControllerTest.java
test_class.identifier: CostEffectivenessVisualsControllerTest
test_class.superclass: extends AbstractEndPointControllerTest
test_case.body: @Test
      public void costEffectivenessTenderAwardAmount() throws Exception {
          final ArrayList<Document> costEffectivenessTenderAwardAmount = costEffectivenessVisualsController
                  .costEffectivenessTenderAwardAmount(new GroupingFilterPagingRequest());
  
          final Document first = costEffectivenessTenderAwardAmount.get(0);
          int year = (int) first.get(CostEffectivenessVisualsController.Keys.YEAR);
          BigDecimal diffTenderAwardAmount = (BigDecimal) first
                  .get(CostEffectivenessVisualsController.Keys.DIFF_TENDER_AWARD_AMOUNT);
          Assert.assertEquals(-5400000, diffTenderAwardAmount.doubleValue(), 0);
          Assert.assertEquals(2014, year);
  
          final Document second = costEffectivenessTenderAwardAmount.get(1);
          year = (int) second.get(CostEffectivenessVisualsController.Keys.YEAR);
          diffTenderAwardAmount = (BigDecimal) second
                  .get(CostEffectivenessVisualsController.Keys.DIFF_TENDER_AWARD_AMOUNT);
          Assert.assertEquals(2015, year);
          Assert.assertEquals(-31000, diffTenderAwardAmount.doubleValue(), 0);
  
  //        final DBObject third = costEffectivenessTenderAwardAmount.get(2);
  //        year = (int) third.get(Fields.UNDERSCORE_ID);
  //        diffTenderAwardAmount = (BigDecimal) third
  //                .get(CostEffectivenessVisualsController.Keys.DIFF_TENDER_AWARD_AMOUNT);
  //        Assert.assertEquals(2014, year);
  //        Assert.assertEquals(600000, diffTenderAwardAmount.doubleValue(), 0);
      }
test_case.class_method_signature: CostEffectivenessVisualsControllerTest.costEffectivenessTenderAwardAmount()
test_case.full_signature: @Test public void costEffectivenessTenderAwardAmount()
test_case.identifier: costEffectivenessTenderAwardAmount
test_case.invocations: costEffectivenessTenderAwardAmount get get get assertEquals doubleValue assertEquals get get get assertEquals assertEquals doubleValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void costEffectivenessTenderAwardAmount()
focal_class.declarator: controllerLookupService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private AsyncControllerLookupService controllerLookupService;
focal_class.type: AsyncControllerLookupService
focal_class.var_name: controllerLookupService
focal_class.file: web/src/main/java/org/devgateway/ocds/web/rest/controller/CostEffectivenessVisualsController.java
focal_class.identifier: CostEffectivenessVisualsController
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Cost effectiveness of Awards: Displays the total amount of active awards grouped by year." + "The tender entity, for each award, has to have amount value. The year is calculated from " + MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) @RequestMapping(value = "/api/costEffectivenessAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.identifier: costEffectivenessAwardAmount
focal_class.modifiers: @ApiOperation(value = "Cost effectiveness of Awards: Displays the total amount of active awards grouped by year." + "The tender entity, for each award, has to have amount value. The year is calculated from " + MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) @RequestMapping(value = "/api/costEffectivenessAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.identifier: costEffectivenessTenderAmount
focal_class.modifiers: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.class_method_signature: CostEffectivenessVisualsController.getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.full_signature: private String getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.identifier: getYearMonthlyKey
focal_class.modifiers: private
focal_class.parameters: (GroupingFilterPagingRequest filter, Document db)
focal_class.return: String
focal_class.signature: String getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.identifier: costEffectivenessTenderAwardAmount
focal_class.modifiers: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.return: ArrayList<Document>
focal_class.signature: ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.superclass: extends GenericOCDSController
focal_method.body: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and "
              + "/api/costEffectivenessAwardAmount."
              + "This endpoint aggregates the responses from the specified endpoints, per year. "
              + "Responds to the same filters.")
      @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST,
              RequestMethod.GET}, produces = "application/json")
      public ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter) {
  
          Future<List<Document>> costEffectivenessAwardAmountFuture = controllerLookupService
                  .asyncInvoke(new AsyncBeanParamControllerMethodCallable<List<Document>, GroupingFilterPagingRequest>() {
                      @Override
                      public List<Document> invokeControllerMethod(GroupingFilterPagingRequest filter) {
                          return costEffectivenessAwardAmount(filter);
                      }
                  }, filter);
  
  
          Future<List<Document>> costEffectivenessTenderAmountFuture = controllerLookupService
                  .asyncInvoke(new AsyncBeanParamControllerMethodCallable<List<Document>, GroupingFilterPagingRequest>() {
                      @Override
                      public List<Document> invokeControllerMethod(GroupingFilterPagingRequest filter) {
                          return costEffectivenessTenderAmount(filter);
                      }
                  }, filter);
  
  
          //this is completely unnecessary since the #get methods are blocking
          //controllerLookupService.waitTillDone(costEffectivenessAwardAmountFuture, costEffectivenessTenderAmountFuture);
  
  
          LinkedHashMap<Object, Document> response = new LinkedHashMap<>();
  
          try {
  
              costEffectivenessAwardAmountFuture.get()
                      .forEach(dbobj -> response.put(getYearMonthlyKey(filter, dbobj), dbobj));
              costEffectivenessTenderAmountFuture.get().forEach(dbobj -> {
                  if (response.containsKey(getYearMonthlyKey(filter, dbobj))) {
                      HashMap<String, Object> map = new HashMap<>(dbobj);
                      map.remove(Keys.YEAR);
                      if (filter.getMonthly()) {
                          map.remove(Keys.MONTH);
                      }
                      response.get(getYearMonthlyKey(filter, dbobj)).putAll(map);
                  } else {
                      response.put(getYearMonthlyKey(filter, dbobj), dbobj);
                  }
              });
  
          } catch (InterruptedException | ExecutionException e) {
              throw new RuntimeException(e);
          }
  
          Collection<Document> respCollection = response.values();
  
          respCollection.forEach(dbobj -> {
  
              BigDecimal totalTenderAmount = BigDecimal
                      .valueOf(dbobj.get(Keys.TOTAL_TENDER_AMOUNT) == null ? 0d
                              : ((Number) dbobj.get(Keys.TOTAL_TENDER_AMOUNT)).doubleValue());
  
              BigDecimal totalAwardAmount = BigDecimal
                      .valueOf(dbobj.get(Keys.TOTAL_AWARD_AMOUNT) == null ? 0d
                              : ((Number) dbobj.get(Keys.TOTAL_AWARD_AMOUNT)).doubleValue());
  
              dbobj.put(
                      Keys.DIFF_TENDER_AWARD_AMOUNT,
                      totalTenderAmount
                              .subtract(totalAwardAmount)
              );
  
              dbobj.put(
                      Keys.PERCENTAGE_AWARD_AMOUNT,
                      totalTenderAmount.compareTo(BigDecimal.ZERO) != 0
                              ? (totalAwardAmount.setScale(15)
                              .divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP)
                              .multiply(ONE_HUNDRED)) : BigDecimal.ZERO
              );
  
              dbobj.put(
                      Keys.PERCENTAGE_DIFF_AMOUNT,
                      totalTenderAmount.compareTo(BigDecimal.ZERO) != 0
                              ? (((BigDecimal) dbobj.get(Keys.DIFF_TENDER_AWARD_AMOUNT)).setScale(15)
                              .divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP)
                              .multiply(ONE_HUNDRED)) : BigDecimal.ZERO
              );
  
          });
  
          return new ArrayList<>(respCollection);
      }
focal_method.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.full_signature: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.identifier: costEffectivenessTenderAwardAmount
focal_method.invocations: asyncInvoke costEffectivenessAwardAmount asyncInvoke costEffectivenessTenderAmount forEach get put getYearMonthlyKey forEach get containsKey getYearMonthlyKey remove getMonthly remove putAll get getYearMonthlyKey put getYearMonthlyKey values forEach valueOf get doubleValue get valueOf get doubleValue get put subtract put compareTo multiply divide setScale put compareTo multiply divide setScale get
focal_method.modifiers: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_method.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.return: ArrayList<Document>
focal_method.signature: ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)