This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 359b4e5e6b0c5f23e5e8a5b6d3e3da538b56dda7
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon May 31 15:45:21 2021 +0100

    fix entity resolution logic
    
    some places expected a function whereas they were being passed the root 
node to search from
---
 .../components/providers/dsl-service.provider.js   | 13 +-----------
 .../app/components/util/model/dsl.model.js         | 23 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git 
a/ui-modules/blueprint-composer/app/components/providers/dsl-service.provider.js
 
b/ui-modules/blueprint-composer/app/components/providers/dsl-service.provider.js
index ae89b37..ee783a6 100644
--- 
a/ui-modules/blueprint-composer/app/components/providers/dsl-service.provider.js
+++ 
b/ui-modules/blueprint-composer/app/components/providers/dsl-service.provider.js
@@ -57,18 +57,7 @@ function DslService($log) {
      * @return {Dsl} a Dsl object containing relationships (referenced 
Entities)
      */
     function parse(dsl, entity, blueprint) {
-        return new DslParser(dsl).parse(entity, function lookupById(id, entity 
= blueprint) {
-            if (entity.id === id) {
-                return entity;
-            }
-            for (let child of entity.childrenAsMap.values()) {
-                let ret = lookupById(id, child);
-                if (ret !== null) {
-                    return ret;
-                }
-            }
-            return null;
-        });
+        return new DslParser(dsl).parse(entity, blueprint);
     }
 
     /**
diff --git 
a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js 
b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
index 0caa5e4..2c1fb40 100644
--- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
+++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
@@ -636,6 +636,21 @@ export class Dsl {
 
 }
 
+function fnLookupInDescendantsById(root) {
+    return id => {
+        if (root.id === id) {
+            return root;
+        }
+        for (let child of root.childrenAsMap.values()) {
+            let ret = fnLookupInDescendantsById(child)(id);
+            if (ret !== null) {
+                return ret;
+            }
+        }
+        return null;
+    };
+}
+
 /**
  * A parser for Dsl expressions.
  */
@@ -653,9 +668,9 @@ export class DslParser {
      * @param {function} entityResolver a function to resolve an entity from 
an ID
      * @return {Dsl} the Dsl object representing this expression
      */
-    parse(entity, entityResolver) {
+    parse(entity, entityResolverOrRoot) {
         if (this.s instanceof String || typeof this.s === 'string') {
-            return this.parseString(this.s.toString().trim(), entity, 
entityResolver);
+            return this.parseString(this.s.toString().trim(), entity, 
entityResolverOrRoot);
         }
         // NUMBER and OTHER kinds are in the CONSTANT family which means they 
aren't DSL expressions
         // (API here could be improved!)
@@ -676,7 +691,9 @@ export class DslParser {
      * @param {function} entityResolver a function to resolve an entity from 
an ID
      * @return {Dsl} the Dsl object representing the expression in s
      */
-    parseString(s, entity, entityResolver) {
+    parseString(s, entity, entityResolverOrRoot) {
+        const entityResolver = (typeof entityResolverOrRoot === 'function') ? 
entityResolverOrRoot : fnLookupInDescendantsById(entityResolverOrRoot);
+
         let t = new Tokenizer(s);
         let dsl = this.expression(t);
         t.skipWhitespace();

Reply via email to