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