Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 812BB200D20 for ; Mon, 2 Oct 2017 14:28:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7FC891609DE; Mon, 2 Oct 2017 12:28:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CE09C1609EF for ; Mon, 2 Oct 2017 14:28:08 +0200 (CEST) Received: (qmail 48923 invoked by uid 500); 2 Oct 2017 12:28:07 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 48885 invoked by uid 99); 2 Oct 2017 12:28:07 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Oct 2017 12:28:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 84C77E2F42; Mon, 2 Oct 2017 12:28:07 +0000 (UTC) From: aledsage To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #821: REST API for accessing adjuncts (includin... Content-Type: text/plain Message-Id: <20171002122807.84C77E2F42@git1-us-west.apache.org> Date: Mon, 2 Oct 2017 12:28:07 +0000 (UTC) archived-at: Mon, 02 Oct 2017 12:28:09 -0000 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)}. + *

+ * + * @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. ---