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");
}
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);
}
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();
}
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();
}
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();
}
}
}
Aggregations