@Test public final void testExecuteWithUrl() throws Exception { final String themeId = "http: final Theme testTheme = new Theme(themeId, "My Theme", "My Theme Description", "http: "authorName", "authorEmail"); context.checking(new Expectations() { { oneOf(personMapper).findById(userId); will(returnValue(person)); oneOf(themeMapper).findByUrl(themeId); will(returnValue(testTheme)); oneOf(person).setTheme(testTheme); allowing(person).getTheme(); oneOf(personMapper).flush(); never(themeMapper).findByUUID(with(any(String.class))); oneOf(deleteCacheKeysMapper).execute(with(any(Set.class))); } }); String actual = (String) sut.execute(buildServerActionContext(themeId)); assertEquals(testTheme.getCssFile(), actual); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { try { String themeId = (String) inActionContext.getParams(); Long userId = inActionContext.getPrincipal().getId(); Theme theme = (Theme) inActionContext.getState().get("THEME"); if (theme == null) { if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}")) { theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1)); } else { theme = themeMapper.findByUrl(themeId); } } if (theme == null) { throw new RuntimeException("Can't find theme."); } Person person = personMapper.findById(userId); log.debug("Got StartPage for " + inActionContext.getPrincipal().getAccountId()); person.setTheme(theme); personMapper.flush(); log.debug("Set theme to " + theme.getName()); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + userId)); return theme.getCssFile(); } catch (Exception ex) { throw new ExecutionException(ex); } }
SetPersonThemeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { try { String themeId = (String) inActionContext.getParams(); Long userId = inActionContext.getPrincipal().getId(); Theme theme = (Theme) inActionContext.getState().get("THEME"); if (theme == null) { if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}")) { theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1)); } else { theme = themeMapper.findByUrl(themeId); } } if (theme == null) { throw new RuntimeException("Can't find theme."); } Person person = personMapper.findById(userId); log.debug("Got StartPage for " + inActionContext.getPrincipal().getAccountId()); person.setTheme(theme); personMapper.flush(); log.debug("Set theme to " + theme.getName()); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + userId)); return theme.getCssFile(); } catch (Exception ex) { throw new ExecutionException(ex); } } }
SetPersonThemeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { try { String themeId = (String) inActionContext.getParams(); Long userId = inActionContext.getPrincipal().getId(); Theme theme = (Theme) inActionContext.getState().get("THEME"); if (theme == null) { if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}")) { theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1)); } else { theme = themeMapper.findByUrl(themeId); } } if (theme == null) { throw new RuntimeException("Can't find theme."); } Person person = personMapper.findById(userId); log.debug("Got StartPage for " + inActionContext.getPrincipal().getAccountId()); person.setTheme(theme); personMapper.flush(); log.debug("Set theme to " + theme.getName()); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + userId)); return theme.getCssFile(); } catch (Exception ex) { throw new ExecutionException(ex); } } SetPersonThemeExecution(final PersonMapper inPersonMapper, final ThemeMapper inThemeMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); }
SetPersonThemeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { try { String themeId = (String) inActionContext.getParams(); Long userId = inActionContext.getPrincipal().getId(); Theme theme = (Theme) inActionContext.getState().get("THEME"); if (theme == null) { if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}")) { theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1)); } else { theme = themeMapper.findByUrl(themeId); } } if (theme == null) { throw new RuntimeException("Can't find theme."); } Person person = personMapper.findById(userId); log.debug("Got StartPage for " + inActionContext.getPrincipal().getAccountId()); person.setTheme(theme); personMapper.flush(); log.debug("Set theme to " + theme.getName()); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + userId)); return theme.getCssFile(); } catch (Exception ex) { throw new ExecutionException(ex); } } SetPersonThemeExecution(final PersonMapper inPersonMapper, final ThemeMapper inThemeMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Serializable execute(final PrincipalActionContext inActionContext); }
SetPersonThemeExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { try { String themeId = (String) inActionContext.getParams(); Long userId = inActionContext.getPrincipal().getId(); Theme theme = (Theme) inActionContext.getState().get("THEME"); if (theme == null) { if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}")) { theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1)); } else { theme = themeMapper.findByUrl(themeId); } } if (theme == null) { throw new RuntimeException("Can't find theme."); } Person person = personMapper.findById(userId); log.debug("Got StartPage for " + inActionContext.getPrincipal().getAccountId()); person.setTheme(theme); personMapper.flush(); log.debug("Set theme to " + theme.getName()); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + userId)); return theme.getCssFile(); } catch (Exception ex) { throw new ExecutionException(ex); } } SetPersonThemeExecution(final PersonMapper inPersonMapper, final ThemeMapper inThemeMapper,
            final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Serializable execute(final PrincipalActionContext inActionContext);  }