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