Index: lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java,v diff -u -r1.1 -r1.2 --- lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java 9 Mar 2006 00:02:12 -0000 1.1 +++ lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java 24 Mar 2006 00:04:41 -0000 1.2 @@ -36,10 +36,14 @@ import org.lamsfoundation.lams.themes.service.IThemeService; import org.lamsfoundation.lams.themes.web.ThemeConstants; import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.util.wddx.FlashMessage; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; +import org.lamsfoundation.lams.usermanagement.exception.UserException; +import org.lamsfoundation.lams.themes.exception.NoSuchThemeException; + /** * * @author Mitchell Seaton @@ -66,6 +70,14 @@ /** Id of user setting the new theme */ public static final String USER_ID_PARAMETER = "userID"; + /** The type the theme should be set for i.e. flash or jsp */ + public static final String TYPE_PARAMETER = "type"; + public static final String HTML_TYPE = "html"; + public static final String FLASH_TYPE = "flash"; + + /** for sending acknowledgment/error messages back to flash */ + private FlashMessage flashMessage; + public IThemeService getThemeService(){ WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServlet().getServletContext()); return (IThemeService) webContext.getBean(ThemeConstants.THEME_SERVICE_BEAN_NAME); @@ -150,12 +162,27 @@ Long themeId = new Long(WebUtil.readLongParam(request,THEME_ID_PARAMETER)); Integer userId = new Integer(WebUtil.readIntParam(request,USER_ID_PARAMETER)); - + String type = WebUtil.readStrParam(request, TYPE_PARAMETER, true); IThemeService themeService = getThemeService(); - String message = themeService.setTheme(userId, themeId); - request.getSession().setAttribute("message",message); - return outputPacket(mapping, request, response, message, "message"); + flashMessage = null; + try { + if(type==null) + flashMessage = themeService.setTheme(userId, themeId); + else if(type.equals(FLASH_TYPE)) + flashMessage = themeService.setFlashTheme(userId, themeId); + else if(type.equals(HTML_TYPE)) + flashMessage = themeService.setHtmlTheme(userId, themeId); + } catch (NoSuchThemeException e) { + flashMessage = FlashMessage.getNoSuchTheme("wddxPacket",themeId); + } catch (UserException e) { + flashMessage = FlashMessage.getNoSuchUserExists("wddxPacket", userId); + } catch ( Exception e) { + flashMessage = FlashMessage.getExceptionOccured("setTheme", e.getMessage()); + } + request.getSession().setAttribute("message", flashMessage.serializeMessage()); + return outputPacket(mapping, request, response, flashMessage.serializeMessage(), "message"); + } } Index: lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java,v diff -u -r1.2 -r1.3 --- lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java 8 Mar 2006 23:55:02 -0000 1.2 +++ lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java 24 Mar 2006 00:01:04 -0000 1.3 @@ -26,6 +26,9 @@ import org.lamsfoundation.lams.usermanagement.dao.IUserDAO; import org.lamsfoundation.lams.themes.dao.ICSSThemeDAO; +import org.lamsfoundation.lams.usermanagement.exception.UserException; +import org.lamsfoundation.lams.themes.exception.NoSuchThemeException; +import org.lamsfoundation.lams.util.wddx.FlashMessage; /** * @@ -40,6 +43,14 @@ /** Message key for successful saved theme - setTheme() method */ public static final String SET_THEME_SAVED_MESSAGE_KEY = "theme.service.setTheme.saved"; + /** Key for saving Flash theme for user */ + public static final String FLASH_KEY = "flash"; + + /** Key for saving Html Theme for user */ + public static final String HTML_KEY = "theme.service.setTheme.saved"; + + + /** * Set IThemeDAO * @@ -86,6 +97,10 @@ public String getThemes() throws IOException; - public String setTheme(Integer userId, Long themeId) throws IOException; + public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; + + public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; + + public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; } Index: lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java,v diff -u -r1.2 -r1.3 --- lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java 8 Mar 2006 23:55:02 -0000 1.2 +++ lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java 24 Mar 2006 00:00:55 -0000 1.3 @@ -35,12 +35,15 @@ import org.lamsfoundation.lams.themes.dto.CSSThemeDTO; import org.lamsfoundation.lams.usermanagement.dao.IUserDAO; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.exception.UserException; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.wddx.FlashMessage; import org.lamsfoundation.lams.util.wddx.WDDXProcessor; import com.allaire.wddx.WddxDeserializationException; import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.themes.exception.NoSuchThemeException; + /** * * @author Mitchell Seaton @@ -190,22 +193,61 @@ * @return String The acknowledgement or error in WDDX format * @throws IOException */ - public String setTheme(Integer userId, Long themeId) throws IOException { + private FlashMessage setTheme(Integer userId, Long themeId, String type) throws IOException, NoSuchThemeException, UserException { User user = userDAO.getUserById(userId); CSSThemeVisualElement theme = themeDAO.getThemeById(themeId); if(theme==null) - flashMessage = FlashMessage.getNoSuchTheme("wddxPacket",themeId); + throw new NoSuchThemeException(); else if(user==null) - flashMessage = FlashMessage.getNoSuchUserExists("wddxPacket", userId); + throw new UserException(); else{ - user.setTheme(theme); + if(type==null) { + user.setHtmlTheme(theme); + user.setFlashTheme(theme); + } + else if(type.equals(IThemeService.FLASH_KEY)) + user.setFlashTheme(theme); + + else if(type.equals(IThemeService.HTML_KEY)) + user.setHtmlTheme(theme); + userDAO.updateUser(user); flashMessage = new FlashMessage("setTheme", messageService.getMessage(IThemeService.SET_THEME_SAVED_MESSAGE_KEY)); } - return flashMessage.serializeMessage(); + return flashMessage; } + /** + * Set the User's theme (Common) + * + * @return FlashMessage The acknowledgement or error in WDDX format + * @throws IOException + */ + public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + return setTheme(userId, themeId, null); + } + /** + * Set the User's HTML theme + * + * @return FlashMessage The acknowledgement or error in WDDX format + * @throws IOException + */ + public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + return setTheme(userId, themeId, IThemeService.HTML_KEY); + } + + /** + * Set the User's Flash theme + * + * @return FlashMessage The acknowledgement or error in WDDX format + * @throws IOException + */ + public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + return setTheme(userId, themeId, IThemeService.FLASH_KEY); + } + + } \ No newline at end of file