View Javadoc

1   package org.kuali.ole.deliver.request.inquiry;
2   
3   import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
4   import org.kuali.ole.deliver.request.service.OleDeliverRequestDocumentHelperServiceImpl;
5   import org.kuali.rice.krad.bo.BusinessObject;
6   import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
7   import org.kuali.rice.krad.datadictionary.exception.UnknownBusinessClassAttributeException;
8   import org.kuali.rice.krad.inquiry.InquirableImpl;
9   import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
10  import org.kuali.rice.krad.service.ModuleService;
11  
12  import java.security.GeneralSecurityException;
13  import java.util.HashMap;
14  import java.util.List;
15  import java.util.Map;
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: ?
20   * Date: 10/24/12
21   * Time: 5:19 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class OleDeliverRequestInquirableImpl extends InquirableImpl{
25      public OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService =  new OleDeliverRequestDocumentHelperServiceImpl();
26  
27      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDeliverRequestInquirableImpl.class);
28      @Override
29      public Object retrieveDataObject(Map<String, String> parameters) {
30          if (dataObjectClass == null) {
31              LOG.error("Data object class must be set in inquirable before retrieving the object");
32              throw new RuntimeException("Data object class must be set in inquirable before retrieving the object");
33          }
34  
35          // build list of key values from the map parameters
36          List<String> pkPropertyNames = getDataObjectMetaDataService().listPrimaryKeyFieldNames(dataObjectClass);
37  
38          // some classes might have alternate keys defined for retrieving
39          List<List<String>> alternateKeyNames = this.getAlternateKeysForClass(dataObjectClass);
40  
41          // add pk set as beginning so it will be checked first for match
42          alternateKeyNames.add(0, pkPropertyNames);
43  
44          List<String> dataObjectKeySet = retrieveKeySetFromMap(alternateKeyNames, parameters);
45          if ((dataObjectKeySet == null) || dataObjectKeySet.isEmpty()) {
46              LOG.warn("Matching key set not found in request for class: " + getDataObjectClass());
47  
48              return null;
49          }
50  
51          // found key set, now build map of key values pairs we can use to retrieve the object
52          Map<String, Object> keyPropertyValues = new HashMap<String, Object>();
53          for (String keyPropertyName : dataObjectKeySet) {
54              String keyPropertyValue = parameters.get(keyPropertyName);
55  
56              // uppercase value if needed
57              Boolean forceUppercase = Boolean.FALSE;
58              try {
59                  forceUppercase = getDataDictionaryService().getAttributeForceUppercase(dataObjectClass,
60                          keyPropertyName);
61              } catch (UnknownBusinessClassAttributeException ex) {
62                  // swallowing exception because this check for ForceUppercase would
63                  // require a DD entry for the attribute, and we will just set force uppercase to false
64                  LOG.warn("Data object class "
65                          + dataObjectClass
66                          + " property "
67                          + keyPropertyName
68                          + " should probably have a DD definition.", ex);
69              }
70  
71              if (forceUppercase.booleanValue() && (keyPropertyValue != null)) {
72                  keyPropertyValue = keyPropertyValue.toUpperCase();
73              }
74  
75              // check security on key field
76              if (getDataObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObjectClass,
77                      keyPropertyName)) {
78                  try {
79                      keyPropertyValue = getEncryptionService().decrypt(keyPropertyValue);
80                  } catch (GeneralSecurityException e) {
81                      LOG.error("Data object class "
82                              + dataObjectClass
83                              + " property "
84                              + keyPropertyName
85                              + " should have been encrypted, but there was a problem decrypting it.", e);
86                      throw new RuntimeException("Data object class "
87                              + dataObjectClass
88                              + " property "
89                              + keyPropertyName
90                              + " should have been encrypted, but there was a problem decrypting it.", e);
91                  }
92              }
93  
94              keyPropertyValues.put(keyPropertyName, keyPropertyValue);
95          }
96  
97          // now retrieve the object based on the key set
98          Object dataObject = null;
99  
100         ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(
101                 getDataObjectClass());
102         if (moduleService != null && moduleService.isExternalizable(getDataObjectClass())) {
103             dataObject = moduleService.getExternalizableBusinessObject(getDataObjectClass().asSubclass(
104                     ExternalizableBusinessObject.class), keyPropertyValues);
105         } else if (BusinessObject.class.isAssignableFrom(getDataObjectClass())) {
106             dataObject = getBusinessObjectService().findByPrimaryKey(getDataObjectClass().asSubclass(
107                     BusinessObject.class), keyPropertyValues);
108         }
109         OleDeliverRequestBo oleDeliverRequestBo =(OleDeliverRequestBo)dataObject;
110         if(oleDeliverRequestBo.getOperatorCreateId()!=null && !oleDeliverRequestBo.getOperatorCreateId().isEmpty()) {
111             oleDeliverRequestBo.setRequestCreator("Operator");
112         }else if(oleDeliverRequestBo.getProxyBorrowerId()!=null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()){
113             oleDeliverRequestBo.setRequestCreator("Proxy Patron");
114         } else{
115             oleDeliverRequestBo.setRequestCreator("Patron");
116         }
117         oleDeliverRequestBo =  oleDeliverRequestDocumentHelperService.processItem(oleDeliverRequestBo);
118         return oleDeliverRequestBo;
119     }
120 
121 
122 
123 }