Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser bug with custom function #244

Open
prabjohns-atex opened this issue Dec 9, 2021 · 2 comments
Open

Parser bug with custom function #244

prabjohns-atex opened this issue Dec 9, 2021 · 2 comments

Comments

@prabjohns-atex
Copy link

prabjohns-atex commented Dec 9, 2021

The following JSLT fails:


let images=[for (.associations) .value.renditions.original if (.value.type == "picture")]
let placecodes=[for (.place) .code if (.profile == "local-authority")]
let securityparents=security-parent-lookup("pa-local-authority",$placecodes[0], $properties.securityParentId, "externalid/dam.assets.incoming.d")
let autoPublish=property-lookup($securityparents[0],"auto-publish","false")

[
{
  "operations": [{
      "_type": "com.atex.onecms.content.SetAliasOperation",
      "namespace": "externalId",
      "alias": "p.DamVideo." + .uri
  }],
  "aspects": {
    "contentData": {
      "data": {
        "_type": "atex.dam.standard.Video",
        "inputTemplate": "p.DamVideo",
        "name": "Video-" + .headline,
        "headline": .headline,
        "description": .body_html ,
        "byline": .byline,
        "source": "PA Radar"
      }
    },
    "p.InsertionInfo": {
      "data": {
        "_type": "p.InsertionInfo",
        "securityParentId": $securityparents[0],
        "associatedSites": $securityparents[1:]
      }
    }
  }
 },
 {
    "dam.ExtraFiles": [
      for ($images) {"url": .href}
    ],
    "operations": [
        {
          "_type": "com.atex.onecms.content.SetAliasOperation",
          "namespace": "externalId",
          "alias": "p.DamWireArticle." + .uri
    }],
    "aspects": {
    "contentData": {
      "data": {
        "_type": "atex.onecms.article",
        "inputTemplate": "p.DamWireArticle",
        "name": "PA-" + .id + "-" + .headline,
        "headline": {"text": .headline},
        "lead" : {"text": .description_text},
        "body" : {"text": .body_html},
        "byline": .byline,
        "source": "PA Radar",
        "resources": ["externalid/p.DamVideo." + .uri]
      }
    },
    "p.InsertionInfo": {
      "data": {
        "_type": "p.InsertionInfo",
        "securityParentId": $securityparents[0],
        "associatedSites": $securityparents[1:]
      }
    },
    "atex.WebContentStatus": {
      "data": {
        "_type": "atex.WebContentStatus",
        "comment": "",
        "status": {
         "statusID":  if ($autoPublish == "true") "ready" else "not-ready",
          "users": [],
          "entryConditions": [],
          "attributes": [],
          "color": "orange",
          "next": [
            "inProgress",
            "review",
            "closed"
          ],
          "name": if ($autoPublish == "true") "ready" else "not-ready"
        }
      }
    },
    "atex.Metadata": {
      "data": {
        "_type": "atex.Metadata",
        "taxonomyIds": ["dam.d"],
        "metadata": {
          "dimensions": [
            {
              "enumerable": false,
              "id": "dimension.Tag",
              "name": "Tag",
              "entities": [for (.subject) {"name": .name}]
            },
            {
              "enumerable": false,
              "id": "dimension.Location",
              "name": "Location",
              "entities": [for (.place) {"name": .name}]
              },
            {
              "enumerable": false,
              "id": "dimension.partition",
              "name": "Partition",
              "entities": [{"name": "incoming", "id":"incoming"}]
              }
          ]
        }
      }
    }
  }
}]

with:

`
com.schibsted.spt.data.jslt.JsltException: Parse error: Encountered " "," ", "" at line 33, column 3.
Was expecting one of:
"]" ...
":" ...
"or" ...
"and" ...
"==" ...
"!=" ...
">=" ...
">" ...
"<" ...
"<=" ...
"+" ...
"-" ...
"*" ...
"/" ...
"|" ...
at :33:2

at com.schibsted.spt.data.jslt.parser.ParserImpl.compileExpression(ParserImpl.java:62)
at com.schibsted.spt.data.jslt.Parser.compile(Parser.java:226)
at com.schibsted.spt.data.jslt.Parser.compileString(Parser.java:86)
at com.atex.integration.camel.jslt.TestJsltCustomFunctions.callParser(TestJsltCustomFunctions.java:195)
at com.atex.integration.camel.jslt.TestJsltCustomFunctions.testLoadingFromTestJSLTNotReady(TestJsltCustomFunctions.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

`

However, add the line:
let dummy=true
at line 6, after the last let statement, and it compiles OK.

/*
    JSLT Function to lookup a property from a given security parent
 */
public class PropertyLookupFunction extends AbstractFunction {

    private PropertyProvider provider;

   public PropertyLookupFunction(PropertyProvider provider) {
       super("property-lookup", 2, 99);
        this.provider = provider;
    }

    @Override
    public JsonNode call(final JsonNode jsonNode, final JsonNode[] params) {

        String siteId = params[0].textValue();
        String key= params[1].textValue();

        String value = null;
        try {
            value = provider.getProperty(siteId, key);
        } catch (CMException e) {
            e.printStackTrace();
        }

        if (value == null) {
            if (params.length > 2) {
                for (int i = 2; i < params.length;i++) {
                    String val = params[i].textValue();
                    if (StringUtils.isNotBlank(val)) {
                        value = val;
                        break;
                    }
                }
            }
        }

        return value == null ? NullNode.instance : new TextNode(value);
    }
}

@prabjohns-atex
Copy link
Author

prabjohns-atex commented Dec 9, 2021

A simpler test case:

let test=is-array($securityparents[0],"auto-publish","false")
[
{
  "aspects": {
    "contentData": {
      "data": {
        "headline": .headline,
        "description": .body_html ,
        "byline": .byline
      }
    }
  }
 },
 {
    "aspects": {
    "contentData": {
      "data": {
        "_type": "atex.onecms.article",
        "lead" : {"text": .description_text},
        "source": "PA Radar",
        "resources": ["externalid/p.DamVideo." + .uri]
      }
    }
  }
}]

@prabjohns-atex
Copy link
Author

Actually, the bug appears to be the use of the array object. The use case is to take a single document and convert into an array of documents. Removing the "[" opening bracket solves the compilation, as does add a dummy let statement without a function.
So the combination of "[" and a function is breaking the parser somewhow.
I tried debugging, but I ran out of time,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant