Search in sources :

Example 1 with RuntimeConfigurationException

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);
}
Also used : RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) Theme(org.ambraproject.wombat.config.theme.Theme) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RuntimeConfigurationException

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);
        }
    }
}
Also used : RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme)

Example 3 with RuntimeConfigurationException

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";
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) Theme(org.ambraproject.wombat.config.theme.Theme) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) CacheKey(org.ambraproject.wombat.util.CacheKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RuntimeConfigurationException (org.ambraproject.wombat.config.RuntimeConfigurationException)3 Theme (org.ambraproject.wombat.config.theme.Theme)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)1 EntityNotFoundException (org.ambraproject.wombat.service.EntityNotFoundException)1 ContentKey (org.ambraproject.wombat.service.remote.ContentKey)1 CacheKey (org.ambraproject.wombat.util.CacheKey)1