Search in sources :

Example 1 with HideOnCloud

use of org.graylog2.shared.rest.HideOnCloud in project graylog2-server by Graylog2.

the class PrefixAddingModelProcessor method processResourceModel.

@Override
public ResourceModel processResourceModel(ResourceModel model, Configuration config) {
    // Create new resource model.
    final ResourceModel.Builder resourceModelBuilder = new ResourceModel.Builder(false);
    for (final Resource resource : model.getResources()) {
        for (Class<?> handlerClass : resource.getHandlerClasses()) {
            final HideOnCloud hideOnCloud = handlerClass.getAnnotation(HideOnCloud.class);
            if (hideOnCloud != null && configuration.isCloud()) {
                break;
            }
            final String packageName = handlerClass.getPackage().getName();
            final Optional<String> packagePrefix = packagePrefixes.entrySet().stream().filter(entry -> packageName.startsWith(entry.getKey())).sorted((o1, o2) -> -o1.getKey().compareTo(o2.getKey())).map(Map.Entry::getValue).findFirst();
            if (packagePrefix.isPresent()) {
                final String prefixedPath = prefixPath(packagePrefix.get(), resource.getPath());
                final Resource newResource = Resource.builder(resource).path(prefixedPath).build();
                resourceModelBuilder.addResource(newResource);
            } else {
                resourceModelBuilder.addResource(resource);
            }
        }
    }
    return resourceModelBuilder.build();
}
Also used : HideOnCloud(org.graylog2.shared.rest.HideOnCloud) Provider(javax.ws.rs.ext.Provider) ImmutableMap(com.google.common.collect.ImmutableMap) Configuration(javax.ws.rs.core.Configuration) Map(java.util.Map) ResourceModel(org.glassfish.jersey.server.model.ResourceModel) Optional(java.util.Optional) ModelProcessor(org.glassfish.jersey.server.model.ModelProcessor) Resource(org.glassfish.jersey.server.model.Resource) Resource(org.glassfish.jersey.server.model.Resource) ResourceModel(org.glassfish.jersey.server.model.ResourceModel) HideOnCloud(org.graylog2.shared.rest.HideOnCloud) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Configuration (javax.ws.rs.core.Configuration)1 Provider (javax.ws.rs.ext.Provider)1 ModelProcessor (org.glassfish.jersey.server.model.ModelProcessor)1 Resource (org.glassfish.jersey.server.model.Resource)1 ResourceModel (org.glassfish.jersey.server.model.ResourceModel)1 HideOnCloud (org.graylog2.shared.rest.HideOnCloud)1