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