1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.uif.service.impl; |
17 | |
|
18 | |
import java.security.GeneralSecurityException; |
19 | |
import java.sql.Date; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Collection; |
22 | |
import java.util.Collections; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.HashSet; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.List; |
27 | |
import java.util.Map; |
28 | |
import java.util.Properties; |
29 | |
import java.util.Set; |
30 | |
|
31 | |
import org.apache.commons.beanutils.PropertyUtils; |
32 | |
import org.apache.commons.lang.BooleanUtils; |
33 | |
import org.apache.commons.lang.StringUtils; |
34 | |
import org.kuali.rice.core.api.encryption.EncryptionService; |
35 | |
import org.kuali.rice.core.api.services.CoreApiServiceLocator; |
36 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
37 | |
import org.kuali.rice.core.util.type.TypeUtils; |
38 | |
import org.kuali.rice.core.web.format.DateFormatter; |
39 | |
import org.kuali.rice.core.web.format.Formatter; |
40 | |
import org.kuali.rice.kim.bo.Person; |
41 | |
import org.kuali.rice.kns.authorization.BusinessObjectRestrictions; |
42 | |
import org.kuali.rice.kns.bo.ExternalizableBusinessObject; |
43 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
44 | |
import org.kuali.rice.kns.datadictionary.RelationshipDefinition; |
45 | |
import org.kuali.rice.kns.exception.ValidationException; |
46 | |
import org.kuali.rice.kns.lookup.HtmlData; |
47 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
48 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
49 | |
import org.kuali.rice.kns.service.BusinessObjectAuthorizationService; |
50 | |
import org.kuali.rice.kns.service.BusinessObjectDictionaryService; |
51 | |
import org.kuali.rice.kns.service.DataObjectMetaDataService; |
52 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
53 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
54 | |
import org.kuali.rice.kns.service.LookupService; |
55 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
56 | |
import org.kuali.rice.kns.service.ModuleService; |
57 | |
import org.kuali.rice.kns.service.PersistenceStructureService; |
58 | |
import org.kuali.rice.kns.uif.UifConstants; |
59 | |
import org.kuali.rice.kns.uif.UifParameters; |
60 | |
import org.kuali.rice.kns.uif.container.LookupView; |
61 | |
import org.kuali.rice.kns.uif.container.View; |
62 | |
import org.kuali.rice.kns.uif.core.Component; |
63 | |
import org.kuali.rice.kns.uif.field.AttributeField; |
64 | |
import org.kuali.rice.kns.uif.field.GeneratedField; |
65 | |
import org.kuali.rice.kns.uif.field.LookupCriteriaAttributeField; |
66 | |
import org.kuali.rice.kns.uif.service.LookupViewHelperService; |
67 | |
import org.kuali.rice.kns.util.BeanPropertyComparator; |
68 | |
import org.kuali.rice.kns.util.ExternalizableBusinessObjectUtils; |
69 | |
import org.kuali.rice.kns.util.GlobalVariables; |
70 | |
import org.kuali.rice.kns.util.KNSConstants; |
71 | |
import org.kuali.rice.kns.util.ObjectUtils; |
72 | |
import org.kuali.rice.kns.util.UrlFactory; |
73 | |
import org.kuali.rice.kns.web.spring.controller.MaintenanceDocumentController; |
74 | |
import org.springframework.web.util.HtmlUtils; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public class LookupViewHelperServiceImpl extends ViewHelperServiceImpl implements LookupViewHelperService { |
80 | 0 | protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupViewHelperServiceImpl.class); |
81 | |
|
82 | |
public static final String TITLE_RETURN_URL_PREPENDTEXT_PROPERTY = "title.return.url.value.prependtext"; |
83 | |
public static final String TITLE_ACTION_URL_PREPENDTEXT_PROPERTY = "title.action.url.value.prependtext"; |
84 | |
public static final String ACTION_URLS_CHILDREN_SEPARATOR = " | "; |
85 | |
public static final String ACTION_URLS_CHILDREN_STARTER = " ["; |
86 | |
public static final String ACTION_URLS_CHILDREN_END = "]"; |
87 | |
public static final String ACTION_URLS_SEPARATOR = " "; |
88 | |
public static final String ACTION_URLS_EMPTY = " "; |
89 | |
|
90 | |
private transient LookupService lookupService; |
91 | |
|
92 | |
private transient EncryptionService encryptionService; |
93 | |
private transient BusinessObjectDictionaryService businessObjectDictionaryService; |
94 | |
private transient DataObjectMetaDataService dataObjectMetaDataService; |
95 | |
private transient MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
96 | |
private transient BusinessObjectAuthorizationService businessObjectAuthorizationService; |
97 | |
private transient PersistenceStructureService persistenceStructureService; |
98 | |
|
99 | |
protected Class<?> dataObjectClass; |
100 | |
protected String returnLocation; |
101 | |
protected String returnFormKey; |
102 | |
protected String docNum; |
103 | |
protected String referencesToRefresh; |
104 | 0 | protected boolean searchUsingOnlyPrimaryKeyValues = false; |
105 | |
protected Map<String, String> fieldConversions; |
106 | |
protected Map parameters; |
107 | |
protected List<String> readOnlyFieldsList; |
108 | 0 | protected boolean atLeastOneRowReturnable = false; |
109 | 0 | protected boolean atLeastOneRowHasActions = false; |
110 | |
|
111 | |
protected List<String> defaultSortAttributeNames; |
112 | |
|
113 | |
protected boolean sortAscending; |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public LookupViewHelperServiceImpl() { |
120 | 0 | super(); |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@Override |
127 | |
public void populateViewFromRequestParameters(View view, Map<String, String> parameters) { |
128 | 0 | super.populateViewFromRequestParameters(view, parameters); |
129 | |
|
130 | |
|
131 | |
|
132 | 0 | setParameters(parameters); |
133 | 0 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public void performInitialization(View view) { |
142 | 0 | if (!LookupView.class.isAssignableFrom(view.getClass())) { |
143 | 0 | throw new IllegalArgumentException("View class '" + view.getClass() + " is not assignable from the '" + LookupView.class + "'"); |
144 | |
} |
145 | 0 | LookupView lookupView = (LookupView) view; |
146 | 0 | initializeLookupViewHelperService(lookupView); |
147 | 0 | super.performInitialization(view); |
148 | 0 | } |
149 | |
|
150 | |
protected void initializeLookupViewHelperService(LookupView lookupView) { |
151 | 0 | setDefaultSortAttributeNames(lookupView.getDefaultSortAttributeNames()); |
152 | 0 | setSortAscending(lookupView.isSortAscending()); |
153 | 0 | setDataObjectClass(lookupView.getDataObjectClassName()); |
154 | 0 | } |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
@Override |
167 | |
protected void initializeAttributeFieldFromDataDictionary(View view, AttributeField field) { |
168 | 0 | super.initializeAttributeFieldFromDataDictionary(view, field); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | 0 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public void validateSearchParameters(List<? extends Component> criteriaComponents, Map<String, String> fieldValues) { |
197 | 0 | if (!getViewDictionaryService().isLookupable(getDataObjectClass())) { |
198 | 0 | throw new RuntimeException("Lookup not defined for data object " + getDataObjectClass()); |
199 | |
} |
200 | 0 | for (Component component : criteriaComponents) { |
201 | 0 | if (AttributeField.class.isAssignableFrom(component.getClass())) { |
202 | 0 | AttributeField attributeField = (AttributeField) component; |
203 | 0 | if (fieldValues.containsKey(attributeField.getPropertyName())) { |
204 | 0 | String attributeValue = fieldValues.get(attributeField.getPropertyName()); |
205 | |
|
206 | |
|
207 | 0 | if (StringUtils.isBlank(attributeValue)) { |
208 | 0 | if (BooleanUtils.isTrue(attributeField.getRequired())) { |
209 | 0 | GlobalVariables.getMessageMap().putError(attributeField.getPropertyName(), RiceKeyConstants.ERROR_REQUIRED, attributeField.getLabel()); |
210 | |
} |
211 | |
} |
212 | 0 | validateSearchParameterWildcardAndOperators(attributeField, attributeValue); |
213 | |
} |
214 | 0 | } |
215 | |
} |
216 | |
|
217 | 0 | if (GlobalVariables.getMessageMap().hasErrors()) { |
218 | 0 | throw new ValidationException("errors in search criteria"); |
219 | |
} |
220 | 0 | } |
221 | |
|
222 | |
protected void validateSearchParameterWildcardAndOperators(AttributeField attributeField, String attributeValue) { |
223 | 0 | if (StringUtils.isBlank(attributeValue)) |
224 | 0 | return; |
225 | |
|
226 | |
|
227 | 0 | boolean found = false; |
228 | 0 | for (int i = 0; i < KNSConstants.QUERY_CHARACTERS.length; i++) { |
229 | 0 | String queryCharacter = KNSConstants.QUERY_CHARACTERS[i]; |
230 | |
|
231 | 0 | if (attributeValue.contains(queryCharacter)) { |
232 | 0 | found = true; |
233 | |
} |
234 | |
} |
235 | 0 | if (!found) |
236 | 0 | return; |
237 | |
|
238 | 0 | String attributeLabel = getDataDictionaryService().getAttributeLabel(getDataObjectClass(), attributeField.getPropertyName()); |
239 | 0 | if ( (LookupCriteriaAttributeField.class.isAssignableFrom(attributeField.getClass())) && |
240 | |
(((LookupCriteriaAttributeField) attributeField).isTreatWildcardsAndOperatorsAsLiteral()) |
241 | |
) { |
242 | 0 | Object dataObjectExample = null; |
243 | |
try { |
244 | 0 | dataObjectExample = getDataObjectClass().newInstance(); |
245 | 0 | } catch (Exception e) { |
246 | 0 | LOG.error("Exception caught instantiating " + getDataObjectClass().getName(), e); |
247 | 0 | throw new RuntimeException("Cannot instantiate " + getDataObjectClass().getName(), e); |
248 | 0 | } |
249 | |
|
250 | 0 | Class<?> propertyType = ObjectUtils.getPropertyType(dataObjectExample, attributeField.getPropertyName(), getPersistenceStructureService()); |
251 | 0 | if (TypeUtils.isIntegralClass(propertyType) || TypeUtils.isDecimalClass(propertyType) || TypeUtils.isTemporalClass(propertyType)) { |
252 | 0 | GlobalVariables.getMessageMap().putError(attributeField.getPropertyName(), RiceKeyConstants.ERROR_WILDCARDS_AND_OPERATORS_NOT_ALLOWED_ON_FIELD, attributeLabel); |
253 | |
} |
254 | 0 | if (TypeUtils.isStringClass(propertyType)) { |
255 | 0 | GlobalVariables.getMessageMap().putInfo(attributeField.getPropertyName(), RiceKeyConstants.INFO_WILDCARDS_AND_OPERATORS_TREATED_LITERALLY, attributeLabel); |
256 | |
} |
257 | 0 | } else { |
258 | 0 | if (getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(getDataObjectClass(), attributeField.getPropertyName())) { |
259 | 0 | if (!attributeValue.endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) { |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | 0 | GlobalVariables.getMessageMap().putError(attributeField.getPropertyName(), RiceKeyConstants.ERROR_SECURE_FIELD, attributeLabel); |
270 | |
} |
271 | |
} |
272 | |
} |
273 | 0 | } |
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
public Map<String, String> performClear(Map<String, String> fieldsForLookup) { |
279 | 0 | Map<String, String> newFieldsForLookup = new HashMap<String, String>(); |
280 | 0 | if (fieldsForLookup != null) { |
281 | 0 | for (Map.Entry<String, String> entry : fieldsForLookup.entrySet()) { |
282 | |
|
283 | 0 | newFieldsForLookup.put(entry.getKey(), null); |
284 | |
} |
285 | |
} |
286 | 0 | return newFieldsForLookup; |
287 | |
} |
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
public Collection<?> performSearch(Map<String, String> criteriaFieldsForLookup, boolean bounded) { |
293 | |
Collection<?> displayList; |
294 | |
|
295 | 0 | preprocessDateFields(criteriaFieldsForLookup); |
296 | |
|
297 | |
|
298 | 0 | displayList = getSearchResultsWithBounding(LookupUtils.forceUppercase(getDataObjectClass(), criteriaFieldsForLookup), !bounded); |
299 | |
|
300 | |
|
301 | 0 | List<String> pkNames = getDataObjectMetaDataService().listPrimaryKeyFieldNames(getDataObjectClass()); |
302 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
303 | 0 | for (Object object : displayList) { |
304 | 0 | if (isResultReturnable(object)) { |
305 | 0 | setAtLeastOneRowReturnable(true); |
306 | |
} |
307 | 0 | BusinessObjectRestrictions dataObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(object, user); |
308 | 0 | String actionUrls = getActionUrls(object, pkNames, dataObjectRestrictions); |
309 | 0 | if (StringUtils.isNotBlank(HtmlUtils.htmlUnescape(actionUrls).replace('\u00A0', '\u0020'))) { |
310 | 0 | setAtLeastOneRowHasActions(true); |
311 | |
} |
312 | 0 | if (isAtLeastOneRowReturnable() && isAtLeastOneRowHasActions()) { |
313 | 0 | break; |
314 | |
} |
315 | 0 | } |
316 | 0 | return displayList; |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
protected Map<String, String> preprocessDateFields(Map<String, String> lookupFormFields) { |
325 | 0 | Map<String, String> fieldsToUpdate = new HashMap<String, String>(); |
326 | 0 | Set<String> fieldsForLookup = lookupFormFields.keySet(); |
327 | 0 | for (String propName : fieldsForLookup) { |
328 | 0 | if (propName.startsWith(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
329 | 0 | String from_DateValue = lookupFormFields.get(propName); |
330 | 0 | String dateFieldName = StringUtils.remove(propName, KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); |
331 | 0 | String to_DateValue = lookupFormFields.get(dateFieldName); |
332 | 0 | String newPropValue = to_DateValue; |
333 | |
|
334 | 0 | if (StringUtils.isNotEmpty(from_DateValue) && StringUtils.isNotEmpty(to_DateValue)) { |
335 | 0 | newPropValue = from_DateValue + KNSConstants.BETWEEN_OPERATOR + to_DateValue; |
336 | 0 | } else if (StringUtils.isNotEmpty(from_DateValue) && StringUtils.isEmpty(to_DateValue)) { |
337 | 0 | newPropValue = ">=" + from_DateValue; |
338 | 0 | } else if (StringUtils.isNotEmpty(to_DateValue) && StringUtils.isEmpty(from_DateValue)) { |
339 | 0 | newPropValue = "<=" + to_DateValue; |
340 | |
} |
341 | |
|
342 | 0 | fieldsToUpdate.put(dateFieldName, newPropValue); |
343 | 0 | } |
344 | |
} |
345 | |
|
346 | 0 | Set<String> keysToUpdate = fieldsToUpdate.keySet(); |
347 | 0 | for (String updateKey : keysToUpdate) { |
348 | 0 | lookupFormFields.put(updateKey, fieldsToUpdate.get(updateKey)); |
349 | |
} |
350 | 0 | return fieldsToUpdate; |
351 | |
} |
352 | |
|
353 | |
protected List<?> getSearchResultsWithBounding(Map<String, String> fieldValues, boolean unbounded) { |
354 | |
|
355 | 0 | LookupUtils.removeHiddenCriteriaFields(getDataObjectClass(), fieldValues); |
356 | |
|
357 | 0 | searchUsingOnlyPrimaryKeyValues = getLookupService().allPrimaryKeyValuesPresentAndNotWildcard(getDataObjectClass(), fieldValues); |
358 | |
|
359 | 0 | setReturnLocation(fieldValues.get(UifParameters.RETURN_LOCATION)); |
360 | 0 | setReturnFormKey(fieldValues.get(UifParameters.RETURN_FORM_KEY)); |
361 | 0 | setReferencesToRefresh(fieldValues.get(KNSConstants.REFERENCES_TO_REFRESH)); |
362 | |
List<?> searchResults; |
363 | 0 | Map<String, String> nonBlankFieldValues = new HashMap<String, String>(); |
364 | 0 | for (String fieldName : fieldValues.keySet()) { |
365 | 0 | String fieldValue = fieldValues.get(fieldName); |
366 | 0 | if (StringUtils.isNotBlank(fieldValue)) { |
367 | 0 | if (fieldValue.endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) { |
368 | 0 | String encryptedValue = StringUtils.removeEnd(fieldValue, EncryptionService.ENCRYPTION_POST_PREFIX); |
369 | |
try { |
370 | 0 | fieldValue = getEncryptionService().decrypt(encryptedValue); |
371 | 0 | } catch (GeneralSecurityException e) { |
372 | 0 | LOG.error("Error decrypting value for business object class " + getDataObjectClass() + " attribute " + fieldName, e); |
373 | 0 | throw new RuntimeException("Error decrypting value for business object class " + getDataObjectClass() + " attribute " + fieldName, e); |
374 | 0 | } |
375 | |
} |
376 | 0 | nonBlankFieldValues.put(fieldName, fieldValue); |
377 | |
} |
378 | 0 | } |
379 | |
|
380 | |
|
381 | |
|
382 | 0 | if (ExternalizableBusinessObject.class.isAssignableFrom(getDataObjectClass())) { |
383 | 0 | ModuleService eboModuleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(getDataObjectClass()); |
384 | 0 | BusinessObjectEntry ddEntry = eboModuleService.getExternalizableBusinessObjectDictionaryEntry(getDataObjectClass()); |
385 | 0 | Map<String, String> filteredFieldValues = new HashMap<String, String>(); |
386 | 0 | for (String fieldName : nonBlankFieldValues.keySet()) { |
387 | 0 | if (ddEntry.getAttributeNames().contains(fieldName)) { |
388 | 0 | filteredFieldValues.put(fieldName, nonBlankFieldValues.get(fieldName)); |
389 | |
} |
390 | |
} |
391 | 0 | searchResults = eboModuleService.getExternalizableBusinessObjectsListForLookup((Class<? extends ExternalizableBusinessObject>) getDataObjectClass(), (Map) filteredFieldValues, unbounded); |
392 | |
|
393 | |
|
394 | 0 | } else if (hasExternalBusinessObjectProperty(getDataObjectClass(), nonBlankFieldValues)) { |
395 | 0 | if (LOG.isDebugEnabled()) { |
396 | 0 | LOG.debug("has EBO reference: " + getDataObjectClass()); |
397 | 0 | LOG.debug("properties: " + nonBlankFieldValues); |
398 | |
} |
399 | |
|
400 | 0 | Map<String, String> nonEboFieldValues = removeExternalizableBusinessObjectFieldValues(getDataObjectClass(), nonBlankFieldValues); |
401 | 0 | if (LOG.isDebugEnabled()) { |
402 | 0 | LOG.debug("Non EBO properties removed: " + nonEboFieldValues); |
403 | |
} |
404 | |
|
405 | 0 | List<String> eboPropertyNames = getExternalizableBusinessObjectProperties(getDataObjectClass(), nonBlankFieldValues); |
406 | 0 | if (LOG.isDebugEnabled()) { |
407 | 0 | LOG.debug("EBO properties: " + eboPropertyNames); |
408 | |
} |
409 | |
|
410 | 0 | for (String eboPropertyName : eboPropertyNames) { |
411 | |
|
412 | 0 | Map<String, String> eboFieldValues = getExternalizableBusinessObjectFieldValues(eboPropertyName, nonBlankFieldValues); |
413 | 0 | if (LOG.isDebugEnabled()) { |
414 | 0 | LOG.debug("EBO properties for master EBO property: " + eboPropertyName); |
415 | 0 | LOG.debug("properties: " + eboFieldValues); |
416 | |
} |
417 | |
|
418 | 0 | ModuleService eboModuleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(getExternalizableBusinessObjectClass(getDataObjectClass(), eboPropertyName)); |
419 | |
|
420 | |
|
421 | 0 | List<?> eboResults = Collections.emptyList(); |
422 | 0 | if (eboModuleService != null) { |
423 | 0 | eboResults = eboModuleService.getExternalizableBusinessObjectsListForLookup(getExternalizableBusinessObjectClass(getDataObjectClass(), eboPropertyName), (Map) eboFieldValues, |
424 | |
unbounded); |
425 | |
} else { |
426 | 0 | LOG.debug("EBO ModuleService is null: " + eboPropertyName); |
427 | |
} |
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
Class<?> eboParentClass; |
434 | |
String eboParentPropertyName; |
435 | 0 | if (ObjectUtils.isNestedAttribute(eboPropertyName)) { |
436 | 0 | eboParentPropertyName = StringUtils.substringBeforeLast(eboPropertyName, "."); |
437 | |
try { |
438 | 0 | eboParentClass = PropertyUtils.getPropertyType(getDataObjectClass().newInstance(), eboParentPropertyName); |
439 | 0 | } catch (Exception ex) { |
440 | 0 | throw new RuntimeException("Unable to create an instance of the business object class: " + getDataObjectClass().getName(), ex); |
441 | 0 | } |
442 | |
} else { |
443 | 0 | eboParentClass = getDataObjectClass(); |
444 | 0 | eboParentPropertyName = null; |
445 | |
} |
446 | 0 | if (LOG.isDebugEnabled()) { |
447 | 0 | LOG.debug("determined EBO parent class/property name: " + eboParentClass + "/" + eboParentPropertyName); |
448 | |
} |
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | 0 | RelationshipDefinition rd = getDataObjectMetaDataService().getDictionaryRelationship(eboParentClass, eboPropertyName); |
454 | 0 | if (LOG.isDebugEnabled()) { |
455 | 0 | LOG.debug("Obtained RelationshipDefinition for " + eboPropertyName); |
456 | 0 | LOG.debug(rd); |
457 | |
} |
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | 0 | if (ObjectUtils.isNotNull(rd)) { |
465 | 0 | if (rd.getPrimitiveAttributes().size() > 1) { |
466 | 0 | throw new RuntimeException("EBO Links don't work for relationships with multiple-field primary keys."); |
467 | |
} |
468 | 0 | String boProperty = rd.getPrimitiveAttributes().get(0).getSourceName(); |
469 | 0 | String eboProperty = rd.getPrimitiveAttributes().get(0).getTargetName(); |
470 | 0 | StringBuffer boPropertyValue = new StringBuffer(); |
471 | |
|
472 | |
|
473 | |
|
474 | 0 | for (Object ebo : eboResults) { |
475 | 0 | if (boPropertyValue.length() != 0) { |
476 | 0 | boPropertyValue.append("|"); |
477 | |
} |
478 | |
try { |
479 | 0 | boPropertyValue.append(PropertyUtils.getProperty(ebo, eboProperty).toString()); |
480 | 0 | } catch (Exception ex) { |
481 | 0 | LOG.warn("Unable to get value for " + eboProperty + " on " + ebo); |
482 | 0 | } |
483 | |
} |
484 | 0 | if (eboParentPropertyName == null) { |
485 | |
|
486 | 0 | nonEboFieldValues.put(boProperty, boPropertyValue.toString()); |
487 | |
} else { |
488 | |
|
489 | |
|
490 | 0 | nonEboFieldValues.put(eboParentPropertyName + "." + boProperty, boPropertyValue.toString()); |
491 | |
} |
492 | |
} |
493 | 0 | } |
494 | 0 | if (LOG.isDebugEnabled()) { |
495 | 0 | LOG.debug("Passing these results into the lookup service: " + nonEboFieldValues); |
496 | |
} |
497 | |
|
498 | |
|
499 | 0 | searchResults = (List<?>) getLookupService().findCollectionBySearchHelper(getDataObjectClass(), nonEboFieldValues, unbounded); |
500 | 0 | } else { |
501 | 0 | searchResults = (List<?>) getLookupService().findCollectionBySearchHelper(getDataObjectClass(), nonBlankFieldValues, unbounded); |
502 | |
} |
503 | |
|
504 | 0 | if (searchResults == null) { |
505 | 0 | searchResults = new ArrayList<Object>(); |
506 | |
} |
507 | |
|
508 | |
|
509 | 0 | List<String> defaultSortColumns = getDefaultSortAttributeNames(); |
510 | 0 | if ((defaultSortColumns != null) && (defaultSortColumns.size() > 0)) { |
511 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true)); |
512 | |
} |
513 | 0 | return searchResults; |
514 | |
} |
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
protected boolean hasExternalBusinessObjectProperty(Class<?> boClass, Map<String, String> fieldValues) { |
520 | |
try { |
521 | 0 | Object sampleBo = boClass.newInstance(); |
522 | 0 | for (String key : fieldValues.keySet()) { |
523 | 0 | if (isExternalBusinessObjectProperty(sampleBo, key)) { |
524 | 0 | return true; |
525 | |
} |
526 | |
} |
527 | 0 | } catch (Exception ex) { |
528 | 0 | LOG.debug("Unable to check " + boClass + " for EBO properties.", ex); |
529 | 0 | } |
530 | 0 | return false; |
531 | |
} |
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
protected boolean isExternalBusinessObjectProperty(Object sampleBo, String propertyName) { |
538 | |
try { |
539 | 0 | if (propertyName.indexOf(".") > 0 && !StringUtils.contains(propertyName, "add.")) { |
540 | 0 | Class<?> propertyClass = PropertyUtils.getPropertyType(sampleBo, StringUtils.substringBeforeLast(propertyName, ".")); |
541 | 0 | if (propertyClass != null) { |
542 | 0 | return ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(propertyClass); |
543 | |
} |
544 | 0 | if (LOG.isDebugEnabled()) { |
545 | 0 | LOG.debug("unable to get class for " + StringUtils.substringBeforeLast(propertyName, ".") + " on " + sampleBo.getClass().getName()); |
546 | |
} |
547 | |
} |
548 | 0 | } catch (Exception e) { |
549 | 0 | LOG.debug("Unable to determine type of property for " + sampleBo.getClass().getName() + "/" + propertyName, e); |
550 | 0 | } |
551 | 0 | return false; |
552 | |
} |
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
protected Map<String, String> removeExternalizableBusinessObjectFieldValues(Class<?> boClass, Map<String, String> fieldValues) { |
559 | 0 | Map<String, String> eboFieldValues = new HashMap<String, String>(); |
560 | |
try { |
561 | 0 | Object sampleBo = boClass.newInstance(); |
562 | 0 | for (String key : fieldValues.keySet()) { |
563 | 0 | if (!isExternalBusinessObjectProperty(sampleBo, key)) { |
564 | 0 | eboFieldValues.put(key, fieldValues.get(key)); |
565 | |
} |
566 | |
} |
567 | 0 | } catch (Exception ex) { |
568 | 0 | LOG.debug("Unable to check " + boClass + " for EBO properties.", ex); |
569 | 0 | } |
570 | 0 | return eboFieldValues; |
571 | |
} |
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
protected Map<String, String> getExternalizableBusinessObjectFieldValues(String eboPropertyName, Map<String, String> fieldValues) { |
577 | 0 | Map<String, String> eboFieldValues = new HashMap<String, String>(); |
578 | 0 | for (String key : fieldValues.keySet()) { |
579 | 0 | if (key.startsWith(eboPropertyName + ".")) { |
580 | 0 | eboFieldValues.put(StringUtils.substringAfterLast(key, "."), fieldValues.get(key)); |
581 | |
} |
582 | |
} |
583 | 0 | return eboFieldValues; |
584 | |
} |
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
protected List<String> getExternalizableBusinessObjectProperties(Class<?> boClass, Map<String, String> fieldValues) { |
592 | 0 | Set<String> eboPropertyNames = new HashSet<String>(); |
593 | |
try { |
594 | 0 | Object sampleBo = boClass.newInstance(); |
595 | 0 | for (String key : fieldValues.keySet()) { |
596 | 0 | if (isExternalBusinessObjectProperty(sampleBo, key)) { |
597 | 0 | eboPropertyNames.add(StringUtils.substringBeforeLast(key, ".")); |
598 | |
} |
599 | |
} |
600 | 0 | } catch (Exception ex) { |
601 | 0 | LOG.debug("Unable to check " + boClass + " for EBO properties.", ex); |
602 | 0 | } |
603 | 0 | return new ArrayList<String>(eboPropertyNames); |
604 | |
} |
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
protected Class<? extends ExternalizableBusinessObject> getExternalizableBusinessObjectClass(Class<?> boClass, String propertyName) { |
615 | |
try { |
616 | 0 | return PropertyUtils.getPropertyType(boClass.newInstance(), StringUtils.substringBeforeLast(propertyName, ".")); |
617 | 0 | } catch (Exception e) { |
618 | 0 | LOG.debug("Unable to determine type of property for " + boClass.getName() + "/" + propertyName, e); |
619 | |
} |
620 | 0 | return null; |
621 | |
} |
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
protected String getMaintenanceDocumentTypeName() { |
629 | 0 | MaintenanceDocumentDictionaryService dd = getMaintenanceDocumentDictionaryService(); |
630 | 0 | String maintDocTypeName = dd.getDocumentTypeName(getDataObjectClass()); |
631 | 0 | return maintDocTypeName; |
632 | |
} |
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
protected boolean allowsMaintenanceNewOrCopyAction() { |
640 | 0 | boolean allowsNewOrCopy = false; |
641 | |
|
642 | 0 | String maintDocTypeName = getMaintenanceDocumentTypeName(); |
643 | |
|
644 | 0 | if (StringUtils.isNotBlank(maintDocTypeName)) { |
645 | 0 | allowsNewOrCopy = getBusinessObjectAuthorizationService().canCreate(getDataObjectClass(), GlobalVariables.getUserSession().getPerson(), maintDocTypeName); |
646 | |
} |
647 | 0 | return allowsNewOrCopy; |
648 | |
} |
649 | |
|
650 | |
protected boolean allowsMaintenanceEditAction(Object dataObject) { |
651 | 0 | boolean allowsEdit = false; |
652 | |
|
653 | 0 | String maintDocTypeName = getMaintenanceDocumentTypeName(); |
654 | |
|
655 | 0 | if (StringUtils.isNotBlank(maintDocTypeName)) { |
656 | 0 | allowsEdit = getBusinessObjectAuthorizationService().canMaintain(dataObject, GlobalVariables.getUserSession().getPerson(), maintDocTypeName); |
657 | |
} |
658 | 0 | return allowsEdit; |
659 | |
} |
660 | |
|
661 | |
protected boolean allowsMaintenanceDeleteAction(Object dataObject) { |
662 | |
|
663 | 0 | boolean allowsMaintain = false; |
664 | 0 | boolean allowsDelete = false; |
665 | |
|
666 | 0 | String maintDocTypeName = getMaintenanceDocumentTypeName(); |
667 | |
|
668 | 0 | if (StringUtils.isNotBlank(maintDocTypeName)) { |
669 | 0 | allowsMaintain = getBusinessObjectAuthorizationService().canMaintain(dataObject, GlobalVariables.getUserSession().getPerson(), maintDocTypeName); |
670 | |
} |
671 | |
|
672 | 0 | allowsDelete = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService().getAllowsRecordDeletion(getDataObjectClass()); |
673 | |
|
674 | 0 | return allowsDelete && allowsMaintain; |
675 | |
} |
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
public String getCreateNewUrl(GeneratedField generatedField) { |
681 | 0 | String url = ""; |
682 | |
|
683 | 0 | if (allowsMaintenanceNewOrCopyAction()) { |
684 | 0 | Properties props = new Properties(); |
685 | |
|
686 | |
|
687 | |
|
688 | 0 | props.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, MaintenanceDocumentController.METHOD_TO_CALL_NEW); |
689 | 0 | props.put(UifParameters.DATA_OBJECT_CLASS_NAME, getDataObjectClass().getName()); |
690 | 0 | props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE); |
691 | |
|
692 | |
|
693 | |
|
694 | 0 | url = UrlFactory.parameterizeUrl(MaintenanceDocumentController.REQUEST_MAPPING_MAINTENANCE, props); |
695 | 0 | url = "<a id=\"" + generatedField.getId() + "\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>"; |
696 | |
} |
697 | |
|
698 | 0 | return url; |
699 | |
} |
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
public String getActionUrlsFromField(GeneratedField generatedField) { |
705 | 0 | Object bo = getLineObjectFromField(generatedField); |
706 | 0 | if (bo == null) { |
707 | 0 | return ACTION_URLS_EMPTY; |
708 | |
} |
709 | 0 | String actionUrls = getActionUrls(bo, getDataObjectMetaDataService().listPrimaryKeyFieldNames(getDataObjectClass()), getBusinessObjectAuthorizationService().getLookupResultRestrictions( |
710 | |
bo, GlobalVariables.getUserSession().getPerson())); |
711 | 0 | return (StringUtils.isNotBlank(actionUrls)) ? actionUrls : ACTION_URLS_EMPTY; |
712 | |
} |
713 | |
|
714 | |
protected Object getLineObjectFromField(GeneratedField generatedField) { |
715 | 0 | Object bo = generatedField.getContext().get(UifConstants.ContextVariableNames.LINE); |
716 | 0 | if (bo == null) { |
717 | 0 | LOG.error("***************************************************************"); |
718 | 0 | LOG.error("**** THERE IS NO BO TO PROCESS - THIS SHOULD NEVER HAPPEN *****"); |
719 | 0 | LOG.error("***************************************************************"); |
720 | 0 | return null; |
721 | |
} |
722 | 0 | return bo; |
723 | |
} |
724 | |
|
725 | |
|
726 | |
|
727 | |
|
728 | |
|
729 | |
|
730 | |
|
731 | |
protected String getActionUrls(Object dataObject, List<String> pkNames, BusinessObjectRestrictions dataObjectRestrictions) { |
732 | 0 | StringBuffer actions = new StringBuffer(); |
733 | 0 | List<HtmlData> htmlDataList = getCustomActionUrls(dataObject, pkNames); |
734 | 0 | for (HtmlData htmlData : htmlDataList) { |
735 | 0 | actions.append(getMaintenanceUrl(dataObject, htmlData, pkNames, dataObjectRestrictions)); |
736 | 0 | if (htmlData.getChildUrlDataList() != null) { |
737 | 0 | if (htmlData.getChildUrlDataList().size() > 0) { |
738 | 0 | actions.append(ACTION_URLS_CHILDREN_STARTER); |
739 | 0 | for (HtmlData childURLData : htmlData.getChildUrlDataList()) { |
740 | 0 | actions.append(getMaintenanceUrl(dataObject, childURLData, pkNames, dataObjectRestrictions)); |
741 | 0 | actions.append(ACTION_URLS_CHILDREN_SEPARATOR); |
742 | |
} |
743 | 0 | if (actions.toString().endsWith(ACTION_URLS_CHILDREN_SEPARATOR)) |
744 | 0 | actions.delete(actions.length() - ACTION_URLS_CHILDREN_SEPARATOR.length(), actions.length()); |
745 | 0 | actions.append(ACTION_URLS_CHILDREN_END); |
746 | |
} |
747 | |
} |
748 | 0 | actions.append(ACTION_URLS_SEPARATOR); |
749 | |
} |
750 | 0 | if (actions.toString().endsWith(ACTION_URLS_SEPARATOR)) |
751 | 0 | actions.delete(actions.length() - ACTION_URLS_SEPARATOR.length(), actions.length()); |
752 | 0 | return actions.toString(); |
753 | |
} |
754 | |
|
755 | |
|
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | |
|
761 | |
protected List<HtmlData> getCustomActionUrls(Object dataObject, List<String> pkNames) { |
762 | 0 | List<HtmlData> htmlDataList = new ArrayList<HtmlData>(); |
763 | |
|
764 | |
|
765 | |
|
766 | 0 | if (allowsMaintenanceEditAction(dataObject)) { |
767 | |
|
768 | 0 | htmlDataList.add(getUrlData(dataObject, MaintenanceDocumentController.METHOD_TO_CALL_EDIT, "edit", pkNames)); |
769 | |
} |
770 | 0 | if (allowsMaintenanceNewOrCopyAction()) { |
771 | |
|
772 | 0 | htmlDataList.add(getUrlData(dataObject, MaintenanceDocumentController.METHOD_TO_CALL_COPY, "copy", pkNames)); |
773 | |
} |
774 | 0 | if (allowsMaintenanceDeleteAction(dataObject)) { |
775 | |
|
776 | 0 | htmlDataList.add(getUrlData(dataObject, MaintenanceDocumentController.METHOD_TO_CALL_DELETE, "delete", pkNames)); |
777 | |
} |
778 | 0 | return htmlDataList; |
779 | |
} |
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | |
|
790 | |
protected AnchorHtmlData getUrlData(Object dataObject, String methodToCall, List<String> pkNames) { |
791 | 0 | return getUrlData(dataObject, methodToCall, methodToCall, pkNames); |
792 | |
} |
793 | |
|
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
|
804 | |
protected AnchorHtmlData getUrlData(Object dataObject, String methodToCall, String displayText, List<String> pkNames) { |
805 | 0 | String href = getActionUrlHref(dataObject, methodToCall, pkNames); |
806 | |
|
807 | 0 | AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, methodToCall, displayText); |
808 | 0 | return anchorHtmlData; |
809 | |
} |
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
protected String getActionUrlHref(Object dataObject, String methodToCall, List<String> pkNames) { |
822 | 0 | Properties props = new Properties(); |
823 | 0 | props.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, methodToCall); |
824 | 0 | props.putAll(getParametersFromPrimaryKey(dataObject, pkNames)); |
825 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
826 | 0 | props.put(KNSConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); |
827 | |
} |
828 | |
|
829 | |
|
830 | 0 | props.put(UifParameters.DATA_OBJECT_CLASS_NAME, dataObject.getClass().getName()); |
831 | 0 | props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE); |
832 | |
|
833 | |
|
834 | 0 | return UrlFactory.parameterizeUrl(MaintenanceDocumentController.REQUEST_MAPPING_MAINTENANCE, props); |
835 | |
} |
836 | |
|
837 | |
protected Properties getParametersFromPrimaryKey(Object dataObject, List<String> pkNames) { |
838 | 0 | Properties props = new Properties(); |
839 | 0 | for (Iterator<String> iter = pkNames.iterator(); iter.hasNext();) { |
840 | 0 | String fieldNm = iter.next(); |
841 | |
|
842 | 0 | Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm); |
843 | 0 | if (fieldVal == null) { |
844 | 0 | fieldVal = KNSConstants.EMPTY_STRING; |
845 | |
} |
846 | 0 | if (fieldVal instanceof java.sql.Date) { |
847 | 0 | String formattedString = ""; |
848 | 0 | if (Formatter.findFormatter(fieldVal.getClass()) != null) { |
849 | 0 | Formatter formatter = Formatter.getFormatter(fieldVal.getClass()); |
850 | 0 | formattedString = (String) formatter.format(fieldVal); |
851 | 0 | fieldVal = formattedString; |
852 | |
} |
853 | |
} |
854 | |
|
855 | |
|
856 | 0 | if (getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObject.getClass(), fieldNm)) { |
857 | |
try { |
858 | 0 | fieldVal = getEncryptionService().encrypt(fieldVal) + EncryptionService.ENCRYPTION_POST_PREFIX; |
859 | 0 | } catch (GeneralSecurityException e) { |
860 | 0 | LOG.error("Exception while trying to encrypted value for inquiry framework.", e); |
861 | 0 | throw new RuntimeException(e); |
862 | 0 | } |
863 | |
|
864 | |
} |
865 | |
|
866 | 0 | props.put(fieldNm, fieldVal.toString()); |
867 | 0 | } |
868 | 0 | return props; |
869 | |
} |
870 | |
|
871 | |
|
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
|
879 | |
|
880 | |
protected String getMaintenanceUrl(Object dataObject, HtmlData htmlData, List<String> pkNames, BusinessObjectRestrictions dataObjectRestrictions) { |
881 | 0 | htmlData.setTitle(getActionUrlTitleText(dataObject, htmlData.getDisplayText(), pkNames, dataObjectRestrictions)); |
882 | 0 | return htmlData.constructCompleteHtmlTag(); |
883 | |
} |
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
|
895 | |
protected String getActionUrlTitleText(Object dataObject, String displayText, List<String> pkNames, BusinessObjectRestrictions dataObjectRestrictions) { |
896 | 0 | String prependTitleText = displayText + " " + getDataDictionaryService().getDataDictionary().getDataObjectEntry(getDataObjectClass().getName()).getObjectLabel() + " " |
897 | |
+ KNSServiceLocator.getKualiConfigurationService().getPropertyString(TITLE_ACTION_URL_PREPENDTEXT_PROPERTY); |
898 | 0 | return HtmlData.getTitleText(prependTitleText, dataObject, pkNames, dataObjectRestrictions); |
899 | |
} |
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
|
923 | |
|
924 | |
public String getReturnUrlForResults(GeneratedField generatedField) { |
925 | 0 | Object dataObject = getLineObjectFromField(generatedField); |
926 | |
|
927 | 0 | if ( (dataObject == null) || (!isResultReturnable(dataObject)) ) { |
928 | 0 | return ACTION_URLS_EMPTY; |
929 | |
} |
930 | 0 | HtmlData temp = getReturnUrl(dataObject, generatedField.getContext(), getReturnKeys(), getBusinessObjectAuthorizationService().getLookupResultRestrictions(dataObject, |
931 | |
GlobalVariables.getUserSession().getPerson())); |
932 | 0 | String url = temp.constructCompleteHtmlTag(); |
933 | 0 | return (StringUtils.isNotBlank(url)) ? url : ACTION_URLS_EMPTY; |
934 | |
} |
935 | |
|
936 | |
protected HtmlData getReturnUrl(Object dataObject, Map<String, Object> context, List<String> returnKeys, BusinessObjectRestrictions businessObjectRestrictions) { |
937 | 0 | View lookupView = (View) context.get(UifConstants.ContextVariableNames.VIEW); |
938 | 0 | Properties props = getReturnUrlParameters(dataObject, getFieldConversions(), lookupView.getViewHelperServiceClassName().getName(), returnKeys); |
939 | |
|
940 | |
|
941 | 0 | return getReturnAnchorHtmlData(dataObject, props, context, returnKeys, businessObjectRestrictions, lookupView.getReturnTarget()); |
942 | |
|
943 | |
|
944 | |
|
945 | |
} |
946 | |
|
947 | |
|
948 | |
|
949 | |
|
950 | |
|
951 | |
protected HtmlData getReturnInputHtmlData(Object dataObject, Properties props, Map<String, Object> context, List<String> returnKeys, BusinessObjectRestrictions businessObjectRestrictions) { |
952 | |
|
953 | |
|
954 | |
|
955 | |
|
956 | |
|
957 | |
|
958 | |
|
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | 0 | return null; |
966 | |
} |
967 | |
|
968 | |
protected HtmlData getReturnAnchorHtmlData(Object dataObject, Properties props, Map<String, Object> context, List<String> returnKeys, BusinessObjectRestrictions businessObjectRestrictions, String returnTarget) { |
969 | 0 | String returnUrlAnchorLabel = KNSServiceLocator.getKualiConfigurationService().getPropertyString(TITLE_RETURN_URL_PREPENDTEXT_PROPERTY); |
970 | 0 | AnchorHtmlData anchor = new AnchorHtmlData(getReturnHrefUsingParameters(props, context, returnKeys), HtmlData.getTitleText(returnUrlAnchorLabel, dataObject, returnKeys, |
971 | |
businessObjectRestrictions)); |
972 | 0 | anchor.setDisplayText(returnUrlAnchorLabel); |
973 | 0 | if (returnTarget != null) { |
974 | 0 | anchor.setTarget(returnTarget); |
975 | 0 | if (!returnTarget.equals("_self") |
976 | |
&& !returnTarget.equals("_parent")) { |
977 | |
|
978 | |
|
979 | |
|
980 | |
|
981 | |
|
982 | |
|
983 | |
|
984 | |
|
985 | |
|
986 | |
|
987 | |
|
988 | |
|
989 | |
|
990 | |
|
991 | |
|
992 | |
|
993 | |
|
994 | |
|
995 | |
|
996 | |
|
997 | |
|
998 | |
|
999 | 0 | anchor.setOnclick("parent.$.fancybox.close();"); |
1000 | |
} |
1001 | |
} |
1002 | 0 | return anchor; |
1003 | |
} |
1004 | |
|
1005 | |
protected String getReturnHrefUsingParameters(Properties props, Map<String, Object> context, List returnKeys) { |
1006 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
1007 | 0 | String href = UrlFactory.parameterizeUrl(getReturnLocation(), props); |
1008 | 0 | return addToReturnHref(href, context); |
1009 | |
} |
1010 | 0 | return ""; |
1011 | |
} |
1012 | |
|
1013 | |
protected String addToReturnHref(String href, Map<String, Object> context) { |
1014 | 0 | StringBuffer buffer = new StringBuffer(href); |
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | 0 | buffer.append("&" + UifParameters.DOC_NUM + "=" + (StringUtils.isEmpty(getDocNum()) ? "" : getDocNum())); |
1022 | 0 | return buffer.toString(); |
1023 | |
} |
1024 | |
|
1025 | |
protected Properties getReturnUrlParameters(Object dataObject, Map<String,String> fieldConversionValues, String lookupImpl, List<String> returnKeys) { |
1026 | 0 | Properties props = new Properties(); |
1027 | 0 | props.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.RETURN_METHOD_TO_CALL); |
1028 | 0 | if (getReturnFormKey() != null) { |
1029 | 0 | props.put(UifParameters.FORM_KEY, getReturnFormKey()); |
1030 | |
} |
1031 | 0 | if (lookupImpl != null) { |
1032 | 0 | props.put(KNSConstants.REFRESH_CALLER, lookupImpl); |
1033 | |
} |
1034 | 0 | if (getDocNum() != null) { |
1035 | 0 | props.put(UifParameters.DOC_NUM, getDocNum()); |
1036 | |
} |
1037 | |
|
1038 | 0 | if (getReferencesToRefresh() != null) { |
1039 | 0 | props.put(KNSConstants.REFERENCES_TO_REFRESH, getReferencesToRefresh()); |
1040 | |
} |
1041 | |
|
1042 | 0 | Iterator<String> returnKeysIt = returnKeys.iterator(); |
1043 | 0 | while (returnKeysIt.hasNext()) { |
1044 | 0 | String fieldNm = returnKeysIt.next(); |
1045 | |
|
1046 | 0 | Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm); |
1047 | 0 | if (fieldVal == null) { |
1048 | 0 | fieldVal = StringUtils.EMPTY; |
1049 | |
} |
1050 | |
|
1051 | 0 | if (getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(getDataObjectClass(), fieldNm)) { |
1052 | |
try { |
1053 | 0 | fieldVal = getEncryptionService().encrypt(fieldVal) + EncryptionService.ENCRYPTION_POST_PREFIX; |
1054 | 0 | } catch (GeneralSecurityException e) { |
1055 | 0 | LOG.error("Exception while trying to encrypted value for inquiry framework.", e); |
1056 | 0 | throw new RuntimeException(e); |
1057 | 0 | } |
1058 | |
|
1059 | |
} |
1060 | |
|
1061 | |
|
1062 | 0 | if (fieldVal instanceof Date) { |
1063 | 0 | DateFormatter dateFormatter = new DateFormatter(); |
1064 | 0 | fieldVal = dateFormatter.format(fieldVal); |
1065 | |
} |
1066 | |
|
1067 | 0 | if (fieldConversionValues.containsKey(fieldNm)) { |
1068 | 0 | fieldNm = fieldConversionValues.get(fieldNm); |
1069 | |
} |
1070 | |
|
1071 | 0 | props.put(fieldNm, fieldVal.toString()); |
1072 | 0 | } |
1073 | |
|
1074 | 0 | return props; |
1075 | |
} |
1076 | |
|
1077 | |
|
1078 | |
|
1079 | |
|
1080 | |
protected List<String> getReturnKeys() { |
1081 | |
List<String> returnKeys; |
1082 | 0 | if (fieldConversions != null && !fieldConversions.isEmpty()) { |
1083 | 0 | returnKeys = new ArrayList<String>(fieldConversions.keySet()); |
1084 | |
} else { |
1085 | 0 | returnKeys = getDataObjectMetaDataService().listPrimaryKeyFieldNames(getDataObjectClass()); |
1086 | |
} |
1087 | |
|
1088 | 0 | return returnKeys; |
1089 | |
} |
1090 | |
|
1091 | |
|
1092 | |
|
1093 | |
|
1094 | |
|
1095 | |
|
1096 | |
|
1097 | |
|
1098 | |
|
1099 | |
|
1100 | |
|
1101 | |
|
1102 | |
protected boolean isResultReturnable(Object dataObject) { |
1103 | 0 | return true; |
1104 | |
} |
1105 | |
|
1106 | |
|
1107 | |
|
1108 | |
|
1109 | |
public Set<String> getConditionallyReadOnlyPropertyNames() { |
1110 | 0 | return new HashSet<String>(); |
1111 | |
} |
1112 | |
|
1113 | |
|
1114 | |
|
1115 | |
|
1116 | |
public Set<String> getConditionallyRequiredPropertyNames() { |
1117 | 0 | return new HashSet<String>(); |
1118 | |
} |
1119 | |
|
1120 | |
|
1121 | |
|
1122 | |
|
1123 | |
public Set<String> getConditionallyHiddenPropertyNames() { |
1124 | 0 | return new HashSet<String>(); |
1125 | |
} |
1126 | |
|
1127 | |
|
1128 | |
|
1129 | |
|
1130 | |
public boolean isAtLeastOneRowReturnable() { |
1131 | 0 | return this.atLeastOneRowReturnable; |
1132 | |
} |
1133 | |
|
1134 | |
|
1135 | |
|
1136 | |
|
1137 | |
public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) { |
1138 | 0 | this.atLeastOneRowReturnable = atLeastOneRowReturnable; |
1139 | 0 | } |
1140 | |
|
1141 | |
|
1142 | |
|
1143 | |
|
1144 | |
public boolean isAtLeastOneRowHasActions() { |
1145 | 0 | return this.atLeastOneRowHasActions; |
1146 | |
} |
1147 | |
|
1148 | |
|
1149 | |
|
1150 | |
|
1151 | |
public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) { |
1152 | 0 | this.atLeastOneRowHasActions = atLeastOneRowHasActions; |
1153 | 0 | } |
1154 | |
|
1155 | |
|
1156 | |
|
1157 | |
|
1158 | |
public Class<?> getDataObjectClass() { |
1159 | 0 | return this.dataObjectClass; |
1160 | |
} |
1161 | |
|
1162 | |
|
1163 | |
|
1164 | |
|
1165 | |
|
1166 | |
public void setDataObjectClass(Class<?> dataObjectClass) { |
1167 | 0 | this.dataObjectClass = dataObjectClass; |
1168 | 0 | } |
1169 | |
|
1170 | |
|
1171 | |
|
1172 | |
|
1173 | |
public String getReturnLocation() { |
1174 | 0 | return this.returnLocation; |
1175 | |
} |
1176 | |
|
1177 | |
|
1178 | |
|
1179 | |
|
1180 | |
|
1181 | |
public void setReturnLocation(String returnLocation) { |
1182 | 0 | this.returnLocation = returnLocation; |
1183 | 0 | } |
1184 | |
|
1185 | |
|
1186 | |
|
1187 | |
|
1188 | |
public String getDocNum() { |
1189 | 0 | return this.docNum; |
1190 | |
} |
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
|
1196 | |
public void setDocNum(String docNum) { |
1197 | 0 | this.docNum = docNum; |
1198 | 0 | } |
1199 | |
|
1200 | |
|
1201 | |
|
1202 | |
|
1203 | |
public String getReferencesToRefresh() { |
1204 | 0 | return this.referencesToRefresh; |
1205 | |
} |
1206 | |
|
1207 | |
|
1208 | |
|
1209 | |
|
1210 | |
|
1211 | |
public void setReferencesToRefresh(String referencesToRefresh) { |
1212 | 0 | this.referencesToRefresh = referencesToRefresh; |
1213 | 0 | } |
1214 | |
|
1215 | |
|
1216 | |
|
1217 | |
|
1218 | |
public Map<String, String> getFieldConversions() { |
1219 | 0 | return this.fieldConversions; |
1220 | |
} |
1221 | |
|
1222 | |
|
1223 | |
|
1224 | |
|
1225 | |
|
1226 | |
public void setFieldConversions(Map<String, String> fieldConversions) { |
1227 | 0 | this.fieldConversions = fieldConversions; |
1228 | 0 | } |
1229 | |
|
1230 | |
|
1231 | |
|
1232 | |
|
1233 | |
public Map getParameters() { |
1234 | 0 | return this.parameters; |
1235 | |
} |
1236 | |
|
1237 | |
|
1238 | |
|
1239 | |
|
1240 | |
|
1241 | |
public void setParameters(Map parameters) { |
1242 | 0 | this.parameters = parameters; |
1243 | 0 | } |
1244 | |
|
1245 | |
|
1246 | |
|
1247 | |
|
1248 | |
public List<String> getReadOnlyFieldsList() { |
1249 | 0 | return this.readOnlyFieldsList; |
1250 | |
} |
1251 | |
|
1252 | |
|
1253 | |
|
1254 | |
|
1255 | |
|
1256 | |
public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) { |
1257 | 0 | this.readOnlyFieldsList = readOnlyFieldsList; |
1258 | 0 | } |
1259 | |
|
1260 | |
|
1261 | |
|
1262 | |
|
1263 | |
public List<String> getDefaultSortAttributeNames() { |
1264 | 0 | return this.defaultSortAttributeNames; |
1265 | |
} |
1266 | |
|
1267 | |
|
1268 | |
|
1269 | |
|
1270 | |
|
1271 | |
public void setDefaultSortAttributeNames(List<String> defaultSortAttributeNames) { |
1272 | 0 | this.defaultSortAttributeNames = defaultSortAttributeNames; |
1273 | 0 | } |
1274 | |
|
1275 | |
|
1276 | |
|
1277 | |
|
1278 | |
public String getReturnFormKey() { |
1279 | 0 | return this.returnFormKey; |
1280 | |
} |
1281 | |
|
1282 | |
|
1283 | |
|
1284 | |
|
1285 | |
public void setReturnFormKey(String returnFormKey) { |
1286 | 0 | this.returnFormKey = returnFormKey; |
1287 | 0 | } |
1288 | |
|
1289 | |
|
1290 | |
|
1291 | |
|
1292 | |
public boolean isSortAscending() { |
1293 | 0 | return this.sortAscending; |
1294 | |
} |
1295 | |
|
1296 | |
|
1297 | |
|
1298 | |
|
1299 | |
|
1300 | |
public void setSortAscending(boolean sortAscending) { |
1301 | 0 | this.sortAscending = sortAscending; |
1302 | 0 | } |
1303 | |
|
1304 | |
public LookupService getLookupService() { |
1305 | 0 | return lookupService != null ? lookupService : KNSServiceLocatorWeb.getLookupService(); |
1306 | |
} |
1307 | |
|
1308 | |
public void setLookupService(LookupService lookupService) { |
1309 | 0 | this.lookupService = lookupService; |
1310 | 0 | } |
1311 | |
|
1312 | |
public EncryptionService getEncryptionService() { |
1313 | 0 | return encryptionService != null ? encryptionService : CoreApiServiceLocator.getEncryptionService(); |
1314 | |
} |
1315 | |
|
1316 | |
public void setEncryptionService(EncryptionService encryptionService) { |
1317 | 0 | this.encryptionService = encryptionService; |
1318 | 0 | } |
1319 | |
|
1320 | |
|
1321 | |
|
1322 | |
|
1323 | |
|
1324 | |
|
1325 | |
public BusinessObjectDictionaryService getBusinessObjectDictionaryService() { |
1326 | 0 | return businessObjectDictionaryService != null ? businessObjectDictionaryService : KNSServiceLocatorWeb.getBusinessObjectDictionaryService(); |
1327 | |
} |
1328 | |
|
1329 | |
|
1330 | |
|
1331 | |
|
1332 | |
|
1333 | |
|
1334 | |
|
1335 | |
public void setBusinessObjectDictionaryService(BusinessObjectDictionaryService businessObjectDictionaryService) { |
1336 | 0 | this.businessObjectDictionaryService = businessObjectDictionaryService; |
1337 | 0 | } |
1338 | |
|
1339 | |
|
1340 | |
|
1341 | |
|
1342 | |
public DataObjectMetaDataService getDataObjectMetaDataService() { |
1343 | 0 | return dataObjectMetaDataService != null ? dataObjectMetaDataService : KNSServiceLocatorWeb.getDataObjectMetaDataService(); |
1344 | |
} |
1345 | |
|
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
public void setDataObjectMetaDataService(DataObjectMetaDataService dataObjectMetaDataService) { |
1350 | 0 | this.dataObjectMetaDataService = dataObjectMetaDataService; |
1351 | 0 | } |
1352 | |
|
1353 | |
|
1354 | |
|
1355 | |
|
1356 | |
|
1357 | |
|
1358 | |
public PersistenceStructureService getPersistenceStructureService() { |
1359 | 0 | return persistenceStructureService != null ? persistenceStructureService : KNSServiceLocator.getPersistenceStructureService(); |
1360 | |
} |
1361 | |
|
1362 | |
|
1363 | |
|
1364 | |
|
1365 | |
|
1366 | |
|
1367 | |
|
1368 | |
public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { |
1369 | 0 | this.persistenceStructureService = persistenceStructureService; |
1370 | 0 | } |
1371 | |
|
1372 | |
public BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
1373 | 0 | return businessObjectAuthorizationService != null ? businessObjectAuthorizationService : KNSServiceLocatorWeb.getBusinessObjectAuthorizationService(); |
1374 | |
} |
1375 | |
|
1376 | |
public void setBusinessObjectAuthorizationService(BusinessObjectAuthorizationService businessObjectAuthorizationService) { |
1377 | 0 | this.businessObjectAuthorizationService = businessObjectAuthorizationService; |
1378 | 0 | } |
1379 | |
|
1380 | |
public MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
1381 | 0 | return maintenanceDocumentDictionaryService != null ? maintenanceDocumentDictionaryService : KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
1382 | |
} |
1383 | |
|
1384 | |
public void setMaintenanceDocumentDictionaryService(MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService) { |
1385 | 0 | this.maintenanceDocumentDictionaryService = maintenanceDocumentDictionaryService; |
1386 | 0 | } |
1387 | |
|
1388 | |
} |