Search in sources :

Example 26 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class KeyValueMethod_Test method testIsValid.

@Test
public void testIsValid() {
    // given
    KeyValueMethod method = KeyValueMethod.PROMILLE;
    KeyTable keyTable = new KeyTable();
    SortedSet<KeyItem> budgetKeyItems = new TreeSet<>();
    for (int i = 0; i < 1; i = i + 1) {
        KeyItem budgetKeyItem = new KeyItem();
        budgetKeyItem.setValue(BigDecimal.valueOf(999.9999));
        budgetKeyItems.add(budgetKeyItem);
    }
    keyTable.setItems(budgetKeyItems);
    keyTable.setPrecision(3);
    // then
    assertThat(method.keySum(keyTable)).isEqualTo(new BigDecimal(1000).setScale(3, BigDecimal.ROUND_HALF_UP));
    assertThat(method.isValid(keyTable)).isTrue();
}
Also used : TreeSet(java.util.TreeSet) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 27 with KeyItem

use of org.estatio.module.budget.dom.keyitem.KeyItem in project estatio by estatio.

the class KeyItemImportExportManager method importBlob.

// endregion
// region > import (action)
@Action(publishing = Publishing.DISABLED, semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(named = "Import", cssClassFa = "fa-upload")
@MemberOrder(name = "keyItems", sequence = "2")
public List<KeyItemImportExportLineItem> importBlob(@Parameter(fileAccept = ".xlsx") @ParameterLayout(named = "Excel spreadsheet") final Blob spreadsheet) {
    WorksheetSpec spec = new WorksheetSpec(KeyItemImportExportLineItem.class, "keyItems");
    List<KeyItemImportExportLineItem> lineItems = excelService.fromExcel(spreadsheet, spec);
    container.informUser(lineItems.size() + " items imported");
    List<KeyItemImportExportLineItem> newItems = new ArrayList<>();
    for (KeyItemImportExportLineItem item : lineItems) {
        item.validate();
        newItems.add(new KeyItemImportExportLineItem(item));
    }
    for (KeyItem keyItem : keyTable.getItems()) {
        Boolean keyItemFound = false;
        for (KeyItemImportExportLineItem lineItem : newItems) {
            if (lineItem.getUnitReference().equals(keyItem.getUnit().getReference())) {
                keyItemFound = true;
                break;
            }
        }
        if (!keyItemFound) {
            KeyItemImportExportLineItem deletedItem = new KeyItemImportExportLineItem(keyItem);
            deletedItem.setStatus(Status.DELETED);
            newItems.add(deletedItem);
        }
    }
    return newItems;
}
Also used : WorksheetSpec(org.isisaddons.module.excel.dom.WorksheetSpec) ArrayList(java.util.ArrayList) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

KeyItem (org.estatio.module.budget.dom.keyitem.KeyItem)27 BigDecimal (java.math.BigDecimal)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)17 KeyTable (org.estatio.module.budget.dom.keytable.KeyTable)7 AbstractBeanPropertiesTest (org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest)6 TreeSet (java.util.TreeSet)3 Action (org.apache.isis.applib.annotation.Action)3 List (java.util.List)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)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 KeyItemImportExportLineItem (org.estatio.module.budgetassignment.imports.KeyItemImportExportLineItem)1 WorksheetSpec (org.isisaddons.module.excel.dom.WorksheetSpec)1