Coverage Report - org.kuali.rice.krad.uif.util.LookupInquiryUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupInquiryUtils
0%
0/28
0%
0/18
6.5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Class for utility methods that pertain to UIF Lookup processing
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
                 // get literal parameter values first
 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  
                 // check if parameter is in request
 62  0
                 else if (request.getParameterMap().containsKey(propertyValueName)) {
 63  0
                         parameterValue = request.getParameter(propertyValueName);
 64  
                 }
 65  
                 // get parameter value from form object
 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  
          * Helper method for building the title text for an element and a map of
 97  
          * key/value pairs
 98  
          * 
 99  
          * @param prependText
 100  
          *            - text to prepend to the title
 101  
          * @param element
 102  
          *            - element class the title is being generated for, used to as
 103  
          *            the parent for getting the key labels
 104  
          * @param keyValueMap
 105  
          *            - map of key value pairs to add to the title text
 106  
          * @return String title text
 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  
 }