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 | |
|
17 | |
|
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 | |
|
32 | 0 | System.out.println("****Inside Global*****"); |
33 | |
|
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 | |
|
38 | 0 | List<Address> addressEntries = author.getAddresses(); |
39 | 0 | System.out.println("Inside Global Aothor address is : " + addressEntries); |
40 | |
|
41 | |
|
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 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
} |