Search in sources :

Example 26 with Site

use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.

the class SiteLinkDirective method getValue.

@Override
protected String getValue(Environment env, Map params) throws TemplateModelException, IOException {
    String path = getStringValue(params.get("path"));
    String targetJournal = getStringValue(params.get("journalKey"));
    String handlerName = getStringValue(params.get("handlerName"));
    boolean absoluteLink = TemplateModelUtil.getBooleanValue((TemplateModel) params.get("absoluteLink"));
    SitePageContext sitePageContext = new SitePageContext(siteResolver, env);
    Site site = sitePageContext.getSite();
    Link.Factory linkFactory = (targetJournal == null) ? (absoluteLink ? Link.toAbsoluteAddress(site) : Link.toLocalSite(site)) : Link.toForeignSite(site, targetJournal, siteSet);
    final Link link;
    if (handlerName != null) {
        Map<String, ?> variables = TemplateModelUtil.getAsMap((TemplateModel) params.get("pathVariables"));
        ListMultimap<String, ?> queryParameters = TemplateModelUtil.getAsMultimap((TemplateModel) params.get("queryParameters"));
        List<?> wildcardValues = TemplateModelUtil.getAsList((TemplateModel) params.get("wildcardValues"));
        link = linkFactory.toPattern(requestMappingContextDictionary, handlerName, variables, queryParameters, wildcardValues);
    } else if (path != null) {
        link = linkFactory.toPath(path);
    } else {
        throw new RuntimeException("Either a path or handlerName parameter is required");
    }
    return link.get(sitePageContext.getRequest());
}
Also used : Site(org.ambraproject.wombat.config.site.Site) Link(org.ambraproject.wombat.config.site.url.Link)

Example 27 with Site

use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.

the class AppRootPage method buildMappingTable.

private ImmutableList<MappingTableRow> buildMappingTable() {
    Table<RequestMappingContext, Site, String> table = HashBasedTable.create();
    Set<RequestMappingContext> sitelessMappings = new HashSet<>();
    ImmutableList<Site> allSites = siteSet.getSites().asList();
    for (RequestMappingContextDictionary.MappingEntry entry : requestMappingContextDictionary.getAll()) {
        RequestMappingContext mapping = entry.getMapping();
        Optional<Site> site = entry.getSite();
        String handlerName = entry.getHandlerName();
        if (site.isPresent()) {
            table.put(mapping, site.get(), handlerName);
        } else {
            sitelessMappings.add(mapping);
            for (Site s : allSites) {
                table.put(mapping, s, handlerName);
            }
        }
    }
    Set<RequestMappingContext> mappings = table.rowKeySet();
    List<MappingTableRow> rows = new ArrayList<>(mappings.size());
    for (final RequestMappingContext mapping : mappings) {
        final List<String> row = new ArrayList<>(allSites.size());
        for (Site site : allSites) {
            String cell = table.get(mapping, site);
            row.add(Strings.nullToEmpty(cell));
        }
        final String mappingRepresentation = represent(mapping);
        final boolean isGlobal = sitelessMappings.contains(mapping);
        rows.add(new MappingTableRow() {

            @Override
            public String getPattern() {
                return mappingRepresentation;
            }

            @Override
            public List<String> getRow() {
                return row;
            }

            @Override
            public boolean isGlobal() {
                return isGlobal;
            }
        });
    }
    return ROW_ORDERING.immutableSortedCopy(rows);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) ArrayList(java.util.ArrayList) RequestMappingContext(org.ambraproject.wombat.config.site.RequestMappingContext) RequestMappingContextDictionary(org.ambraproject.wombat.config.site.RequestMappingContextDictionary) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

Site (org.ambraproject.wombat.config.site.Site)27 HashMap (java.util.HashMap)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)7 Test (org.junit.Test)7 Link (org.ambraproject.wombat.config.site.url.Link)6 ImmutableList (com.google.common.collect.ImmutableList)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 SiteSet (org.ambraproject.wombat.config.site.SiteSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 StringWriter (java.io.StringWriter)4 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)4 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 RequestMappingContextDictionary (org.ambraproject.wombat.config.site.RequestMappingContextDictionary)3 Theme (org.ambraproject.wombat.config.theme.Theme)3 Logger (org.slf4j.Logger)3