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