1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.businessobject.lookup;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.kuali.ole.coa.businessobject.Account;
24 import org.kuali.ole.select.OleSelectConstant;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEKeyConstants;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.kim.api.services.IdentityManagementService;
31 import org.kuali.rice.kns.lookup.HtmlData;
32 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
33 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
34 import org.kuali.rice.krad.bo.BusinessObject;
35 import org.kuali.rice.krad.util.GlobalVariables;
36 import org.kuali.rice.krad.util.KRADConstants;
37
38
39
40
41 public class KualiAccountLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
42
43 ThreadLocal<Person> currentUser = new ThreadLocal<Person>();
44
45
46
47
48
49
50
51
52 @Override
53 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
54 StringBuffer actions = new StringBuffer();
55 Account theAccount = (Account) businessObject;
56 List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
57 Person user = GlobalVariables.getUserSession().getPerson();
58 AnchorHtmlData urlDataCopy = getUrlData(businessObject, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL, pkNames);
59
60 if (theAccount.isActive()) {
61 anchorHtmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
62 }
63 else {
64 String principalId = user.getPrincipalId();
65 String namespaceCode = OLEConstants.PermissionNames.EDIT_INACTIVE_ACCOUNT.namespace;
66 String permissionName = OLEConstants.PermissionNames.EDIT_INACTIVE_ACCOUNT.name;
67
68 IdentityManagementService identityManagementService = SpringContext.getBean(IdentityManagementService.class);
69 boolean isAuthorized = identityManagementService.hasPermission(principalId, namespaceCode, permissionName);
70
71 if (isAuthorized) {
72 anchorHtmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
73 }
74 else {
75 urlDataCopy.setPrependDisplayText(" ");
76 }
77 }
78 anchorHtmlDataList.add(urlDataCopy);
79
80 return anchorHtmlDataList;
81 }
82
83
84
85
86
87
88
89
90 @Override
91 public List<? extends BusinessObject> getSearchResults(Map<String, String> parameters) {
92 Map<String, String> activeMap = new HashMap<String, String>();
93 List<Account> accountDetails = new ArrayList<Account>();
94
95 boolean flag = false;
96 if (parameters.containsKey(OLEPropertyConstants.CLOSED)) {
97 final String closedValue = parameters.get(OLEPropertyConstants.CLOSED);
98
99 if (closedValue != null && closedValue.length() != 0) {
100 if ("Y1T".indexOf(closedValue) > -1) {
101 parameters.put(OLEPropertyConstants.ACTIVE, "N");
102 }
103 else if ("N0F".indexOf(closedValue) > -1) {
104 parameters.put(OLEPropertyConstants.ACTIVE, "Y");
105 }
106 }
107
108 parameters.remove(OLEPropertyConstants.CLOSED);
109 }
110
111
112 final String restrictedValue = parameters.get(OleSelectConstant.RESTRICTED);
113 boolean containsChartCode = false;
114 if(!"".equals(parameters.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE))){
115 containsChartCode=true;
116 }
117 if(parameters.containsKey(OleSelectConstant.RESTRICTED)){
118
119 if(restrictedValue.equalsIgnoreCase("Y")){
120 parameters.put(OLEPropertyConstants.ACCOUNT_RESTRICTED_STATUS_CODE, "T|R");
121 }
122 else if(restrictedValue.equalsIgnoreCase("N")){
123 parameters.put(OLEPropertyConstants.ACCOUNT_RESTRICTED_STATUS_CODE, "U|N");
124 }
125 }
126 parameters.remove(OleSelectConstant.RESTRICTED);
127
128 String subFundGroupCodeValue = parameters.get(OleSelectConstant.SUBFUND_GROUP_CODE);
129 String vendorNameValue = parameters.get(OleSelectConstant.VENDOR_NAME);
130 String subFundGroupParameter = getParameterService()
131 .getParameterValueAsString(Account.class, OleSelectConstant.SUB_FUND_GRP_CD);
132 if (subFundGroupCodeValue.equalsIgnoreCase(subFundGroupParameter) && vendorNameValue.isEmpty()) {
133
134 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
135 GlobalVariables.getMessageMap().putError(OleSelectConstant.VENDOR_NAME, OLEKeyConstants.ERROR_VENDOR_DEPOSIT_ACCOUNT);
136 flag = true;
137
138 }
139 else if ((!subFundGroupCodeValue.equalsIgnoreCase(subFundGroupParameter) || (subFundGroupCodeValue
140 .isEmpty())) && !vendorNameValue.isEmpty()) {
141
142 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
143 GlobalVariables.getMessageMap().putError(OleSelectConstant.VENDOR_NAME, OLEKeyConstants.ERROR_SUBFUND_GROUP_CODE);
144 flag = true;
145 }
146 if(!flag) {
147 final String vendorDepositAccount = parameters.get(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
148 if(vendorDepositAccount.equalsIgnoreCase("true")) {
149
150
151 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
152
153 parameters.put(OleSelectConstant.VENDOR_NAME, "");
154 accountDetails = (List<Account>) super.getSearchResults(parameters);
155 for (int vendorKey = 0; vendorKey < accountDetails.size(); vendorKey++) {
156 accountDetails.get(vendorKey).setVendorHeaderGeneratedIdentifier(null);
157 accountDetails.get(vendorKey).setVendorDetailAssignedIdentifier(null);
158 }
159
160 }
161 else {
162
163 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
164 parameters.remove(OleSelectConstant.VENDOR_NAME);
165
166 accountDetails = (List<Account>) super.getSearchResults(parameters);
167 if(containsChartCode){
168 if(restrictedValue.equalsIgnoreCase("N")) {
169 for (int i=0; i< accountDetails.size(); i++) {
170 if (accountDetails.get(i).getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_TEMPORARY_RESTRICTED_CODE) || accountDetails.get(i).getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_RESTRICTED_CODE)) {
171 accountDetails.remove(i);
172 }
173 }
174 }
175 }
176 }
177 }
178 return accountDetails;
179 }
180
181 }