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
19
20
21
22
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
36 List<String> pkPropertyNames = getDataObjectMetaDataService().listPrimaryKeyFieldNames(dataObjectClass);
37
38
39 List<List<String>> alternateKeyNames = this.getAlternateKeysForClass(dataObjectClass);
40
41
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
52 Map<String, Object> keyPropertyValues = new HashMap<String, Object>();
53 for (String keyPropertyName : dataObjectKeySet) {
54 String keyPropertyValue = parameters.get(keyPropertyName);
55
56
57 Boolean forceUppercase = Boolean.FALSE;
58 try {
59 forceUppercase = getDataDictionaryService().getAttributeForceUppercase(dataObjectClass,
60 keyPropertyName);
61 } catch (UnknownBusinessClassAttributeException ex) {
62
63
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
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
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 }