mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
50 lines
1.8 KiB
Java
50 lines
1.8 KiB
Java
|
/*
|
||
|
* Copyright (C) 2023 Simon Bruder
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
package catering.inventory;
|
||
|
|
||
|
import org.salespointframework.core.DataInitializer;
|
||
|
import org.salespointframework.inventory.UniqueInventory;
|
||
|
import org.salespointframework.inventory.UniqueInventoryItem;
|
||
|
import org.salespointframework.quantity.Quantity;
|
||
|
import org.springframework.stereotype.Component;
|
||
|
import org.springframework.util.Assert;
|
||
|
|
||
|
import catering.catalog.CateringCatalog;
|
||
|
|
||
|
@Component
|
||
|
class InventoryInitializer implements DataInitializer {
|
||
|
private final UniqueInventory<UniqueInventoryItem> inventory;
|
||
|
private final CateringCatalog cateringCatalog;
|
||
|
|
||
|
InventoryInitializer(UniqueInventory<UniqueInventoryItem> inventory, CateringCatalog cateringCatalog) {
|
||
|
Assert.notNull(inventory, "Inventory must not be null!");
|
||
|
Assert.notNull(cateringCatalog, "CateringCatalog must not be null!");
|
||
|
|
||
|
this.inventory = inventory;
|
||
|
this.cateringCatalog = cateringCatalog;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void initialize() {
|
||
|
cateringCatalog.findAll().forEach(product -> {
|
||
|
if (inventory.findByProduct(product).isEmpty()) {
|
||
|
inventory.save(new UniqueInventoryItem(product, Quantity.of(10)));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|