1 package edu.sampleu.bookstore.rule;
2
3 import edu.sampleu.bookstore.bo.Address;
4 import edu.sampleu.bookstore.bo.Author;
5 import org.kuali.rice.core.api.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 import java.util.List;
12
13
14
15
16
17
18 public class AuthorMaintenanceDocumentRule extends MaintenanceDocumentRuleBase {
19 private static final String AUTHOR_ENTRIES_PROPERTY_PATH = KRADConstants.DOCUMENT_PROPERTY_NAME
20 + ".authorEntries";
21 private static final String NO_ADDRESS_TYPE_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
22 private static final String ERROR_MESSAGE_NO_ADDTYPE_FOUND = "You must add atleast one address for Author.";
23 private static final String SAME_ADDRESS_TYPE_ERROR_KEY = RiceKeyConstants.ERROR_CUSTOM;
24 private static final String ERROR_MESSAGE_SAME_ADDTYPR_FOUND = "You must not repeat address type for addresses of Author.";
25
26 @Override
27 protected boolean processGlobalRouteDocumentBusinessRules(
28 MaintenanceDocument document) {
29
30 System.out.println("****Inside Global*****");
31
32 Author author = (Author)document.getDocumentDataObject();
33 System.out.println("Inside Global Aothor Got is : " + author);
34 System.out.println("****Inside Global*****");
35
36 List<Address> addressEntries = author.getAddresses();
37 System.out.println("Inside Global Aothor address is : " + addressEntries);
38
39
40 if (addressEntries == null || addressEntries.isEmpty()) {
41 System.out.println("--Got addressEntries Null--");
42 GlobalVariables.getMessageMap().putError(
43 AUTHOR_ENTRIES_PROPERTY_PATH,NO_ADDRESS_TYPE_ERROR_KEY,
44 ERROR_MESSAGE_NO_ADDTYPE_FOUND);
45 return false;
46 } else {
47 System.out.println("--Got addressEntries Obj--");
48 System.out.println("Inside Global Aothor address Size is : " + addressEntries.size());
49 Address tempAddress = null;
50 for(Address address : addressEntries){
51 tempAddress = address;
52 for(Address address2 : addressEntries){
53 if(!tempAddress.equals(address2)){
54 if(tempAddress.getAddressType()!= null && tempAddress.getAddressType() != null && tempAddress.getAddressType().getType().equals(address2.getAddressType().getType())){
55 System.out.println("Got Same Address Typr");
56 GlobalVariables.getMessageMap().putError(
57 AUTHOR_ENTRIES_PROPERTY_PATH,SAME_ADDRESS_TYPE_ERROR_KEY,
58 ERROR_MESSAGE_SAME_ADDTYPR_FOUND);
59 return false;
60 }
61 }else {
62 System.out.println("Got Same Address Object");
63 }
64 }
65 }
66
67 }
68
69
70
71 return super.processGlobalRouteDocumentBusinessRules(document);
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 }