Coverage Report - com.buckosoft.PicMan.web.UserConfigFormController
 
Classes in this File Line Coverage Branch Coverage Complexity
UserConfigFormController
0%
0/38
0%
0/8
2.333
 
 1  
 /******************************************************************************
 2  
  * UserConfigFormController.java - The Spring controller to edit PicMan's User config
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2009 - Dick Balaska
 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  
 /** The Spring controller to edit the User's preferences
 27  
  * @author Dick Balaska
 28  
  * @since 2009/06/18
 29  
  * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/web/UserConfigFormController.java">UserConfigFormController.java</a>
 30  
  */
 31  
 public class UserConfigFormController extends BSAccountSimpleFormController {
 32  
 
 33  
         private static final boolean DEBUG = true;
 34  0
     protected final Log logger = LogFactory.getLog(getClass());
 35  
 
 36  
         private PicManFacade        pmf;
 37  
         
 38  
         /** Set the reference to the PicMan API.
 39  
          * @param pmf The PicManFacade
 40  
          */
 41  0
         public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
 42  
 
 43  0
         public UserConfigFormController() {
 44  0
                 setSessionForm(true);
 45  0
                 setValidateOnBinding(false);
 46  0
                 setCommandName("userConfigForm");
 47  0
                 setFormView("UserConfigForm");
 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  0
                         logger.info("formBackingObject session " + userWebSession);
 57  0
                 UserConfigForm ucf = new UserConfigForm();
 58  
 
 59  0
                 ucf.setUserWebSession(userWebSession);
 60  0
                 ucf.setUser(user);
 61  0
                 ucf.setSets(pmf.getDB().getSets());
 62  
                 //logger.info("formBacking: roots=" + pmf.getSystem().getRoot(0));
 63  0
                 return(ucf);
 64  
         }
 65  
 
 66  
         protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
 67  
                         throws Exception {
 68  
                 if (DEBUG)
 69  0
                         logger.info("onBindAndValidate");
 70  0
                 UserConfigForm ucf = (UserConfigForm) command;
 71  0
                 User user = ucf.getUser();
 72  0
                 if (request.getParameter("user.picBrowserShowRatings") == null)
 73  0
                         user.setPicBrowserShowRatings(false);
 74  0
                 if (request.getParameter("user.homeDebug") == null)
 75  0
                         user.setHomeDebug(false);
 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  0
                 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  0
                 response.sendRedirect("home.do");
 93  
 
 94  0
                 UserConfigForm ucf = (UserConfigForm) command;
 95  0
                 pmf.getDB().storeUser(ucf.getUser());
 96  
                 
 97  0
                 if (success) {
 98  0
                         return(null);
 99  
                 }
 100  
                 else
 101  0
                         return super.onSubmit(request, response, command, errors);
 102  
         }
 103  
 }