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 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
76 parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue)
77 + EncryptionService.ENCRYPTION_POST_PREFIX;
78 }
79 }
80 catch (GeneralSecurityException e) {
81 LOG.error("Unable to encrypt value for property name: " + propertyName);
82 throw new RuntimeException(e);
83 }
84 }
85
86 return parameterValue;
87 }
88
89 public static String getBaseLookupUrl() {
90 return KRADServiceLocator.getKualiConfigurationService().
91 getPropertyValueAsString(KRADConstants.KRAD_LOOKUP_URL_KEY);
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 public static String getLinkTitleText(String prependText, Class<?> element, Map<String, String> keyValueMap) {
108 StringBuffer titleText = new StringBuffer(prependText);
109 for (String key : keyValueMap.keySet()) {
110 String fieldVal = keyValueMap.get(key).toString();
111
112 titleText.append(" " + KRADServiceLocatorWeb.getDataDictionaryService().getAttributeLabel(element, key) + "="
113 + fieldVal.toString());
114 }
115
116 return titleText.toString();
117 }
118
119 }