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