001    package org.kuali.ole.patron.controller;
002    
003    import org.apache.commons.lang.StringUtils;
004    import org.apache.commons.net.ntp.TimeStamp;
005    import org.apache.log4j.Logger;
006    import org.kuali.ole.OLEConstants;
007    import org.kuali.ole.patron.api.OlePatronDefinition;
008    import org.kuali.ole.patron.bo.*;
009    import org.kuali.ole.service.OlePatronHelperService;
010    import org.kuali.ole.service.OlePatronHelperServiceImpl;
011    import org.kuali.ole.service.OlePatronMaintenanceDocumentServiceImpl;
012    import org.kuali.ole.service.OlePatronService;
013    import org.kuali.rice.core.api.criteria.CriteriaLookupService;
014    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
015    import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
016    import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
017    import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
018    import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
019    import org.kuali.rice.kim.impl.identity.entity.EntityBo;
020    import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
021    import org.kuali.rice.krad.maintenance.MaintenanceDocument;
022    import org.kuali.rice.krad.maintenance.MaintenanceUtils;
023    import org.kuali.rice.krad.service.KRADServiceLocator;
024    import org.kuali.rice.krad.service.MaintenanceDocumentService;
025    import org.kuali.rice.krad.uif.UifParameters;
026    import org.kuali.rice.krad.uif.view.View;
027    import org.kuali.rice.krad.util.GlobalVariables;
028    import org.kuali.rice.krad.util.KRADConstants;
029    import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
030    import org.kuali.rice.krad.web.form.DocumentFormBase;
031    import org.kuali.rice.krad.web.form.MaintenanceForm;
032    import org.kuali.rice.krad.web.form.UifFormBase;
033    import org.springframework.stereotype.Controller;
034    import org.springframework.validation.BindingResult;
035    import org.springframework.web.bind.annotation.ModelAttribute;
036    import org.springframework.web.bind.annotation.RequestMapping;
037    import org.springframework.web.bind.annotation.RequestMethod;
038    import org.springframework.web.multipart.MultipartFile;
039    import org.springframework.web.servlet.ModelAndView;
040    
041    import javax.imageio.ImageIO;
042    import javax.servlet.http.HttpServletRequest;
043    import javax.servlet.http.HttpServletResponse;
044    import java.awt.*;
045    import java.awt.image.BufferedImage;
046    import java.io.ByteArrayInputStream;
047    import java.io.ByteArrayOutputStream;
048    import java.text.SimpleDateFormat;
049    import java.util.*;
050    import java.util.List;
051    
052    /**
053     * .OlePatronMaintenanceDocumentController invokes MaintenanceDocumentController and returns instance of MaintenanceDocumentService.
054     */
055    @Controller
056    @RequestMapping(value = "/patronMaintenance")
057    public class OlePatronMaintenanceDocumentController extends MaintenanceDocumentController {
058    
059        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronMaintenanceDocumentController.class);
060        private OlePatronService olePatronService;
061        private OlePatronHelperService olePatronHelperService = new OlePatronHelperServiceImpl();
062        private byte[] imageInByte;
063    
064        public OlePatronService getOlePatronService() {
065            if (olePatronService != null) {
066                olePatronService = GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_SERVICE);
067            }
068            return olePatronService;
069        }
070    
071        /**
072         * This method returns the instance of olePatronMaintenanceDocumentService
073         * @return olePatronMaintenanceDocumentService(MaintenanceDocumentService)
074         */
075        @Override
076        protected MaintenanceDocumentService getMaintenanceDocumentService() {
077            return GlobalResourceLoader.getService(OLEConstants.OlePatron.OLE_PATRON_MAINTENANCE_DOC_SERVICE);
078        }
079    
080        /**
081         * Use to create a link delete in the lookup result action field which will use to delete patron record..
082         * @param form
083         * @param result
084         * @param request
085         * @param response
086         * @return ModelAndView
087         * @throws Exception
088         */
089        @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
090        public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result,
091                                              HttpServletRequest request, HttpServletResponse response) throws Exception {
092            LOG.debug(" Inside maintenanceDelete ");
093            setupMaintenanceForDelete(form, request, OLEConstants.OlePatron.OLE_PATRON_DELETE);
094            return getUIFModelAndView(form);
095        }
096    
097        /**
098         * To delete the whole patron document.
099         * @param form
100         * @param result
101         * @param request
102         * @param response
103         * @return Close the document
104         * @throws Exception
105         */
106        @RequestMapping(params = "methodToCall=" + "deleteDocument")
107        public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result,
108                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
109    
110            LOG.debug(" Inside deleteDocument ");
111            MaintenanceDocument document = form.getDocument();
112            OlePatronDocument olePatronDocument = new OlePatronDocument();
113            try {
114                if (document.getDocumentDataObject() != null) {
115                    olePatronDocument = (OlePatronDocument) document.getDocumentDataObject();
116                    if (olePatronDocument != null && olePatronDocument.getOlePatronId() != null) {
117                        boolean deletePatronDetail = olePatronHelperService.deletePatron(olePatronDocument);
118                        if (deletePatronDetail) {
119                            return close(form, result, request, response);
120                        } else {
121                            GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_HAS_LOAN);
122                            return getUIFModelAndView(form);
123                        }
124                    } else {
125                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
126                        return getUIFModelAndView(form);
127                    }
128                }
129            } catch (Exception ex) {
130                LOG.error(ex.getMessage());
131            }
132            return close(form, result, request, response);
133        }
134    
135    
136        /**
137         * This method populates confirmation to delete the document.
138         *
139         * @param form
140         * @param request
141         * @param maintenanceAction
142         */
143        protected void setupMaintenanceForDelete(MaintenanceForm form, HttpServletRequest request, String maintenanceAction) {
144            LOG.debug(" Inside setupMaintenanceForDelete ");
145            MaintenanceDocument document = form.getDocument();
146            if (document == null) {
147                document = getMaintenanceDocumentService()
148                        .setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
149                                maintenanceAction);
150    
151                form.setDocument(document);
152                form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
153            }
154    
155            form.setMaintenanceAction(maintenanceAction);
156            OlePatronMaintenanceDocumentServiceImpl olePatronMaintenanceDocumentServicec = (OlePatronMaintenanceDocumentServiceImpl) getMaintenanceDocumentService();
157            olePatronMaintenanceDocumentServicec.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
158            MaintenanceUtils.checkForLockingDocument(document, false);
159        }
160    
161        /**
162         * To submit or route the patron maintenance document
163         * @param form document form base containing the document instance that will be routed
164         * @return ModelAndView
165         */
166        @Override
167        @RequestMapping(params = "methodToCall=route")
168        public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
169                                  HttpServletRequest request, HttpServletResponse response){
170    
171            LOG.debug(" Inside route method of patron maintenance controller ");
172            ModelAndView modelAndView;
173            MaintenanceForm mainForm = (MaintenanceForm) form;
174            MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
175    
176            SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
177            OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
178            List<OleProxyPatronDocument> oleProxyPatronDocumentList = newOlePatronDocument.getOleProxyPatronDocuments();
179            List<OleProxyPatronDocument> proxyPatronDocumentList = new ArrayList<OleProxyPatronDocument>();
180            if (oleProxyPatronDocumentList.size() > 0) {
181                for (OleProxyPatronDocument oleProxyPatronDocument : oleProxyPatronDocumentList) {
182                    Map<String, String> proxyMap = new HashMap<String, String>();
183                    proxyMap.put(OLEConstants.OlePatron.PATRON_ID, oleProxyPatronDocument.getProxyPatronId());
184                    OlePatronDocument tempDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, proxyMap);
185                    if (tempDocument != null) {
186                        oleProxyPatronDocument.setProxyPatronBarcode(tempDocument.getBarcode());
187                        oleProxyPatronDocument.setProxyPatronFirstName(tempDocument.getEntity().getNames().get(0).getFirstName());
188                        oleProxyPatronDocument.setProxyPatronLastName(tempDocument.getEntity().getNames().get(0).getLastName());
189                        proxyPatronDocumentList.add(oleProxyPatronDocument);
190                    }
191                }
192                newOlePatronDocument.setOleProxyPatronDocuments(proxyPatronDocumentList);
193            }
194    
195            List<OleProxyPatronDocument> proxyPatron = newOlePatronDocument.getOleProxyPatronDocuments();
196            String patronId = "";
197            Date proxyActDate = null;
198            Date proxyExpDate = null;
199    
200    
201            if (proxyPatron.size() > 0) {
202                for (OleProxyPatronDocument proxy : proxyPatron) {
203                    patronId = proxy.getProxyPatronId();
204                    proxyActDate = proxy.getProxyPatronActivationDate();
205                    proxyExpDate = proxy.getProxyPatronExpirationDate();
206                    Map<String, String> patronMap = new HashMap<String, String>();
207                    patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
208                    OlePatronDocument patronDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
209                    if (patronDocument != null) {
210                        Date patronExpDate = patronDocument.getExpirationDate();
211                        Date patronActDate = patronDocument.getActivationDate();
212                        if (proxyActDate != null) {
213                            if (patronActDate != null && fmt.format(patronActDate).compareTo(fmt.format(proxyActDate)) > 0) {
214                                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_ACTIVATION_DATE);
215                                return getUIFModelAndView(mainForm);
216                            }
217                        }
218                        if (proxyExpDate != null) {
219                            if (patronExpDate != null) {
220                                if (fmt.format(proxyExpDate).compareTo(fmt.format(patronExpDate)) > 0) {
221                                    GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_REAL_PATRON_EXPIRATION_DATE);
222                                    return getUIFModelAndView(mainForm);
223                                }
224                            }
225                        }
226                    }
227                    boolean lostBarcodeCheck = olePatronHelperService.CheckBarcodeAndLostBarcode(newOlePatronDocument);
228                    if(lostBarcodeCheck) {
229                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BARCODE_INVALID);
230                        return getUIFModelAndView(mainForm);
231                    }
232                    boolean isBorrowerTypeActive = olePatronHelperService.isBorrowerTypeActive(newOlePatronDocument);
233                    if(!isBorrowerTypeActive) {
234                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_BORROWER_TYPE_INACTIVE);
235                        return getUIFModelAndView(mainForm);
236                    }
237                    if (patronId != null && newOlePatronDocument.getOlePatronId() != null && newOlePatronDocument.getOlePatronId().equals(patronId)) {
238                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ID);
239                        return getUIFModelAndView(mainForm);
240                    } else if (proxyActDate != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(proxyActDate)) > 0) {
241                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_ACTIVATION_DATE);
242                        return getUIFModelAndView(mainForm);
243                    } else {
244                        if (proxyExpDate != null) {
245                            if (proxyActDate != null) {
246                                if ((fmt.format(proxyActDate).compareTo(fmt.format(proxyExpDate)) >= 0)) {
247                                    GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
248                                    return getUIFModelAndView(mainForm);
249                                }
250                            } else if (fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(proxyExpDate)) > 0) {
251                                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PROXY_PATRON_EXPIRATION_DATE);
252                                return getUIFModelAndView(mainForm);
253                            }
254                        }
255                    }
256                }
257            }
258            if (newOlePatronDocument.isGeneralBlock() && (newOlePatronDocument.getGeneralBlockNotes() == null || newOlePatronDocument.getGeneralBlockNotes().equals(""))) {
259                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_GENERAL_BLOCK_NOTES, OLEConstants.OlePatron.PATRON_GENERAL_BLOCK_NOTES);
260                return getUIFModelAndView(mainForm);
261            } else if (newOlePatronDocument.getActivationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(newOlePatronDocument.getActivationDate())) > 0) {
262                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_ACTIVATION_DATE);
263                return getUIFModelAndView(mainForm);
264            } 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)) {
265                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_EXPIRATION_DATE);
266                return getUIFModelAndView(mainForm);
267            } else if (newOlePatronDocument.getOlePatronId() != null) {
268                Map<String, String> tempId = new HashMap<String, String>();
269                tempId.put(OLEConstants.OlePatron.PATRON_ID, newOlePatronDocument.getOlePatronId());
270                OlePatronDocument tempDocument = (OlePatronDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, tempId);
271                if (tempDocument != null) {
272                    if (tempDocument.getEntity() != null) {
273                        List<EntityAddressBo> addressBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getAddresses();
274                        if (addressBoList.size() > 0) {
275                            for (int i = 0; i < addressBoList.size(); i++) {
276                                EntityAddressBo entityAddressBo = addressBoList.get(i);
277                                Map<String, Object> criteria = new HashMap<String, Object>();
278                                criteria.put(OLEConstants.OlePatron.OLE_ADDRESS_ID, entityAddressBo.getId());
279                                OleAddressBo oleAddressBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleAddressBo.class, criteria);
280    
281                                if (oleAddressBo != null) {
282                                    if (oleAddressBo.getAddressValidTo() != null && oleAddressBo.getAddressValidFrom() != null && fmt.format(oleAddressBo.getAddressValidFrom()).compareTo(fmt.format(oleAddressBo.getAddressValidTo())) >= 0) {
283                                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_VALID_ADDRESS_TO_DATE);
284                                        return getUIFModelAndView(mainForm);
285                                    }
286                                }
287                                if (entityAddressBo != null) {
288                                    KRADServiceLocator.getBusinessObjectService().delete(oleAddressBo);
289                                    KRADServiceLocator.getBusinessObjectService().delete(entityAddressBo);
290                                }
291                            }
292                        }
293                        List<EntityEmailBo> emailBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getEmailAddresses();
294                        if (emailBoList.size() > 0) {
295                            KRADServiceLocator.getBusinessObjectService().delete(emailBoList);
296                        }
297                        List<EntityPhoneBo> phoneBoList = tempDocument.getEntity().getEntityTypeContactInfos().get(0).getPhoneNumbers();
298                        if (phoneBoList.size() > 0) {
299                            KRADServiceLocator.getBusinessObjectService().delete(phoneBoList);
300                        }
301                        List<OlePatronNotes> patronNotesList = tempDocument.getNotes();
302                        if (patronNotesList.size() > 0) {
303                            KRADServiceLocator.getBusinessObjectService().delete(patronNotesList);
304                        }
305                        List<OlePatronLostBarcode> lostBarcodeList = tempDocument.getLostBarcodes();
306                        if (lostBarcodeList.size() > 0) {
307                            KRADServiceLocator.getBusinessObjectService().delete(lostBarcodeList);
308                        }
309                        List<EntityEmploymentBo> employmentBoList = tempDocument.getEntity().getEmploymentInformation();
310                        if (employmentBoList.size() > 0) {
311                            KRADServiceLocator.getBusinessObjectService().delete(employmentBoList);
312                        }
313                        List<EntityAffiliationBo> affiliationBoList = tempDocument.getEntity().getAffiliations();
314                        if (affiliationBoList.size() > 0) {
315                            KRADServiceLocator.getBusinessObjectService().delete(affiliationBoList);
316                        }
317                        List<OleProxyPatronDocument> proxyPatronDocuments = tempDocument.getOleProxyPatronDocuments();
318                        if (proxyPatronDocuments.size() > 0) {
319                            KRADServiceLocator.getBusinessObjectService().delete(proxyPatronDocuments);
320                        }
321                        List<OlePatronLocalIdentificationBo> patronLocalIdentificationBos = tempDocument.getOlePatronLocalIds();
322                        if(patronLocalIdentificationBos.size() > 0) {
323                            KRADServiceLocator.getBusinessObjectService().delete(patronLocalIdentificationBos);
324                        }
325                    }
326                }
327            }
328            return super.route(mainForm, result, request, response);
329        }
330    
331    
332        @RequestMapping(params = "methodToCall=lostBarcode")
333        public ModelAndView lostBarcode(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
334                                  HttpServletRequest request, HttpServletResponse response) {
335    
336            LOG.debug(" Inside route method of patron maintenance controller ");
337            ModelAndView modelAndView;
338            MaintenanceForm mainForm = (MaintenanceForm) form;
339            MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
340            OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
341            String lostBarcode = newOlePatronDocument.getBarcode();
342            OlePatronLostBarcode olePatronLostBarcode = new OlePatronLostBarcode();
343            olePatronLostBarcode.setInvalidOrLostBarcodeNumber(lostBarcode);
344            olePatronLostBarcode.setInvalidOrLostBarcodeEffDate(new Date());
345            olePatronLostBarcode.setRevertBarcode(true);
346            List<OlePatronLostBarcode> lostBarcodes = newOlePatronDocument.getLostBarcodes();
347            List<OlePatronLostBarcode> lostBarcodeList = new ArrayList<OlePatronLostBarcode>();
348            lostBarcodeList.add(olePatronLostBarcode);
349            if (lostBarcodes.size() > 0) {
350                for (OlePatronLostBarcode lostPatronBarcode : lostBarcodes) {
351                    lostPatronBarcode.setRevertBarcode(false);
352                    lostBarcodeList.add(lostPatronBarcode);
353                }
354            }
355            newOlePatronDocument.setLostBarcodes(lostBarcodeList);
356            newOlePatronDocument.setBarcode(null);
357            GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ENTER_PATRON_BARCODE);
358            return getUIFModelAndView(mainForm);
359        }
360    
361        @RequestMapping(params = "methodToCall=uploadImage")
362        public ModelAndView uploadImage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
363                                        HttpServletRequest request, HttpServletResponse response) {
364            ModelAndView modelAndView;
365            MaintenanceForm mainForm = (MaintenanceForm) form;
366            MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
367            OlePatronDocument newOlePatronDocument = (OlePatronDocument) document.getNewMaintainableObject().getDataObject();
368            MultipartFile multipartFile = mainForm.getAttachmentFile();
369            String fileName = multipartFile.getOriginalFilename();
370            if (validateFile(multipartFile.getOriginalFilename())) {
371                try {
372                    byte[] fileContent = multipartFile.getBytes();
373                    BufferedImage patronImage = ImageIO.read(new ByteArrayInputStream(fileContent));
374                    if(patronImage.getWidth() >= 100 || patronImage.getHeight() >= 100) {
375                        BufferedImage resizedImage = new BufferedImage(100,100,1);
376                        Graphics2D g = resizedImage.createGraphics();
377                        g.drawImage(patronImage, 0, 0, 100, 100, null);
378                        g.dispose();
379                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
380                        ImageIO.write(resizedImage, "jpg", baos);
381                        byte[] res=baos.toByteArray();
382                        imageInByte=baos.toByteArray();
383                        newOlePatronDocument.setPatronPhotograph(res);
384                    } else {
385                        GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_SIZE);
386                        return getUIFModelAndView(mainForm);
387                    }
388                } catch (Exception ex) {
389                    LOG.error(ex.getMessage());
390                }
391            } else {
392                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_PHOTOGRAPH_FORMAT);
393                return getUIFModelAndView(mainForm);
394            }
395            return getUIFModelAndView(mainForm);
396        }
397    
398        /**
399         *  This method validate the image file type.
400         * @param inputFile
401         * @return boolean
402         */
403        public boolean validateFile(String inputFile) {
404            return (inputFile.contains(".jpg") || inputFile.contains(".png") || inputFile.contains(".jpeg") || inputFile.contains(".gif")? true:false);
405        }
406    
407        @RequestMapping(params = "methodToCall=getImage")
408        public ModelAndView getImage(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result,
409                                     HttpServletRequest request, HttpServletResponse response) {
410            try {
411                String patronId = request.getParameter(OLEConstants.OlePatron.PATRON_ID);
412                if (patronId != null) {
413                    Map patronMap = new HashMap();
414                    patronMap.put(OLEConstants.OlePatron.PATRON_ID, patronId);
415                    OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
416                    byte[] patronPhoto = olePatronDocument.getPatronPhotograph();
417                    if (patronPhoto != null) {
418                        if(imageInByte == null || patronPhoto.equals(imageInByte)) {
419                        response.setContentType("image/jpg");
420                        response.getOutputStream().write(patronPhoto);
421                        } else {
422                            response.setContentType("image/jpg");
423                            response.getOutputStream().write(imageInByte);
424                        }
425                    } else {
426                        response.setContentType("image/jpg");
427                        response.getOutputStream().write(imageInByte);
428                    }
429                } else {
430                    if (imageInByte != null) {
431                        response.setContentType("image/jpg");
432                        response.getOutputStream().write(imageInByte);
433                    }
434                }
435            } catch (Exception ex) {
436                ex.printStackTrace();
437            }
438            return null;
439        }
440    }