Search in sources :

Example 1 with EntityCost

use of org.finos.waltz.model.cost.EntityCost in project waltz by khartec.

the class CostService method summariseByCostKindAndSelector.

public EntityCostsSummary summariseByCostKindAndSelector(Long costKindId, IdSelectionOptions selectionOptions, EntityKind targetKind, int limit) {
    GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, selectionOptions);
    Set<EntityCost> topCosts = time("topCosts: " + selectionOptions.entityReference(), () -> costDao.findTopCostsForCostKindAndSelector(costKindId, genericSelector, limit));
    Integer year = maybeFirst(topCosts).map(EntityCost::year).orElse(LocalDate.now().getYear());
    BigDecimal totalCost = time("totalCosts: " + selectionOptions.entityReference(), () -> costDao.getTotalForKindAndYearBySelector(costKindId, year, genericSelector));
    Tuple2<Integer, Integer> mappedAndMissingCounts = time("missingCosts: " + selectionOptions.entityReference(), () -> costDao.getMappedAndMissingCountsForKindAndYearBySelector(costKindId, year, genericSelector));
    return ImmutableEntityCostsSummary.builder().costKind(costKindDao.getById(costKindId)).year(year).total(ofNullable(totalCost).orElse(BigDecimal.ZERO)).topCosts(topCosts).mappedCount(mappedAndMissingCounts.v1).missingCount(mappedAndMissingCounts.v2).build();
}
Also used : EntityCost(org.finos.waltz.model.cost.EntityCost) GenericSelector(org.finos.waltz.data.GenericSelector) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 GenericSelector (org.finos.waltz.data.GenericSelector)1 EntityCost (org.finos.waltz.model.cost.EntityCost)1