1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.encryption.EncryptionService;
21 import org.kuali.rice.core.web.format.Formatter;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24 import org.kuali.rice.krad.util.KRADConstants;
25 import org.kuali.rice.krad.web.form.UifFormBase;
26
27 import javax.servlet.http.HttpServletRequest;
28 import java.security.GeneralSecurityException;
29 import java.util.Map;
30
31
32
33
34
35
36 public class LookupInquiryUtils {
37 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupInquiryUtils.class);
38
39 public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
40 Class<?> lookupObjectClass, String propertyName, String propertyValueName) {
41 String parameterValue = "";
42
43
44 if (StringUtils.startsWith(propertyValueName, "'") && StringUtils.endsWith(propertyValueName, "'")) {
45 parameterValue = StringUtils.removeStart(propertyValueName, "'");
46 parameterValue = StringUtils.removeEnd(propertyValueName, "'");
47 }
48 else if (parameterValue.startsWith(KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
49 + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
50 parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
51 + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER);
52 }
53
54 else if (request.getParameterMap().containsKey(propertyValueName)) {
55 parameterValue = request.getParameter(propertyValueName);
56 }
57
58 else {
59 Object value = ObjectPropertyUtils.getPropertyValue(form, propertyValueName);
60 if (value != null) {
61 if (value instanceof String) {
62 parameterValue = (String) value;
63 }
64
65 Formatter formatter = Formatter.getFormatter(value.getClass());
66 parameterValue = (String) formatter.format(value);
67 }
68 }
69
70 if (parameterValue != null
71 && lookupObjectClass != null
72 && KRADServiceLocatorWeb.getDataObjectAuthorizationService()
73 .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) {
74 try {
75 parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue)
76 + EncryptionService.ENCRYPTION_POST_PREFIX;
77 }
78 catch (GeneralSecurityException e) {
79 LOG.error("Unable to encrypt value for property name: " + propertyName);
80 throw new RuntimeException(e);
81 }
82 }
83
84 return parameterValue;
85 }
86
87 public static String getBaseLookupUrl() {
88 return KRADServiceLocator.getKualiConfigurationService().
89 getPropertyValueAsString(KRADConstants.KRAD_LOOKUP_URL_KEY);
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 public static String getLinkTitleText(String prependText, Class<?> element, Map<String, String> keyValueMap) {
106 StringBuffer titleText = new StringBuffer(prependText);
107 for (String key : keyValueMap.keySet()) {
108 String fieldVal = keyValueMap.get(key).toString();
109
110 titleText.append(KRADServiceLocatorWeb.getDataDictionaryService().getAttributeLabel(element, key) + "="
111 + fieldVal.toString() + " ");
112 }
113
114 return titleText.toString();
115 }
116
117 }