use of org.ambraproject.wombat.config.RuntimeConfigurationException in project wombat by PLOS.
the class SiteContentController method siteContentHomePage.
/**
* controller for site content home pages
*/
@RequestMapping(name = "siteContentHome", value = "/s", method = RequestMethod.GET)
public String siteContentHomePage(Model model, @SiteParam Site site) throws IOException {
Theme theme = site.getTheme();
Map<String, Object> pageConfig = theme.getConfigMap("siteContent");
String homeRepoKey = (String) pageConfig.get("homeRepoKey");
if (homeRepoKey == null) {
throw new RuntimeConfigurationException("Content repo key for site content home page not configured for theme " + theme.toString());
}
return renderSiteContent(model, site, homeRepoKey);
}
use of org.ambraproject.wombat.config.RuntimeConfigurationException in project wombat by PLOS.
the class SiteSet method validateSchemes.
/**
* @throws RuntimeConfigurationException if there a detectable collision between site config values
*/
private static void validateSchemes(Collection<Site> sites) {
Map<String, Site> keys = Maps.newHashMapWithExpectedSize(sites.size());
Map<SiteRequestScheme, Site> requestSchemes = Maps.newHashMapWithExpectedSize(sites.size());
for (Site site : sites) {
Site previous;
String key = site.getKey();
previous = keys.put(key, site);
if (previous != null) {
throw new RuntimeConfigurationException("Multiple sites have the same key: " + key);
}
/*
* Depends on the equals and hashCode implementations of the SiteRequestPredicate implementations contained in
* the SiteRequestScheme. If they don't provide good overrides, this check is still safe against false positives
* but may not catch all error conditions.
*/
SiteRequestScheme requestScheme = site.getRequestScheme();
previous = requestSchemes.put(requestScheme, site);
if (previous != null) {
String message = String.format("Multiple sites (%s, %s) have the same request scheme: %s", key, previous.getKey(), requestScheme);
throw new RuntimeConfigurationException(message);
}
}
}
use of org.ambraproject.wombat.config.RuntimeConfigurationException in project wombat by PLOS.
the class SiteContentController method renderSiteContent.
@RequestMapping(name = "siteContent", value = "/s/{pageName}")
public String renderSiteContent(Model model, @SiteParam Site site, @PathVariable String pageName) throws IOException {
Theme theme = site.getTheme();
Map<String, Object> pageConfig = theme.getConfigMap("siteContent");
String repoKeyPrefix = (String) pageConfig.get("contentRepoKeyPrefix");
if (repoKeyPrefix == null) {
throw new RuntimeConfigurationException("Content repo prefix not configured for theme " + theme.toString());
}
String repoKey = repoKeyPrefix + "." + pageName;
CacheKey cacheKey = CacheKey.create("siteContent_meta", repoKey);
// versioning is not supported for site content
ContentKey version = ContentKey.createForLatestVersion(repoKey);
try {
// Check for validity of the content repo key prior to rendering page. Return a 404 if no object found.
editorialContentApi.requestMetadata(cacheKey, version);
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
}
model.addAttribute("siteContentRepoKey", repoKey);
return site + "/ftl/siteContent/container";
}
Aggregations