{
String themeId = (String) inActionContext.getParams();
Long userId = inActionContext.getPrincipal().getId();
// try grabbing theme from validation
Theme theme = (Theme) inActionContext.getState().get("THEME");
if (theme == null)
{
if (themeId.startsWith("{") && themeId.substring(themeId.length() - 1).equals("}"))
{
// theme is UUID
theme = themeMapper.findByUUID(themeId.substring(1, themeId.length() - 1));
}
else
{
// Theme is a URL, find or create.
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);
}