1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
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
45 System.out.println("****Inside Global*****");
46
47 Author author = (Author)document.getDocumentDataObject();
48 System.out.println("Inside Global Aothor Got is : " + author);
49 System.out.println("****Inside Global*****");
50
51 List<Address> addressEntries = author.getAddresses();
52 System.out.println("Inside Global Aothor address is : " + addressEntries);
53
54
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 }