Index: lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java =================================================================== diff -u -rff998b6871c3f347f979a0181856fdf5c78b6813 -r321817ba99727a14bbe975a021341b14979ab9c3 --- lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java (.../ThemeAction.java) (revision ff998b6871c3f347f979a0181856fdf5c78b6813) +++ lams_central/src/java/org/lamsfoundation/lams/themes/web/ThemeAction.java (.../ThemeAction.java) (revision 321817ba99727a14bbe975a021341b14979ab9c3) @@ -42,8 +42,10 @@ import org.springframework.web.context.support.WebApplicationContextUtils; import org.lamsfoundation.lams.usermanagement.exception.UserException; -import org.lamsfoundation.lams.themes.exception.NoSuchThemeException; +import org.lamsfoundation.lams.themes.exception.ThemeException; +import org.lamsfoundation.lams.util.MessageService; + /** * * @author Mitchell Seaton @@ -75,6 +77,8 @@ 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; @@ -164,6 +168,8 @@ Integer userId = new Integer(WebUtil.readIntParam(request,USER_ID_PARAMETER)); String type = WebUtil.readStrParam(request, TYPE_PARAMETER, true); IThemeService themeService = getThemeService(); + MessageService messageService = themeService.getMessageService(); + flashMessage = null; try { @@ -173,10 +179,12 @@ flashMessage = themeService.setFlashTheme(userId, themeId); else if(type.equals(HTML_TYPE)) flashMessage = themeService.setHtmlTheme(userId, themeId); - } catch (NoSuchThemeException e) { - flashMessage = FlashMessage.getNoSuchTheme("wddxPacket",themeId); + else + throw new ThemeException(messageService.getMessage(IThemeService.NO_SUCH_THEME_TYPE_KEY)); + } catch (ThemeException e) { + flashMessage = new FlashMessage("wddxPacket", e.getMessage(), FlashMessage.ERROR); } catch (UserException e) { - flashMessage = FlashMessage.getNoSuchUserExists("wddxPacket", userId); + flashMessage = new FlashMessage("wddxPacket", e.getMessage(), FlashMessage.ERROR); } catch ( Exception e) { flashMessage = FlashMessage.getExceptionOccured("setTheme", e.getMessage()); } Index: lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java =================================================================== diff -u -rff998b6871c3f347f979a0181856fdf5c78b6813 -r321817ba99727a14bbe975a021341b14979ab9c3 --- lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java (.../IThemeService.java) (revision ff998b6871c3f347f979a0181856fdf5c78b6813) +++ lams_common/src/java/org/lamsfoundation/lams/themes/service/IThemeService.java (.../IThemeService.java) (revision 321817ba99727a14bbe975a021341b14979ab9c3) @@ -27,7 +27,8 @@ 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.themes.exception.ThemeException; +import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.wddx.FlashMessage; /** @@ -49,8 +50,16 @@ /** Key for saving Html Theme for user */ public static final String HTML_KEY = "theme.service.setTheme.saved"; + public static final String NO_SUCH_THEME_TYPE_KEY = "theme.service.setTheme.type.invalid"; + public static final String NO_SUCH_THEME_KEY = "theme.service.setTheme.noSuchTheme"; + public static final String NO_SUCH_USER_KEY = "theme.service.setTheme.noSuchUser"; + + public void setMessageService(MessageService messageService); + + public MessageService getMessageService(); + /** * Set IThemeDAO * @@ -97,10 +106,10 @@ public String getThemes() throws IOException; - public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; + public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException; - public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; + public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException; - public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException; + public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException; } Index: lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java =================================================================== diff -u -rff998b6871c3f347f979a0181856fdf5c78b6813 -r321817ba99727a14bbe975a021341b14979ab9c3 --- lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java (.../ThemeService.java) (revision ff998b6871c3f347f979a0181856fdf5c78b6813) +++ lams_common/src/java/org/lamsfoundation/lams/themes/service/ThemeService.java (.../ThemeService.java) (revision 321817ba99727a14bbe975a021341b14979ab9c3) @@ -42,7 +42,7 @@ import com.allaire.wddx.WddxDeserializationException; import org.lamsfoundation.lams.util.MessageService; -import org.lamsfoundation.lams.themes.exception.NoSuchThemeException; +import org.lamsfoundation.lams.themes.exception.ThemeException; /** * @@ -193,14 +193,14 @@ * @return String The acknowledgement or error in WDDX format * @throws IOException */ - private FlashMessage setTheme(Integer userId, Long themeId, String type) throws IOException, NoSuchThemeException, UserException { + private FlashMessage setTheme(Integer userId, Long themeId, String type) throws IOException, ThemeException, UserException { User user = userDAO.getUserById(userId); CSSThemeVisualElement theme = themeDAO.getThemeById(themeId); if(theme==null) - throw new NoSuchThemeException(); + throw new ThemeException(messageService.getMessage(IThemeService.NO_SUCH_THEME_KEY)); else if(user==null) - throw new UserException(); + throw new UserException(messageService.getMessage(IThemeService.NO_SUCH_USER_KEY)); else{ if(type==null) { user.setHtmlTheme(theme); @@ -225,7 +225,7 @@ * @return FlashMessage The acknowledgement or error in WDDX format * @throws IOException */ - public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + public FlashMessage setTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException { return setTheme(userId, themeId, null); } @@ -235,7 +235,7 @@ * @return FlashMessage The acknowledgement or error in WDDX format * @throws IOException */ - public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + public FlashMessage setHtmlTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException { return setTheme(userId, themeId, IThemeService.HTML_KEY); } @@ -245,7 +245,7 @@ * @return FlashMessage The acknowledgement or error in WDDX format * @throws IOException */ - public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, NoSuchThemeException, UserException { + public FlashMessage setFlashTheme(Integer userId, Long themeId) throws IOException, ThemeException, UserException { return setTheme(userId, themeId, IThemeService.FLASH_KEY); }