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  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Business Rule for Book Order Document that follows prior to submit action.
 31  
  * Checks that book order/orders is/are not null or Empty and all the attributes are mentioned for each order.
 32  
  */
 33  
 
 34  0
 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  0
                 System.out.println("@@@@ IN RULE CHECK");
 47  
                 
 48  
                 // cast the document to a BookOrderDocument
 49  0
                 BookOrderDocument bookOrderDocument = (BookOrderDocument)document;
 50  
                 
 51  
                 // get the list of book orders of the book order document
 52  0
                 List<BookOrder> bookOrders = bookOrderDocument.getBookOrders();
 53  
                 
 54  
                 // make sure that the list is not empty
 55  0
                 if (bookOrders == null || bookOrders.isEmpty()) {
 56  0
                         GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, NO_BOOK_ORDERS_ERROR_KEY, ERROR_MESSAGE_NO_ORDERS);
 57  0
                         System.out.println("@@@@ FALSE RULE CHECK");
 58  0
                         return false;
 59  
                 } else {
 60  0
                         for(BookOrder bookOrder : bookOrders){                                
 61  0
                                 if(bookOrder.getBookId() == null || bookOrder.getDiscount() == null || bookOrder.getQuantity() == null){
 62  0
                                         GlobalVariables.getMessageMap().putError(BOOK_ORDERS_PROPERTY_PATH, BOOK_ORDERS_EMPTY_ERROR_KEY, ERROR_MESSAGE_EMPTY_ORDERS);
 63  0
                                         System.out.println("@@@@ FALSE RULE CHECK");
 64  0
                                         return false;
 65  
                                 }                                
 66  
                         }
 67  
                         
 68  
                 }
 69  0
                 System.out.println("@@@@ TRUE RULE CHECK");
 70  
                 
 71  0
                 return super.processCustomRouteDocumentBusinessRules(document);
 72  
         }
 73  
 
 74  
         
 75  
 
 76  
         
 77  
         
 78  
 }