1 package edu.sampleu.bookstore.rule;
2
3 import edu.sampleu.bookstore.bo.BookOrder;
4 import edu.sampleu.bookstore.document.BookOrderDocument;
5 import org.kuali.rice.core.api.util.RiceKeyConstants;
6 import org.kuali.rice.krad.document.Document;
7 import org.kuali.rice.krad.rules.TransactionalDocumentRuleBase;
8 import org.kuali.rice.krad.util.GlobalVariables;
9 import org.kuali.rice.krad.util.KRADConstants;
10
11 import java.util.List;
12
13
14
15
16
17
18
19 public class BookOrderDocumentRule extends TransactionalDocumentRuleBase {
20
21 private static final String BOOK_ORDERS_PROPERTY_PATH = KRADConstants.DOCUMENT_PROPERTY_NAME + ".bookOrders";
22 private static final String NO_BOOK_ORDERS_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
23 private static final String ERROR_MESSAGE_NO_ORDERS = "You must add at least one entry to your book order.";
24
25 private static final String BOOK_ORDERS_EMPTY_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
26 private static final String ERROR_MESSAGE_EMPTY_ORDERS = "You must add attributes to your book order.";
27
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(Document document) {
30
31 System.out.println("@@@@ IN RULE CHECK");
32
33
34 BookOrderDocument bookOrderDocument = (BookOrderDocument)document;
35
36
37 List<BookOrder> bookOrders = bookOrderDocument.getBookOrders();
38
39
40 if (bookOrders == null || bookOrders.isEmpty()) {
41 GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, NO_BOOK_ORDERS_ERROR_KEY, ERROR_MESSAGE_NO_ORDERS);
42 System.out.println("@@@@ FALSE RULE CHECK");
43 return false;
44 } else {
45 for(BookOrder bookOrder : bookOrders){
46 if(bookOrder.getBookId() == null || bookOrder.getDiscount() == null || bookOrder.getQuantity() == null){
47 GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, BOOK_ORDERS_EMPTY_ERROR_KEY, ERROR_MESSAGE_EMPTY_ORDERS);
48 System.out.println("@@@@ FALSE RULE CHECK");
49 return false;
50 }
51 }
52
53 }
54 System.out.println("@@@@ TRUE RULE CHECK");
55
56 return super.processCustomRouteDocumentBusinessRules(document);
57 }
58
59
60
61
62
63 }