1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.web;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.springframework.validation.BindException;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import com.buckosoft.BSAccount.web.BSAccountSimpleFormController;
22 import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
23 import com.buckosoft.PicMan.business.NewPicScannerImpl;
24 import com.buckosoft.PicMan.business.PicManFacade;
25
26 public class ScanForNewPicsFormController extends BSAccountSimpleFormController {
27
28
29 protected final Log logger = LogFactory.getLog(getClass());
30
31 private PicManFacade pmf;
32
33 public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
34 public PicManFacade getPicMan() { return(pmf); }
35
36 public ScanForNewPicsFormController() {
37 setSessionForm(true);
38 setValidateOnBinding(false);
39 setCommandName("scanForNewPicsForm");
40 setFormView("ScanForNewPicsForm");
41 }
42
43 protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
44 throws Exception {
45 }
46
47 protected Object formBackingObject(HttpServletRequest request) throws Exception {
48 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
49 logger.info("formBackingObject with session " + userWebSession);
50 ScanForNewPicsForm smf = new ScanForNewPicsForm();
51
52 smf.setUserWebSession(userWebSession);
53 smf.setNewPicScanner(new NewPicScannerImpl(pmf));
54 return(smf);
55 }
56
57
58 protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
59 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
60 Map<String, Object> myModel = new HashMap<String, Object>();
61 myModel.put("userWebSession", userWebSession);
62 logger.info("referenceData with session " + userWebSession);
63
64 return myModel;
65 }
66
67 protected ModelAndView onSubmit(
68 HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
69 throws Exception {
70
71 ScanForNewPicsForm setupForm = (ScanForNewPicsForm) command;
72
73
74
75
76
77 errors.setNestedPath("ScanForNewPics");
78
79 errors.setNestedPath("");
80
81 boolean success;
82 success = setupForm.getNewPicScanner().processNewPics();
83 if (!success) {
84 logger.info("Error processing new pics");
85 errors.reject("NEW_PIC_SCANNER_FAILED",
86 "An error occured processing the new pics");
87 errors.reject("NEW_PICS_SCANNER_FAILED_INFO",
88 setupForm.getNewPicScanner().getProcessNewPicsErrorMessage());
89
90 }
91 if (success)
92 {
93 response.sendRedirect("home.do");
94 return(null);
95 }
96 else
97 return(showForm(request, response, errors));
98
99 }
100
101 }