// 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 inventory; private final CateringCatalog cateringCatalog; InventoryInitializer(UniqueInventory 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))); } }); } }