Search in sources :

Example 1 with RequestMappingContext

use of org.ambraproject.wombat.config.site.RequestMappingContext 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

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 RequestMappingContext (org.ambraproject.wombat.config.site.RequestMappingContext)1 RequestMappingContextDictionary (org.ambraproject.wombat.config.site.RequestMappingContextDictionary)1 Site (org.ambraproject.wombat.config.site.Site)1