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