Coverage Report - edu.sampleu.bookstore.rule.BookOrderDocumentRule
 
Classes in this File Line Coverage Branch Coverage Complexity
BookOrderDocumentRule
0%
0/15
0%
0/12
9
 
 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.krad.document.Document;
 7  
 
 8  
 import org.kuali.rice.krad.rules.TransactionalDocumentRuleBase;
 9  
 import org.kuali.rice.krad.util.GlobalVariables;
 10  
 import org.kuali.rice.krad.util.KRADConstants;
 11  
 import edu.sampleu.bookstore.bo.BookOrder;
 12  
 import edu.sampleu.bookstore.document.BookOrderDocument;
 13  
 
 14  
 
 15  
 /*
 16  
  * Business Rule for Book Order Document that follows prior to submit action.
 17  
  * Checks that book order/orders is/are not null or Empty and all the attributes are mentioned for each order.
 18  
  */
 19  
 
 20  0
 public class BookOrderDocumentRule extends TransactionalDocumentRuleBase {
 21  
 
 22  
         private static final String BOOK_ORDERS_PROPERTY_PATH = KRADConstants.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  0
                 System.out.println("@@@@ IN RULE CHECK");
 33  
                 
 34  
                 // cast the document to a BookOrderDocument
 35  0
                 BookOrderDocument bookOrderDocument = (BookOrderDocument)document;
 36  
                 
 37  
                 // get the list of book orders of the book order document
 38  0
                 List<BookOrder> bookOrders = bookOrderDocument.getBookOrders();
 39  
                 
 40  
                 // make sure that the list is not empty
 41  0
                 if (bookOrders == null || bookOrders.isEmpty()) {
 42  0
                         GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, NO_BOOK_ORDERS_ERROR_KEY, ERROR_MESSAGE_NO_ORDERS);
 43  0
                         System.out.println("@@@@ FALSE RULE CHECK");
 44  0
                         return false;
 45  
                 } else {
 46  0
                         for(BookOrder bookOrder : bookOrders){                                
 47  0
                                 if(bookOrder.getBookId() == null || bookOrder.getDiscount() == null || bookOrder.getQuantity() == null){
 48  0
                                         GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, BOOK_ORDERS_EMPTY_ERROR_KEY, ERROR_MESSAGE_EMPTY_ORDERS);
 49  0
                                         System.out.println("@@@@ FALSE RULE CHECK");
 50  0
                                         return false;
 51  
                                 }                                
 52  
                         }
 53  
                         
 54  
                 }
 55  0
                 System.out.println("@@@@ TRUE RULE CHECK");
 56  
                 
 57  0
                 return super.processCustomRouteDocumentBusinessRules(document);
 58  
         }
 59  
 
 60  
         
 61  
 
 62  
         
 63  
         
 64  
 }