petshop-05-checks.spp
petshop/fulfillment/petshop-05-checks.spp
Download original file · Petstore source contents
1domain petshop;23atomic check checkShipmentAgreementInput(ShipmentAgreement) {4require(ShipmentAgreement.tracking != null && ShipmentAgreement.tracking != "", "TRACKING_REQUIRED");5}67atomic check checkShipmentEligibility(ShopOrder) {8require(ShopOrder.status == OrderStatus.PAID, "ORDER_NOT_SHIPPABLE");9}1011atomic check checkDeliveryEligibility(ShopOrder) {12require(ShopOrder.status == OrderStatus.SHIPPED, "ORDER_NOT_DELIVERABLE");13}1415atomic check checkReservedInventory(ShopOrder, StockLine[]) {16for (OrderLine line : ShopOrder.lines) {17boolean found = false;18for (StockLine stock : StockLine[]) {19if (stock.goods.sku == line.goods.sku) {20int needed = 0;21for (OrderLine ordered : ShopOrder.lines) {22if (ordered.goods.sku == line.goods.sku) {23needed += ordered.quantity;24}25}26require(stock.reserved >= needed, "RESERVATION_MISSING");27found = true;28}29}30require(found, "INVENTORY_ITEM_NOT_FOUND");31}32}