Coverage Report - edu.sampleu.bookstore.rule.AuthorMaintenanceDocumentRule
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorMaintenanceDocumentRule
0%
0/24
0%
0/16
11
 
 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.MaintenanceDocument;
 7  
 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
 8  
 import org.kuali.rice.kns.util.GlobalVariables;
 9  
 import org.kuali.rice.kns.util.KNSConstants;
 10  
 
 11  
 
 12  
 import edu.sampleu.bookstore.bo.Author;
 13  
 import edu.sampleu.bookstore.bo.Address;
 14  
 
 15  
 /*
 16  
  * Business Rule for Author Document that follows prior to submit action.
 17  
  * Checks that Author Document has at least one address and no two address should be of same type. 
 18  
  */
 19  
 
 20  0
 public class AuthorMaintenanceDocumentRule extends MaintenanceDocumentRuleBase {
 21  
         private static final String AUTHOR_ENTRIES_PROPERTY_PATH = KNSConstants.DOCUMENT_PROPERTY_NAME
 22  
                         + ".authorEntries";
 23  
         private static final String NO_ADDRESS_TYPE_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
 24  
         private static final String ERROR_MESSAGE_NO_ADDTYPE_FOUND = "You must add atleast one address for Author.";
 25  
         private static final String SAME_ADDRESS_TYPE_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
 26  
         private static final String ERROR_MESSAGE_SAME_ADDTYPR_FOUND = "You must not repeat address type for addresses of Author.";
 27  
 
 28  
         @Override
 29  
         protected boolean processGlobalRouteDocumentBusinessRules(
 30  
                         MaintenanceDocument document) {
 31  
                 // TODO Auto-generated method stub
 32  0
                 System.out.println("****Inside Global*****");
 33  
                 // cast the document to a Author Document
 34  0
                 Author author = (Author)document.getDocumentBusinessObject();
 35  0
                 System.out.println("Inside Global Aothor Got is : " + author);
 36  0
                 System.out.println("****Inside Global*****");
 37  
                 // get the list of book order entries off of the book order document
 38  0
                 List<Address> addressEntries = author.getAddresses();
 39  0
                 System.out.println("Inside Global Aothor address is : " + addressEntries);
 40  
                 
 41  
                 // make sure that the list is not empty
 42  0
                 if (addressEntries == null || addressEntries.isEmpty()) {
 43  0
                         System.out.println("--Got addressEntries Null--");
 44  0
                         GlobalVariables.getMessageMap().putError(
 45  
                                         AUTHOR_ENTRIES_PROPERTY_PATH,NO_ADDRESS_TYPE_ERROR_KEY,
 46  
                                         ERROR_MESSAGE_NO_ADDTYPE_FOUND);
 47  0
                         return false;
 48  
                 } else {
 49  0
                         System.out.println("--Got addressEntries Obj--");
 50  0
                         System.out.println("Inside Global Aothor address Size is : " + addressEntries.size());
 51  0
                         Address tempAddress = null;
 52  0
                         for(Address address : addressEntries){
 53  0
                                 tempAddress = address;
 54  0
                                 for(Address address2 : addressEntries){
 55  0
                                         if(!tempAddress.equals(address2)){
 56  0
                                                 if(tempAddress.getAddressType()!= null && tempAddress.getAddressType() != null && tempAddress.getAddressType().getType().equals(address2.getAddressType().getType())){
 57  0
                                                         System.out.println("Got Same Address Typr");
 58  0
                                                         GlobalVariables.getMessageMap().putError(
 59  
                                                                         AUTHOR_ENTRIES_PROPERTY_PATH,SAME_ADDRESS_TYPE_ERROR_KEY,
 60  
                                                                         ERROR_MESSAGE_SAME_ADDTYPR_FOUND);
 61  0
                                                         return false;
 62  
                                                 }
 63  
                                         }else {
 64  0
                                                 System.out.println("Got Same Address Object");
 65  
                                         } 
 66  
                                 }
 67  
                         }
 68  
                         
 69  
                 }
 70  
                 
 71  
                 
 72  
                 
 73  0
                 return super.processGlobalRouteDocumentBusinessRules(document);
 74  
         }
 75  
 
 76  
 //        @Override
 77  
 //        protected boolean processCustomRouteDocumentBusinessRules(Document document) {
 78  
 //                System.out.println("****Inside Custom*****");
 79  
 //                // cast the document to a Author Document
 80  
 //                AuthorDocument author = (AuthorDocument) document;
 81  
 //
 82  
 //                // get the list of book order entries off of the book order document
 83  
 //                List<Address> addressEntries = author.getAuthorAddEntries();
 84  
 //
 85  
 //                // make sure that the list is not empty
 86  
 //                if (addressEntries == null && addressEntries.isEmpty()) {
 87  
 //                        System.out.println("Got address Null");
 88  
 //                        GlobalVariables.getMessageMap().putError(
 89  
 //                                        AUTHOR_ENTRIES_PROPERTY_PATH, SAME_ADDRESS_TYPE_ERROR_KEY,
 90  
 //                                        ERROR_MESSAGE);
 91  
 //                        return false;
 92  
 //                }
 93  
 //
 94  
 //                return super.processCustomRouteDocumentBusinessRules(document);
 95  
 //        }
 96  
 
 97  
 }