View Javadoc

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