| 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.PicManFacade; |
| 24 | |
import com.buckosoft.PicMan.db.DatabaseFacade; |
| 25 | |
import com.buckosoft.PicMan.domain.System; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class SystemSetupFormController extends BSAccountSimpleFormController { |
| 33 | |
|
| 34 | |
private static final boolean DEBUG = false; |
| 35 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 36 | |
|
| 37 | |
private PicManFacade pmf; |
| 38 | |
private DatabaseFacade dbf; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | public void setPicMan(PicManFacade pmf) { this.pmf = pmf; } |
| 44 | |
|
| 45 | |
|
| 46 | 0 | public void setDatabase(DatabaseFacade dbf) { this.dbf = dbf; } |
| 47 | 0 | public DatabaseFacade getDatabase() { return(dbf); } |
| 48 | |
|
| 49 | 0 | public SystemSetupFormController() { |
| 50 | 0 | setSessionForm(true); |
| 51 | 0 | setValidateOnBinding(false); |
| 52 | 0 | setCommandName("systemSetupForm"); |
| 53 | 0 | setFormView("SystemSetupForm"); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
| 57 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 58 | |
if (DEBUG) |
| 59 | |
logger.info("formBackingObject session " + userWebSession); |
| 60 | 0 | SystemSetupForm ssf = new SystemSetupForm(); |
| 61 | |
|
| 62 | 0 | ssf.setSystem(dbf.getSystem()); |
| 63 | 0 | ssf.setDbUrl(dbf.getDbUrl()); |
| 64 | 0 | ssf.setDbUser(dbf.getDbUser()); |
| 65 | 0 | ssf.setUserWebSession(userWebSession); |
| 66 | |
|
| 67 | |
String v; |
| 68 | 0 | v = request.getParameter("deleteErrors"); |
| 69 | 0 | if (v != null) { |
| 70 | 0 | pmf.emptyErrorLog(); |
| 71 | 0 | ssf.setMessage("Emptied Error Log"); |
| 72 | |
} |
| 73 | 0 | v = request.getParameter("buildThumbCache"); |
| 74 | 0 | if (v != null) { |
| 75 | 0 | ssf.setMessage("Queued build thumb Cache"); |
| 76 | 0 | pmf.getThumbCache().setBuildThumbCache(true); |
| 77 | |
} |
| 78 | 0 | v = request.getParameter("deleteThumbCache"); |
| 79 | 0 | if (v != null) { |
| 80 | 0 | ssf.setClickedDeleteCache(true); |
| 81 | |
} |
| 82 | 0 | return(ssf); |
| 83 | |
} |
| 84 | |
|
| 85 | |
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) |
| 86 | |
throws Exception { |
| 87 | |
|
| 88 | 0 | SystemSetupForm ssf = (SystemSetupForm) command; |
| 89 | |
if (DEBUG) |
| 90 | |
logger.info("onBindAndValidate"); |
| 91 | 0 | if (request.getParameter("deleteCacheConfirmed") != null) |
| 92 | 0 | return; |
| 93 | |
|
| 94 | 0 | if (request.getParameter("system.engineOn") == null) { |
| 95 | 0 | ssf.getSystem().setEngineOn(false); |
| 96 | |
} |
| 97 | 0 | if (request.getParameter("system.engineRunOnce") == null) { |
| 98 | 0 | ssf.getSystem().setEngineRunOnce(false); |
| 99 | |
} |
| 100 | 0 | if (request.getParameter("system.syncEnable") == null) { |
| 101 | 0 | ssf.getSystem().setSyncEnable(false); |
| 102 | |
} |
| 103 | 0 | if (request.getParameter("system.useThumbCache") == null) { |
| 104 | 0 | ssf.getSystem().setUseThumbCache(false); |
| 105 | |
} |
| 106 | 0 | if (request.getParameter("system.skipXThumbs") == null) { |
| 107 | 0 | ssf.getSystem().setSkipXThumbs(false); |
| 108 | |
} |
| 109 | 0 | if (request.getParameter("system.showRateOnPics") == null) { |
| 110 | 0 | ssf.getSystem().setShowRateOnPics(false); |
| 111 | |
} |
| 112 | 0 | if (request.getParameter("system.jobLogSummaryOnly") == null) { |
| 113 | 0 | ssf.getSystem().setJobLogSummaryOnly(false); |
| 114 | |
} |
| 115 | 0 | if (ssf.getSystem().isUseThumbCache()) { |
| 116 | 0 | if (ssf.getSystem().getThumbCacheDirectory() == null |
| 117 | 0 | || ssf.getSystem().getThumbCacheDirectory().length() == 0) { |
| 118 | 0 | errors.reject("X", "Can't use Thumb Cache with no directory"); |
| 119 | |
} |
| 120 | 0 | if (ssf.getSystem().getThumbCacheSize() == 0) { |
| 121 | 0 | errors.reject("X", "Thumbs subdir size must be greater than 0"); |
| 122 | |
} |
| 123 | |
} |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception { |
| 127 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 128 | 0 | Map<String, Object> myModel = new HashMap<String, Object>(); |
| 129 | 0 | myModel.put("userWebSession", userWebSession); |
| 130 | |
if (DEBUG) |
| 131 | |
logger.info("referenceData session " + userWebSession); |
| 132 | |
|
| 133 | 0 | return myModel; |
| 134 | |
} |
| 135 | |
|
| 136 | |
protected ModelAndView onSubmit( |
| 137 | |
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) |
| 138 | |
throws Exception { |
| 139 | |
|
| 140 | 0 | SystemSetupForm ssf = (SystemSetupForm) command; |
| 141 | |
|
| 142 | 0 | boolean success = true; |
| 143 | 0 | if (ssf.isClickedDeleteCache()) |
| 144 | 0 | success = false; |
| 145 | 0 | if (ssf.isDeleteCacheConfirmed()) { |
| 146 | 0 | pmf.getThumbCache().deleteCache(); |
| 147 | 0 | success = true; |
| 148 | |
} else { |
| 149 | |
if (DEBUG) |
| 150 | |
logger.info("engineOn=" + String.valueOf(ssf.getSystem().isEngineOn())); |
| 151 | |
|
| 152 | 0 | System newSystem = ssf.getSystem(); |
| 153 | |
|
| 154 | 0 | dbf.saveSystem(newSystem); |
| 155 | |
|
| 156 | |
} |
| 157 | 0 | pmf.setupThumbCache(); |
| 158 | 0 | if (success) { |
| 159 | 0 | response.sendRedirect("home.do"); |
| 160 | 0 | return(null); |
| 161 | |
} |
| 162 | |
else |
| 163 | 0 | return super.onSubmit(request, response, command, errors); |
| 164 | |
} |
| 165 | |
} |