Search in sources :

Example 1 with Distributable

use of org.estatio.module.budget.dom.Distributable in project estatio by estatio.

the class KeyTable method generateItems.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
public KeyTable generateItems() {
    // delete old items
    for (Iterator<KeyItem> it = this.getItems().iterator(); it.hasNext(); ) {
        it.next().deleteBudgetKeyItem();
    }
    /*
        create list of input pairs: identifier - sourcevalue
        sourcevalue is determined by FoundationValueType
        */
    List<Distributable> input = new ArrayList<>();
    for (Unit unit : unitRepository.findByProperty(this.getBudget().getProperty())) {
        if (unitIntervalValidForThisKeyTable(unit)) {
            BigDecimal sourceValue;
            if (getFoundationValueType().valueOf(unit) != null) {
                sourceValue = getFoundationValueType().valueOf(unit);
            } else {
                sourceValue = BigDecimal.ZERO;
            }
            KeyItem newItem = new KeyItem();
            newItem.setSourceValue(sourceValue);
            newItem.setValue(BigDecimal.ZERO);
            newItem.setUnit(unit);
            newItem.setKeyTable(this);
            persistIfNotAlready(newItem);
            input.add(newItem);
        }
    }
    /*
        call distribute method
         */
    DistributionService distributionService = new DistributionService();
    distributionService.distribute(input, getKeyValueMethod().divider(this), getPrecision());
    return this;
}
Also used : Distributable(org.estatio.module.budget.dom.Distributable) ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) Unit(org.estatio.module.asset.dom.Unit) BigDecimal(java.math.BigDecimal) DistributionService(org.estatio.module.budget.dom.DistributionService) Action(org.apache.isis.applib.annotation.Action)

Aggregations

BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Action (org.apache.isis.applib.annotation.Action)1 Unit (org.estatio.module.asset.dom.Unit)1 Distributable (org.estatio.module.budget.dom.Distributable)1 DistributionService (org.estatio.module.budget.dom.DistributionService)1 KeyItem (org.estatio.module.budget.dom.keyitem.KeyItem)1