1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.web;
9
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.List;
13 import java.util.Map;
14
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.springframework.validation.BindException;
21 import org.springframework.web.servlet.ModelAndView;
22
23 import com.buckosoft.BSAccount.web.BSAccountSimpleFormController;
24 import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
25 import com.buckosoft.PicMan.business.PicManFacade;
26 import com.buckosoft.PicMan.db.DatabaseFacade;
27 import com.buckosoft.PicMan.domain.Pic;
28 import com.buckosoft.PicMan.domain.Root;
29
30
31
32
33
34
35
36
37 public class DatabaseConverterFormController extends BSAccountSimpleFormController {
38
39
40 protected final Log logger = LogFactory.getLog(getClass());
41
42 private DatabaseFacade dbf;
43 private PicManFacade pmf;
44
45 public DatabaseConverterFormController() {
46 setSessionForm(true);
47 setValidateOnBinding(true);
48 setCommandName("databaseConverterForm");
49 setFormView("DatabaseConverterForm");
50 }
51
52 public void setPicMan(PicManFacade pmf) {
53 this.pmf = pmf;
54 pmf = this.pmf;
55 }
56
57 public void setDatabase(DatabaseFacade dbf) {
58 this.dbf = dbf;
59 }
60
61 protected Object formBackingObject(HttpServletRequest request) throws Exception {
62 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
63 DatabaseConverterForm dcf = new DatabaseConverterForm();
64
65 dcf.setUserWebSession(userWebSession);
66 dcf.setRoots(dbf.getRoots());
67
68 String v;
69 v = request.getParameter("updSize");
70 if (v != null) {
71 dbf.getSystem().setUpdatePicSize(true);
72 dcf.setMessage("Queued updating sizes");
73 }
74 v = request.getParameter("mlbFilters");
75 if (v != null) {
76 dbf.getSystem().setUpdateMlbFilters(true);
77 dcf.setMessage("Queued MlbFilterFixer");
78 }
79 v = request.getParameter("md5sum");
80 if (v != null) {
81 dbf.getSystem().setUpdateMD5Sums(true);
82 dcf.setMessage("Queued UpdateMD5Sums");
83 }
84 v = request.getParameter("mosaicVectors");
85 if (v != null) {
86 dbf.getSystem().setCalcMosaicVectors(true);
87 dcf.setMessage("Queued calc mosaic vectors");
88 }
89 return(dcf);
90 }
91
92 protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
93 throws Exception {
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 }
111
112 protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
113 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
114 Map<String, Object> myModel = new HashMap<String, Object>();
115 myModel.put("userWebSession", userWebSession);
116
117
118
119 return myModel;
120 }
121
122 protected ModelAndView onSubmit(
123 HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
124 throws Exception {
125
126 DatabaseConverterForm dcf = (DatabaseConverterForm) command;
127
128 boolean success = true;
129
130
131 logger.info("oldName= '" + dcf.getOldName() + "'");
132 logger.info("newName= '" + dcf.getNewName() + "'");
133
134 if (dcf.getOldName().length() > 0 && dcf.getNewName().length() > 0) {
135 dcf.setMessage("Moved '" + dcf.getOldName() + "' to root '" + dcf.getNewName() + "'");
136 logger.info("oldName action");
137 Root root = dbf.getRoot(dcf.getNewName());
138 logger.info("rid = " + root.getRid());
139 List<Pic> pics = dbf.getPics();
140 Iterator<Pic> iter = pics.iterator();
141 while (iter.hasNext()) {
142 Pic pic = iter.next();
143 logger.info("Pic = " + pic.getName() + " loc: " + pic.getLocation());
144 if (pic.getLocation().startsWith(dcf.getOldName())) {
145 pic.setLocation(pic.getLocation().substring(dcf.getOldName().length()));
146 pic.setRid(root.getRid());
147 logger.info("Upd = " + pic.getName() + " loc: " + pic.getLocation());
148 dbf.updatePic(pic);
149 }
150 }
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 if (success) {
178 response.sendRedirect("databaseConverter.do");
179 return(null);
180 }
181 else
182 return super.onSubmit(request, response, command, errors);
183 }
184 }