swt23w23/src/main/java/catering/inventory/InventoryInizializer.java
Simon Bruder bac025fd0a
Make project REUSE compliant
This finally makes the licensing under AGPL-3.0-or-later explicit after
I got the okay from the kickstart source owners.

This also checks the REUSE compliance in a pre commit hook, and
therefore also in CI.
2023-12-11 17:59:14 +01:00

36 lines
1.2 KiB
Java

// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2023 swt23w23
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)));
}
});
}
}