| 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 | 0 | public class LookupInquiryUtils { |
| 37 | 0 | 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 | 0 | String parameterValue = ""; |
| 42 | |
|
| 43 | |
|
| 44 | 0 | if (StringUtils.startsWith(propertyValueName, "'") && StringUtils.endsWith(propertyValueName, "'")) { |
| 45 | 0 | parameterValue = StringUtils.removeStart(propertyValueName, "'"); |
| 46 | 0 | parameterValue = StringUtils.removeEnd(propertyValueName, "'"); |
| 47 | |
} |
| 48 | 0 | else if (parameterValue.startsWith(KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX |
| 49 | |
+ KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) { |
| 50 | 0 | parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX |
| 51 | |
+ KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER); |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | else if (request.getParameterMap().containsKey(propertyValueName)) { |
| 55 | 0 | parameterValue = request.getParameter(propertyValueName); |
| 56 | |
} |
| 57 | |
|
| 58 | |
else { |
| 59 | 0 | Object value = ObjectPropertyUtils.getPropertyValue(form, propertyValueName); |
| 60 | 0 | if (value != null) { |
| 61 | 0 | if (value instanceof String) { |
| 62 | 0 | parameterValue = (String) value; |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | Formatter formatter = Formatter.getFormatter(value.getClass()); |
| 66 | 0 | parameterValue = (String) formatter.format(value); |
| 67 | |
} |
| 68 | |
} |
| 69 | |
|
| 70 | 0 | if (parameterValue != null |
| 71 | |
&& lookupObjectClass != null |
| 72 | |
&& KRADServiceLocatorWeb.getDataObjectAuthorizationService() |
| 73 | |
.attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) { |
| 74 | |
try { |
| 75 | 0 | parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue) |
| 76 | |
+ EncryptionService.ENCRYPTION_POST_PREFIX; |
| 77 | |
} |
| 78 | 0 | catch (GeneralSecurityException e) { |
| 79 | 0 | LOG.error("Unable to encrypt value for property name: " + propertyName); |
| 80 | 0 | throw new RuntimeException(e); |
| 81 | 0 | } |
| 82 | |
} |
| 83 | |
|
| 84 | 0 | return parameterValue; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public static String getBaseLookupUrl() { |
| 88 | 0 | 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 | 0 | StringBuffer titleText = new StringBuffer(prependText); |
| 107 | 0 | for (String key : keyValueMap.keySet()) { |
| 108 | 0 | String fieldVal = keyValueMap.get(key).toString(); |
| 109 | |
|
| 110 | 0 | titleText.append(KRADServiceLocatorWeb.getDataDictionaryService().getAttributeLabel(element, key) + "=" |
| 111 | |
+ fieldVal.toString() + " "); |
| 112 | 0 | } |
| 113 | |
|
| 114 | 0 | return titleText.toString(); |
| 115 | |
} |
| 116 | |
|
| 117 | |
} |