brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbouron <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #821: REST API for accessing adjuncts (includin...
Date Thu, 28 Sep 2017 13:12:42 GMT
Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/821#discussion_r141607044
  
    --- 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 --
    
    You can group the loops of the same type, that would reduce in half the processing time


---

Mime
View raw message