View Javadoc

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.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  
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  public class AuthorMaintenanceDocumentRule extends MaintenanceDocumentRuleBase {
21  	private static final String AUTHOR_ENTRIES_PROPERTY_PATH = KRADConstants.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  		System.out.println("****Inside Global*****");
33  		// cast the document to a Author Document
34  		Author author = (Author)document.getDocumentDataObject();
35  		System.out.println("Inside Global Aothor Got is : " + author);
36  		System.out.println("****Inside Global*****");
37  		// get the list of book order entries off of the book order document
38  		List<Address> addressEntries = author.getAddresses();
39  		System.out.println("Inside Global Aothor address is : " + addressEntries);
40  		
41  		// make sure that the list is not empty
42  		if (addressEntries == null || addressEntries.isEmpty()) {
43  			System.out.println("--Got addressEntries Null--");
44  			GlobalVariables.getMessageMap().putError(
45  					AUTHOR_ENTRIES_PROPERTY_PATH,NO_ADDRESS_TYPE_ERROR_KEY,
46  					ERROR_MESSAGE_NO_ADDTYPE_FOUND);
47  			return false;
48  		} else {
49  			System.out.println("--Got addressEntries Obj--");
50  			System.out.println("Inside Global Aothor address Size is : " + addressEntries.size());
51  			Address tempAddress = null;
52  			for(Address address : addressEntries){
53  				tempAddress = address;
54  				for(Address address2 : addressEntries){
55  					if(!tempAddress.equals(address2)){
56  						if(tempAddress.getAddressType()!= null && tempAddress.getAddressType() != null && tempAddress.getAddressType().getType().equals(address2.getAddressType().getType())){
57  							System.out.println("Got Same Address Typr");
58  							GlobalVariables.getMessageMap().putError(
59  									AUTHOR_ENTRIES_PROPERTY_PATH,SAME_ADDRESS_TYPE_ERROR_KEY,
60  									ERROR_MESSAGE_SAME_ADDTYPR_FOUND);
61  							return false;
62  						}
63  					}else {
64  						System.out.println("Got Same Address Object");
65  					} 
66  				}
67  			}
68  			
69  		}
70  		
71  		
72  		
73  		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  }