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();
}
Aggregations