| 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.domain.User; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
public class MosaicDisplayConfigFormController extends BSAccountSimpleFormController { |
| 32 | |
|
| 33 | |
private static final boolean DEBUG = false; |
| 34 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 35 | |
|
| 36 | |
private PicManFacade pmf; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | 0 | public void setPicMan(PicManFacade pmf) { this.pmf = pmf; } |
| 42 | |
|
| 43 | 0 | public MosaicDisplayConfigFormController() { |
| 44 | 0 | setSessionForm(true); |
| 45 | 0 | setValidateOnBinding(false); |
| 46 | 0 | setCommandName("mosaicDisplayConfigForm"); |
| 47 | 0 | setFormView("MosaicDisplayConfigForm"); |
| 48 | 0 | } |
| 49 | |
|
| 50 | |
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
| 51 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 52 | 0 | User user = null; |
| 53 | 0 | if (userWebSession != null) |
| 54 | 0 | user = (User)userWebSession.getUser(); |
| 55 | |
if (DEBUG) |
| 56 | |
logger.info("formBackingObject session " + userWebSession); |
| 57 | 0 | MosaicDisplayConfigForm mdcf = new MosaicDisplayConfigForm(); |
| 58 | |
|
| 59 | 0 | mdcf.setUserWebSession(userWebSession); |
| 60 | 0 | mdcf.setUser(user); |
| 61 | |
|
| 62 | |
String v; |
| 63 | 0 | v = request.getParameter("removeMosaics"); |
| 64 | 0 | if (v != null) { |
| 65 | 0 | int i = pmf.getMosaicMan().emptyMosaicQueue(); |
| 66 | 0 | mdcf.setMessage("Removed " + i + " queued Mosaics"); |
| 67 | |
} |
| 68 | 0 | return(mdcf); |
| 69 | |
} |
| 70 | |
|
| 71 | |
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) |
| 72 | |
throws Exception { |
| 73 | |
|
| 74 | |
if (DEBUG) |
| 75 | |
logger.info("onBindAndValidate"); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception { |
| 79 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 80 | 0 | Map<String, Object> myModel = new HashMap<String, Object>(); |
| 81 | 0 | myModel.put("userWebSession", userWebSession); |
| 82 | |
if (DEBUG) |
| 83 | |
logger.info("referenceData session " + userWebSession); |
| 84 | |
|
| 85 | 0 | return myModel; |
| 86 | |
} |
| 87 | |
|
| 88 | |
protected ModelAndView onSubmit( |
| 89 | |
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) |
| 90 | |
throws Exception { |
| 91 | 0 | boolean success = true; |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | 0 | MosaicDisplayConfigForm mdcf = (MosaicDisplayConfigForm) command; |
| 98 | |
|
| 99 | |
|
| 100 | 0 | pmf.getDB().storeUser(mdcf.getUser()); |
| 101 | |
|
| 102 | 0 | if (success) { |
| 103 | |
try { |
| 104 | 0 | if (!response.isCommitted()) |
| 105 | 0 | response.sendRedirect("mosaic.do"); |
| 106 | 0 | } catch (IllegalStateException e) { |
| 107 | 0 | return super.onSubmit(request, response, command, errors); |
| 108 | 0 | } |
| 109 | 0 | return(null); |
| 110 | |
} |
| 111 | |
else |
| 112 | 0 | return super.onSubmit(request, response, command, errors); |
| 113 | |
} |
| 114 | |
} |