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