Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/821#discussion_r142124445
--- Diff:
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
---
@@ -130,6 +143,36 @@ public Policy getPolicy(Entity entity, String policy) {
throw WebResourceUtils.notFound("Cannot find policy '%s' in entity
'%s'", policy, entity);
}
+
+ /** finds the policy indicated by the given ID or name.
+ * @see {@link #getAdjunct(String,String,String)}.
+ * <p>
+ *
+ * @throws 404 or 412 (unless input is null in which case output is
null) */
+ public EntityAdjunct getAdjunct(Entity entity, String adjunct) {
+ if (adjunct==null) return null;
+
+ for (Policy p: entity.policies()) {
+ if (adjunct.equals(p.getId())) return p;
+ }
+ for (Policy p: entity.policies()) {
+ if (adjunct.equals(p.getDisplayName())) return p;
+ }
+ for (Enricher p: entity.enrichers()) {
+ if (adjunct.equals(p.getId())) return p;
+ }
+ for (Enricher p: entity.enrichers()) {
+ if (adjunct.equals(p.getDisplayName())) return p;
+ }
+ for (Feed p: ((EntityInternal)entity).feeds()) {
+ if (adjunct.equals(p.getId())) return p;
+ }
+ for (Feed p: ((EntityInternal)entity).feeds()) {
+ if (adjunct.equals(p.getDisplayName())) return p;
+ }
--- End diff --
Depends whether we worry about a display name being the same as an id
anywhere - and thus what guarantees we're trying to give.
I probably agree @tbouron. If we do want to keep them separate, we should
iterate over all ids (policies, enrichers, feeds) before going on to display
names.
---