From 4cbab258632bd0c8cb66801d2df9217892022367 Mon Sep 17 00:00:00 2001 From: akaash2512 Date: Mon, 3 Feb 2025 23:46:40 +0100 Subject: [PATCH 1/4] feat(editor): added script for value finder --- .../frontend/model/samples/value-finder.json | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main/frontend/model/samples/value-finder.json diff --git a/src/main/frontend/model/samples/value-finder.json b/src/main/frontend/model/samples/value-finder.json new file mode 100644 index 0000000..d362445 --- /dev/null +++ b/src/main/frontend/model/samples/value-finder.json @@ -0,0 +1,81 @@ +{ + "logLevel":"info", + "hops":[ + { + "type":"runScript", + "code":"output = utils.file.txt(\"properties_containing_hardcoded_urls\");\nSQL2Query = str:join([\"SELECT * FROM [nt:base] AS node WHERE ISDESCENDANTNODE([\",args.path,\"])\"])\nif (args.resourceTypeInclude != null && args.resourceTypeInclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] LIKE \\\"\",args.resourceTypeInclude,\"\\\"\"])\n}\nif (args.resourceTypeExclude != null && args.resourceTypeExclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] NOT LIKE \\\"\",args.resourceTypeExclude,\"\\\"\"])\n}", + "extension":"jexl", + "putLocalsBackIntoScope":true + }, + { + "type":"nodeQuery", + "query":"${SQL2Query}", + "queryType":"JCR-SQL2", + "hops":[ + { + "type":"each", + "expression":"node.properties", + "hops":[ + { + "type":"filterNode", + "expression":"str:contains(property.name, args.propertyName)", + "hops":[ + { + "type":"declare", + "declarations":{ + "joinedPropertyValue":"str:join(jcr:vals(node, property.name))" + } + }, + { + "type":"filterNode", + "expression":"str:contains(joinedPropertyValue, args.propertyValue)", + "hops":[ + { + "type":"runScript", + "code":"output.append(node.path);\noutput.append(\"-\");\noutput.append(property.name);\noutput.append(\":\");\noutput.append(joinedPropertyValue);\noutput.append(\"\\n\");", + "extension":"jexl", + "putLocalsBackIntoScope":true + } + ] + } + ] + } + ], + "iterator":"property" + } + ] + } + ], + "parameters":[ + { + "name":"path", + "defaultValue":"/content/project/de", + "type":"text", + "evaluation":"STRING" + }, + { + "name":"resourceTypeInclude", + "defaultValue":"", + "type":"text", + "evaluation":"STRING" + }, + { + "name":"resourceTypeExclude", + "defaultValue":"", + "type":"text", + "evaluation":"STRING" + }, + { + "name":"propertyName", + "defaultValue":"textIsTrue", + "type":"text", + "evaluation":"STRING" + }, + { + "name":"propertyValue", + "defaultValue":"false", + "type":"text", + "evaluation":"STRING" + } + ] +} From 41261e2d2f22f4260012233c108b28837afa64e9 Mon Sep 17 00:00:00 2001 From: TAABAAK2 Date: Tue, 4 Feb 2025 12:09:08 +0100 Subject: [PATCH 2/4] fix(editor): formatting issues --- .../frontend/model/samples/value-finder.json | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/main/frontend/model/samples/value-finder.json b/src/main/frontend/model/samples/value-finder.json index d362445..9c7667e 100644 --- a/src/main/frontend/model/samples/value-finder.json +++ b/src/main/frontend/model/samples/value-finder.json @@ -1,81 +1,81 @@ { - "logLevel":"info", - "hops":[ - { - "type":"runScript", - "code":"output = utils.file.txt(\"properties_containing_hardcoded_urls\");\nSQL2Query = str:join([\"SELECT * FROM [nt:base] AS node WHERE ISDESCENDANTNODE([\",args.path,\"])\"])\nif (args.resourceTypeInclude != null && args.resourceTypeInclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] LIKE \\\"\",args.resourceTypeInclude,\"\\\"\"])\n}\nif (args.resourceTypeExclude != null && args.resourceTypeExclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] NOT LIKE \\\"\",args.resourceTypeExclude,\"\\\"\"])\n}", - "extension":"jexl", - "putLocalsBackIntoScope":true - }, - { - "type":"nodeQuery", - "query":"${SQL2Query}", - "queryType":"JCR-SQL2", - "hops":[ - { - "type":"each", - "expression":"node.properties", - "hops":[ - { - "type":"filterNode", - "expression":"str:contains(property.name, args.propertyName)", - "hops":[ - { - "type":"declare", - "declarations":{ - "joinedPropertyValue":"str:join(jcr:vals(node, property.name))" - } - }, - { - "type":"filterNode", - "expression":"str:contains(joinedPropertyValue, args.propertyValue)", - "hops":[ - { - "type":"runScript", - "code":"output.append(node.path);\noutput.append(\"-\");\noutput.append(property.name);\noutput.append(\":\");\noutput.append(joinedPropertyValue);\noutput.append(\"\\n\");", - "extension":"jexl", - "putLocalsBackIntoScope":true - } - ] - } - ] - } - ], - "iterator":"property" - } - ] - } - ], - "parameters":[ - { - "name":"path", - "defaultValue":"/content/project/de", - "type":"text", - "evaluation":"STRING" - }, - { - "name":"resourceTypeInclude", - "defaultValue":"", - "type":"text", - "evaluation":"STRING" - }, - { - "name":"resourceTypeExclude", - "defaultValue":"", - "type":"text", - "evaluation":"STRING" - }, - { - "name":"propertyName", - "defaultValue":"textIsTrue", - "type":"text", - "evaluation":"STRING" - }, - { - "name":"propertyValue", - "defaultValue":"false", - "type":"text", - "evaluation":"STRING" - } - ] + "logLevel": "info", + "hops": [ + { + "type": "runScript", + "code": "output = utils.file.txt(\"properties_containing_hardcoded_urls\");\nSQL2Query = str:join([\"SELECT * FROM [nt:base] AS node WHERE ISDESCENDANTNODE([\",args.path,\"])\"])\nif (args.resourceTypeInclude != null && args.resourceTypeInclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] LIKE \\\"\",args.resourceTypeInclude,\"\\\"\"])\n}\nif (args.resourceTypeExclude != null && args.resourceTypeExclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] NOT LIKE \\\"\",args.resourceTypeExclude,\"\\\"\"])\n}", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "nodeQuery", + "query": "${SQL2Query}", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "each", + "expression": "node.properties", + "hops": [ + { + "type": "filterNode", + "expression": "str:contains(property.name, args.propertyName)", + "hops": [ + { + "type": "declare", + "declarations": { + "joinedPropertyValue": "str:join(jcr:vals(node, property.name))" + } + }, + { + "type": "filterNode", + "expression": "str:contains(joinedPropertyValue, args.propertyValue)", + "hops": [ + { + "type": "runScript", + "code": "output.append(node.path);\noutput.append(\"-\");\noutput.append(property.name);\noutput.append(\":\");\noutput.append(joinedPropertyValue);\noutput.append(\"\\n\");", + "extension": "jexl", + "putLocalsBackIntoScope": true + } + ] + } + ] + } + ], + "iterator": "property" + } + ] + } + ], + "parameters": [ + { + "name": "path", + "defaultValue": "/content/project/de", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "resourceTypeInclude", + "defaultValue": "", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "resourceTypeExclude", + "defaultValue": "", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "propertyName", + "defaultValue": "textIsTrue", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "propertyValue", + "defaultValue": "false", + "type": "text", + "evaluation": "STRING" + } + ] } From 29c6f161f1702e715d3614c79489ec0d4d7d16ad Mon Sep 17 00:00:00 2001 From: TAABAAK2 Date: Wed, 5 Feb 2025 02:14:27 +0100 Subject: [PATCH 3/4] feat(editor): added sample for change property value --- .../frontend/model/samples/change-value.json | 54 +++++++++++++++++++ src/main/frontend/model/samples/index.ts | 11 +++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/frontend/model/samples/change-value.json diff --git a/src/main/frontend/model/samples/change-value.json b/src/main/frontend/model/samples/change-value.json new file mode 100644 index 0000000..fba7393 --- /dev/null +++ b/src/main/frontend/model/samples/change-value.json @@ -0,0 +1,54 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "each", + "expression": "args.transformRulesFile", + "hops": [ + { + "type": "runScript", + "code": "/*\n The transformRulesFile file should be in the form ; ex.:\n oldtext1;newtext1\n oldtext2;newtext2\n*/\n\nsplit = str:split(vals, ';');\n\nif(arr:getLength(split) == 2) {\n oldValue = split[0];\n newValue = split[1];\n} else {\n oldValue = \"\";\n newValue = \"\";\n}\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:base] AS node\nWHERE ISDESCENDANTNODE([${args.path}]) AND node.* LIKE '%${oldValue}%'", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "each", + "expression": "node.properties", + "hops": [ + { + "type": "runScript", + "code": "propertyValue = jcr:vals(node,property.name);\nnewPropertyValue = propertyValue;\nflag = false;\nif (propertyValue != null) {\n if (arr:getLength(propertyValue) == 1) {\n // Handle case when propertyValue is a single string\n if (propertyValue[0].class.name == 'java.lang.String' && propertyValue[0].contains(oldValue)) {\n newPropertyValue = propertyValue[0].replaceAll(oldValue, newValue);\n flag = true;\n }\n } else {\n // Handle case when propertyValue is an array (or iterable)\n newPropertyValue = [...];\n for (item : propertyValue){\n if (item.class.name == 'java.lang.String' && item.contains(oldValue)) {\n newItem = item.replaceAll(oldValue, newValue);\n newPropertyValue.add(newItem);\n flag = true;\n }else{\n newPropertyValue.add(item);\n }\n }\n }\n}\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "filterNode", + "expression": "flag == true", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "${property.name}", + "value": "newPropertyValue" + } + ] + } + ], + "iterator": "property" + } + ] + } + ], + "iterator": "vals" + } + ], + "parameters": [ + { "name": "path", "defaultValue": "/content/project/de", "type": "text", "evaluation": "STRING" }, + { "name": "transformRulesFile", "defaultValue": "", "type": "file", "evaluation": "LINES" } + ] +} diff --git a/src/main/frontend/model/samples/index.ts b/src/main/frontend/model/samples/index.ts index 0920d2d..77e0b0d 100644 --- a/src/main/frontend/model/samples/index.ts +++ b/src/main/frontend/model/samples/index.ts @@ -14,7 +14,8 @@ import renameProperty from './rename-property.json'; import addOrReplaceProperty from './add-or-replace-property.json'; import addNode from './add-node.json'; import renameNode from './rename-node.json'; - +import valueFinder from './value-finder.json'; +import changePropertyValue from './change-value.json'; import { Hop, HOP_DEFINITIONS } from '../hops'; import { Script } from '../Script'; @@ -85,6 +86,14 @@ export const SAMPLES: Sample[] = [ config: renameProperty as Script, label: 'Sample: Rename property', }, + { + config: valueFinder as Script, + label: 'Sample: Value Finder', + }, + { + config: changePropertyValue as Script, + label: 'Sample: Change Property Value', + }, { config: addNode as Script, label: 'Sample: Add node', From 14377df0ffc0e838ad529665ff584bc83ddf307e Mon Sep 17 00:00:00 2001 From: TAABAAK2 Date: Thu, 6 Feb 2025 01:10:24 +0100 Subject: [PATCH 4/4] fix(editor): fix review comments --- src/main/frontend/model/samples/value-finder.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/model/samples/value-finder.json b/src/main/frontend/model/samples/value-finder.json index 9c7667e..17ee6f9 100644 --- a/src/main/frontend/model/samples/value-finder.json +++ b/src/main/frontend/model/samples/value-finder.json @@ -1,15 +1,10 @@ { "logLevel": "info", "hops": [ - { - "type": "runScript", - "code": "output = utils.file.txt(\"properties_containing_hardcoded_urls\");\nSQL2Query = str:join([\"SELECT * FROM [nt:base] AS node WHERE ISDESCENDANTNODE([\",args.path,\"])\"])\nif (args.resourceTypeInclude != null && args.resourceTypeInclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] LIKE \\\"\",args.resourceTypeInclude,\"\\\"\"])\n}\nif (args.resourceTypeExclude != null && args.resourceTypeExclude.trim() != ''){\n SQL2Query = str:join ([SQL2Query,\" AND node.[sling:resourceType] NOT LIKE \\\"\",args.resourceTypeExclude,\"\\\"\"])\n}", - "extension": "jexl", - "putLocalsBackIntoScope": true - }, + { "type": "declare", "declarations": { "output": "utils.file.txt(\"properties_containing_hardcoded_urls\")" } }, { "type": "nodeQuery", - "query": "${SQL2Query}", + "query": "SELECT * FROM [nt:base] AS node WHERE ISDESCENDANTNODE([${args.path}])\n${(args.resourceTypeInclude != null && args.resourceTypeInclude.trim() != '') ? ` AND node.[sling:resourceType] LIKE \"${args.resourceTypeInclude}\"` : ''}\n${(args.resourceTypeExclude != null && args.resourceTypeExclude.trim() != '') ? ` AND node.[sling:resourceType] LIKE \"${args.resourceTypeExclude}\"` : ''}", "queryType": "JCR-SQL2", "hops": [ {