| 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 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 41 | |
|
| 42 | |
private DatabaseFacade dbf; |
| 43 | |
private PicManFacade pmf; |
| 44 | |
|
| 45 | 0 | public DatabaseConverterFormController() { |
| 46 | 0 | setSessionForm(true); |
| 47 | 0 | setValidateOnBinding(true); |
| 48 | 0 | setCommandName("databaseConverterForm"); |
| 49 | 0 | setFormView("DatabaseConverterForm"); |
| 50 | 0 | } |
| 51 | |
|
| 52 | |
public void setPicMan(PicManFacade pmf) { |
| 53 | 0 | this.pmf = pmf; |
| 54 | 0 | pmf = this.pmf; |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
public void setDatabase(DatabaseFacade dbf) { |
| 58 | 0 | this.dbf = dbf; |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
| 62 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 63 | 0 | DatabaseConverterForm dcf = new DatabaseConverterForm(); |
| 64 | |
|
| 65 | 0 | dcf.setUserWebSession(userWebSession); |
| 66 | 0 | dcf.setRoots(dbf.getRoots()); |
| 67 | |
|
| 68 | |
String v; |
| 69 | 0 | v = request.getParameter("updSize"); |
| 70 | 0 | if (v != null) { |
| 71 | 0 | dbf.getSystem().setUpdatePicSize(true); |
| 72 | 0 | dcf.setMessage("Queued updating sizes"); |
| 73 | |
} |
| 74 | 0 | v = request.getParameter("mlbFilters"); |
| 75 | 0 | if (v != null) { |
| 76 | 0 | dbf.getSystem().setUpdateMlbFilters(true); |
| 77 | 0 | dcf.setMessage("Queued MlbFilterFixer"); |
| 78 | |
} |
| 79 | 0 | v = request.getParameter("md5sum"); |
| 80 | 0 | if (v != null) { |
| 81 | 0 | dbf.getSystem().setUpdateMD5Sums(true); |
| 82 | 0 | dcf.setMessage("Queued UpdateMD5Sums"); |
| 83 | |
} |
| 84 | 0 | v = request.getParameter("mosaicVectors"); |
| 85 | 0 | if (v != null) { |
| 86 | 0 | dbf.getSystem().setCalcMosaicVectors(true); |
| 87 | 0 | dcf.setMessage("Queued calc mosaic vectors"); |
| 88 | |
} |
| 89 | 0 | 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 | 0 | } |
| 111 | |
|
| 112 | |
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception { |
| 113 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 114 | 0 | Map<String, Object> myModel = new HashMap<String, Object>(); |
| 115 | 0 | myModel.put("userWebSession", userWebSession); |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | 0 | return myModel; |
| 120 | |
} |
| 121 | |
|
| 122 | |
protected ModelAndView onSubmit( |
| 123 | |
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) |
| 124 | |
throws Exception { |
| 125 | |
|
| 126 | 0 | DatabaseConverterForm dcf = (DatabaseConverterForm) command; |
| 127 | |
|
| 128 | 0 | boolean success = true; |
| 129 | |
|
| 130 | |
|
| 131 | 0 | logger.info("oldName= '" + dcf.getOldName() + "'"); |
| 132 | 0 | logger.info("newName= '" + dcf.getNewName() + "'"); |
| 133 | |
|
| 134 | 0 | if (dcf.getOldName().length() > 0 && dcf.getNewName().length() > 0) { |
| 135 | 0 | dcf.setMessage("Moved '" + dcf.getOldName() + "' to root '" + dcf.getNewName() + "'"); |
| 136 | 0 | logger.info("oldName action"); |
| 137 | 0 | Root root = dbf.getRoot(dcf.getNewName()); |
| 138 | 0 | logger.info("rid = " + root.getRid()); |
| 139 | 0 | List<Pic> pics = dbf.getPics(); |
| 140 | 0 | Iterator<Pic> iter = pics.iterator(); |
| 141 | 0 | while (iter.hasNext()) { |
| 142 | 0 | Pic pic = iter.next(); |
| 143 | 0 | logger.info("Pic = " + pic.getName() + " loc: " + pic.getLocation()); |
| 144 | 0 | if (pic.getLocation().startsWith(dcf.getOldName())) { |
| 145 | 0 | pic.setLocation(pic.getLocation().substring(dcf.getOldName().length())); |
| 146 | 0 | pic.setRid(root.getRid()); |
| 147 | 0 | logger.info("Upd = " + pic.getName() + " loc: " + pic.getLocation()); |
| 148 | 0 | dbf.updatePic(pic); |
| 149 | |
} |
| 150 | 0 | } |
| 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 | 0 | if (success) { |
| 178 | 0 | response.sendRedirect("databaseConverter.do"); |
| 179 | 0 | return(null); |
| 180 | |
} |
| 181 | |
else |
| 182 | 0 | return super.onSubmit(request, response, command, errors); |
| 183 | |
} |
| 184 | |
} |