View Javadoc
1   package org.kuali.ole;
2   
3   import org.apache.commons.beanutils.PropertyUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.kuali.rice.core.api.CoreApiServiceLocator;
6   import org.kuali.rice.core.api.config.property.ConfigurationService;
7   import org.kuali.rice.core.api.encryption.EncryptionService;
8   import org.kuali.rice.core.api.search.SearchOperator;
9   import org.kuali.rice.core.api.util.RiceKeyConstants;
10  import org.kuali.rice.core.api.util.type.TypeUtils;
11  import org.kuali.rice.kim.api.identity.Person;
12  import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
13  import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
14  import org.kuali.rice.krad.datadictionary.DataObjectEntry;
15  import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
16  import org.kuali.rice.krad.lookup.*;
17  import org.kuali.rice.krad.service.*;
18  import org.kuali.rice.krad.uif.UifConstants;
19  import org.kuali.rice.krad.uif.UifParameters;
20  import org.kuali.rice.krad.uif.UifPropertyPaths;
21  import org.kuali.rice.krad.uif.control.Control;
22  import org.kuali.rice.krad.uif.control.HiddenControl;
23  import org.kuali.rice.krad.uif.control.ValueConfiguredControl;
24  import org.kuali.rice.krad.uif.element.Action;
25  import org.kuali.rice.krad.uif.element.Link;
26  import org.kuali.rice.krad.uif.field.InputField;
27  import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
28  import org.kuali.rice.krad.uif.util.ComponentUtils;
29  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
30  import org.kuali.rice.krad.uif.util.ScriptUtils;
31  import org.kuali.rice.krad.uif.view.View;
32  import org.kuali.rice.krad.util.*;
33  import org.kuali.rice.krad.lookup.LookupForm;
34  import org.kuali.rice.krad.lookup.Lookupable;
35  
36  import java.security.GeneralSecurityException;
37  import java.util.*;
38  
39  /**
40   * Created by pvsubrah on 5/5/14.
41   */
42  
43  //TODO: This class will need to be retired once there is a permanent fix for the securefieldpaternmatching
44  //TODO: in KRADUtils thats used bu the LookupableImpl
45  
46  public class OleLookupableImpl extends LookupableImpl {
47      private static final long serialVersionUID = 1885161468871327740L;
48      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupableImpl.class);
49  
50      /**
51       * Returns a map of the configured return keys with their selected values.
52       *
53       * @param lookupView lookup view instance containing lookup configuration
54       * @param lookupForm lookup form instance containing the data
55       * @param dataObject data object instance
56       * @return Map<String, String> map of return key/value pairs
57       */
58      @Override
59      protected Map<String, String> getReturnKeyValues(LookupView lookupView, LookupForm lookupForm, Object dataObject) {
60          List<String> returnKeys;
61  
62          if (lookupForm.getFieldConversions() != null && !lookupForm.getFieldConversions().isEmpty()) {
63              returnKeys = new ArrayList<String>(lookupForm.getFieldConversions().keySet());
64          } else {
65              returnKeys = getLegacyDataAdapter().listPrimaryKeyFieldNames(getDataObjectClass());
66          }
67  
68          List<String> secureReturnKeys = lookupView.getAdditionalSecurePropertyNames();
69  
70          return getPropertyKeyValuesFromDataObject(returnKeys, dataObject);
71      }
72  
73      //TODO: This code snippet is from KRADUtils of Rice 2.3.2
74      public Map<String, String> getPropertyKeyValuesFromDataObject(List<String> propertyNames, Object dataObject) {
75          Map<String, String> propertyKeyValues = new HashMap<String, String>();
76  
77          if (dataObject == null) {
78              return propertyKeyValues;
79          }
80  
81          // iterate through properties and add a map entry for each
82          for (String propertyName : propertyNames) {
83              Object propertyValue = ObjectPropertyUtils.getPropertyValue(dataObject, propertyName);
84              if (propertyValue == null) {
85                  propertyValue = StringUtils.EMPTY;
86              }
87  
88              if (KRADServiceLocatorWeb.getDataObjectAuthorizationService()
89                      .attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObject.getClass(), propertyName)) {
90                  try {
91                      if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
92                          propertyValue = CoreApiServiceLocator.getEncryptionService().encrypt(propertyValue)
93                                  + EncryptionService.ENCRYPTION_POST_PREFIX;
94                      }
95                  } catch (GeneralSecurityException e) {
96                      throw new RuntimeException("Exception while trying to encrypt value for key/value map.", e);
97                  }
98              }
99  
100             // TODO: need to apply formatting to return value once util class is ready
101             propertyKeyValues.put(propertyName, propertyValue.toString());
102         }
103 
104         return propertyKeyValues;
105     }
106 }