1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.lookup; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
20 | |
import org.kuali.rice.core.util.KeyValue; |
21 | |
import org.kuali.rice.kew.util.KEWConstants; |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
23 | |
import org.kuali.rice.kim.api.type.KimType; |
24 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
25 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
26 | |
import org.kuali.rice.kim.dao.KimRoleDao; |
27 | |
import org.kuali.rice.kim.impl.type.KimTypeBo; |
28 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
29 | |
import org.kuali.rice.kim.util.KimConstants; |
30 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm; |
31 | |
import org.kuali.rice.kns.authorization.BusinessObjectRestrictions; |
32 | |
import org.kuali.rice.kns.bo.BusinessObject; |
33 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
34 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
35 | |
import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition; |
36 | |
import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition; |
37 | |
import org.kuali.rice.kns.lookup.HtmlData; |
38 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
39 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
40 | |
import org.kuali.rice.kns.service.ModuleService; |
41 | |
import org.kuali.rice.kns.util.BeanPropertyComparator; |
42 | |
import org.kuali.rice.kns.util.GlobalVariables; |
43 | |
import org.kuali.rice.kns.util.KNSConstants; |
44 | |
import org.kuali.rice.kns.util.UrlFactory; |
45 | |
import org.kuali.rice.kns.web.struts.form.KualiForm; |
46 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
47 | |
import org.kuali.rice.kns.web.ui.Field; |
48 | |
import org.kuali.rice.kns.web.ui.Row; |
49 | |
|
50 | |
import java.util.ArrayList; |
51 | |
import java.util.Collection; |
52 | |
import java.util.Collections; |
53 | |
import java.util.Comparator; |
54 | |
import java.util.HashMap; |
55 | |
import java.util.List; |
56 | |
import java.util.Map; |
57 | |
import java.util.Properties; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | public class RoleLookupableHelperServiceImpl extends KimLookupableHelperServiceImpl { |
66 | |
|
67 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RoleLookupableHelperServiceImpl.class); |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | private List<Row> roleRows = new ArrayList<Row>(); |
73 | 0 | private List<Row> attrRows = new ArrayList<Row>(); |
74 | |
private KimRoleDao roleDao; |
75 | |
private String typeId; |
76 | |
private AttributeDefinitionMap attrDefinitions; |
77 | |
|
78 | |
@Override |
79 | |
public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) { |
80 | 0 | RoleImpl roleImpl = (RoleImpl) bo; |
81 | 0 | List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); |
82 | 0 | if(allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME)){ |
83 | 0 | anchorHtmlDataList.add(getEditRoleUrl(roleImpl)); |
84 | |
} |
85 | 0 | return anchorHtmlDataList; |
86 | |
} |
87 | |
|
88 | |
protected HtmlData getEditRoleUrl(RoleImpl roleImpl) { |
89 | 0 | String href = ""; |
90 | |
|
91 | 0 | Properties parameters = new Properties(); |
92 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.DOC_HANDLER_METHOD); |
93 | 0 | parameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND); |
94 | 0 | parameters.put(KNSConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME); |
95 | 0 | parameters.put(KimConstants.PrimaryKeyConstants.ROLE_ID, roleImpl.getRoleId()); |
96 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
97 | 0 | parameters.put(KNSConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); |
98 | |
} |
99 | 0 | href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION, parameters); |
100 | |
|
101 | 0 | AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, |
102 | |
KNSConstants.DOC_HANDLER_METHOD, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL); |
103 | 0 | return anchorHtmlData; |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
protected HtmlData getReturnAnchorHtmlData(BusinessObject businessObject, Properties parameters, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions){ |
108 | 0 | RoleImpl roleImpl = (RoleImpl) businessObject; |
109 | 0 | HtmlData anchorHtmlData = super.getReturnAnchorHtmlData(businessObject, parameters, lookupForm, returnKeys, businessObjectRestrictions); |
110 | |
|
111 | |
|
112 | 0 | KualiForm myForm = (KualiForm) GlobalVariables.getUserSession().retrieveObject(getDocFormKey()); |
113 | 0 | if (myForm == null || !(myForm instanceof IdentityManagementRoleDocumentForm)){ |
114 | 0 | if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(KimTypeBo.to(roleImpl.getKimRoleType()))){ |
115 | 0 | ((AnchorHtmlData)anchorHtmlData).setHref(""); |
116 | |
} |
117 | |
} |
118 | 0 | return anchorHtmlData; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public List<? extends BusinessObject> getSearchResults(java.util.Map<String,String> fieldValues) { |
123 | 0 | for (Map.Entry<String,String> entry : fieldValues.entrySet()) { |
124 | 0 | if (entry.getKey().equals(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID)) { |
125 | 0 | entry.getValue(); |
126 | 0 | break; |
127 | |
} |
128 | |
} |
129 | |
|
130 | 0 | List<RoleImpl> baseLookup = (List<RoleImpl>)super.getSearchResults(fieldValues); |
131 | |
|
132 | 0 | return baseLookup; |
133 | |
} |
134 | |
|
135 | |
private List<KeyValue> getRoleTypeOptions() { |
136 | 0 | List<KeyValue> options = new ArrayList<KeyValue>(); |
137 | 0 | options.add(new ConcreteKeyValue("", "")); |
138 | |
|
139 | 0 | Collection<KimType> kimGroupTypes = KimApiServiceLocator.getKimTypeInfoService().findAllKimTypes(); |
140 | |
|
141 | 0 | for (KimType kimType : kimGroupTypes) { |
142 | 0 | if (KimTypeLookupableHelperServiceImpl.hasRoleTypeService(kimType)) { |
143 | 0 | String value = kimType.getNamespaceCode().trim() + KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR + kimType.getName().trim(); |
144 | 0 | options.add(new ConcreteKeyValue(kimType.getId(), value)); |
145 | 0 | } |
146 | |
} |
147 | 0 | Collections.sort(options, new Comparator<KeyValue>() { |
148 | |
@Override |
149 | |
public int compare(KeyValue k1, KeyValue k2) { |
150 | 0 | return k1.getValue().compareTo(k2.getValue()); |
151 | |
} |
152 | |
}); |
153 | 0 | return options; |
154 | |
} |
155 | |
|
156 | |
private String getAttrDefnId(AttributeDefinition definition) { |
157 | 0 | if (definition instanceof KimDataDictionaryAttributeDefinition) { |
158 | 0 | return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
159 | |
} else { |
160 | 0 | return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
161 | |
|
162 | |
} |
163 | |
} |
164 | |
|
165 | |
public List<Row> getRoleRows() { |
166 | 0 | return this.roleRows; |
167 | |
} |
168 | |
|
169 | |
public void setRoleRows(List<Row> roleRows) { |
170 | 0 | this.roleRows = roleRows; |
171 | 0 | } |
172 | |
|
173 | |
public KimRoleDao getRoleDao() { |
174 | 0 | return this.roleDao; |
175 | |
} |
176 | |
|
177 | |
public void setRoleDao(KimRoleDao roleDao) { |
178 | 0 | this.roleDao = roleDao; |
179 | 0 | } |
180 | |
|
181 | |
public AttributeDefinitionMap getAttrDefinitions() { |
182 | 0 | return this.attrDefinitions; |
183 | |
} |
184 | |
|
185 | |
public void setAttrDefinitions(AttributeDefinitionMap attrDefinitions) { |
186 | 0 | this.attrDefinitions = attrDefinitions; |
187 | 0 | } |
188 | |
|
189 | |
public List<Row> getAttrRows() { |
190 | 0 | return this.attrRows; |
191 | |
} |
192 | |
|
193 | |
public void setAttrRows(List<Row> attrRows) { |
194 | 0 | this.attrRows = attrRows; |
195 | 0 | } |
196 | |
|
197 | |
public String getTypeId() { |
198 | 0 | return this.typeId; |
199 | |
} |
200 | |
|
201 | |
public void setTypeId(String typeId) { |
202 | 0 | this.typeId = typeId; |
203 | 0 | } |
204 | |
|
205 | |
@Override |
206 | |
public List<Row> getRows() { |
207 | 0 | new ArrayList<Row>(); |
208 | 0 | if (getRoleRows().isEmpty()) { |
209 | 0 | List<Row> rows = super.getRows(); |
210 | 0 | List<Row> returnRows = new ArrayList<Row>(); |
211 | 0 | for (Row row : rows) { |
212 | 0 | for (int i = row.getFields().size() - 1; i >= 0; i--) { |
213 | 0 | Field field = row.getFields().get(i); |
214 | 0 | if (field.getPropertyName().equals("kimTypeId")) { |
215 | 0 | Field typeField = new Field(); |
216 | 0 | typeField.setFieldLabel("Type"); |
217 | 0 | typeField.setPropertyName("kimTypeId"); |
218 | 0 | typeField.setFieldValidValues(getRoleTypeOptions()); |
219 | 0 | typeField.setFieldType(Field.DROPDOWN); |
220 | 0 | typeField.setMaxLength(100); |
221 | 0 | typeField.setSize(40); |
222 | |
|
223 | |
|
224 | 0 | row.getFields().set(i, typeField); |
225 | |
} |
226 | |
} |
227 | 0 | returnRows.add(row); |
228 | |
} |
229 | 0 | setRoleRows(returnRows); |
230 | |
|
231 | |
} |
232 | 0 | if (getAttrRows().isEmpty()) { |
233 | |
|
234 | 0 | return getRoleRows(); |
235 | |
} else { |
236 | 0 | List<Row> fullRows = new ArrayList<Row>(); |
237 | 0 | fullRows.addAll(getRoleRows()); |
238 | |
|
239 | 0 | return fullRows; |
240 | |
} |
241 | |
|
242 | |
} |
243 | |
|
244 | |
@Override |
245 | |
protected List<? extends BusinessObject> getSearchResultsHelper( |
246 | |
Map<String, String> fieldValues, boolean unbounded) { |
247 | |
List searchResults; |
248 | 0 | Map<String,String> nonBlankFieldValues = new HashMap<String, String>(); |
249 | 0 | boolean includeAttr = false; |
250 | 0 | for (String fieldName : fieldValues.keySet()) { |
251 | 0 | if (StringUtils.isNotBlank(fieldValues.get(fieldName)) ) { |
252 | 0 | nonBlankFieldValues.put(fieldName, fieldValues.get(fieldName)); |
253 | 0 | if (fieldName.contains(".")) { |
254 | 0 | includeAttr = true; |
255 | |
} |
256 | |
} |
257 | |
} |
258 | |
|
259 | 0 | if (includeAttr) { |
260 | 0 | ModuleService eboModuleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService( getBusinessObjectClass() ); |
261 | 0 | BusinessObjectEntry ddEntry = eboModuleService.getExternalizableBusinessObjectDictionaryEntry(getBusinessObjectClass()); |
262 | 0 | Map<String,String> filteredFieldValues = new HashMap<String, String>(); |
263 | 0 | for (String fieldName : nonBlankFieldValues.keySet()) { |
264 | 0 | if (ddEntry.getAttributeNames().contains(fieldName) || fieldName.contains(".")) { |
265 | 0 | filteredFieldValues.put(fieldName, nonBlankFieldValues.get(fieldName)); |
266 | |
} |
267 | |
} |
268 | 0 | searchResults = eboModuleService.getExternalizableBusinessObjectsListForLookup(getBusinessObjectClass(), (Map)filteredFieldValues, unbounded); |
269 | |
|
270 | 0 | } else { |
271 | 0 | searchResults = super.getSearchResultsHelper(fieldValues, unbounded); |
272 | |
} |
273 | 0 | List defaultSortColumns = getDefaultSortColumns(); |
274 | 0 | if (defaultSortColumns.size() > 0) { |
275 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true)); |
276 | |
} |
277 | 0 | return searchResults; |
278 | |
|
279 | |
} |
280 | |
|
281 | |
private static final String ROLE_ID_URL_KEY = "&"+KimConstants.PrimaryKeyConstants.ROLE_ID+"="; |
282 | |
|
283 | |
|
284 | |
|
285 | |
@Override |
286 | |
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) { |
287 | 0 | AnchorHtmlData inquiryHtmlData = (AnchorHtmlData)super.getInquiryUrl(bo, propertyName); |
288 | 0 | if(inquiryHtmlData!=null && StringUtils.isNotBlank(inquiryHtmlData.getHref()) && inquiryHtmlData.getHref().contains(ROLE_ID_URL_KEY)) { |
289 | 0 | inquiryHtmlData.setHref(getCustomRoleInquiryHref(getBackLocation(), inquiryHtmlData.getHref())); |
290 | |
} |
291 | 0 | return inquiryHtmlData; |
292 | |
} |
293 | |
|
294 | |
public static String getCustomRoleInquiryHref(String href){ |
295 | 0 | return getCustomRoleInquiryHref("", href); |
296 | |
} |
297 | |
|
298 | |
static String getCustomRoleInquiryHref(String backLocation, String href){ |
299 | 0 | Properties parameters = new Properties(); |
300 | 0 | String hrefPart = ""; |
301 | 0 | String docTypeAction = ""; |
302 | 0 | if(StringUtils.isBlank(backLocation) || backLocation.contains(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION) |
303 | |
|| !backLocation.contains(KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION)){ |
304 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION; |
305 | |
} else{ |
306 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION; |
307 | |
} |
308 | 0 | if (StringUtils.isNotBlank(href) && href.contains(ROLE_ID_URL_KEY)) { |
309 | 0 | int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.ROLE_ID+"="); |
310 | 0 | int idx2 = href.indexOf("&", idx1+1); |
311 | 0 | if (idx2 < 0) { |
312 | 0 | idx2 = href.length(); |
313 | |
} |
314 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
315 | 0 | hrefPart = href.substring(idx1, idx2); |
316 | |
} |
317 | 0 | return UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+docTypeAction, parameters)+hrefPart; |
318 | |
} |
319 | |
|
320 | |
} |