Coverage Report - com.buckosoft.PicMan.web.DatabaseConverterFormController
 
Classes in this File Line Coverage Branch Coverage Complexity
DatabaseConverterFormController
0%
0/62
0%
0/18
2.429
 
 1  
 /******************************************************************************
 2  
  * DatabaseConverterFormController.java - The Spring controller to alter my running production database.
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2006 - Dick Balaska
 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  
  * The Spring controller to alter my running production database.
 32  
  * Sometimes, it is easier to throw some code in here then it is to try to 
 33  
  * fix the database with phpMyAdmin.
 34  
  * @author Dick Balaska
 35  
  * @since 2006/09/29
 36  
  */
 37  
 public class DatabaseConverterFormController extends BSAccountSimpleFormController {
 38  
 
 39  
 //        private static final boolean DEBUG = true;
 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;                // to remove an "unread locally" warning.
 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  
                 AccountForm accountForm = (AccountForm) command;
 97  
                 Account account = accountForm.getAccount();
 98  
 
 99  
                 if (request.getParameter("account.listOption") == null) {
 100  
                         account.setListOption(false);
 101  
                 }
 102  
                 if (request.getParameter("account.bannerOption") == null) {
 103  
                         account.setBannerOption(false);
 104  
                 }
 105  
 
 106  
                 errors.setNestedPath("account");
 107  
                 getValidator().validate(account, errors);
 108  
                 errors.setNestedPath("");
 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  
 //                if (DEBUG)
 117  
 //                        logger.info("referenceData ChainManForm with session " + userWebSession);
 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  
                 // boolean action = false;
 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  
                 if (cmf.getChainToDelete().length() > 0) {
 154  
                         Chain chain = new Chain();
 155  
                         chain.setName(cmf.getChainToDelete());
 156  
                         dbf.deleteChain(chain);
 157  
                         action = true;
 158  
                 }
 159  
                 if (!action && cmf.getNewChainName().length() > 0) {
 160  
                         if (DEBUG)
 161  
                                 logger.info("Adding new Chain '" + cmf.getNewChainName());
 162  
                         Chain c = new Chain();
 163  
                         c.setName(cmf.getNewChainName());
 164  
                         dbf.storeChain(c);
 165  
                         newChainName = c.getName();
 166  
                         action = true;
 167  
                         
 168  
                 }
 169  
                 if (!action && cmf.getActiveChain() != null) {
 170  
                         Chain c = cmf.getActiveChain();
 171  
                         LinkedList<SetSize> newSetsSizes = parseSetsSizes(request);
 172  
                         c.setSetSizes(newSetsSizes);
 173  
                         dbf.storeChain(c);
 174  
                         action = true;
 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  
 }