Search in sources :

Example 1 with KeyItemImportExportLineItem

use of org.estatio.module.budgetassignment.imports.KeyItemImportExportLineItem 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

ArrayList (java.util.ArrayList)1 List (java.util.List)1 KeyItem (org.estatio.module.budget.dom.keyitem.KeyItem)1 KeyTable (org.estatio.module.budget.dom.keytable.KeyTable)1 KeyItemImportExportLineItem (org.estatio.module.budgetassignment.imports.KeyItemImportExportLineItem)1