Search in sources :

Example 11 with KeyItem

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

the class KeyItem_Test method testValidateChangeAuditedValue.

@Test
public void testValidateChangeAuditedValue() {
    // given
    KeyTable table = new KeyTable();
    table.setPrecision(3);
    KeyItem item = new KeyItem();
    item.setAuditedValue(new BigDecimal(2));
    item.setKeyTable(table);
    assertTrue(item.getAuditedValue().equals(new BigDecimal(2)));
    // when, then
    assertEquals(item.validateChangeAuditedValue(BigDecimal.valueOf(-0.001)), "Value cannot be less than zero");
}
Also used : KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Example 12 with KeyItem

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

the class KeyItem_Test method testValidateChangeSourceValue.

@Test
public void testValidateChangeSourceValue() {
    // given
    KeyTable table = new KeyTable();
    table.setPrecision(3);
    KeyItem item = new KeyItem();
    item.setSourceValue(new BigDecimal(2));
    item.setKeyTable(table);
    assertTrue(item.getSourceValue().equals(new BigDecimal(2)));
    // when, then
    assertEquals(item.validateChangeSourceValue(BigDecimal.valueOf(-0.001)), "Source Value must be positive");
    assertEquals(item.validateChangeSourceValue(BigDecimal.ZERO), null);
}
Also used : KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) BigDecimal(java.math.BigDecimal) AbstractBeanPropertiesTest(org.incode.module.unittestsupport.dom.bean.AbstractBeanPropertiesTest) Test(org.junit.Test)

Example 13 with KeyItem

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

the class KeyValueMethod_Test method testIsNotValid.

@Test
public void testIsNotValid() {
    // 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.999));
        budgetKeyItems.add(budgetKeyItem);
    }
    keyTable.setItems(budgetKeyItems);
    keyTable.setPrecision(3);
    // then
    assertThat(method.keySum(keyTable)).isEqualTo(BigDecimal.valueOf(999.999).setScale(3, BigDecimal.ROUND_HALF_UP));
    assertThat(method.isValid(keyTable)).isFalse();
}
Also used : TreeSet(java.util.TreeSet) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem) Test(org.junit.Test)

Example 14 with KeyItem

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

the class KeyValueMethod_Test method testIsAlsoValid.

@Test
public void testIsAlsoValid() {
    // 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(1000.0001));
        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 15 with KeyItem

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

the class BudgetImportExportManager method importKeyTables.

private void importKeyTables(final List<BudgetImportExport> budgetItemLines, final List<List<?>> objects) {
    List<KeyTable> keyTablesToImport = keyTablesToImport(budgetItemLines);
    List<KeyItemImportExportLineItem> keyItemLines = (List<KeyItemImportExportLineItem>) objects.get(1);
    // filter case where no key items are filled in
    if (keyItemLines.size() == 0) {
        return;
    }
    for (KeyTable keyTable : keyTablesToImport) {
        List<KeyItemImportExportLineItem> itemsToImportForKeyTable = new ArrayList<>();
        for (KeyItemImportExportLineItem keyItemLine : keyItemLines) {
            if (keyItemLine.getKeyTableName().equals(keyTable.getName())) {
                itemsToImportForKeyTable.add(new KeyItemImportExportLineItem(keyItemLine));
            }
        }
        for (KeyItem keyItem : keyTable.getItems()) {
            Boolean keyItemFound = false;
            for (KeyItemImportExportLineItem lineItem : itemsToImportForKeyTable) {
                if (lineItem.getUnitReference().equals(keyItem.getUnit().getReference())) {
                    keyItemFound = true;
                    break;
                }
            }
            if (!keyItemFound) {
                KeyItemImportExportLineItem deletedItem = new KeyItemImportExportLineItem(keyItem);
                deletedItem.setStatus(Status.DELETED);
                itemsToImportForKeyTable.add(deletedItem);
            }
        }
        for (KeyItemImportExportLineItem item : itemsToImportForKeyTable) {
            serviceRegistry2.injectServicesInto(item);
            item.validate();
            item.apply();
        }
    }
}
Also used : KeyItemImportExportLineItem(org.estatio.module.budgetassignment.imports.KeyItemImportExportLineItem) ArrayList(java.util.ArrayList) KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) ArrayList(java.util.ArrayList) List(java.util.List) KeyItem(org.estatio.module.budget.dom.keyitem.KeyItem)

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