View Javadoc

1   package org.kuali.ole.patron.controller;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.patron.bo.*;
6   import org.kuali.ole.service.OlePatronHelperService;
7   import org.kuali.ole.service.OlePatronHelperServiceImpl;
8   import org.kuali.ole.service.OlePatronMaintenanceDocumentServiceImpl;
9   import org.kuali.ole.service.OlePatronService;
10  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
11  import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
12  import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
13  import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
14  import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
15  import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
16  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
17  import org.kuali.rice.krad.maintenance.MaintenanceUtils;
18  import org.kuali.rice.krad.service.KRADServiceLocator;
19  import org.kuali.rice.krad.service.MaintenanceDocumentService;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.util.KRADConstants;
22  import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
23  import org.kuali.rice.krad.web.form.DocumentFormBase;
24  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
25  import org.springframework.stereotype.Controller;
26  import org.springframework.validation.BindingResult;
27  import org.springframework.web.bind.annotation.ModelAttribute;
28  import org.springframework.web.bind.annotation.RequestMapping;
29  import org.springframework.web.bind.annotation.RequestMethod;
30  import org.springframework.web.multipart.MultipartFile;
31  import org.springframework.web.servlet.ModelAndView;
32  
33  import javax.imageio.ImageIO;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  import java.awt.*;
37  import java.awt.image.BufferedImage;
38  import java.io.ByteArrayInputStream;
39  import java.io.ByteArrayOutputStream;
40  import java.text.SimpleDateFormat;
41  import java.util.*;
42  import java.util.List;
43  
44  /**
45   * .OlePatronMaintenanceDocumentController invokes MaintenanceDocumentController and returns instance of MaintenanceDocumentService.
46   */
47  @Controller
48  @RequestMapping(value = "/patronMaintenance")
49  public class OlePatronMaintenanceDocumentController extends MaintenanceDocumentController {
50  
51      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronMaintenanceDocumentController.class);
52      private OlePatronService olePatronService;
53      private OlePatronHelperService olePatronHelperService = new OlePatronHelperServiceImpl();
54      private byte[] imageInByte;
55  
56      public OlePatronService getOlePatronService() {
57          if (olePatronService != null) {
58              olePatronService = GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_SERVICE);
59          }
60          return olePatronService;
61      }
62  
63      /**
64       * This method returns the instance of olePatronMaintenanceDocumentService
65       * @return olePatronMaintenanceDocumentService(MaintenanceDocumentService)
66       */
67      @Override
68      protected MaintenanceDocumentService getMaintenanceDocumentService() {
69          return GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_MAINTENANCE_DOC_SERVICE);
70      }
71  
72      /**
73       * Use to create a link delete in the lookup result action field which will use to delete patron record..
74       * @param form
75       * @param result
76       * @param request
77       * @param response
78       * @return ModelAndView
79       * @throws Exception
80       */
81      @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
82      public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
83                                            HttpServletRequest request, HttpServletResponse response) throws Exception {
84          LOG.debug(" Inside maintenanceDelete ");
85          setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_DELETE);
86          return getUIFModelAndView(form);
87      }
88  
89      /**
90       * To delete the whole patron document.
91       * @param form
92       * @param result
93       * @param request
94       * @param response
95       * @return Close the document
96       * @throws Exception
97       */
98      @RequestMapping(params = "methodToCall=" + "deleteDocument")
99      public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
100                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
101 
102         LOG.debug(" Inside deleteDocument ");
103         MaintenanceDocument document = form.getDocument();
104         OlePatronDocument olePatronDocument = new OlePatronDocument();
105         try {
106             if (document.getDocumentDataObject() != null) {
107                 olePatronDocument = (OlePatronDocument) document.getDocumentDataObject();
108                 if (olePatronDocument != null && olePatronDocument.getOlePatronId() != null) {
109                     boolean deletePatronDetail = olePatronHelperService.deletePatron(olePatronDocument);
110                     if (deletePatronDetail) {
111                         return close(form, result, request, response);
112                     } else {
113                         GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_HAS_LOAN);
114                         return getUIFModelAndView(form);
115                     }
116                 } else {
117                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
118                     return getUIFModelAndView(form);
119                 }
120             }
121         } catch (Exception ex) {
122             LOG.error(ex.getMessage());
123         }
124         return close(form, result, request, response);
125     }
126 
127 
128     /**
129      * This method populates confirmation to delete the document.
130      *
131      * @param form
132      * @param request
133      * @param maintenanceAction
134      */
135     protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) {
136         LOG.debug(" Inside setupMaintenanceForDelete ");
137         MaintenanceDocument document = form.getDocument();
138         if (document == null) {
139             document = getMaintenanceDocumentService()
140                     .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
141                             maintenanceAction);
142 
143             form.setDocument(document);
144             form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
145         }
146 
147         form.setMaintenanceAction(maintenanceAction);
148         OlePatronMaintenanceDocumentServiceImpl olePatronMaintenanceDocumentServicec = (OlePatronMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
149         olePatronMaintenanceDocumentServicec.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
150         MaintenanceUtils.checkForLockingDocument(document, false);
151     }
152 
153     /**
154      * To submit or route the patron maintenance document
155      * @param form document form base containing the document instance that will be routed
156      * @return ModelAndView
157      */
158     @Override
159     @RequestMapping(params = "methodToCall=route")
160     public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
161                               HttpServletRequest request, HttpServletResponse response){
162 
163         LOG.debug(" Inside route method of patron maintenance controller ");
164         ModelAndView modelAndView;
165         MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
166         MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
167 
168         SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
169         OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
170         List<OleProxyPatronDocument> oleProxyPatronDocumentList = newOlePatronDocument.getOleProxyPatronDocuments();
171         List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
172         if (oleProxyPatronDocumentList.size() > 0) {
173             for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocumentList) {
174                 Map<String, String> proxyMap = new HashMap<String, String>();
175                 proxyMap.put(OLEConstants.OlePatron.PATRON_ID, oleProxyPatronDocument.getProxyPatronId());
176                 OlePatronDocument tempDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, proxyMap);
177                 if (tempDocument != null) {
178                     oleProxyPatronDocument.setProxyPatronBarcode(tempDocument.getBarcode());
179                     oleProxyPatronDocument.setProxyPatronFirstName(tempDocument.getEntity().getNames().get(0).getFirstName());
180                     oleProxyPatronDocument.setProxyPatronLastName(tempDocument.getEntity().getNames().get(0).getLastName());
181                     proxyPatronDocumentList.add(oleProxyPatronDocument);
182                 }
183             }
184             newOlePatronDocument.setOleProxyPatronDocuments(proxyPatronDocumentList);
185         }
186 
187         List<OleProxyPatronDocument> proxyPatron = newOlePatronDocument.getOleProxyPatronDocuments();
188         String patronId = "";
189         Date proxyActDate = null;
190         Date proxyExpDate = null;
191 
192 
193         if (proxyPatron.size() > 0) {
194             for (OleProxyPatronDocument proxy : proxyPatron) {
195                 patronId = proxy.getProxyPatronId();
196                 proxyActDate = proxy.getProxyPatronActivationDate();
197                 proxyExpDate = proxy.getProxyPatronExpirationDate();
198                 Map<String, String> patronMap = new HashMap<String, String>();
199                 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
200                 OlePatronDocument patronDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
201                 if (patronDocument != null) {
202                     Date patronExpDate = patronDocument.getExpirationDate();
203                     Date patronActDate = patronDocument.getActivationDate();
204                     if (proxyActDate != null) {
205                         if (patronActDate != null && fmt.format(patronActDate).compareTo(fmt.format(proxyActDate)) > 0) {
206                             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_ACTIVATION_DATE);
207                             return getUIFModelAndView(mainForm);
208                         }
209                     }
210                     if (proxyExpDate != null) {
211                         if (patronExpDate != null) {
212                             if (fmt.format(proxyExpDate).compareTo(fmt.format(patronExpDate)) > 0) {
213                                 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_EXPIRATION_DATE);
214                                 return getUIFModelAndView(mainForm);
215                             }
216                         }
217                     }
218                 }
219                 boolean lostBarcodeCheck = olePatronHelperService.CheckBarcodeAndLostBarcode(newOlePatronDocument);
220                 if(lostBarcodeCheck) {
221                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BARCODE_INVALID);
222                     return getUIFModelAndView(mainForm);
223                 }
224                 boolean isBorrowerTypeActive = olePatronHelperService.isBorrowerTypeActive(newOlePatronDocument);
225                 if(!isBorrowerTypeActive) {
226                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BORROWER_TYPE_INACTIVE);
227                     return getUIFModelAndView(mainForm);
228                 }
229                 if (patronId != null && newOlePatronDocument.getOlePatronId() != null && newOlePatronDocument.getOlePatronId().equals(patronId)) {
230                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ID);
231                     return getUIFModelAndView(mainForm);
232                 } else if (proxyActDate != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(proxyActDate)) > 0) {
233                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ACTIVATION_DATE);
234                     return getUIFModelAndView(mainForm);
235                 } else {
236                     if (proxyExpDate != null) {
237                         if (proxyActDate != null) {
238                             if ((fmt.format(proxyActDate).compareTo(fmt.format(proxyExpDate)) >= 0)) {
239                                 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
240                                 return getUIFModelAndView(mainForm);
241                             }
242                         } else if (fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(proxyExpDate)) > 0) {
243                             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
244                             return getUIFModelAndView(mainForm);
245                         }
246                     }
247                 }
248             }
249         }
250         if (newOlePatronDocument.isGeneralBlock() && (newOlePatronDocument.getGeneralBlockNotes() == null || newOlePatronDocument.getGeneralBlockNotes().equals(""))) {
251             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_GENERAL_BLOCK_NOTES, OLEConstants.OlePatron.PATRON_GENERAL_BLOCK_NOTES);
252             return getUIFModelAndView(mainForm);
253         } else if (newOlePatronDocument.getActivationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(newOlePatronDocument.getActivationDate())) > 0) {
254             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_ACTIVATION_DATE);
255             return getUIFModelAndView(mainForm);
256         } 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)) {
257             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_EXPIRATION_DATE);
258             return getUIFModelAndView(mainForm);
259         } else if (newOlePatronDocument.getOlePatronId() != null) {
260             Map<String, String> tempId = new HashMap<String, String>();
261             tempId.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
262             OlePatronDocument tempDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, tempId);
263             if (tempDocument != null) {
264                 if (tempDocument.getEntity() != null) {
265                     List<EntityAddressBo> addressBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getAddresses();
266                     if (addressBoList.size() > 0) {
267                         for (int i = 0; i < addressBoList.size(); i++) {
268                             EntityAddressBo entityAddressBo = addressBoList.get(i);
269                             Map<String, Object> criteria = new HashMap<String, Object>();
270                             criteria.put(OLEConstants.OlePatron.OLE_ADDRESS_ID, entityAddressBo.getId());
271                             OleAddressBo oleAddressBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleAddressBo.class, criteria);
272 
273                             if (oleAddressBo != null) {
274                                 if (oleAddressBo.getAddressValidTo() != null && oleAddressBo.getAddressValidFrom() != null && fmt.format(oleAddressBo.getAddressValidFrom()).compareTo(fmt.format(oleAddressBo.getAddressValidTo())) >= 0) {
275                                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_VALID_ADDRESS_TO_DATE);
276                                     return getUIFModelAndView(mainForm);
277                                 }
278                             }
279                             if (entityAddressBo != null) {
280                                 KRADServiceLocator.getBusinessObjectService().delete(oleAddressBo);
281                                 KRADServiceLocator.getBusinessObjectService().delete(entityAddressBo);
282                             }
283                         }
284                     }
285                     List<EntityEmailBo> emailBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getEmailAddresses();
286                     if (emailBoList.size() > 0) {
287                         KRADServiceLocator.getBusinessObjectService().delete(emailBoList);
288                     }
289                     List<EntityPhoneBo> phoneBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getPhoneNumbers();
290                     if (phoneBoList.size() > 0) {
291                         KRADServiceLocator.getBusinessObjectService().delete(phoneBoList);
292                     }
293                     List<OlePatronNotes> patronNotesList = tempDocument.getNotes();
294                     if (patronNotesList.size() > 0) {
295                         KRADServiceLocator.getBusinessObjectService().delete(patronNotesList);
296                     }
297                     List<OlePatronLostBarcode> lostBarcodeList = tempDocument.getLostBarcodes();
298                     if (lostBarcodeList.size() > 0) {
299                         KRADServiceLocator.getBusinessObjectService().delete(lostBarcodeList);
300                     }
301                     List<EntityEmploymentBo> employmentBoList = tempDocument.getEntity().getEmploymentInformation();
302                     if (employmentBoList.size() > 0) {
303                         KRADServiceLocator.getBusinessObjectService().delete(employmentBoList);
304                     }
305                     List<EntityAffiliationBo> affiliationBoList = tempDocument.getEntity().getAffiliations();
306                     if (affiliationBoList.size() > 0) {
307                         KRADServiceLocator.getBusinessObjectService().delete(affiliationBoList);
308                     }
309                     List<OleProxyPatronDocument> proxyPatronDocuments = tempDocument.getOleProxyPatronDocuments();
310                     if (proxyPatronDocuments.size() > 0) {
311                         KRADServiceLocator.getBusinessObjectService().delete(proxyPatronDocuments);
312                     }
313                     List<OlePatronLocalIdentificationBo> patronLocalIdentificationBos = tempDocument.getOlePatronLocalIds();
314                     if(patronLocalIdentificationBos.size() > 0) {
315                         KRADServiceLocator.getBusinessObjectService().delete(patronLocalIdentificationBos);
316                     }
317                 }
318             }
319         }
320         newOlePatronDocument.setUpload(false);
321         return super.route(mainForm, result, request, response);
322     }
323 
324 
325     @RequestMapping(params = "methodToCall=lostBarcode")
326     public ModelAndView lostBarcode(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
327                               HttpServletRequest request, HttpServletResponse response) {
328 
329         LOG.debug(" Inside route method of patron maintenance controller ");
330         ModelAndView modelAndView;
331         MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
332         MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
333         OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
334         String lostBarcode = newOlePatronDocument.getBarcode();
335         OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
336         olePatronLostBarcode.setInvalidOrLostBarcodeNumber(lostBarcode);
337         olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new java.sql.Date(new Date().getTime()));
338         olePatronLostBarcode.setRevertBarcode(true);
339         List<OlePatronLostBarcode> lostBarcodes = newOlePatronDocument.getLostBarcodes();
340         List<OlePatronLostBarcode> lostBarcodeList = new ArrayList<OlePatronLostBarcode>();
341         lostBarcodeList.add(olePatronLostBarcode);
342         if (lostBarcodes.size() > 0) {
343             for (OlePatronLostBarcode lostPatronBarcode : lostBarcodes) {
344                 lostPatronBarcode.setRevertBarcode(false);
345                 lostBarcodeList.add(lostPatronBarcode);
346             }
347         }
348         newOlePatronDocument.setLostBarcodes(lostBarcodeList);
349         newOlePatronDocument.setBarcode(null);
350         GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ENTER_PATRON_BARCODE);
351         return getUIFModelAndView(mainForm);
352     }
353 
354     @RequestMapping(params = "methodToCall=uploadImage")
355     public ModelAndView uploadImage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
356                                     HttpServletRequest request, HttpServletResponse response) {
357         ModelAndView modelAndView;
358         MaintenanceDocumentForm mainForm = (MaintenanceDocumentForm) form;
359         MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
360         OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
361         MultipartFile multipartFile = mainForm.getAttachmentFile();
362         String fileName = multipartFile.getOriginalFilename();
363         if (validateFile(multipartFile.getOriginalFilename())) {
364             try {
365                 byte[] fileContent = multipartFile.getBytes();
366                 BufferedImage patronImage = ImageIO.read(new ByteArrayInputStream(fileContent));
367                 if(patronImage.getWidth() >= 100 || patronImage.getHeight() >= 100) {
368                     BufferedImage resizedImage = new BufferedImage(100,100,1);
369                     Graphics2D g = resizedImage.createGraphics();
370                     g.drawImage(patronImage, 0, 0, 100, 100, null);
371                     g.dispose();
372                     ByteArrayOutputStream baos = new ByteArrayOutputStream();
373                     ImageIO.write(resizedImage, "jpg", baos);
374                     byte[] res=baos.toByteArray();
375                     imageInByte=baos.toByteArray();
376                     newOlePatronDocument.setPatronPhotograph(res);
377                 } else {
378                     GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_SIZE);
379                     return getUIFModelAndView(mainForm);
380                 }
381             } catch (Exception ex) {
382                 LOG.error(ex.getMessage());
383             }
384         } else if(fileName!=null && fileName.isEmpty()){
385             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_WITHOUT_FILE);
386             return getUIFModelAndView(mainForm);
387         } else{
388             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_FORMAT);
389             return getUIFModelAndView(mainForm);
390         }
391         return getUIFModelAndView(mainForm);
392     }
393 
394     /**
395      *  This method validate the image file type.
396      * @param inputFile
397      * @return boolean
398      */
399     public boolean validateFile(String inputFile) {
400         return (inputFile.contains(".jpg") || inputFile.contains(".png") || inputFile.contains(".jpeg") || inputFile.contains(".gif")? true:false);
401     }
402 
403     @RequestMapping(params = "methodToCall=getImage")
404     public ModelAndView getImage(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
405                                  HttpServletRequest request, HttpServletResponse response) {
406         try {
407              String inquiry = "false";
408              if(request.getParameter("patronInquiryFlag")!= null){
409                  inquiry = (String)request.getParameter("patronInquiryFlag");
410              }
411 
412             if(inquiry.equalsIgnoreCase("false")){
413 
414 
415             String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
416             if (patronId != null && !patronId.equals("")) {
417                 Map patronMap = new HashMap();
418                 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
419                 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
420                 byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
421                 if (patronPhoto != null) {
422                     if(imageInByte == null || !patronPhoto.equals(imageInByte)) {
423                     response.setContentType("image/jpg");
424                     response.getOutputStream().write(patronPhoto);
425                     } else {
426                         response.setContentType("image/jpg");
427                         response.getOutputStream().write(imageInByte);
428                     }
429                 } else {
430                     response.setContentType("image/jpg");
431                     response.getOutputStream().write(imageInByte);
432                 }
433             } else {
434                 if (imageInByte != null) {
435                     response.setContentType("image/jpg");
436                     response.getOutputStream().write(imageInByte);
437                 }
438             }
439             }else {
440                 Map patronMap = new HashMap();
441                 String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
442                 if (patronId != null && !patronId.equals("")) {
443                 patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
444                 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
445                 byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
446                 if (patronPhoto != null) {
447 
448                         response.setContentType("image/jpg");
449                         response.getOutputStream().write(patronPhoto);
450 
451                 }
452                 }
453             }
454 
455         } catch (Exception ex) {
456             ex.printStackTrace();
457         }
458         return null;
459     }
460 
461     @RequestMapping(params = "methodToCall=getImageForLoan")
462     public ModelAndView getImageForLoan(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
463                                  HttpServletRequest request, HttpServletResponse response) {
464         try {
465                 String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
466                 if (patronId != null && !patronId.equals("")) {
467                     Map patronMap = new HashMap();
468                     patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
469                     OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
470                     byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
471                     if (patronPhoto != null) {
472                        response.setContentType("image/jpg");
473                        response.getOutputStream().write(patronPhoto);
474                     }
475                 }
476         } catch (Exception ex) {
477             ex.printStackTrace();
478         }
479         return null;
480     }
481 }