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', 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..17ee6f9 --- /dev/null +++ b/src/main/frontend/model/samples/value-finder.json @@ -0,0 +1,76 @@ +{ + "logLevel": "info", + "hops": [ + { "type": "declare", "declarations": { "output": "utils.file.txt(\"properties_containing_hardcoded_urls\")" } }, + { + "type": "nodeQuery", + "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": [ + { + "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" + } + ] +}