1 package org.kuali.ole.deliver.inquiry;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.OLEPropertyConstants;
5 import org.kuali.ole.deliver.bo.*;
6 import org.kuali.ole.deliver.processor.LoanProcessor;
7 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
8 import org.kuali.rice.core.api.config.property.ConfigContext;
9 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
10 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
11 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
12 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
13 import org.kuali.rice.krad.bo.BusinessObject;
14 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
15 import org.kuali.rice.krad.datadictionary.exception.UnknownBusinessClassAttributeException;
16 import org.kuali.rice.krad.inquiry.InquirableImpl;
17 import org.kuali.rice.krad.service.KRADServiceLocator;
18 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
19 import org.kuali.rice.krad.service.ModuleService;
20
21 import java.security.GeneralSecurityException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30 public class OlePatronInquirableImpl extends InquirableImpl {
31 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronInquirableImpl.class);
32
33
34
35
36
37
38
39 String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
40
41 public Object retrieveDataObject(Map<String, String> parameters) {
42 if (dataObjectClass == null) {
43 LOG.error("Data object class must be set in inquirable before retrieving the object");
44 throw new RuntimeException("Data object class must be set in inquirable before retrieving the object");
45 }
46
47
48 List<String> pkPropertyNames = getDataObjectMetaDataService().listPrimaryKeyFieldNames(dataObjectClass);
49
50
51 List<List<String>> alternateKeyNames = this.getAlternateKeysForClass(dataObjectClass);
52
53
54 alternateKeyNames.add(0, pkPropertyNames);
55
56 List<String> dataObjectKeySet = retrieveKeySetFromMap(alternateKeyNames, parameters);
57 if ((dataObjectKeySet == null) || dataObjectKeySet.isEmpty()) {
58 LOG.warn("Matching key set not found in request for class: " + getDataObjectClass());
59
60 return null;
61 }
62 String patronHome = parameters.get("flow");
63
64
65 Map<String, Object> keyPropertyValues = new HashMap<String, Object>();
66 for (String keyPropertyName : dataObjectKeySet) {
67 String keyPropertyValue = parameters.get(keyPropertyName);
68
69
70 Boolean forceUppercase = Boolean.FALSE;
71 try {
72 forceUppercase = getDataDictionaryService().getAttributeForceUppercase(dataObjectClass,
73 keyPropertyName);
74 } catch (UnknownBusinessClassAttributeException ex) {
75
76
77 LOG.warn("Data object class "
78 + dataObjectClass
79 + " property "
80 + keyPropertyName
81 + " should probably have a DD definition.", ex);
82 }
83
84 if (forceUppercase.booleanValue() && (keyPropertyValue != null)) {
85 keyPropertyValue = keyPropertyValue.toUpperCase();
86 }
87
88
89 if (getDataObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObjectClass,
90 keyPropertyName)) {
91 try {
92 keyPropertyValue = getEncryptionService().decrypt(keyPropertyValue);
93 } catch (GeneralSecurityException e) {
94 LOG.error("Data object class "
95 + dataObjectClass
96 + " property "
97 + keyPropertyName
98 + " should have been encrypted, but there was a problem decrypting it.", e);
99 throw new RuntimeException("Data object class "
100 + dataObjectClass
101 + " property "
102 + keyPropertyName
103 + " should have been encrypted, but there was a problem decrypting it.", e);
104 }
105 }
106
107 keyPropertyValues.put(keyPropertyName, keyPropertyValue);
108 }
109
110
111 Object dataObject = null;
112
113 ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(
114 getDataObjectClass());
115 if (moduleService != null && moduleService.isExternalizable(getDataObjectClass())) {
116 dataObject = moduleService.getExternalizableBusinessObject(getDataObjectClass().asSubclass(
117 ExternalizableBusinessObject.class), keyPropertyValues);
118 } else if (BusinessObject.class.isAssignableFrom(getDataObjectClass())) {
119 dataObject = getBusinessObjectService().findByPrimaryKey(getDataObjectClass().asSubclass(
120 BusinessObject.class), keyPropertyValues);
121 }
122
123 EntityAddressBo entityAddress = new EntityAddressBo();
124 List<OleEntityAddressBo> oleEntityAddressList = new ArrayList<OleEntityAddressBo>();
125 OlePatronDocument patronDocument = (OlePatronDocument) dataObject;
126 if (patronDocument != null) {
127 EntityBo kimEnity = patronDocument.getEntity();
128 if (kimEnity.getNames().size() > 0) {
129 patronDocument.setName(kimEnity.getNames().get(0));
130 }
131 if(kimEnity.getEntityTypeContactInfos().size()>0){
132 List<EntityAddressBo> entityAddressList = kimEnity.getEntityTypeContactInfos().get(0).getAddresses();
133 for (EntityAddressBo entityAdd : entityAddressList) {
134 OleEntityAddressBo entityAddressBo = new OleEntityAddressBo();
135 entityAddressBo.setEntityAddressBo(entityAdd);
136 Map addMap = new HashMap();
137
138 addMap.put("id", entityAdd.getId());
139 OleAddressBo oleAddressBo = getBusinessObjectService().findByPrimaryKey(OleAddressBo.class, addMap);
140 entityAddressBo.setOleAddressBo(oleAddressBo);
141 oleEntityAddressList.add(entityAddressBo);
142 }
143 patronDocument.setOleEntityAddressBo(oleEntityAddressList);
144 patronDocument.setPhones(kimEnity.getEntityTypeContactInfos().get(0).getPhoneNumbers());
145 patronDocument.setEmails(kimEnity.getEntityTypeContactInfos().get(0).getEmailAddresses());
146 patronDocument.setPatronAffiliations(getPatronAffiliationFromEntity(kimEnity.getAffiliations(), kimEnity.getEmploymentInformation()));
147 if (patronHome != null) {
148 if (patronHome.equalsIgnoreCase("start"))
149 patronDocument.setPatronHomePage(false);
150 else
151 patronDocument.setPatronHomePage(true);
152 }
153 }
154
155
156 }
157
158 return patronDocument;
159 }
160
161 private List<OlePatronAffiliation> getPatronAffiliationFromEntity(List<EntityAffiliationBo> affiliations,
162 List<EntityEmploymentBo> employeeDetails) {
163 List<OlePatronAffiliation> patronAffiliations = new ArrayList<OlePatronAffiliation>();
164 for (EntityAffiliationBo entityAffiliationBo : affiliations) {
165 OlePatronAffiliation patronAffiliation = new OlePatronAffiliation(entityAffiliationBo);
166 List<EntityEmploymentBo> employmentBos = new ArrayList<EntityEmploymentBo>();
167 for (EntityEmploymentBo entityEmploymentBo : employeeDetails) {
168 if (patronAffiliation.getEntityAffiliationId().equalsIgnoreCase(entityEmploymentBo.getEntityAffiliationId())) {
169 employmentBos.add(entityEmploymentBo);
170 }
171 patronAffiliation.setEmployments(employmentBos);
172 }
173 patronAffiliations.add(patronAffiliation);
174 }
175 return patronAffiliations;
176 }
177
178 public String getTempCircRecords(String olePatronId) {
179 String url = baseUrl + "/portal.do?channelTitle=Patron&channelUrl=" + baseUrl + "/ole-kr-krad/temporaryCirculationRecord?viewId=OleTemporaryCirculationHistoryRecordView&methodToCall=viewTempCircRecords&patronId=" + olePatronId;
180 return url;
181 }
182
183 public String getLoanedRecords(String olePatronId) {
184
185 String url = baseUrl + "/portal.do?channelTitle=Patron&channelUrl=" + baseUrl + "/ole-kr-krad/patronLoanedRecord?viewId=OlePatronLoanedRecordView&methodToCall=viewLoanedRecords&patronId=" + olePatronId;
186 return url;
187 }
188
189 public String getRequestedRecords(String olePatronId) {
190 String url = baseUrl + "/portal.do?channelTitle=Patron&channelUrl=" + baseUrl + "/ole-kr-krad/patronRequestedRecord?viewId=OlePatronRequestedRecordView&methodToCall=viewRequestedRecords&patronId=" + olePatronId;
191 return url;
192 }
193
194 public String getCountOfPendingRequests(String itemId){
195 Map itemMap = new HashMap();
196 itemMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemId);
197 List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, itemMap);
198 if (oleDeliverRequestBoList!=null && oleDeliverRequestBoList.size()>0) {
199
200 return "View all requests";
201 }
202 else
203 return " ";
204 }
205
206 public String getHrefLink(String item,String instance,String bib){
207 String inquiryUrl= ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE)+
208 "/ole-kr-krad/editorcontroller?viewId=EditorView&methodToCall=load&docCategory=work&docType=item&editable=false&docFormat=oleml&docId="+item+"&instanceId="+instance+"&bibId="+bib+"";
209 return inquiryUrl;
210 }
211
212 }