petshop-05-checks.spp
petshop/order/petshop-05-checks.spp
Download original file · Petstore source contents
1domain petshop;23atomic check checkQuotationInput(Cart, Goods[]) {4require(cart.lines != null, RejectionCode.EMPTY_CART);5int count = 0;6for (CartLine line : cart.lines) {7require(line != null && line.quantity != null && line.quantity > 0, RejectionCode.INVALID_QUANTITY);8boolean found = false;9for (Goods product : goodss) {10if (product.sku == line.goods.sku) {11found = true;12}13}14require(found, RejectionCode.PRODUCT_UNAVAILABLE);15count++;16}17require(count > 0, RejectionCode.EMPTY_CART);18}1920atomic check checkUnpaidCancellationAgreementInput(UnpaidCancellationAgreement) {21require( unpaidCancellationAgreement.reason != BLANK, RejectionCode.REASON_REQUIRED );22}2324atomic check checkUnpaidCancellation(ShopOrder) {25require(shopOrder.status == OrderStatus.UNPAID, RejectionCode.ORDER_NOT_CANCELLABLE);26}2728atomic check checkPaidCancellationAgreementInput(PaidCancellationAgreement) {29require( paidCancellationAgreement.reason != BLANK, RejectionCode.REASON_REQUIRED );30}3132atomic check checkPaidCancellation(ShopOrder) {33require(shopOrder.status == OrderStatus.PAID, RejectionCode.ORDER_NOT_CANCELLABLE);34}3536atomic check checkOrderReservation(ShopOrder, StockLine[]) {37for (OrderLine line : shopOrder.lines) {38boolean found = false;39for (StockLine stock : stockLines) {40if (stock.goods.sku == line.goods.sku) {41int needed = 0;42for (OrderLine ordered : shopOrder.lines) {43if (ordered.goods.sku == line.goods.sku) {44needed += ordered.quantity;45}46}47require(stock.available >= needed, RejectionCode.INSUFFICIENT_STOCK);48found = true;49}50}51require(found, RejectionCode.INVENTORY_ITEM_NOT_FOUND);52}53}