1 package org.kuali.ole.deliver.controller;
2
3 import java.awt.Graphics2D;
4 import java.awt.image.BufferedImage;
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7 import java.sql.Timestamp;
8 import java.text.DateFormat;
9 import java.text.ParseException;
10 import java.text.SimpleDateFormat;
11 import java.util.*;
12
13 import javax.imageio.ImageIO;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16
17 import org.apache.commons.collections.CollectionUtils;
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.ole.DocumentUniqueIDPrefix;
21 import org.kuali.ole.OLEConstants;
22 import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
23 import org.kuali.ole.deliver.bo.*;
24 import org.kuali.ole.deliver.form.OlePatronMaintenanceDocumentForm;
25 import org.kuali.ole.deliver.processor.LoanProcessor;
26 import org.kuali.ole.deliver.service.OLEDeliverService;
27 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
28 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
29 import org.kuali.ole.docstore.common.document.ItemOleml;
30 import org.kuali.ole.docstore.common.document.content.enums.DocType;
31 import org.kuali.ole.docstore.common.document.content.instance.Item;
32 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
33 import org.kuali.ole.docstore.common.document.content.instance.MissingPieceItemRecord;
34 import org.kuali.ole.service.OlePatronHelperService;
35 import org.kuali.ole.service.OlePatronHelperServiceImpl;
36 import org.kuali.ole.service.OlePatronMaintenanceDocumentServiceImpl;
37 import org.kuali.ole.service.OlePatronService;
38 import org.kuali.ole.sys.context.SpringContext;
39 import org.kuali.rice.core.api.datetime.DateTimeService;
40 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
41 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
42 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
43 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
44 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
45 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
46 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
47 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
48 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
49 import org.kuali.rice.krad.maintenance.MaintenanceUtils;
50 import org.kuali.rice.krad.service.KRADServiceLocator;
51 import org.kuali.rice.krad.service.MaintenanceDocumentService;
52 import org.kuali.rice.krad.uif.UifParameters;
53 import org.kuali.rice.krad.uif.container.CollectionGroup;
54 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
55 import org.kuali.rice.krad.uif.util.ProcessLogger;
56 import org.kuali.rice.krad.util.GlobalVariables;
57 import org.kuali.rice.krad.util.KRADConstants;
58 import org.kuali.rice.krad.util.ObjectUtils;
59 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
60 import org.kuali.rice.krad.web.form.DocumentFormBase;
61 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
62 import org.kuali.rice.krad.web.form.UifFormBase;
63 import org.springframework.stereotype.Controller;
64 import org.springframework.validation.BindingResult;
65 import org.springframework.web.bind.annotation.ModelAttribute;
66 import org.springframework.web.bind.annotation.RequestMapping;
67 import org.springframework.web.bind.annotation.RequestMethod;
68 import org.springframework.web.multipart.MultipartFile;
69 import org.springframework.web.servlet.ModelAndView;
70
71
72
73
74 @Controller
75 @RequestMapping(value = "/patronMaintenance")
76 public class OlePatronMaintenanceDocumentController extends MaintenanceDocumentController {
77
78 private static final Logger LOG = Logger.getLogger(OlePatronMaintenanceDocumentController.class);
79 private OlePatronService olePatronService;
80 private OlePatronHelperService olePatronHelperService = new OlePatronHelperServiceImpl();
81 private byte[] imageInByte;
82 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
83 private DateTimeService dateTimeService;
84 private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
85
86 @Override
87 protected MaintenanceDocumentForm createInitialForm(
88 HttpServletRequest request) {
89 return new OlePatronMaintenanceDocumentForm();
90 }
91
92 public DateTimeService getDateTimeService() {
93 return (DateTimeService)SpringContext.getService("dateTimeService");
94 }
95
96 public void setDateTimeService(DateTimeService dateTimeService) {
97 this.dateTimeService = dateTimeService;
98 }
99
100 public OlePatronService getOlePatronService() {
101 if (olePatronService != null) {
102 olePatronService = GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_SERVICE);
103 }
104 return olePatronService;
105 }
106
107 private LoanProcessor loanProcessor;
108
109 private OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperService() {
110 if (oleDeliverRequestDocumentHelperService == null) {
111 oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
112 }
113 return oleDeliverRequestDocumentHelperService;
114 }
115
116 private DocstoreClientLocator docstoreClientLocator;
117
118 public DocstoreClientLocator getDocstoreClientLocator() {
119
120 if (docstoreClientLocator == null) {
121 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
122
123 }
124 return docstoreClientLocator;
125 }
126
127
128
129
130
131
132 @Override
133 protected MaintenanceDocumentService getMaintenanceDocumentService() {
134 return GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_MAINTENANCE_DOC_SERVICE);
135 }
136
137
138 @Override
139 @RequestMapping(params = "methodToCall=maintenanceEdit")
140 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
141 HttpServletRequest request, HttpServletResponse response) throws Exception {
142
143 MaintenanceDocumentForm maintenanceForm = form;
144 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
145 MaintenanceDocument document = maintenanceForm.getDocument();
146 super.maintenanceEdit(form, result, request, response);
147 OlePatronDocument olePatronDocument = (OlePatronDocument) document.getOldMaintainableObject().getDataObject();
148 olePatronDocument.getAddresses().clear();
149 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
150 if (olePatronDocument.getActivationDate() == null)
151 olePatronDocument.setActivationDate(getDateTimeService().getCurrentDate());
152 OlePatronDocument patronDocument = (OlePatronDocument)document.getNewMaintainableObject().getDataObject();
153 patronDocument.setBarcodeEditable(false);
154 if((patronDocument.getExpirationDate() != null && patronDocument.getActivationDate() != null && fmt.format(patronDocument.getActivationDate()).compareTo(fmt.format(patronDocument.getExpirationDate())) >= 0) || (patronDocument.getExpirationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(patronDocument.getExpirationDate())) > 0)){
155 patronDocument.setExpirationFlag(false);
156 }
157 olePatronDocument.setShowLoanedRecords(false);
158 olePatronDocument.setShowRequestedItems(false);
159 olePatronDocument.setShowTemporaryCirculationHistoryRecords(false);
160 return getUIFModelAndView(form);
161 }
162
163 @Override
164 @RequestMapping(params = "methodToCall=maintenanceCopy")
165 public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
166 MaintenanceDocumentForm maintenanceForm = form;
167 setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION);
168 super.maintenanceCopy(form, result, request, response);
169 MaintenanceDocument document = maintenanceForm.getDocument();
170 OlePatronDocument patronDocument=(OlePatronDocument)document.getNewMaintainableObject().getDataObject();
171 if(patronDocument.getOlePatronLocalIds()!=null && patronDocument.getOlePatronLocalIds().size()>0){
172 for(OlePatronLocalIdentificationBo olePatronLocalIdentificationBo:patronDocument.getOlePatronLocalIds()){
173 olePatronLocalIdentificationBo.setPatronLocalSeqId(null);
174 olePatronLocalIdentificationBo.setOlePatronId(null);
175 olePatronLocalIdentificationBo.setOlePatronDocument(null);
176 }
177 }
178 patronDocument.setShowLoanedRecords(false);
179 patronDocument.setShowRequestedItems(false);
180 patronDocument.setShowTemporaryCirculationHistoryRecords(false);
181 return getUIFModelAndView(form);
182 }
183
184
185
186
187
188
189
190
191
192
193
194 @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
195 public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
196 HttpServletRequest request, HttpServletResponse response) throws Exception {
197 LOG.debug(" Inside maintenanceDelete ");
198 setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_DELETE);
199 MaintenanceDocumentForm maintenanceForm = form;
200 MaintenanceDocument document = maintenanceForm.getDocument();
201 OlePatronDocument olePatronDocument = (OlePatronDocument) document.getOldMaintainableObject().getDataObject();
202 OlePatronDocument patronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
203 olePatronDocument.setBarcodeEditable(false);
204 patronDocument.setBarcodeEditable(false);
205 olePatronDocument.setShowLoanedRecords(false);
206 olePatronDocument.setShowRequestedItems(false);
207 olePatronDocument.setShowTemporaryCirculationHistoryRecords(false);
208 return getUIFModelAndView(form);
209 }
210
211
212
213
214
215
216
217
218
219
220
221 @RequestMapping(params = "methodToCall=" + "deleteDocument")
222 public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
223 HttpServletRequest request, HttpServletResponse response) throws Exception {
224
225 LOG.debug(" Inside deleteDocument ");
226 MaintenanceDocument document = form.getDocument();
227 OlePatronDocument olePatronDocument = new OlePatronDocument();
228 try {
229 if (document.getDocumentDataObject() != null) {
230 olePatronDocument = (OlePatronDocument) document.getDocumentDataObject();
231 if (olePatronDocument != null && olePatronDocument.getOlePatronId() != null) {
232 boolean deletePatronDetail = olePatronHelperService.deletePatron(olePatronDocument);
233 if (deletePatronDetail) {
234 return back(form, result, request, response);
235 } else {
236 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_HAS_LOAN);
237 return getUIFModelAndView(form);
238 }
239 } else {
240 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
241 return getUIFModelAndView(form);
242 }
243 }
244 } catch (Exception ex) {
245 LOG.error("Exception while delete document", ex);
246 }
247 return back(form, result, request, response);
248 }
249
250
251
252
253
254
255
256
257
258 protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) {
259 LOG.debug(" Inside setupMaintenanceForDelete ");
260 MaintenanceDocument document = form.getDocument();
261 if (document == null) {
262 document = getMaintenanceDocumentService()
263 .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
264 maintenanceAction);
265
266 form.setDocument(document);
267 form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
268 }
269
270 form.setMaintenanceAction(maintenanceAction);
271 OlePatronMaintenanceDocumentServiceImpl olePatronMaintenanceDocumentServicec = (OlePatronMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
272 olePatronMaintenanceDocumentServicec.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
273 MaintenanceUtils.checkForLockingDocument(document, false);
274 }
275
276
277 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=searchAddLine")
278 public ModelAndView searchAddLine(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
279 HttpServletRequest request, HttpServletResponse response) {
280 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
281 String selectedCollectionPath = maintenanceForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
282 CollectionGroup collectionGroup = maintenanceForm.getPostedView().getViewIndex().getCollectionGroupByPath(
283 selectedCollectionPath);
284 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
285 Object eventObject = ObjectPropertyUtils.getPropertyValue(maintenanceForm, addLinePath);
286 OleProxyPatronDocument oleProxyPatronDocument = (OleProxyPatronDocument) eventObject;
287 OlePatronDocument tempDocument = null;
288 if(StringUtils.isNotBlank(oleProxyPatronDocument.getProxyPatronBarcode())) {
289 Map<String, String> proxyMap = new HashMap<String, String>();
290 proxyMap.put(OLEConstants.OlePatron.BARCODE, oleProxyPatronDocument.getProxyPatronBarcode());
291 tempDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, proxyMap);
292 }
293 if (tempDocument != null) {
294 oleProxyPatronDocument.setProxyPatronId(tempDocument.getOlePatronId());
295 oleProxyPatronDocument.setProxyPatronBarcode(tempDocument.getBarcode());
296 oleProxyPatronDocument.setProxyPatronFirstName(tempDocument.getEntity().getNames().get(0).getFirstName());
297 oleProxyPatronDocument.setProxyPatronLastName(tempDocument.getEntity().getNames().get(0).getLastName());
298 super.addLine(form, result, request, response);
299 } else if(StringUtils.isNotBlank(oleProxyPatronDocument.getProxyPatronBarcode())) {
300 GlobalVariables.getMessageMap().putErrorForSectionId("OlePatronDocument-ProxySection", OLEConstants.OlePatron.INVALID_BARCODE, oleProxyPatronDocument.getProxyPatronBarcode());
301 }
302
303 return getUIFModelAndView(form);
304 }
305
306
307
308
309 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addPhoneNumber")
310 public ModelAndView addPhoneNumber(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
311 HttpServletRequest request, HttpServletResponse response) {
312 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
313 String selectedCollectionPath = maintenanceForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
314 CollectionGroup collectionGroup = maintenanceForm.getPostedView().getViewIndex().getCollectionGroupByPath(
315 selectedCollectionPath);
316 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
317 Object eventObject = ObjectPropertyUtils.getPropertyValue(maintenanceForm, addLinePath);
318 OleEntityPhoneBo oleEntityPhoneBo = (OleEntityPhoneBo) eventObject;
319 boolean isValidPhoneNumber=false;
320 if (LOG.isDebugEnabled()) {
321 LOG.debug("Validating the Phone Number Format - ##########, (###)###-#### , ###-###-#### , ### ###-#### , ### ### ####");
322 }
323 if(oleEntityPhoneBo != null && oleEntityPhoneBo.getEntityPhoneBo() != null) {
324 if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("\\d{10}")) isValidPhoneNumber=true;
325 else if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("\\d{3}[-]\\d{3}[-]\\d{4}")) isValidPhoneNumber=true;
326 else if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("\\d{3}[\\s]\\d{3}[-]\\d{4}")) isValidPhoneNumber=true;
327 else if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("\\d{3}[\\s]\\d{3}[\\s]\\d{4}")) isValidPhoneNumber=true;
328 else if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("\\(\\d{3}\\)[\\s]\\d{3}[-]\\d{4}")) isValidPhoneNumber=true;
329 else if (oleEntityPhoneBo.getEntityPhoneBo().getPhoneNumber().matches("^\\+(?:[0-9].?){6,14}[0-9]$")) isValidPhoneNumber=true;
330 else isValidPhoneNumber=false;
331 }
332 if(!isValidPhoneNumber){
333 GlobalVariables.getMessageMap().putErrorForSectionId("OlePatronDocument-Phone", OLEConstants.INVALID_PHONE_NUMBER_FORMAT);
334 }
335 if (isValidPhoneNumber) {
336 ModelAndView modelAndView = super.addLine(form, result, request, response);
337 return modelAndView;
338 } else {
339 return getUIFModelAndView(form);
340 }
341 }
342
343 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addEmailAddress")
344 public ModelAndView addEmailAddress(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
345 HttpServletRequest request, HttpServletResponse response) {
346 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
347 String selectedCollectionPath = maintenanceForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
348 CollectionGroup collectionGroup = maintenanceForm.getPostedView().getViewIndex().getCollectionGroupByPath(
349 selectedCollectionPath);
350 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
351 Object eventObject = ObjectPropertyUtils.getPropertyValue(maintenanceForm, addLinePath);
352 return super.addLine(form, result, request, response);
353 }
354
355 @Override
356 public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
357 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
358 LOG.debug(" Inside route method of patron maintenance controller ");
359 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
360 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
361 String action = mainForm.getMaintenanceAction();
362 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
363 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
364 List<OleLoanDocument> oleLoanDocumentList = newOlePatronDocument.getOleLoanDocuments();
365 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
366 if (oleLoanDocument.isMissingPieceFlag()) {
367 if (oleLoanDocument.getMissingPiecesCount() == null || oleLoanDocument.getMissingPiecesCount() != null && oleLoanDocument.getMissingPiecesCount().equalsIgnoreCase("")) {
368 oleLoanDocument.setNoOfMissingPiecesEditable(true);
369 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_INFO);
370 return getUIFModelAndView(form);
371 }
372 if (oleLoanDocument.getMissingPiecesCount() != null && !oleLoanDocument.getMissingPiecesCount().equalsIgnoreCase("")) {
373 int count = Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
374 if (count < 1) {
375 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_GREATER, new String[]{"Missing Piece Count", "1"});
376 return getUIFModelAndView(form);
377 }
378 }
379 if (oleLoanDocument.getItemNumberOfPieces() == null || oleLoanDocument.getItemNumberOfPieces() != null && oleLoanDocument.getItemNumberOfPieces().toString().equalsIgnoreCase("")) {
380 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_ITEM_INFO);
381 oleLoanDocument.setNoOfPiecesEditable(true);
382 return getUIFModelAndView(form);
383 }
384 if(oleLoanDocument.getItemNumberOfPieces().intValue()<1){
385 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_GREATER, new String[]{"no of piece", "1"});
386 return getUIFModelAndView(form);
387 }
388 int missingPieceCount=Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
389 int numberOfPieces=oleLoanDocument.getItemNumberOfPieces();
390 if(missingPieceCount>numberOfPieces){
391 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_LESSER, new String[]{"Missing Piece Count", "no of pieces"});
392 return getUIFModelAndView(form);
393 }
394 }
395
396 }
397 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
398 try {
399 String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
400 Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
401 boolean isMissingPieceFlagEnabled=(oleItem != null && oleItem.isMissingPieceFlag())?true:false;
402 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
403 if(oleLoanDocument.isMissingPieceFlag() && !isMissingPieceFlagEnabled){
404 MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
405 missingPieceItemRecord.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
406 missingPieceItemRecord.setMissingPieceCount(oleLoanDocument.getMissingPiecesCount());
407 missingPieceItemRecord.setMissingPieceDate(simpleDateFormat.format(getDateTimeService().getCurrentDate()));
408 missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
409 missingPieceItemRecord.setPatronBarcode(newOlePatronDocument.getBarcode());
410 missingPieceItemRecord.setPatronId(newOlePatronDocument.getOlePatronId());
411 missingPieceItemRecord.setItemId(oleLoanDocument.getItemUuid());
412 if (CollectionUtils.isNotEmpty(oleItem.getMissingPieceItemRecordList())) {
413
414 oleItem.getMissingPieceItemRecordList().add(missingPieceItemRecord);
415 } else {
416 List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<MissingPieceItemRecord>();
417 missingPieceItemRecords.add(missingPieceItemRecord);
418 oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
419
420 }
421 }else{
422 Map<String, String> map = new HashMap<>();
423 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(oleLoanDocument.getItemUuid()));
424 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> missingPieceItemRecordList1 = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord>) KRADServiceLocator.getBusinessObjectService()
425 .findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord.class, map, "missingPieceItemId", true);
426 List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<>();
427 for (int index = 0; index < missingPieceItemRecordList1.size(); index++) {
428 MissingPieceItemRecord missingPieceItemRecord1 = new MissingPieceItemRecord();
429 if (index == missingPieceItemRecordList1.size() - 1) {
430 if(!oleLoanDocument.isMissingPieceFlag()){
431 oleLoanDocument.setMissingPieceNote(null);
432 }
433 DateFormat dateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
434 String missingPieceItemDate = dateFormat.format(getDateTimeService().getCurrentDate());
435 missingPieceItemRecord1.setMissingPieceDate(missingPieceItemDate);
436 missingPieceItemRecord1.setPatronBarcode(newOlePatronDocument.getBarcode());
437 missingPieceItemRecord1.setMissingPieceCount(oleLoanDocument.getMissingPiecesCount());
438 missingPieceItemRecord1.setPatronId(newOlePatronDocument.getOlePatronId());
439 missingPieceItemRecord1.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
440 missingPieceItemRecord1.setItemId(DocumentUniqueIDPrefix.getDocumentId(oleLoanDocument.getItemUuid()));
441 missingPieceItemRecord1.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
442 missingPieceItemRecords.add(missingPieceItemRecord1);
443
444 } else {
445 if (missingPieceItemRecordList1.get(index).getMissingPieceDate() != null && !missingPieceItemRecordList1.get(index).getMissingPieceDate().toString().isEmpty()) {
446 SimpleDateFormat dateToSimpleDateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
447 Date missingPieceItemDate = null;
448 if(null != (missingPieceItemRecordList1.get(index).getMissingPieceDate())){
449 try {
450 missingPieceItemDate = new Date(missingPieceItemRecordList1.get(index).getMissingPieceDate().getTime());
451 } catch (org.kuali.ole.sys.exception.ParseException e) {
452 LOG.error("format string to Date " + e);
453 }
454 }
455 missingPieceItemRecord1.setMissingPieceDate(dateToSimpleDateFormat.format(missingPieceItemDate).toString());
456 }
457 missingPieceItemRecord1.setMissingPieceFlagNote(missingPieceItemRecordList1.get(index).getMissingPieceFlagNote());
458 missingPieceItemRecord1.setMissingPieceCount(missingPieceItemRecordList1.get(index).getMissingPieceCount());
459 missingPieceItemRecord1.setOperatorId(missingPieceItemRecordList1.get(index).getOperatorId());
460 missingPieceItemRecord1.setPatronId(missingPieceItemRecordList1.get(index).getPatronId());
461 missingPieceItemRecord1.setItemId(missingPieceItemRecordList1.get(index).getItemId());
462 missingPieceItemRecord1.setPatronBarcode(newOlePatronDocument.getBarcode());
463 missingPieceItemRecords.add(missingPieceItemRecord1);
464 }
465 }
466 oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
467 }
468 if (oleLoanDocument.isClaimsReturnedIndicator()) {
469 getLoanProcessor().updateClaimsReturnedHistory(oleItem,oleLoanDocument,newOlePatronDocument.getOlePatronId());
470 oleItem.setClaimsReturnedFlag(oleLoanDocument.isClaimsReturnedIndicator());
471 getOleDeliverRequestDocumentHelperService().cancelPendingRequestForClaimsReturnedItem(oleItem.getItemIdentifier());
472 oleItem.setClaimsReturnedNote(oleLoanDocument.getClaimsReturnNote());
473 oleItem.setClaimsReturnedFlagCreateDate(df.format(getDateTimeService().getCurrentDate()));
474 } else {
475 oleItem.setClaimsReturnedFlag(oleLoanDocument.isClaimsReturnedIndicator());
476 oleItem.setClaimsReturnedNote(null);
477 oleItem.setClaimsReturnedFlagCreateDate(null);
478 }
479 oleItem.setMissingPieceFlag(oleLoanDocument.isMissingPieceFlag());
480 oleItem.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
481 if(oleLoanDocument.isItemDamagedStatus()){
482 getLoanProcessor().updateItemDamagedHistory(oleItem,oleLoanDocument,newOlePatronDocument.getOlePatronId());
483 oleItem.setItemDamagedStatus(oleLoanDocument.isItemDamagedStatus());
484 oleItem.setDamagedItemNote(oleLoanDocument.getItemDamagedNote());
485 } else {
486 oleItem.setItemDamagedStatus(oleLoanDocument.isItemDamagedStatus());
487 oleItem.setDamagedItemNote(null);
488 }
489 oleItem.setMissingPiecesCount(oleLoanDocument.getMissingPiecesCount());
490 if(oleLoanDocument.getItemNumberOfPieces()!=null&& !oleLoanDocument.getItemNumberOfPieces().toString().equalsIgnoreCase("")){
491 oleItem.setNumberOfPieces(oleLoanDocument.getItemNumberOfPieces().toString());
492 }
493 org.kuali.ole.docstore.common.document.Item itemXML = new ItemOleml();
494 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
495 itemXML.setContent(itemOlemlRecordProcessor.toXML(oleItem));
496 itemXML.setCategory(OLEConstants.WORK_CATEGORY);
497 itemXML.setType(DocType.ITEM.getCode());
498 itemXML.setFormat(OLEConstants.OLEML_FORMAT);
499 itemXML.setId(oleLoanDocument.getItemUuid());
500 getDocstoreClientLocator().getDocstoreClient().updateItem(itemXML);
501 } catch (Exception e) {
502 throw new RuntimeException(e);
503 }
504 }
505 if(!olePatronHelperService.validatePatron(newOlePatronDocument)) {
506 return getUIFModelAndView(form);
507 }
508 if (!KRADConstants.MAINTENANCE_EDIT_ACTION.equals(action)) {
509 if (newOlePatronDocument.getOlePatronId() == null || newOlePatronDocument.getOlePatronId().isEmpty()) {
510 if (newOlePatronDocument.getActivationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(newOlePatronDocument.getActivationDate())) > 0) {
511 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_ACTIVATION_DATE);
512
513 return getUIFModelAndView(mainForm);
514 }
515 }
516 } else {
517 Map<String, String> patronMap = new HashMap<String, String>();
518 patronMap.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
519 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
520 SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
521 Date todayDate=getDateTimeService().getCurrentDate();
522 String format=simpleDateFormat.format(getDateTimeService().getCurrentDate());
523 try {
524 todayDate=simpleDateFormat.parse(format);
525 } catch (ParseException e) {
526 e.printStackTrace();
527 }
528 if(newOlePatronDocument.getActivationDate()!=null && newOlePatronDocument.getActivationDate().compareTo(todayDate)<0 && patronDocument!=null && patronDocument.getActivationDate()!=null && patronDocument.getActivationDate().compareTo(newOlePatronDocument.getActivationDate())>0){
529 if (!newOlePatronDocument.isPopupDialog()) {
530 newOlePatronDocument.setPopupDialog(true);
531 newOlePatronDocument.setUiMessageType("patron-message-info");
532 newOlePatronDocument.setPatronMessage(OLEConstants.OlePatron.ERROR_PATRON_NEW_PAST_DATE+"<br/>"+OLEConstants.PROCEED_MESSAGE);
533 return getUIFModelAndView(mainForm);
534 }
535 }
536 }
537
538 newOlePatronDocument.setPopupDialog(false);
539 newOlePatronDocument.setOleLoanDocuments(oleLoanDocumentList);
540 List<OleProxyPatronDocument> oleProxyPatronDocumentList = newOlePatronDocument.getOleProxyPatronDocuments();
541 List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
542 if (oleProxyPatronDocumentList.size() > 0) {
543 for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocumentList) {
544 Map<String, String> proxyMap = new HashMap<String, String>();
545 proxyMap.put(OLEConstants.OlePatron.PATRON_ID, oleProxyPatronDocument.getProxyPatronId());
546 OlePatronDocument tempDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, proxyMap);
547 if (tempDocument != null) {
548 oleProxyPatronDocument.setProxyPatronBarcode(tempDocument.getBarcode());
549 oleProxyPatronDocument.setProxyPatronFirstName(tempDocument.getEntity().getNames().get(0).getFirstName());
550 oleProxyPatronDocument.setProxyPatronLastName(tempDocument.getEntity().getNames().get(0).getLastName());
551 proxyPatronDocumentList.add(oleProxyPatronDocument);
552 }
553 }
554 newOlePatronDocument.setOleProxyPatronDocuments(proxyPatronDocumentList);
555 }
556
557 if (newOlePatronDocument.getOlePatronId() != null && !newOlePatronDocument.getOlePatronId().equalsIgnoreCase("")) {
558 Map<String, String> map = new HashMap<String, String>();
559 map.put(OLEConstants.OlePatron.PATRON_LOST_BARCODE_FLD, newOlePatronDocument.getBarcode());
560 map.put("active", "N");
561 List<OlePatronLostBarcode> olePatronLostBarcodes = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, map);
562 if (olePatronLostBarcodes.size() > 0 && (!newOlePatronDocument.isSkipBarcodeValidation())) {
563 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_DUPLICATE_BARCODE);
564 return getUIFModelAndView(mainForm);
565 }
566
567 boolean isBarcodeContainsInLostSection = false;
568 if(newOlePatronDocument.getLostBarcodes()!=null&& newOlePatronDocument.getBarcode()!=null){
569
570 for(OlePatronLostBarcode olePatronLostBarcode:olePatronLostBarcodes){
571 if(olePatronLostBarcode.getInvalidOrLostBarcodeNumber()!=null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())){
572 isBarcodeContainsInLostSection=true;
573 }
574 }
575 }
576
577 if (newOlePatronDocument.isBarcodeEditable()&& !newOlePatronDocument.isReinstated()) {
578 for (OlePatronLostBarcode olePatronLostBarcode : newOlePatronDocument.getLostBarcodes()) {
579 if (olePatronLostBarcode.getInvalidOrLostBarcodeNumber() != null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())) {
580 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_BARCODE_BLOCK_MANUALLY,new String[]{newOlePatronDocument.getBarcode()});
581 newOlePatronDocument.setBarcode(null);
582 newOlePatronDocument.setBarcodeEditable(true);
583 newOlePatronDocument.setReinstated(false);
584 return getUIFModelAndView(mainForm);
585 }
586 }
587 }
588 if (!isBarcodeContainsInLostSection) {
589
590 Map<String, String> patronMap = new HashMap<String, String>();
591 patronMap.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
592 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
593 if (patronDocument != null && patronDocument.getBarcode() != null && !(patronDocument.getBarcode().equalsIgnoreCase(""))) {
594 if (newOlePatronDocument.getLostBarcodes() == null) {
595 newOlePatronDocument.setLostBarcodes(new ArrayList<OlePatronLostBarcode>());
596 }
597 if (!patronDocument.getBarcode().equalsIgnoreCase(newOlePatronDocument.getBarcode()) && (!newOlePatronDocument.isBarcodeChanged())) {
598 if (patronDocument != null && patronDocument.getBarcode() != null) {
599 boolean isNeedToUpdateBarcode=false;
600 String originalBarcode=patronDocument.getBarcode();
601 for(OlePatronLostBarcode olePatronLostBarcode:newOlePatronDocument.getLostBarcodes()){
602 if(olePatronLostBarcode.getInvalidOrLostBarcodeNumber()!=null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(originalBarcode)){
603 isNeedToUpdateBarcode=true;
604 }
605 }
606 if (!isNeedToUpdateBarcode) {
607 OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
608 olePatronLostBarcode.setInvalidOrLostBarcodeNumber(patronDocument.getBarcode());
609 olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
610 olePatronLostBarcode.setRevertBarcode(true);
611 olePatronLostBarcode.setDescription("");
612 olePatronLostBarcode.setStatus("Lost");
613 newOlePatronDocument.getLostBarcodes().add(olePatronLostBarcode);
614 }
615 }
616
617 }
618 }
619 }
620 }
621
622 List<OleProxyPatronDocument> proxyPatron = newOlePatronDocument.getOleProxyPatronDocuments();
623 String patronId = "";
624 Date proxyActDate = null;
625 Date proxyExpDate = null;
626 if (proxyPatron.size() > 0) {
627 for (OleProxyPatronDocument proxy : proxyPatron) {
628 patronId = proxy.getProxyPatronId();
629 proxyActDate = proxy.getProxyPatronActivationDate();
630 proxyExpDate = proxy.getProxyPatronExpirationDate();
631 Map<String, String> patronMap = new HashMap<String, String>();
632 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
633 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
634 if (patronDocument != null) {
635 Date patronExpDate = patronDocument.getExpirationDate();
636 Date patronActDate = patronDocument.getActivationDate();
637 if (proxyActDate != null) {
638 if (patronActDate != null && fmt.format(patronActDate).compareTo(fmt.format(proxyActDate)) > 0) {
639 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_ACTIVATION_DATE);
640 return getUIFModelAndView(mainForm);
641 }
642 }
643 if (proxyExpDate != null) {
644 if (patronExpDate != null) {
645 if (fmt.format(proxyExpDate).compareTo(fmt.format(patronExpDate)) > 0) {
646 if(newOlePatronDocument.isExpirationFlag()){
647 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_EXPIRATION_DATE);
648 return getUIFModelAndView(mainForm);
649 }
650 }
651 }
652 }
653 }
654 boolean isBorrowerTypeActive = olePatronHelperService.isBorrowerTypeActive(newOlePatronDocument);
655 if (!isBorrowerTypeActive) {
656 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BORROWER_TYPE_INACTIVE);
657 return getUIFModelAndView(mainForm);
658 }
659 if (patronId != null && newOlePatronDocument.getOlePatronId() != null && newOlePatronDocument.getOlePatronId().equals(patronId)) {
660 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ID);
661 return getUIFModelAndView(mainForm);
662 } else {
663 if (proxyExpDate != null) {
664 if (proxyActDate != null) {
665 if ((fmt.format(proxyActDate).compareTo(fmt.format(proxyExpDate)) >= 0)) {
666 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
667 return getUIFModelAndView(mainForm);
668 }
669 }
670 }
671 }
672 }
673 }
674 return super.save(form, result, request, response);
675 }
676
677
678
679
680
681
682
683 @Override
684 @RequestMapping(params = "methodToCall=route")
685 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
686 HttpServletRequest request, HttpServletResponse response) {
687 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
688 LOG.debug(" Inside route method of patron maintenance controller ");
689 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
690 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
691 String action = mainForm.getMaintenanceAction();
692 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
693 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
694 List<OleLoanDocument> oleLoanDocumentList = newOlePatronDocument.getOleLoanDocuments();
695 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
696 if (oleLoanDocument.isLoanModified()) {
697 if (oleLoanDocument.isMissingPieceFlag()) {
698 if (oleLoanDocument.getMissingPiecesCount() == null || oleLoanDocument.getMissingPiecesCount() != null && oleLoanDocument.getMissingPiecesCount().equalsIgnoreCase("")) {
699 oleLoanDocument.setNoOfMissingPiecesEditable(true);
700 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_INFO);
701 return getUIFModelAndView(form);
702 }
703 if (oleLoanDocument.getMissingPiecesCount() != null && !oleLoanDocument.getMissingPiecesCount().equalsIgnoreCase("")) {
704 int count = Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
705 if (count < 1) {
706 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_GREATER, new String[]{"Missing Piece Count", "1"});
707 return getUIFModelAndView(form);
708 }
709 }
710 if (oleLoanDocument.getItemNumberOfPieces() == null || oleLoanDocument.getItemNumberOfPieces() != null && oleLoanDocument.getItemNumberOfPieces().toString().equalsIgnoreCase("")) {
711 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_ITEM_INFO);
712 oleLoanDocument.setNoOfPiecesEditable(true);
713 return getUIFModelAndView(form);
714 }
715 if (oleLoanDocument.getItemNumberOfPieces().intValue() < 1) {
716 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_GREATER, new String[]{"no of piece", "1"});
717 oleLoanDocument.setNoOfPiecesEditable(true);
718 oleLoanDocument.setNoOfMissingPiecesEditable(true);
719 return getUIFModelAndView(form);
720 }
721 int missingPieceCount = Integer.parseInt(oleLoanDocument.getMissingPiecesCount());
722 int numberOfPieces = oleLoanDocument.getItemNumberOfPieces();
723 if (missingPieceCount > numberOfPieces) {
724 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PATRON_LOANED_ITEM_SECTION, OLEConstants.OlePatron.ERROR_PATRON_MISSING_PIECE_ITEM_COUNT_LESSER, new String[]{"Missing Piece Count", "no of pieces"});
725 oleLoanDocument.setNoOfPiecesEditable(true);
726 oleLoanDocument.setNoOfMissingPiecesEditable(true);
727 return getUIFModelAndView(form);
728 }
729 }
730 try {
731 String itemXmlContent = getLoanProcessor().getItemXML(oleLoanDocument.getItemUuid());
732 Item oleItem = getLoanProcessor().getItemPojo(itemXmlContent);
733 boolean isMissingPieceFlagEnabled=(oleItem != null && oleItem.isMissingPieceFlag())?true:false;
734 if (oleLoanDocument.isClaimsReturnedIndicator()) {
735 getLoanProcessor().updateClaimsReturnedHistory(oleItem,oleLoanDocument,newOlePatronDocument.getOlePatronId());
736 oleItem.setClaimsReturnedFlag(oleLoanDocument.isClaimsReturnedIndicator());
737 getOleDeliverRequestDocumentHelperService().cancelPendingRequestForClaimsReturnedItem(oleItem.getItemIdentifier());
738 oleItem.setClaimsReturnedNote(oleLoanDocument.getClaimsReturnNote());
739 oleItem.setClaimsReturnedFlagCreateDate(df.format(getDateTimeService().getCurrentDate()));
740 } else {
741 oleItem.setClaimsReturnedFlag(oleLoanDocument.isClaimsReturnedIndicator());
742 oleItem.setClaimsReturnedNote(null);
743 oleItem.setClaimsReturnedFlagCreateDate(null);
744 }
745 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
746 String parsedDate = simpleDateFormat.format((new Date()));
747 if(oleLoanDocument.isMissingPieceFlag() && !isMissingPieceFlagEnabled){
748 MissingPieceItemRecord missingPieceItemRecord = new MissingPieceItemRecord();
749 missingPieceItemRecord.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
750 missingPieceItemRecord.setMissingPieceCount(oleLoanDocument.getMissingPiecesCount());
751 missingPieceItemRecord.setMissingPieceDate(parsedDate);
752 missingPieceItemRecord.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
753 missingPieceItemRecord.setPatronBarcode(newOlePatronDocument.getBarcode());
754 missingPieceItemRecord.setPatronId(newOlePatronDocument.getOlePatronId());
755 missingPieceItemRecord.setItemId(oleLoanDocument.getItemUuid());
756 if (CollectionUtils.isNotEmpty(oleItem.getMissingPieceItemRecordList())) {
757
758 oleItem.getMissingPieceItemRecordList().add(missingPieceItemRecord);
759 } else {
760 List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<MissingPieceItemRecord>();
761 missingPieceItemRecords.add(missingPieceItemRecord);
762 oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
763 }
764 }else{
765 Map<String, String> map = new HashMap<>();
766 map.put("itemId", DocumentUniqueIDPrefix.getDocumentId(oleLoanDocument.getItemUuid()));
767 List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord> missingPieceItemRecordList1 = (List<org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord>) KRADServiceLocator.getBusinessObjectService()
768 .findMatchingOrderBy(org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.MissingPieceItemRecord.class, map, "missingPieceItemId", true);
769 List<MissingPieceItemRecord> missingPieceItemRecords = new ArrayList<>();
770 for (int index = 0; index < missingPieceItemRecordList1.size(); index++) {
771 MissingPieceItemRecord missingPieceItemRecord1 = new MissingPieceItemRecord();
772 if (index == missingPieceItemRecordList1.size() - 1) {
773 if(!oleLoanDocument.isMissingPieceFlag()){
774 oleLoanDocument.setMissingPieceNote(null);
775 }
776 DateFormat dateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
777 String missingPieceItemDate = dateFormat.format((new Date()));
778 missingPieceItemRecord1.setMissingPieceDate(missingPieceItemDate);
779 missingPieceItemRecord1.setMissingPieceCount(oleLoanDocument.getMissingPiecesCount());
780 missingPieceItemRecord1.setPatronBarcode(newOlePatronDocument.getBarcode());
781 missingPieceItemRecord1.setPatronId(newOlePatronDocument.getOlePatronId());
782 missingPieceItemRecord1.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
783 missingPieceItemRecord1.setItemId(DocumentUniqueIDPrefix.getDocumentId(oleLoanDocument.getItemUuid()));
784 missingPieceItemRecord1.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
785 missingPieceItemRecords.add(missingPieceItemRecord1);
786
787 } else {
788 if (missingPieceItemRecordList1.get(index).getMissingPieceDate() != null && !missingPieceItemRecordList1.get(index).getMissingPieceDate().toString().isEmpty()) {
789 SimpleDateFormat dateToSimpleDateFormat = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE);
790 Date missingPieceItemDate = null;
791 if(null != (missingPieceItemRecordList1.get(index).getMissingPieceDate())){
792 try {
793 missingPieceItemDate = new Date(missingPieceItemRecordList1.get(index).getMissingPieceDate().getTime());
794 } catch (org.kuali.ole.sys.exception.ParseException e) {
795 LOG.error("format string to Date " + e);
796 }
797 }
798 missingPieceItemRecord1.setMissingPieceDate(dateToSimpleDateFormat.format(missingPieceItemDate).toString());
799 }
800 missingPieceItemRecord1.setMissingPieceFlagNote(missingPieceItemRecordList1.get(index).getMissingPieceFlagNote());
801 missingPieceItemRecord1.setMissingPieceCount(missingPieceItemRecordList1.get(index).getMissingPieceCount());
802 missingPieceItemRecord1.setOperatorId(missingPieceItemRecordList1.get(index).getOperatorId());
803 missingPieceItemRecord1.setPatronBarcode(newOlePatronDocument.getBarcode());
804 missingPieceItemRecord1.setPatronId(missingPieceItemRecordList1.get(index).getPatronId());
805 missingPieceItemRecord1.setItemId(missingPieceItemRecordList1.get(index).getItemId());
806 missingPieceItemRecords.add(missingPieceItemRecord1);
807 }
808 }
809 oleItem.setMissingPieceItemRecordList(missingPieceItemRecords);
810 }
811 oleItem.setMissingPieceFlag(oleLoanDocument.isMissingPieceFlag());
812 oleItem.setMissingPieceFlagNote(oleLoanDocument.getMissingPieceNote());
813 if(oleLoanDocument.isItemDamagedStatus()){
814 getLoanProcessor().updateItemDamagedHistory(oleItem,oleLoanDocument,newOlePatronDocument.getOlePatronId());
815 oleItem.setItemDamagedStatus(oleLoanDocument.isItemDamagedStatus());
816 oleItem.setDamagedItemNote(oleLoanDocument.getItemDamagedNote());
817 } else {
818 oleItem.setItemDamagedStatus(oleLoanDocument.isItemDamagedStatus());
819 oleItem.setDamagedItemNote(null);
820 }
821 oleItem.setMissingPiecesCount(oleLoanDocument.getMissingPiecesCount());
822 if (oleLoanDocument.getItemNumberOfPieces() != null && !oleLoanDocument.getItemNumberOfPieces().toString().equalsIgnoreCase("")) {
823 oleItem.setNumberOfPieces(oleLoanDocument.getItemNumberOfPieces().toString());
824 }
825 org.kuali.ole.docstore.common.document.Item itemXML = new ItemOleml();
826 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
827 itemXML.setContent(itemOlemlRecordProcessor.toXML(oleItem));
828 itemXML.setCategory(OLEConstants.WORK_CATEGORY);
829 itemXML.setType(DocType.ITEM.getCode());
830 itemXML.setFormat(OLEConstants.OLEML_FORMAT);
831 itemXML.setId(oleLoanDocument.getItemUuid());
832 getDocstoreClientLocator().getDocstoreClient().updateItem(itemXML);
833 } catch (Exception e) {
834 throw new RuntimeException(e);
835 }
836 }
837
838 }
839 if(!olePatronHelperService.validatePatron(newOlePatronDocument)) {
840 return getUIFModelAndView(form);
841 }
842 if (!KRADConstants.MAINTENANCE_EDIT_ACTION.equals(action)) {
843 if (newOlePatronDocument.getOlePatronId() == null || newOlePatronDocument.getOlePatronId().isEmpty()) {
844 if (newOlePatronDocument.getActivationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(newOlePatronDocument.getActivationDate())) > 0) {
845 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_ACTIVATION_DATE);
846 return getUIFModelAndView(mainForm);
847 }
848 }
849 } else {
850 Map<String, String> patronMap = new HashMap<String, String>();
851 patronMap.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
852 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
853 SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
854 Date todayDate=getDateTimeService().getCurrentDate();
855 String format=simpleDateFormat.format(getDateTimeService().getCurrentDate());
856 try {
857 todayDate=simpleDateFormat.parse(format);
858 } catch (ParseException e) {
859 e.printStackTrace();
860 }
861 if(newOlePatronDocument.getActivationDate()!=null && newOlePatronDocument.getActivationDate().compareTo(todayDate)<0 && patronDocument!=null && patronDocument.getActivationDate()!=null && patronDocument.getActivationDate().compareTo(newOlePatronDocument.getActivationDate())>0){
862 if (!newOlePatronDocument.isPopupDialog()) {
863 newOlePatronDocument.setPopupDialog(true);
864 newOlePatronDocument.setUiMessageType("patron-message-info");
865 newOlePatronDocument.setPatronMessage(OLEConstants.OlePatron.ERROR_PATRON_NEW_PAST_DATE+"<br/>"+OLEConstants.PROCEED_MESSAGE);
866 return getUIFModelAndView(mainForm);
867 }
868 }
869 }
870
871 newOlePatronDocument.setPopupDialog(false);
872 newOlePatronDocument.setOleLoanDocuments(oleLoanDocumentList);
873 List<OleProxyPatronDocument> oleProxyPatronDocumentList = newOlePatronDocument.getOleProxyPatronDocuments();
874 List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
875 if (oleProxyPatronDocumentList.size() > 0) {
876 for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocumentList) {
877 Map<String, String> proxyMap = new HashMap<String, String>();
878 proxyMap.put(OLEConstants.OlePatron.PATRON_ID, oleProxyPatronDocument.getProxyPatronId());
879 OlePatronDocument tempDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, proxyMap);
880 if (tempDocument != null) {
881 oleProxyPatronDocument.setProxyPatronBarcode(tempDocument.getBarcode());
882 oleProxyPatronDocument.setProxyPatronFirstName(tempDocument.getEntity().getNames().get(0).getFirstName());
883 oleProxyPatronDocument.setProxyPatronLastName(tempDocument.getEntity().getNames().get(0).getLastName());
884 proxyPatronDocumentList.add(oleProxyPatronDocument);
885 }
886 }
887 newOlePatronDocument.setOleProxyPatronDocuments(proxyPatronDocumentList);
888 }
889
890 if (newOlePatronDocument.getOlePatronId() != null && !newOlePatronDocument.getOlePatronId().equalsIgnoreCase("")) {
891
892 if (newOlePatronDocument.isBarcodeEditable()&& !newOlePatronDocument.isReinstated()) {
893 for (OlePatronLostBarcode olePatronLostBarcode : newOlePatronDocument.getLostBarcodes()) {
894 if (olePatronLostBarcode.getInvalidOrLostBarcodeNumber() != null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())) {
895 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_BARCODE_BLOCK_MANUALLY,new String[]{newOlePatronDocument.getBarcode()});
896 newOlePatronDocument.setBarcode(null);
897 newOlePatronDocument.setBarcodeEditable(true);
898 newOlePatronDocument.setReinstated(false);
899 olePatronLostBarcode.setStatus(OLEConstants.OlePatron.NEWBARCODE_STATUS);
900 olePatronLostBarcode.setDescription(OLEConstants.OlePatron.NEWBARCODE_DESCRIPTION);
901 return getUIFModelAndView(mainForm);
902 }
903 }
904 }
905 Map<String, String> map = new HashMap<String, String>();
906 map.put(OLEConstants.OlePatron.PATRON_LOST_BARCODE_FLD, newOlePatronDocument.getBarcode());
907 map.put("active", "N");
908 List<OlePatronLostBarcode> olePatronLostBarcodes = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, map);
909 if (olePatronLostBarcodes.size() > 0 && (!newOlePatronDocument.isSkipBarcodeValidation())) {
910 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_DUPLICATE_BARCODE);
911 return getUIFModelAndView(mainForm);
912 }
913
914 boolean isBarcodeContainsInLostSection = false;
915 if(newOlePatronDocument.getLostBarcodes()!=null&& newOlePatronDocument.getBarcode()!=null){
916
917 for(OlePatronLostBarcode olePatronLostBarcode:olePatronLostBarcodes){
918 if(olePatronLostBarcode.getInvalidOrLostBarcodeNumber()!=null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())){
919 isBarcodeContainsInLostSection=true;
920 }
921 }
922 }
923 if (!isBarcodeContainsInLostSection) {
924
925 Map<String, String> patronMap = new HashMap<String, String>();
926 patronMap.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
927 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
928 if (patronDocument != null && patronDocument.getBarcode() != null && !(patronDocument.getBarcode().equalsIgnoreCase(""))) {
929 if (newOlePatronDocument.getLostBarcodes() == null) {
930 newOlePatronDocument.setLostBarcodes(new ArrayList<OlePatronLostBarcode>());
931 }
932 if (!patronDocument.getBarcode().equalsIgnoreCase(newOlePatronDocument.getBarcode()) && (!newOlePatronDocument.isBarcodeChanged())) {
933 if (patronDocument != null && patronDocument.getBarcode() != null) {
934 boolean isNeedToUpdateBarcode=false;
935 String originalBarcode=patronDocument.getBarcode();
936 for(OlePatronLostBarcode olePatronLostBarcode:newOlePatronDocument.getLostBarcodes()){
937 if(olePatronLostBarcode.getInvalidOrLostBarcodeNumber()!=null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(originalBarcode)){
938 isNeedToUpdateBarcode=true;
939 }
940 }
941 if (!isNeedToUpdateBarcode) {
942 OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
943 olePatronLostBarcode.setInvalidOrLostBarcodeNumber(patronDocument.getBarcode());
944 olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
945 olePatronLostBarcode.setRevertBarcode(true);
946 olePatronLostBarcode.setDescription("");
947 olePatronLostBarcode.setStatus("Lost");
948 newOlePatronDocument.getLostBarcodes().add(olePatronLostBarcode);
949 }
950 }
951
952 }
953 }
954 }
955 }
956
957 List<OleProxyPatronDocument> proxyPatron = newOlePatronDocument.getOleProxyPatronDocuments();
958 String patronId = "";
959 Date proxyActDate = null;
960 Date proxyExpDate = null;
961 if (proxyPatron.size() > 0) {
962 for (OleProxyPatronDocument proxy : proxyPatron) {
963 patronId = proxy.getProxyPatronId();
964 proxyActDate = proxy.getProxyPatronActivationDate();
965 proxyExpDate = proxy.getProxyPatronExpirationDate();
966 Map<String, String> patronMap = new HashMap<String, String>();
967 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
968 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
969 if (patronDocument != null) {
970 Date patronExpDate = patronDocument.getExpirationDate();
971 Date patronActDate = patronDocument.getActivationDate();
972 if (proxyActDate != null) {
973 if (patronActDate != null && fmt.format(patronActDate).compareTo(fmt.format(proxyActDate)) > 0) {
974 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_ACTIVATION_DATE);
975 return getUIFModelAndView(mainForm);
976 }
977 }
978 if (proxyExpDate != null) {
979 if (patronExpDate != null) {
980 if (fmt.format(proxyExpDate).compareTo(fmt.format(patronExpDate)) > 0) {
981 if(newOlePatronDocument.isExpirationFlag()){
982 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_EXPIRATION_DATE);
983 return getUIFModelAndView(mainForm);
984 }
985 }
986 }
987 }
988 }
989
990 boolean isBorrowerTypeActive = olePatronHelperService.isBorrowerTypeActive(newOlePatronDocument);
991 if (!isBorrowerTypeActive) {
992 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BORROWER_TYPE_INACTIVE);
993 return getUIFModelAndView(mainForm);
994 }
995 if (patronId != null && newOlePatronDocument.getOlePatronId() != null && newOlePatronDocument.getOlePatronId().equals(patronId)) {
996 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ID);
997 return getUIFModelAndView(mainForm);
998 } else {
999 if (proxyExpDate != null) {
1000 if (proxyActDate != null) {
1001 if ((fmt.format(proxyActDate).compareTo(fmt.format(proxyExpDate)) >= 0)) {
1002 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
1003 return getUIFModelAndView(mainForm);
1004 }
1005 }
1006 }
1007 }
1008 }
1009 }
1010 if (newOlePatronDocument.isGeneralBlock() && (newOlePatronDocument.getGeneralBlockNotes() == null || newOlePatronDocument.getGeneralBlockNotes().equals(""))) {
1011 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_GENERAL_BLOCK_NOTES, OLEConstants.OlePatron.PATRON_GENERAL_BLOCK_NOTES);
1012 return getUIFModelAndView(mainForm);
1013 } else if ((newOlePatronDocument.getExpirationDate() != null && newOlePatronDocument.getActivationDate() != null && fmt.format(newOlePatronDocument.getActivationDate()).compareTo(fmt.format(newOlePatronDocument.getExpirationDate())) >= 0) || (newOlePatronDocument.getExpirationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(newOlePatronDocument.getExpirationDate())) > 0)) {
1014 if(newOlePatronDocument.isExpirationFlag()){
1015 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_EXPIRATION_DATE);
1016 return getUIFModelAndView(mainForm);
1017 }
1018 } else if (newOlePatronDocument.getOlePatronId() != null) {
1019 Map<String, String> tempId = new HashMap<String, String>();
1020 tempId.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
1021 OlePatronDocument tempDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, tempId);
1022 if (tempDocument != null) {
1023 if (tempDocument.getEntity() != null) {
1024 if (newOlePatronDocument.getDeletedOleEntityAddressBo().size() > 0) {
1025 for(OleEntityAddressBo oleEntityAddressBo:newOlePatronDocument.getDeletedOleEntityAddressBo()){
1026 KRADServiceLocator.getBusinessObjectService().delete(oleEntityAddressBo.getOleAddressBo());
1027 KRADServiceLocator.getBusinessObjectService().delete(oleEntityAddressBo.getEntityAddressBo());
1028 }
1029 }
1030 if(CollectionUtils.isNotEmpty(newOlePatronDocument.getDeletedOleEntityEmailBo())) {
1031 for(OleEntityEmailBo oleEntityEmailBo : newOlePatronDocument.getDeletedOleEntityEmailBo()) {
1032 KRADServiceLocator.getBusinessObjectService().delete(oleEntityEmailBo.getOleEmailBo());
1033 KRADServiceLocator.getBusinessObjectService().delete(oleEntityEmailBo.getEntityEmailBo());
1034 }
1035 }
1036 Map<String, String> mapEntityId = new HashMap<String, String>();
1037 mapEntityId.put("entityId", newOlePatronDocument.getOlePatronId());
1038 List<EntityNameBo> entityNameBos = tempDocument.getEntity().getNames();
1039 if (entityNameBos.size() > 0) {
1040 KRADServiceLocator.getBusinessObjectService().deleteMatching(EntityNameBo.class,mapEntityId);
1041 }
1042 if(CollectionUtils.isNotEmpty(newOlePatronDocument.getDeletedOleEntityPhoneBo())) {
1043 for(OleEntityPhoneBo oleEntityPhoneBo : newOlePatronDocument.getDeletedOleEntityPhoneBo()) {
1044 KRADServiceLocator.getBusinessObjectService().delete(oleEntityPhoneBo.getOlePhoneBo());
1045 KRADServiceLocator.getBusinessObjectService().delete(oleEntityPhoneBo.getEntityPhoneBo());
1046 }
1047 }
1048 if(newOlePatronDocument.getDeletedNotes().size()>0){
1049 KRADServiceLocator.getBusinessObjectService().delete(newOlePatronDocument.getDeletedNotes());
1050 }
1051
1052 List<OlePatronLostBarcode> lostBarcodeList = tempDocument.getLostBarcodes();
1053 if (lostBarcodeList.size() > 0) {
1054 KRADServiceLocator.getBusinessObjectService().delete(lostBarcodeList);
1055 }
1056 if(newOlePatronDocument.getDeletedEmployments().size()>0){
1057 KRADServiceLocator.getBusinessObjectService().delete(newOlePatronDocument.getDeletedEmployments());
1058 }
1059 if(newOlePatronDocument.getDeletedPatronAffiliations().size()>0){
1060 for(OlePatronAffiliation olePatronAffiliation:newOlePatronDocument.getDeletedPatronAffiliations()){
1061 if(olePatronAffiliation.getEmployments()!=null && olePatronAffiliation.getEmployments().size()>0){
1062 KRADServiceLocator.getBusinessObjectService().delete(newOlePatronDocument.getDeletedOleProxyPatronDocuments());
1063 }
1064 Map<String,String> affiliationsMap=new HashMap<String,String>();
1065 affiliationsMap.put("id",olePatronAffiliation.getEntityAffiliationId());
1066 KRADServiceLocator.getBusinessObjectService().deleteMatching(EntityAffiliationBo.class,affiliationsMap);
1067
1068 }
1069 }
1070 if(newOlePatronDocument.getDeletedOleProxyPatronDocuments().size()>0){
1071 KRADServiceLocator.getBusinessObjectService().delete(newOlePatronDocument.getDeletedOleProxyPatronDocuments());
1072 }
1073 if(newOlePatronDocument.getDeletedOlePatronLocalIds().size()>0){
1074 KRADServiceLocator.getBusinessObjectService().delete(newOlePatronDocument.getDeletedOlePatronLocalIds());
1075 }
1076 }
1077 }
1078 }
1079 if (newOlePatronDocument.getLostBarcodes() != null) {
1080 for (OlePatronLostBarcode lostBarcodes : newOlePatronDocument.getLostBarcodes()) {
1081 if (lostBarcodes.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())) {
1082 lostBarcodes.setActive(true);
1083 }
1084 }
1085 }
1086 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(action)) {
1087 newOlePatronDocument.setEntity(olePatronHelperService.editAndSaveEntityBo(newOlePatronDocument));
1088 Map<String, Object> criteria = new HashMap<String, Object>();
1089 criteria.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
1090 KRADServiceLocator.getBusinessObjectService().deleteMatching(OleAddressBo.class, criteria);
1091 prepareOleAddressForSave(newOlePatronDocument);
1092 KRADServiceLocator.getBusinessObjectService().deleteMatching(OlePhoneBo.class, criteria);
1093 prepareOlePhoneForSave(newOlePatronDocument);
1094 KRADServiceLocator.getBusinessObjectService().deleteMatching(OleEmailBo.class, criteria);
1095 prepareOleEmailForSave(newOlePatronDocument);
1096 }
1097 if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(action) || KRADConstants.MAINTENANCE_NEW_ACTION.equals(action)) {
1098 newOlePatronDocument.setEntity(olePatronHelperService.copyAndSaveEntityBo(newOlePatronDocument));
1099 newOlePatronDocument.setOlePatronId(newOlePatronDocument.getEntity().getId());
1100 for (OleEntityAddressBo oleEntityAddressBo : newOlePatronDocument.getOleEntityAddressBo()) {
1101 if(oleEntityAddressBo.getOleAddressBo()!=null){
1102 oleEntityAddressBo.getOleAddressBo().setOleAddressId(null);
1103 }
1104 }
1105 prepareOleAddressForSave(newOlePatronDocument);
1106 for(OleEntityPhoneBo oleEntityPhoneBo : newOlePatronDocument.getOleEntityPhoneBo()) {
1107 if(oleEntityPhoneBo.getOlePhoneBo() != null) {
1108 oleEntityPhoneBo.getOlePhoneBo().setOlePhoneId(null);
1109 }
1110 }
1111 prepareOlePhoneForSave(newOlePatronDocument);
1112 for(OleEntityEmailBo oleEntityEmailBo : newOlePatronDocument.getOleEntityEmailBo()) {
1113 if(oleEntityEmailBo.getOleEmailBo() != null) {
1114 oleEntityEmailBo.getOleEmailBo().setOleEmailId(null);
1115 }
1116 }
1117 prepareOleEmailForSave(newOlePatronDocument);
1118 }
1119
1120 if(StringUtils.isNotBlank(newOlePatronDocument.getOlePatronId())){
1121 Map<String,String> notesMap=new HashMap<String,String>();
1122 notesMap.put("olePatronId", newOlePatronDocument.getOlePatronId());
1123 List<OlePatronNotes> olePatronNotesList = (List<OlePatronNotes>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronNotes.class,notesMap);
1124 if(CollectionUtils.isNotEmpty(olePatronNotesList)){
1125 Map<String,OlePatronNotes> patronNotesMap = new HashMap<>();
1126 for(OlePatronNotes olePatronNotes : olePatronNotesList){
1127 patronNotesMap.put(olePatronNotes.getPatronNoteId(),olePatronNotes);
1128 }
1129 if(CollectionUtils.isNotEmpty(newOlePatronDocument.getNotes())){
1130 for(OlePatronNotes olePatronNotes : newOlePatronDocument.getNotes()){
1131 if(patronNotesMap.containsKey(olePatronNotes.getPatronNoteId())){
1132 OlePatronNotes patronDbNote = patronNotesMap.get(olePatronNotes.getPatronNoteId());
1133 if(!patronDbNote.getPatronNoteTypeId().equals(olePatronNotes.getPatronNoteTypeId()) ||
1134 !patronDbNote.getPatronNoteText().equals(olePatronNotes.getPatronNoteText())){
1135 olePatronNotes.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1136 olePatronNotes.setNoteCreatedOrUpdatedDate(new Timestamp(System.currentTimeMillis()));
1137 }
1138 }
1139 }
1140 }
1141 }
1142 }
1143
1144 ModelAndView model = null;
1145 try {
1146 model = super.route(mainForm, result, request, response);
1147 } catch (Exception e) {
1148 return model;
1149 }
1150 return model;
1151 }
1152
1153
1154 @RequestMapping(params = "methodToCall=lostBarcode")
1155 public ModelAndView lostBarcode(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1156 HttpServletRequest request, HttpServletResponse response) {
1157
1158 LOG.debug(" Inside route method of patron maintenance controller ");
1159 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
1160 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
1161 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1162 if (StringUtils.isBlank(newOlePatronDocument.getBarcode()) || StringUtils.isEmpty(newOlePatronDocument.getBarcode())) {
1163 newOlePatronDocument.setBarcodeEditable(true);
1164 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REQUIRED, new String[]{"Barcode"});
1165 return getUIFModelAndView(mainForm);
1166 }
1167 newOlePatronDocument.setReinstated(false);
1168 boolean isBarcodeExistInOLE = false;
1169 Map<String, String> patronMap = new HashMap<String, String>();
1170 patronMap.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
1171 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
1172 if (newOlePatronDocument.getBarcode() != null && (!newOlePatronDocument.getBarcode().equalsIgnoreCase(""))) {
1173 Map<String, String> map = new HashMap<String, String>();
1174 map.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
1175 map.put("active", "N");
1176 List<OlePatronLostBarcode> olePatronLostBarcodes = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, map);
1177 if (olePatronLostBarcodes.size() > 0 && (!newOlePatronDocument.isSkipBarcodeValidation())) {
1178 isBarcodeExistInOLE = true;
1179 }
1180 if (patronDocument != null && patronDocument.getBarcode() != null && patronDocument.getBarcode().equalsIgnoreCase(newOlePatronDocument.getBarcode())) {
1181 isBarcodeExistInOLE = true;
1182 }
1183 }
1184 if (LOG.isDebugEnabled()){
1185 LOG.debug("Allow the patron to add barcode "+isBarcodeExistInOLE);
1186 }
1187 if (!isBarcodeExistInOLE) {
1188
1189 newOlePatronDocument.setBarcodeEditable(true);
1190 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_BARCODE_EXIST_LOST_SECTION);
1191 return getUIFModelAndView(mainForm);
1192 }
1193 for(OlePatronLostBarcode olePatronLostBarcode:newOlePatronDocument.getLostBarcodes()){
1194
1195 if(olePatronLostBarcode.getInvalidOrLostBarcodeNumber()!=null && olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(newOlePatronDocument.getBarcode())){
1196 if (!(patronDocument != null && patronDocument.getBarcode().equalsIgnoreCase(newOlePatronDocument.getBarcode()))) {
1197 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REQUIRED, new String[]{"Barcode"});
1198 return getUIFModelAndView(mainForm);
1199 }
1200 }
1201 }
1202 if (isBarcodeExistInOLE) {
1203 if (!newOlePatronDocument.isInvalidateBarcode()) {
1204 if (StringUtils.isBlank(newOlePatronDocument.getBarcode()) || StringUtils.isEmpty(newOlePatronDocument.getBarcode())) {
1205 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REQUIRED, new String[]{"Barcode"});
1206 return getUIFModelAndView(mainForm);
1207 }
1208 newOlePatronDocument.setBarcodeEditable(true);
1209 newOlePatronDocument.setLostDescription("");
1210 newOlePatronDocument.setInvalidateBarcode(true);
1211 return getUIFModelAndView(mainForm);
1212 }
1213 boolean isBarcodeExist = false;
1214 newOlePatronDocument.setBarcodeChanged(true);
1215 newOlePatronDocument.setInvalidateBarcode(false);
1216 String lostBarcode = newOlePatronDocument.getBarcode();
1217 OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
1218 olePatronLostBarcode.setInvalidOrLostBarcodeNumber(lostBarcode);
1219 olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
1220 olePatronLostBarcode.setRevertBarcode(true);
1221 if(StringUtils.isBlank(newOlePatronDocument.getLostOperatorId())) {
1222 olePatronLostBarcode.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1223 }else {
1224 olePatronLostBarcode.setOperatorId(newOlePatronDocument.getLostOperatorId());
1225 }
1226 olePatronLostBarcode.setDescription(newOlePatronDocument.getLostDescription());
1227 olePatronLostBarcode.setStatus(newOlePatronDocument.getLostStatus());
1228 List<OlePatronLostBarcode> lostBarcodes = newOlePatronDocument.getLostBarcodes();
1229 List<OlePatronLostBarcode> lostBarcodeList = new ArrayList<OlePatronLostBarcode>();
1230 if (!isBarcodeExist) {
1231 lostBarcodeList.add(olePatronLostBarcode);
1232 if (lostBarcodes.size() > 0) {
1233 for (OlePatronLostBarcode lostPatronBarcode : lostBarcodes) {
1234 lostPatronBarcode.setRevertBarcode(false);
1235 lostBarcodeList.add(lostPatronBarcode);
1236 }
1237 }
1238 newOlePatronDocument.setLostBarcodes(lostBarcodeList);
1239 }
1240 newOlePatronDocument.setReinstated(false);
1241 newOlePatronDocument.setBarcode(null);
1242 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ENTER_PATRON_BARCODE);
1243 }
1244 return getUIFModelAndView(mainForm);
1245 }
1246
1247 @RequestMapping(params = "methodToCall=reinstateBarcode")
1248 public ModelAndView reinstateBarcode(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1249 HttpServletRequest request, HttpServletResponse response) {
1250
1251 LOG.debug(" Inside route method of patron maintenance controller ");
1252 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
1253 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
1254 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1255 String oldBarcode=newOlePatronDocument.getBarcode();
1256 if (!newOlePatronDocument.isReinstateBarcode()) {
1257 newOlePatronDocument.setReinstateBarcode(true);
1258 if (oldBarcode != null && !oldBarcode.equalsIgnoreCase("")) {
1259 newOlePatronDocument.setBarcodeEditable(false);
1260 } else {
1261 newOlePatronDocument.setBarcodeEditable(true);
1262 }
1263 return getUIFModelAndView(mainForm);
1264 }
1265
1266
1267 boolean isBarcodeExistInOLE=false;
1268
1269 if (oldBarcode != null && !oldBarcode.equalsIgnoreCase("")) {
1270 Map<String, String> map = new HashMap<String, String>();
1271 map.put(OLEConstants.OlePatron.PATRON_LOST_BARCODE_FLD, newOlePatronDocument.getBarcode());
1272 List<OlePatronLostBarcode> olePatronLostBarcodes = (List<OlePatronLostBarcode>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronLostBarcode.class, map);
1273 map.clear();
1274 map.put("barcode",oldBarcode);
1275 List<OlePatronDocument> patronDocuments = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, map);
1276 if (olePatronLostBarcodes.size() > 0 || patronDocuments.size()>0) {
1277 isBarcodeExistInOLE=true;
1278 }
1279 if(!isBarcodeExistInOLE){
1280 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,OLEConstants.OlePatron.PATRON_BARCODE_DOES_NOT_EXIST_REINSTATE,new String[]{oldBarcode});
1281 }
1282 }
1283 OlePatronLostBarcode olePatronLostBarcodeHistory = new OlePatronLostBarcode();
1284 for (OlePatronLostBarcode olePatronLostBarcode : newOlePatronDocument.getLostBarcodes()) {
1285 if (olePatronLostBarcode.isActive()) {
1286 newOlePatronDocument.setBarcode(olePatronLostBarcode.getInvalidOrLostBarcodeNumber());
1287 olePatronLostBarcodeHistory.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1288 olePatronLostBarcodeHistory.setInvalidOrLostBarcodeNumber(newOlePatronDocument.getBarcode());
1289 olePatronLostBarcodeHistory.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
1290 olePatronLostBarcodeHistory.setRevertBarcode(true);
1291 olePatronLostBarcodeHistory.setDescription(newOlePatronDocument.getLostDescription());
1292 olePatronLostBarcodeHistory.setStatus(newOlePatronDocument.getLostStatus());
1293 }
1294
1295 }
1296 newOlePatronDocument.getLostBarcodes().add(olePatronLostBarcodeHistory);
1297
1298 OlePatronLostBarcode invalidBarcode = new OlePatronLostBarcode();
1299 invalidBarcode.setInvalidOrLostBarcodeNumber(oldBarcode);
1300 invalidBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
1301 invalidBarcode.setDescription(OLEConstants.OlePatron.NEWBARCODE_DESCRIPTION);
1302 invalidBarcode.setStatus(OLEConstants.OlePatron.NEWBARCODE_STATUS);
1303 invalidBarcode.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1304 newOlePatronDocument.getLostBarcodes().add(invalidBarcode);
1305
1306 boolean isOldBarcodeExist=false;
1307 for (OlePatronLostBarcode olePatronLostBarcode : newOlePatronDocument.getLostBarcodes()) {
1308 if (olePatronLostBarcode.getInvalidOrLostBarcodeNumber().equalsIgnoreCase(oldBarcode)) {
1309 isOldBarcodeExist=true;
1310 }
1311 }
1312 if (oldBarcode != null && !oldBarcode.equalsIgnoreCase("")) {
1313 if (!isOldBarcodeExist && isBarcodeExistInOLE) {
1314 OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
1315 olePatronLostBarcode.setInvalidOrLostBarcodeNumber(oldBarcode);
1316 olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Timestamp(getDateTimeService().getCurrentDate().getTime()));
1317 olePatronLostBarcode.setRevertBarcode(true);
1318 olePatronLostBarcode.setDescription(OLEConstants.OlePatron.NEWBARCODE_DESCRIPTION);
1319 olePatronLostBarcode.setStatus(OLEConstants.OlePatron.NEWBARCODE_STATUS);
1320 olePatronLostBarcode.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1321 newOlePatronDocument.getLostBarcodes().add(olePatronLostBarcode);
1322 }
1323 }
1324 newOlePatronDocument.setBarcodeEditable(false);
1325 newOlePatronDocument.setBarcodeChanged(true);
1326 newOlePatronDocument.setReinstated(true);
1327 newOlePatronDocument.setSkipBarcodeValidation(true);
1328 newOlePatronDocument.setReinstateBarcode(false);
1329 return getUIFModelAndView(mainForm);
1330 }
1331
1332 @RequestMapping(params = "methodToCall=refreshInvalidOrLostBarcodeSection")
1333 public ModelAndView refreshInvalidOrLostBarcodeSection(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1334 HttpServletRequest request, HttpServletResponse response) {
1335
1336 LOG.debug(" Inside route method of patron maintenance controller ");
1337 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
1338 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1339 for (OlePatronLostBarcode lostBarcode : newOlePatronDocument.getLostBarcodes()) {
1340 if (lostBarcode.getId() != null) {
1341 Map<String, String> map = new HashMap<String, String>();
1342 map.put(OLEConstants.OlePatron.PATRON_ID, lostBarcode.getId());
1343 OlePatronLostBarcode olePatronLostBarcode = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronLostBarcode.class, map);
1344 if (olePatronLostBarcode != null) {
1345 lostBarcode.setActive(olePatronLostBarcode.isActive());
1346 } else {
1347 lostBarcode.setActive(false);
1348 }
1349 }
1350 if(lostBarcode.getId() == null) {
1351 lostBarcode.setActive(false);
1352 }
1353 }
1354 return navigate(form, result, request, response);
1355 }
1356
1357 @RequestMapping(params = "methodToCall=uploadImage")
1358 public ModelAndView uploadImage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1359 HttpServletRequest request, HttpServletResponse response) {
1360 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
1361 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
1362 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1363 MultipartFile multipartFile = mainForm.getAttachmentFile();
1364 if (multipartFile == null) {
1365 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_WITHOUT_FILE);
1366 return getUIFModelAndView(mainForm);
1367 }
1368 String fileName = multipartFile.getOriginalFilename();
1369 if (validateFile(multipartFile.getOriginalFilename())) {
1370 try {
1371 byte[] fileContent = multipartFile.getBytes();
1372 BufferedImage patronImage = ImageIO.read(new ByteArrayInputStream(fileContent));
1373 if (patronImage.getWidth() >= 100 || patronImage.getHeight() >= 100) {
1374 BufferedImage resizedImage = new BufferedImage(100, 100, 1);
1375 Graphics2D g = resizedImage.createGraphics();
1376 g.drawImage(patronImage, 0, 0, 100, 100, null);
1377 g.dispose();
1378 ByteArrayOutputStream baos = new ByteArrayOutputStream();
1379 ImageIO.write(resizedImage, "jpg", baos);
1380 byte[] res = baos.toByteArray();
1381 imageInByte = baos.toByteArray();
1382 newOlePatronDocument.setPatronPhotograph(res);
1383 } else {
1384 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_SIZE);
1385 return getUIFModelAndView(mainForm);
1386 }
1387 } catch (Exception ex) {
1388 LOG.error("Exception while uploading image", ex);
1389 }
1390 } else if (fileName != null && fileName.isEmpty()) {
1391 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_WITHOUT_FILE);
1392 return getUIFModelAndView(mainForm);
1393 } else {
1394 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_FORMAT);
1395 return getUIFModelAndView(mainForm);
1396 }
1397
1398 return getUIFModelAndView(mainForm);
1399 }
1400
1401 @RequestMapping(params = "methodToCall=deleteImage")
1402 public ModelAndView deleteImage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1403 HttpServletRequest request, HttpServletResponse response) {
1404 MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
1405 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
1406 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1407 newOlePatronDocument.setPatronPhotograph(null);
1408 newOlePatronDocument.setDeleteImageFlag(true);
1409 return getUIFModelAndView(mainForm);
1410 }
1411
1412
1413
1414
1415
1416
1417
1418 public boolean validateFile(String inputFile) {
1419 return (inputFile.contains(".jpg") || inputFile.contains(".png") || inputFile.contains(".jpeg") || inputFile.contains(".gif") ? true : false);
1420 }
1421
1422 @RequestMapping(params = "methodToCall=getImage")
1423 public ModelAndView getImage(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
1424 HttpServletRequest request, HttpServletResponse response) {
1425 try {
1426 String inquiry = "false";
1427 if (request.getParameter("patronInquiryFlag") != null) {
1428 inquiry = request.getParameter("patronInquiryFlag");
1429 }
1430 String deleteImageFlag = request.getParameter("deleteImageFlag");
1431 if (inquiry.equalsIgnoreCase("false")) {
1432 String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
1433 if (patronId != null && !patronId.equals("")) {
1434 Map patronMap = new HashMap();
1435 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
1436 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
1437 byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
1438 if (patronPhoto != null && deleteImageFlag.equals("false")) {
1439 if (imageInByte == null || !patronPhoto.equals(imageInByte)) {
1440 response.setContentType("image/jpg");
1441 response.getOutputStream().write(patronPhoto);
1442 } else {
1443 response.setContentType("image/jpg");
1444 response.getOutputStream().write(imageInByte);
1445 }
1446 } else {
1447 response.setContentType("image/jpg");
1448 response.getOutputStream().write(imageInByte);
1449 }
1450 } else {
1451 if (imageInByte != null) {
1452 response.setContentType("image/jpg");
1453 response.getOutputStream().write(imageInByte);
1454 }
1455 }
1456 } else {
1457
1458 Map patronMap = new HashMap();
1459 String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
1460 if (patronId != null && !patronId.equals("")) {
1461 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
1462 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
1463 olePatronDocument.setDeleteImageFlag(false);
1464 byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
1465 if (patronPhoto != null) {
1466 response.setContentType("image/jpg");
1467 response.getOutputStream().write(patronPhoto);
1468 }
1469 }
1470 }
1471
1472 } catch (Exception ex) {
1473 LOG.error("Exception while getting image", ex);
1474 }
1475 return null;
1476 }
1477
1478 @RequestMapping(params = "methodToCall=getImageForLoan")
1479 public ModelAndView getImageForLoan(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
1480 HttpServletRequest request, HttpServletResponse response) {
1481 try {
1482 String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
1483 if (patronId != null && !patronId.equals("")) {
1484 Map patronMap = new HashMap();
1485 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
1486 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
1487 byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
1488 if (patronPhoto != null) {
1489 response.setContentType("image/jpg");
1490 response.getOutputStream().write(patronPhoto);
1491 }
1492 }
1493 } catch (Exception ex) {
1494 LOG.error("Exception while getting image for loan", ex);
1495 }
1496 return null;
1497 }
1498
1499 @RequestMapping(params = "methodToCall=refreshProgGroup")
1500 public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
1501 HttpServletRequest request, HttpServletResponse response) throws Exception {
1502 MaintenanceDocument document = form.getDocument();
1503 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1504 if (newOlePatronDocument.getOleLoanDocuments() != null) {
1505 for (OleLoanDocument loanDocument : newOlePatronDocument.getOleLoanDocuments()) {
1506 if(loanDocument.isMissingPieceFlag() && loanDocument.getMissingPiecesCount()==null || (loanDocument.getMissingPiecesCount()!=null && loanDocument.getMissingPiecesCount().equalsIgnoreCase(""))){
1507 loanDocument.setNoOfMissingPiecesEditable(true);
1508 } else {
1509 loanDocument.setNoOfMissingPiecesEditable(false);
1510 }
1511
1512 if(loanDocument.isMissingPieceFlag() && loanDocument.getItemNumberOfPieces()==null || (loanDocument.getItemNumberOfPieces()!=null && loanDocument.getItemNumberOfPieces().toString().equalsIgnoreCase(""))){
1513 loanDocument.setNoOfPiecesEditable(true);
1514 } else {
1515 loanDocument.setNoOfPiecesEditable(false);
1516 }
1517 }
1518 }
1519
1520 return getUIFModelAndView(form);
1521 }
1522
1523
1524
1525
1526
1527
1528 private LoanProcessor getLoanProcessor() {
1529 if (loanProcessor == null) {
1530 loanProcessor = new LoanProcessor();
1531 }
1532 return loanProcessor;
1533 }
1534
1535 private void prepareOleAddressForSave(OlePatronDocument newOlePatronDocument) {
1536 if (newOlePatronDocument.getOleEntityAddressBo() != null) {
1537 newOlePatronDocument.getOleAddresses().clear();
1538 int i=0;
1539 for (OleEntityAddressBo oleEntityAddressBo : newOlePatronDocument.getOleEntityAddressBo()) {
1540 if (oleEntityAddressBo.getEntityAddressBo().getId() == null) {
1541 if (newOlePatronDocument.getEntity() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos().size() > 0) {
1542 EntityTypeContactInfoBo entityTypeContactInfo = newOlePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1543 if (entityTypeContactInfo.getAddresses() != null && entityTypeContactInfo.getAddresses().size() > 0 && entityTypeContactInfo.getAddresses().size()>i) {
1544 if(oleEntityAddressBo.getEntityAddressBo()!=null){
1545 entityTypeContactInfo.getAddresses().get(i).setDefaultValue(oleEntityAddressBo.getEntityAddressBo().isDefaultValue());
1546 entityTypeContactInfo.getAddresses().get(i).setActive(oleEntityAddressBo.getEntityAddressBo().isActive());
1547 }
1548 oleEntityAddressBo.setEntityAddressBo(entityTypeContactInfo.getAddresses().get(i));
1549 }
1550 }
1551 }
1552 i++;
1553 }
1554 for (OleEntityAddressBo oleEntityAddressBo : newOlePatronDocument.getOleEntityAddressBo()) {
1555 if (oleEntityAddressBo.getEntityAddressBo() != null && oleEntityAddressBo.getEntityAddressBo().getId() != null) {
1556
1557 oleEntityAddressBo.getOleAddressBo().setOleAddressId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_ADD_S").toString());
1558
1559 oleEntityAddressBo.getOleAddressBo().setId(oleEntityAddressBo.getEntityAddressBo().getId());
1560 oleEntityAddressBo.getOleAddressBo().setOlePatronId(newOlePatronDocument.getOlePatronId());
1561 oleEntityAddressBo.getOleAddressBo().setVersionNumber(null);
1562 oleEntityAddressBo.getOleAddressBo().setObjectId(null);
1563 oleEntityAddressBo.getOleAddressBo().setAddressSource(oleEntityAddressBo.getOleAddressBo().getAddressSource());
1564 oleEntityAddressBo.getOleAddressBo().setAddressValidFrom(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom());
1565 oleEntityAddressBo.getOleAddressBo().setAddressValidTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo());
1566 oleEntityAddressBo.getOleAddressBo().setAddressVerified(oleEntityAddressBo.getOleAddressBo().isAddressVerified());
1567 }
1568 OleAddressBo oleAddressBo = (OleAddressBo) ObjectUtils.deepCopy(oleEntityAddressBo.getOleAddressBo());
1569 EntityAddressBo entityAddressBo = (EntityAddressBo) ObjectUtils.deepCopy(oleEntityAddressBo.getEntityAddressBo());
1570 oleEntityAddressBo.getOleAddressBo().setEntityAddress(entityAddressBo);
1571 newOlePatronDocument.getOleAddresses().add(oleAddressBo);
1572 }
1573 }
1574 }
1575
1576 private void prepareOlePhoneForSave(OlePatronDocument newOlePatronDocument) {
1577 if (newOlePatronDocument.getOleEntityPhoneBo() != null) {
1578 newOlePatronDocument.getOlePhones().clear();
1579 int i=0;
1580 for (OleEntityPhoneBo oleEntityPhoneBo : newOlePatronDocument.getOleEntityPhoneBo()) {
1581 if (oleEntityPhoneBo.getEntityPhoneBo().getId() == null) {
1582 if (newOlePatronDocument.getEntity() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos().size() > 0) {
1583 EntityTypeContactInfoBo entityTypeContactInfo = newOlePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1584 if (CollectionUtils.isNotEmpty(entityTypeContactInfo.getPhoneNumbers()) && entityTypeContactInfo.getPhoneNumbers().size()>i) {
1585 if(oleEntityPhoneBo.getEntityPhoneBo()!=null){
1586 entityTypeContactInfo.getPhoneNumbers().get(i).setDefaultValue(oleEntityPhoneBo.getEntityPhoneBo().isDefaultValue());
1587 entityTypeContactInfo.getPhoneNumbers().get(i).setActive(oleEntityPhoneBo.getEntityPhoneBo().isActive());
1588 }
1589 oleEntityPhoneBo.setEntityPhoneBo(entityTypeContactInfo.getPhoneNumbers().get(i));
1590 }
1591 }
1592 }
1593 i++;
1594 }
1595 for (OleEntityPhoneBo oleEntityPhoneBo : newOlePatronDocument.getOleEntityPhoneBo()) {
1596 if (oleEntityPhoneBo.getEntityPhoneBo() != null && oleEntityPhoneBo.getEntityPhoneBo().getId() != null) {
1597
1598 oleEntityPhoneBo.getOlePhoneBo().setOlePhoneId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_PHONE_S").toString());
1599
1600 oleEntityPhoneBo.getOlePhoneBo().setId(oleEntityPhoneBo.getEntityPhoneBo().getId());
1601 oleEntityPhoneBo.getOlePhoneBo().setOlePatronId(newOlePatronDocument.getOlePatronId());
1602 oleEntityPhoneBo.getOlePhoneBo().setVersionNumber(null);
1603 oleEntityPhoneBo.getOlePhoneBo().setObjectId(null);
1604 oleEntityPhoneBo.getOlePhoneBo().setPhoneSource(oleEntityPhoneBo.getOlePhoneBo().getPhoneSource());
1605 }
1606 OlePhoneBo olePhoneBo = (OlePhoneBo) ObjectUtils.deepCopy(oleEntityPhoneBo.getOlePhoneBo());
1607 EntityPhoneBo entityPhoneBo = (EntityPhoneBo) ObjectUtils.deepCopy(oleEntityPhoneBo.getEntityPhoneBo());
1608 oleEntityPhoneBo.getOlePhoneBo().setEntityPhoneBo(entityPhoneBo);
1609 newOlePatronDocument.getOlePhones().add(olePhoneBo);
1610 }
1611 }
1612 }
1613
1614 private void prepareOleEmailForSave(OlePatronDocument newOlePatronDocument) {
1615 if (newOlePatronDocument.getOleEntityEmailBo() != null) {
1616 newOlePatronDocument.getOleEmails().clear();
1617 int i=0;
1618 for (OleEntityEmailBo oleEntityEmailBo : newOlePatronDocument.getOleEntityEmailBo()) {
1619 if (oleEntityEmailBo.getEntityEmailBo().getId() == null) {
1620 if (newOlePatronDocument.getEntity() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos() != null && newOlePatronDocument.getEntity().getEntityTypeContactInfos().size() > 0) {
1621 EntityTypeContactInfoBo entityTypeContactInfo = newOlePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1622 if (CollectionUtils.isNotEmpty(entityTypeContactInfo.getEmailAddresses()) && entityTypeContactInfo.getEmailAddresses().size()>i) {
1623 if(oleEntityEmailBo.getEntityEmailBo()!=null){
1624 entityTypeContactInfo.getEmailAddresses().get(i).setDefaultValue(oleEntityEmailBo.getEntityEmailBo().isDefaultValue());
1625 entityTypeContactInfo.getEmailAddresses().get(i).setActive(oleEntityEmailBo.getEntityEmailBo().isActive());
1626 }
1627 oleEntityEmailBo.setEntityEmailBo(entityTypeContactInfo.getEmailAddresses().get(i));
1628 }
1629 }
1630 }
1631 i++;
1632 }
1633 for (OleEntityEmailBo oleEntityEmailBo: newOlePatronDocument.getOleEntityEmailBo()) {
1634 if (oleEntityEmailBo.getEntityEmailBo() != null && oleEntityEmailBo.getEntityEmailBo().getId() != null) {
1635
1636 oleEntityEmailBo.getOleEmailBo().setOleEmailId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_EMAIL_S").toString());
1637
1638 oleEntityEmailBo.getOleEmailBo().setId(oleEntityEmailBo.getEntityEmailBo().getId());
1639 oleEntityEmailBo.getOleEmailBo().setOlePatronId(newOlePatronDocument.getOlePatronId());
1640 oleEntityEmailBo.getOleEmailBo().setVersionNumber(null);
1641 oleEntityEmailBo.getOleEmailBo().setObjectId(null);
1642 oleEntityEmailBo.getOleEmailBo().setEmailSource(oleEntityEmailBo.getOleEmailBo().getEmailSource());
1643 }
1644 OleEmailBo oleEmailBo = (OleEmailBo) ObjectUtils.deepCopy(oleEntityEmailBo.getOleEmailBo());
1645 EntityEmailBo entityEmailBo = (EntityEmailBo) ObjectUtils.deepCopy(oleEntityEmailBo.getEntityEmailBo());
1646 oleEntityEmailBo.getOleEmailBo().setEntityEmailBo(entityEmailBo);
1647 newOlePatronDocument.getOleEmails().add(oleEmailBo);
1648 }
1649 }
1650 }
1651
1652 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteAddress")
1653 public ModelAndView deleteAddress(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1654 HttpServletRequest request, HttpServletResponse response) {
1655 LOG.debug("Initialized addLine method");
1656 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1657 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1658 MaintenanceDocument document = form.getDocument();
1659 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1660 newOlePatronDocument.getDeletedOleEntityAddressBo().add(newOlePatronDocument.getOleEntityAddressBo().get(Integer.parseInt(selectedLineIndex)));
1661 return deleteLine(uifForm, result, request, response);
1662 }
1663
1664 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deletePhoneNumber")
1665 public ModelAndView deletePhoneNumber(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1666 HttpServletRequest request, HttpServletResponse response) {
1667 LOG.debug("Initialized addLine method");
1668 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1669 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1670 MaintenanceDocument document = form.getDocument();
1671 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1672 newOlePatronDocument.getDeletedOleEntityPhoneBo().add(newOlePatronDocument.getOleEntityPhoneBo().get(Integer.parseInt(selectedLineIndex)));
1673 return deleteLine(uifForm, result, request, response);
1674
1675 }
1676
1677 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteEmailAddress")
1678 public ModelAndView deleteEmailAddress(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1679 HttpServletRequest request, HttpServletResponse response) {
1680 LOG.debug("Initialized addLine method");
1681 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1682 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1683 MaintenanceDocument document = form.getDocument();
1684 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1685 newOlePatronDocument.getDeletedOleEntityEmailBo().add(newOlePatronDocument.getOleEntityEmailBo().get(Integer.parseInt(selectedLineIndex)));
1686 return deleteLine(uifForm, result, request, response);
1687
1688 }
1689
1690 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteProxyPatron")
1691 public ModelAndView deleteProxyPatron(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1692 HttpServletRequest request, HttpServletResponse response) {
1693 LOG.debug("Initialized addLine method");
1694 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1695 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1696 MaintenanceDocument document = form.getDocument();
1697 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1698 newOlePatronDocument.getDeletedOleProxyPatronDocuments().add(newOlePatronDocument.getOleProxyPatronDocuments().get(Integer.parseInt(selectedLineIndex)));
1699 return deleteLine(uifForm, result, request, response);
1700
1701 }
1702
1703 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteNotes")
1704 public ModelAndView deleteNotes(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1705 HttpServletRequest request, HttpServletResponse response) {
1706 LOG.debug("Initialized addLine method");
1707 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1708 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1709 MaintenanceDocument document = form.getDocument();
1710 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1711 newOlePatronDocument.getDeletedNotes().add(newOlePatronDocument.getNotes().get(Integer.parseInt(selectedLineIndex)));
1712 return deleteLine(uifForm, result, request, response);
1713
1714 }
1715
1716 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteOlePatronLocalIds")
1717 public ModelAndView deleteOlePatronLocalIds(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1718 HttpServletRequest request, HttpServletResponse response) {
1719 LOG.debug("Initialized addLine method");
1720 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1721 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1722 MaintenanceDocument document = form.getDocument();
1723 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1724 newOlePatronDocument.getDeletedOlePatronLocalIds().add(newOlePatronDocument.getOlePatronLocalIds().get(Integer.parseInt(selectedLineIndex)));
1725 return deleteLine(uifForm, result, request, response);
1726
1727 }
1728
1729
1730
1731 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deletePatronAffiliations")
1732 public ModelAndView deletePatronAffiliations(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1733 HttpServletRequest request, HttpServletResponse response) {
1734 LOG.debug("Initialized addLine method");
1735 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1736 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1737 MaintenanceDocument document = form.getDocument();
1738 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1739 newOlePatronDocument.getDeletedPatronAffiliations().add(newOlePatronDocument.getPatronAffiliations().get(Integer.parseInt(selectedLineIndex)));
1740 newOlePatronDocument.getDeletedEmployments().addAll(newOlePatronDocument.getPatronAffiliations().get(Integer.parseInt(selectedLineIndex)).getEmployments());
1741
1742 return deleteLine(uifForm, result, request, response);
1743 }
1744
1745 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteEmploymentBo")
1746 public ModelAndView deleteEmploymentBo(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1747 HttpServletRequest request, HttpServletResponse response) {
1748 LOG.debug("Initialized addLine method");
1749 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1750 Map<String,String> actionParameters = form.getActionParameters();
1751 String subCollectionIndex = actionParameters.get(UifParameters.SELECTED_LINE_INDEX);
1752 String mainCollectionIndex= StringUtils.substringBefore(StringUtils.substringAfter(actionParameters.get(UifParameters.SELLECTED_COLLECTION_PATH),"["),"]");
1753 MaintenanceDocument document = form.getDocument();
1754 OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
1755 EntityEmploymentBo entityEmploymentBo=newOlePatronDocument.getPatronAffiliations().get(Integer.parseInt(mainCollectionIndex)).getEmployments().get(Integer.parseInt(subCollectionIndex));
1756 if(entityEmploymentBo!=null){
1757 newOlePatronDocument.getDeletedEmployments().add(entityEmploymentBo);
1758 newOlePatronDocument.getPatronAffiliations().get(Integer.parseInt(mainCollectionIndex)).getEmployments().remove(Integer.parseInt(subCollectionIndex));
1759 return getUIFModelAndView(uifForm);
1760 }else{
1761 newOlePatronDocument.getDeletedEmployments().add(entityEmploymentBo);
1762 return deleteLine(uifForm, result, request, response);
1763 }
1764 }
1765
1766 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=showPatronLoanedItem")
1767 public ModelAndView showPatronLoanedItem(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1768 HttpServletRequest request, HttpServletResponse response) {
1769 LOG.debug("Patron View : showing Patron Loaned Records");
1770 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1771 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1772 try {
1773 olePatronDocument.setOleLoanDocuments(getOleLoanDocumentsFromSolrBuilder().getPatronLoanedItemBySolr
1774 (olePatronDocument.getOlePatronId(), null));
1775 if(CollectionUtils.isNotEmpty(olePatronDocument.getOleLoanDocuments())) {
1776 for(OleLoanDocument oleLoanDocument : olePatronDocument.getOleLoanDocuments()) {
1777 if(StringUtils.isNotEmpty(oleLoanDocument.getRealPatronName())) {
1778 Map patronMap = new HashMap();
1779 patronMap.put(OLEConstants.OlePatron.PATRON_ID, oleLoanDocument.getRealPatronName());
1780 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
1781 if(patronDocument != null){
1782 patronDocument = OLEDeliverService.populatePatronName(patronDocument);
1783 oleLoanDocument.setRealPatronName(patronDocument.getPatronName());
1784 oleLoanDocument.setProxyPatronBarcode(patronDocument.getBarcode());
1785 oleLoanDocument.setProxyPatronBarcodeUrl(OLEConstants.ASSIGN_INQUIRY_PATRON_ID + patronDocument.getOlePatronId() + OLEConstants.ASSIGN_PATRON_INQUIRY);
1786 }
1787 }
1788 }
1789 }
1790 } catch (Exception e) {
1791 LOG.error("While fetching loan records error occured" + e);
1792 }
1793 olePatronDocument.setShowLoanedRecords(true);
1794 return getUIFModelAndView(form);
1795 }
1796
1797 private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
1798 if (null == oleLoanDocumentsFromSolrBuilder) {
1799 oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
1800 }
1801 return oleLoanDocumentsFromSolrBuilder;
1802 }
1803
1804 public void setOleLoanDocumentsFromSolrBuilder(OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder) {
1805 this.oleLoanDocumentsFromSolrBuilder = oleLoanDocumentsFromSolrBuilder;
1806 }
1807
1808 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=hidePatronLoanedItem")
1809 public ModelAndView hidePatronLoanedItem(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1810 HttpServletRequest request, HttpServletResponse response) {
1811 LOG.debug("Patron View : Hiding Patron Loaned Records");
1812 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1813 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1814 olePatronDocument.setShowLoanedRecords(false);
1815 return getUIFModelAndView(form);
1816 }
1817
1818 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=showPatronRequestedRecords")
1819 public ModelAndView showPatronRequestedRecords(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1820 HttpServletRequest request, HttpServletResponse response) {
1821 LOG.debug("Patron View : showing Patron Requested Records");
1822 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1823 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1824 try {
1825 OleDeliverRequestDocumentHelperServiceImpl requestService = new OleDeliverRequestDocumentHelperServiceImpl();
1826 List<OleDeliverRequestBo> oleDeliverRequestBoList = olePatronDocument.getOleDeliverRequestBos();
1827 if (oleDeliverRequestBoList.size() > 0) {
1828 for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1829 OleItemSearch oleItemSearch = requestService.getItemDetailsForPatron(oleDeliverRequestBoList.get(i).getItemUuid());
1830 if (oleItemSearch != null && oleItemSearch.getItemBarCode() != null) {
1831 oleDeliverRequestBoList.get(i).setTitle(oleItemSearch.getTitle());
1832 oleDeliverRequestBoList.get(i).setCallNumber(oleItemSearch.getCallNumber());
1833 }
1834 }
1835 }
1836 olePatronDocument.setOleDeliverRequestBos(loanProcessor.getPatronRequestRecords(olePatronDocument.getOlePatronId()));
1837 } catch (Exception e) {
1838 LOG.error("While fetching Patron Requested Records error occured" + e);
1839 }
1840 olePatronDocument.setShowRequestedItems(true);
1841 return getUIFModelAndView(form);
1842 }
1843
1844 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=hidePatronRequestedRecords")
1845 public ModelAndView hidePatronRequestedRecords(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1846 HttpServletRequest request, HttpServletResponse response) {
1847 LOG.debug("Patron View : Hiding Patron Loaned Records");
1848 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1849 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1850 olePatronDocument.setOleDeliverRequestBos(new ArrayList<OleDeliverRequestBo>());
1851 olePatronDocument.setShowRequestedItems(false);
1852 return getUIFModelAndView(form);
1853 }
1854
1855 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=showTemporaryCirculationHistoryRecords")
1856 public ModelAndView showTemporaryCirculationHistoryRecords(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1857 HttpServletRequest request, HttpServletResponse response) {
1858 LOG.debug("Patron View : showing Patron TemporaryCirculationHistory Records");
1859 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1860 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1861 try {
1862 olePatronDocument.setOleTemporaryCirculationHistoryRecords(getOleLoanDocumentsFromSolrBuilder().getPatronTemporaryCirculationHistoryRecords(olePatronDocument.getOlePatronId()));
1863 } catch (Exception e) {
1864 LOG.error("While fetching Patron TemporaryCirculationHistory Records error occured" + e);
1865 }
1866
1867 olePatronDocument.setShowTemporaryCirculationHistoryRecords(true);
1868 return getUIFModelAndView(form);
1869 }
1870 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=hideTemporaryCirculationHistoryRecords")
1871 public ModelAndView hideTemporaryCirculationHistoryRecords(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1872 HttpServletRequest request, HttpServletResponse response) {
1873 LOG.debug("Patron View : Hiding Patron Loaned Records");
1874 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1875 OlePatronDocument olePatronDocument=(OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1876 olePatronDocument.setOleTemporaryCirculationHistoryRecords(new ArrayList<OleTemporaryCirculationHistory>());
1877 olePatronDocument.setShowTemporaryCirculationHistoryRecords(false);
1878 return getUIFModelAndView(form);
1879 }
1880
1881 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshLoanedItemSection")
1882 public ModelAndView refreshLoanedItemSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1883 HttpServletRequest request, HttpServletResponse response) {
1884 LOG.debug("Patron View : Hiding Patron Loaned Records");
1885 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
1886 return getUIFModelAndView(form);
1887 }
1888
1889 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProxyPatron")
1890 public ModelAndView refreshProxyPatron(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1891 HttpServletRequest request, HttpServletResponse response) throws Exception {
1892
1893 if ((uifForm instanceof OlePatronMaintenanceDocumentForm)
1894 && !((OlePatronMaintenanceDocumentForm) uifForm).isFilterProxySection()) {
1895
1896 OlePatronMaintenanceDocumentForm form = (OlePatronMaintenanceDocumentForm) uifForm;
1897 OlePatronDocument olePatron =
1898 (OlePatronDocument)form.getDocument().getNewMaintainableObject().getDataObject();
1899
1900 List<OleProxyPatronDocument> oleProxyPatronDocuments = olePatron.getOleProxyPatronDocuments();
1901 List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
1902 ProcessLogger.trace("patron:proxy:begin:"
1903 + oleProxyPatronDocuments.size());
1904 if (oleProxyPatronDocuments.size() > 0) {
1905 for (Iterator<OleProxyPatronDocument> proxyPatronIterator = oleProxyPatronDocuments.iterator(); proxyPatronIterator.hasNext(); ) {
1906 OleProxyPatronDocument oleProxyPatronDocument = proxyPatronIterator.next();
1907 Map map = new HashMap();
1908 map.put(OLEConstants.OlePatron.PATRON_ID, oleProxyPatronDocument.getProxyPatronId());
1909 ProcessLogger.trace("patron:proxy:"
1910 + oleProxyPatronDocument.getProxyPatronId());
1911 OlePatronDocument olePatronDocument = getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, map);
1912 oleProxyPatronDocument.setProxyPatronBarcode(olePatronDocument.getBarcode());
1913 oleProxyPatronDocument.setProxyPatronFirstName(olePatronDocument.getEntity().getNames().get(0).getFirstName());
1914 oleProxyPatronDocument.setProxyPatronLastName(olePatronDocument.getEntity().getNames().get(0).getLastName());
1915 proxyPatronDocumentList.add(oleProxyPatronDocument);
1916 }
1917 olePatron.setOleProxyPatronDocuments(proxyPatronDocumentList);
1918 ProcessLogger.trace("patron:proxy:end");
1919 }
1920 }
1921
1922 return super.refresh(uifForm, result, request, response);
1923 }
1924
1925 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addNotes")
1926 public ModelAndView addNotes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1927 HttpServletRequest request, HttpServletResponse response) {
1928 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
1929 MaintenanceDocument maintenanceDocument = maintenanceForm.getDocument();
1930 String selectedCollectionPath = maintenanceForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1931 CollectionGroup collectionGroup = maintenanceForm.getPostedView().getViewIndex().getCollectionGroupByPath(
1932 selectedCollectionPath);
1933 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
1934 Object eventObject = ObjectPropertyUtils.getPropertyValue(maintenanceForm, addLinePath);
1935 OlePatronNotes olePatronNotes = (OlePatronNotes) eventObject;
1936 olePatronNotes.setOperatorId(GlobalVariables.getUserSession().getPrincipalId());
1937 olePatronNotes.setNoteCreatedOrUpdatedDate(new Timestamp(System.currentTimeMillis()));
1938 return super.addLine(form, result, request, response);
1939 }
1940
1941
1942 }