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