From 5516e12ea61052cf72e695f5866467070186bc44 Mon Sep 17 00:00:00 2001 From: marcofra Date: Mon, 16 Dec 2024 11:14:24 +0100 Subject: [PATCH 01/12] feat(editor): add additional sample scripts --- src/main/frontend/model/samples/add-node.json | 43 +++++++++++ .../samples/add-or-replace-property.json | 33 ++++++++ .../samples/batch-search-and-replace.json | 77 +++++++++++++++++++ .../model/samples/check-hardcoded-urls.json | 70 +++++++++++++++++ .../frontend/model/samples/delete-nodes.json | 26 +++++++ src/main/frontend/model/samples/index.ts | 45 +++++++++++ .../model/samples/migrate-resource-type.json | 46 +++++++++++ .../remove-deprecated-legacy-urls.json | 51 ++++++++++++ .../frontend/model/samples/rename-node.json | 38 +++++++++ .../model/samples/rename-property.json | 32 ++++++++ 10 files changed, 461 insertions(+) create mode 100644 src/main/frontend/model/samples/add-node.json create mode 100644 src/main/frontend/model/samples/add-or-replace-property.json create mode 100644 src/main/frontend/model/samples/batch-search-and-replace.json create mode 100644 src/main/frontend/model/samples/check-hardcoded-urls.json create mode 100644 src/main/frontend/model/samples/delete-nodes.json create mode 100644 src/main/frontend/model/samples/migrate-resource-type.json create mode 100644 src/main/frontend/model/samples/remove-deprecated-legacy-urls.json create mode 100644 src/main/frontend/model/samples/rename-node.json create mode 100644 src/main/frontend/model/samples/rename-property.json diff --git a/src/main/frontend/model/samples/add-node.json b/src/main/frontend/model/samples/add-node.json new file mode 100644 index 0000000..2292f85 --- /dev/null +++ b/src/main/frontend/model/samples/add-node.json @@ -0,0 +1,43 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "nodeName": "\"nName\"", + "jcrPrimaryType": "\"cq:PageContent\"", + "slingResourceType": "\"swisscom/components/structure/page\"" + } + }, + { + "type": "each", + "expression": "['de', 'fr', 'it', 'en']", + "hops": [ + { + "type": "nodeQuery", + "query": "/* The search query has to return the parent nodes we want to act on */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}])", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "createChildNode", + "conflict": "force", + "name": "${nodeName}", + "runOnExistingNode": false, + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "sling:resourceType", + "value": "slingResourceType" + } + ], + "primaryType": "${jcrPrimaryType}" + } + ] + } + ], + "iterator": "lang" + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/add-or-replace-property.json b/src/main/frontend/model/samples/add-or-replace-property.json new file mode 100644 index 0000000..2b8fd58 --- /dev/null +++ b/src/main/frontend/model/samples/add-or-replace-property.json @@ -0,0 +1,33 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "propertyName": "\"pName\"", + "propertyValue": "\"pValue\"" + } + }, + { + "type": "each", + "expression": "['de', 'fr', 'it', 'en']", + "hops": [ + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}])", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "${propertyName}", + "value": "propertyValue" + } + ] + } + ], + "iterator": "lang" + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/batch-search-and-replace.json b/src/main/frontend/model/samples/batch-search-and-replace.json new file mode 100644 index 0000000..7a45478 --- /dev/null +++ b/src/main/frontend/model/samples/batch-search-and-replace.json @@ -0,0 +1,77 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] WHERE ISDESCENDANTNODE([/content/example]) AND [sling:resourceType] = 'granite/ui/components/coral/foundation/form/textfield'", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "each", + "expression": "args.inputPropertyValues", + "hops": [ + { + "type": "runScript", + "code": "/*\n The inputPropertyValues file should be in the format ,, ex.:\n propertyName,oldVal,newVal\n propertyName1,oldVal1,newVal1\n*/\n\nsplitted = str:split(vals, ',');\n\nif(arr:getLength(splitted) == 3) {\n propertyName = splitted[0];\n oldValue = splitted[1];\n newValue = splitted[2];\n} else {\n propertyName = \"\";\n oldValue = \"\";\n newValue = \"\";\n}\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "filterNode", + "expression": "jcr:val(node, propertyName) == oldValue", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "${propertyName}", + "value": "newValue" + } + ] + } + ], + "iterator": "vals" + } + ] + }, + { + "type": "each", + "expression": "args.inputXPath", + "hops": [ + { + "type": "runScript", + "code": "/*\n The inputXPath file should be in the form ;; ex.:\n propertyName;/jcr:root/content/swisscom/de//*[@sling:resourceType='foundation/components/parsys']/*[not(@sling:resourceType)];newVal\n propertyName1;/jcr:root/content/swisscom/de//*[(jcr:like(@sling:resourceType, 'swisscom/components/content/text'))];newVal1\n*/\n\nsplitted = str:split(vals, ';');\n\nif(arr:getLength(splitted) == 3) {\n propertyName = splitted[0];\n xPathQuery = splitted[1];\n newValue = splitted[2];\n} else {\n propertyName = \"\";\n xPathQuery = \"\";\n newValue = \"\";\n}\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "nodeQuery", + "query": "${xPathQuery}", + "queryType": "xpath", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "${propertyName}", + "value": "newValue" + } + ] + } + ], + "iterator": "vals" + } + ], + "parameters": [ + { + "name": "inputPropertyValues", + "defaultValue": "", + "type": "file", + "evaluation": "LINES" + }, + { + "name": "inputXPath", + "defaultValue": "", + "type": "file", + "evaluation": "LINES" + } + ] +} diff --git a/src/main/frontend/model/samples/check-hardcoded-urls.json b/src/main/frontend/model/samples/check-hardcoded-urls.json new file mode 100644 index 0000000..14febae --- /dev/null +++ b/src/main/frontend/model/samples/check-hardcoded-urls.json @@ -0,0 +1,70 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "path": "\"/content/swisscom/de\"", + "phrase": "\"https://www.swisscom.ch/content/de\"", + "extension": "\".html\"" + } + }, + { + "type": "runScript", + "code": "xPathQuery = str:join([\"/jcr:root\", path, \"//*[jcr:contains(., '\", phrase, \"') and jcr:contains(., '\", extension, \"') ]\"]);\n\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "nodeQuery", + "query": "${xPathQuery}", + "queryType": "xpath", + "hops": [ + { + "type": "each", + "expression": "node.properties", + "hops": [ + { + "type": "filterNode", + "expression": "property.type == 1 && !property.multiple && str:contains(jcr:val(node, property.name), phrase ) && str:contains(jcr:val(node, property.name), extension) ", + "hops": [ + { + "type": "runScript", + "code": "log.info(property.path)", + "extension": "js", + "putLocalsBackIntoScope": true + } + ] + }, + { + "type": "filterNode", + "expression": "property.type == 1 && property.multiple", + "hops": [ + { + "type": "declare", + "declarations": { + "joinedProperty": "str:join(jcr:vals(node, property.name))" + } + }, + { + "type": "filterNode", + "expression": "str:contains(joinedProperty, phrase) && str:contains(joinedProperty, extension)", + "hops": [ + { + "type": "runScript", + "code": "log.info(property.path)", + "extension": "js", + "putLocalsBackIntoScope": true + } + ] + } + ] + } + ], + "iterator": "property" + } + ] + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/delete-nodes.json b/src/main/frontend/model/samples/delete-nodes.json new file mode 100644 index 0000000..c6776d5 --- /dev/null +++ b/src/main/frontend/model/samples/delete-nodes.json @@ -0,0 +1,26 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "each", + "expression": "['de', 'fr', 'it', 'en']", + "hops": [ + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}]) AND [cq:template] = '/conf/swisscom/settings/wcm/templates/swisscom-content-page'", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "moveNode", + "conflict": "ignore", + "newName": "/dev/null" + } + ] + } + ], + "iterator": "lang", + "assumeNodes": false + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/index.ts b/src/main/frontend/model/samples/index.ts index beecf48..d6edd53 100644 --- a/src/main/frontend/model/samples/index.ts +++ b/src/main/frontend/model/samples/index.ts @@ -4,6 +4,15 @@ import removeTempGulpPackages from './remove-gulp-packages.json'; import updateBuildTimestamp from './update-build-timestamp.json'; import findComponentAndPage from './find-component-and-page.json'; import createMissingJcrContentNodes from './create-missing-jcr-content-nodes.json'; +import migrateResourceType from './migrate-resource-type.json'; +import batchSearchAndReplace from './batch-search-and-replace.json'; +import checkHardcodedUrls from './check-hardcoded-urls.json'; +import removeDeprecatedLegacyUrls from './remove-deprecated-legacy-urls.json'; +import deleteNodes from './delete-nodes.json'; +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 { Hop, HOP_DEFINITIONS } from '../hops'; import { Script } from '../Script'; @@ -47,4 +56,40 @@ export const SAMPLES: Sample[] = [ config: createMissingJcrContentNodes as Script, label: 'Sample: Create missing jcr:content node for pages', }, + { + config: migrateResourceType as Script, + label: 'Sample: Migrate Resource Type', + }, + { + config: batchSearchAndReplace as Script, + label: 'Sample: Batch search and replace', + }, + { + config: checkHardcodedUrls as Script, + label: 'Sample: Check hardcoded urls', + }, + { + config: removeDeprecatedLegacyUrls as Script, + label: 'Sample: Remove deprecated legacy urls', + }, + { + config: addOrReplaceProperty as Script, + label: 'Sample: Add or replace property', + }, + { + config: renameProperty as Script, + label: 'Sample: Rename property', + }, + { + config: addNode as Script, + label: 'Sample: Add node', + }, + { + config: renameNode as Script, + label: 'Sample: Rename node', + }, + { + config: deleteNodes as Script, + label: 'Sample: Delete nodes', + }, ]; diff --git a/src/main/frontend/model/samples/migrate-resource-type.json b/src/main/frontend/model/samples/migrate-resource-type.json new file mode 100644 index 0000000..23a80e0 --- /dev/null +++ b/src/main/frontend/model/samples/migrate-resource-type.json @@ -0,0 +1,46 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "sourceResourceType": "\"swisscom/components/content/accordion\"", + "destinationResourceType": "\"swisscom/components/content/accordion-new\"" + } + }, + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] as component WHERE component.[sling:resourceType] = \"${sourceResourceType}\"", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "sling:resourceType", + "value": "destinationResourceType" + } + ] + }, + { + "type": "declare", + "declarations": { + "sourceTemplate": "\"/conf/swisscom/settings/wcm/templates/swisscom-content-page\"", + "destinationTemplate": "\"/conf/swisscom/settings/wcm/templates/swisscom-content-page-new\"" + } + }, + { + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] AS page WHERE [cq:template] = \"${sourceTemplate}\"", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "cq:template", + "value": "destinationTemplate" + } + ] + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/remove-deprecated-legacy-urls.json b/src/main/frontend/model/samples/remove-deprecated-legacy-urls.json new file mode 100644 index 0000000..c39b104 --- /dev/null +++ b/src/main/frontend/model/samples/remove-deprecated-legacy-urls.json @@ -0,0 +1,51 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "patterns": "[\"%.php%\",\"%.jsp%\"]" + } + }, + { + "type": "each", + "expression": "patterns", + "hops": [ + { + "type": "nodeQuery", + "query": "/jcr:root/content//jcr:content[jcr:like(@legacyURL,'${pattern}')]", + "queryType": "xpath", + "hops": [ + { + "type": "runScript", + "code": "legacyURLArray = jcr:vals(node, \"legacyURL\");\nfilteredLegacyURLArray = [...];", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "each", + "expression": "legacyURLArray", + "hops": [ + { + "type": "runScript", + "code": "extension = str:remove(pattern, \"%\");\nif(!str:endsWith(url, extension)) {\n filteredLegacyURLArray.add(url);\n}\n\n", + "extension": "jexl", + "putLocalsBackIntoScope": true + } + ], + "iterator": "url" + }, + { + "type": "setProperty", + "conflict": "force", + "propertyName": "legacyURL", + "value": "filteredLegacyURLArray" + } + ] + } + ], + "iterator": "pattern" + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/rename-node.json b/src/main/frontend/model/samples/rename-node.json new file mode 100644 index 0000000..f9eb103 --- /dev/null +++ b/src/main/frontend/model/samples/rename-node.json @@ -0,0 +1,38 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "nodeOldName": "\"oldName\"", + "nodeNewName": "\"newName\"" + } + }, + { + "type": "each", + "expression": "['de', 'fr', 'it', 'en']", + "hops": [ + { + "type": "nodeQuery", + "query": "/* The search query has to return the parent nodes we want to act on. */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}/res/_/aaaaaaaaaaaaaaaaaaaaaaaa])", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "childNodes", + "namePattern": "${nodeOldName}", + "hops": [ + { + "type": "moveNode", + "conflict": "force", + "newName": "${nodeNewName}" + } + ] + } + ] + } + ], + "iterator": "lang" + } + ], + "parameters": [] +} diff --git a/src/main/frontend/model/samples/rename-property.json b/src/main/frontend/model/samples/rename-property.json new file mode 100644 index 0000000..7666b55 --- /dev/null +++ b/src/main/frontend/model/samples/rename-property.json @@ -0,0 +1,32 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "declare", + "declarations": { + "path": "\"/content/swisscom/de\"", + "sourcePropertyName": "\"navTitle\"", + "destinationPropertyName": "\"navTitle-new\"" + } + }, + { + "type": "runScript", + "code": "xPathQuery = str:join([\"/jcr:root\", path, \"//*[@\", sourcePropertyName, \"]\"]);", + "extension": "jexl", + "putLocalsBackIntoScope": true + }, + { + "type": "nodeQuery", + "query": "${xPathQuery}", + "queryType": "xpath", + "hops": [ + { + "type": "renameProperty", + "newName": "${destinationPropertyName}", + "propertyName": "${sourcePropertyName}" + } + ] + } + ], + "parameters": [] +} From 3700132324da341cced4ef9b74075b780e8fc494 Mon Sep 17 00:00:00 2001 From: marcofra <52889478+marcofra@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:21:40 +0100 Subject: [PATCH 02/12] feat(editor): apply suggestion change type --- src/main/frontend/model/samples/migrate-resource-type.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/model/samples/migrate-resource-type.json b/src/main/frontend/model/samples/migrate-resource-type.json index 23a80e0..afcb41f 100644 --- a/src/main/frontend/model/samples/migrate-resource-type.json +++ b/src/main/frontend/model/samples/migrate-resource-type.json @@ -30,7 +30,7 @@ }, { "type": "nodeQuery", - "query": "SELECT * FROM [nt:unstructured] AS page WHERE [cq:template] = \"${sourceTemplate}\"", + "query": "SELECT * FROM [cq:PageContent] AS page WHERE [cq:template] = \"${sourceTemplate}\"", "queryType": "JCR-SQL2", "hops": [ { From 36f8219502bc86e71c8d8cef4096107bb5cda028 Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 12:01:33 +0100 Subject: [PATCH 03/12] feat(editor): remove iteration, move declarations to parameters --- src/main/frontend/model/samples/add-node.json | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/frontend/model/samples/add-node.json b/src/main/frontend/model/samples/add-node.json index 2292f85..f0c01d8 100644 --- a/src/main/frontend/model/samples/add-node.json +++ b/src/main/frontend/model/samples/add-node.json @@ -2,42 +2,44 @@ "logLevel": "info", "hops": [ { - "type": "declare", - "declarations": { - "nodeName": "\"nName\"", - "jcrPrimaryType": "\"cq:PageContent\"", - "slingResourceType": "\"swisscom/components/structure/page\"" - } - }, - { - "type": "each", - "expression": "['de', 'fr', 'it', 'en']", + "type": "nodeQuery", + "query": "/* The search query has to return the parent nodes we want to act on */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/project])", + "queryType": "JCR-SQL2", "hops": [ { - "type": "nodeQuery", - "query": "/* The search query has to return the parent nodes we want to act on */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}])", - "queryType": "JCR-SQL2", + "type": "createChildNode", + "conflict": "force", + "name": "${args.nName}", + "runOnExistingNode": false, "hops": [ { - "type": "createChildNode", + "type": "setProperty", "conflict": "force", - "name": "${nodeName}", - "runOnExistingNode": false, - "hops": [ - { - "type": "setProperty", - "conflict": "force", - "propertyName": "sling:resourceType", - "value": "slingResourceType" - } - ], - "primaryType": "${jcrPrimaryType}" + "propertyName": "sling:resourceType", + "value": "args.slingResourceType" } - ] + ], + "primaryType": "${args.jcrPrimaryType}" } - ], - "iterator": "lang" + ] } ], - "parameters": [] + "parameters": [ + { + "name": "nName", + "defaultValue": "nName", + "evaluation": "STRING" + }, + { + "name": "jcrPrimaryType", + "defaultValue": "cq:PageContent", + "evaluation": "STRING", + "type": "text" + }, + { + "name": "slingResourceType", + "defaultValue": "project/components/page", + "evaluation": "STRING" + } + ] } From bb1982853f975221b2e88e88e5a7f7577a3a878b Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 12:12:31 +0100 Subject: [PATCH 04/12] feat(editor): remove iteration, move declarations to parameters, change content path --- .../samples/add-or-replace-property.json | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/frontend/model/samples/add-or-replace-property.json b/src/main/frontend/model/samples/add-or-replace-property.json index 2b8fd58..f5accc0 100644 --- a/src/main/frontend/model/samples/add-or-replace-property.json +++ b/src/main/frontend/model/samples/add-or-replace-property.json @@ -2,32 +2,31 @@ "logLevel": "info", "hops": [ { - "type": "declare", - "declarations": { - "propertyName": "\"pName\"", - "propertyValue": "\"pValue\"" - } - }, - { - "type": "each", - "expression": "['de', 'fr', 'it', 'en']", + "type": "nodeQuery", + "query": "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/project/language])", + "queryType": "JCR-SQL2", "hops": [ { - "type": "nodeQuery", - "query": "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}])", - "queryType": "JCR-SQL2", - "hops": [ - { - "type": "setProperty", - "conflict": "force", - "propertyName": "${propertyName}", - "value": "propertyValue" - } - ] + "type": "setProperty", + "conflict": "force", + "propertyName": "${args.propertyName}", + "value": "args.propertyValue" } - ], - "iterator": "lang" + ] } ], - "parameters": [] + "parameters": [ + { + "name": "propertyName", + "defaultValue": "pName", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "propertyValue", + "defaultValue": "pValue", + "type": "text", + "evaluation": "STRING" + } + ] } From 9b78e6b81dd12db8be0e39a7e474dea0306e5099 Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 13:41:11 +0100 Subject: [PATCH 05/12] feat(editor): rename variable --- src/main/frontend/model/samples/batch-search-and-replace.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/model/samples/batch-search-and-replace.json b/src/main/frontend/model/samples/batch-search-and-replace.json index 7a45478..9dd116f 100644 --- a/src/main/frontend/model/samples/batch-search-and-replace.json +++ b/src/main/frontend/model/samples/batch-search-and-replace.json @@ -12,7 +12,7 @@ "hops": [ { "type": "runScript", - "code": "/*\n The inputPropertyValues file should be in the format ,, ex.:\n propertyName,oldVal,newVal\n propertyName1,oldVal1,newVal1\n*/\n\nsplitted = str:split(vals, ',');\n\nif(arr:getLength(splitted) == 3) {\n propertyName = splitted[0];\n oldValue = splitted[1];\n newValue = splitted[2];\n} else {\n propertyName = \"\";\n oldValue = \"\";\n newValue = \"\";\n}\n", + "code": "/*\n The inputPropertyValues file should be in the format ,, ex.:\n propertyName,oldVal,newVal\n propertyName1,oldVal1,newVal1\n*/\n\nsplit = str:split(vals, ',');\n\nif(arr:getLength(split) == 3) {\n propertyName = split[0];\n oldValue = split[1];\n newValue = split[2];\n} else {\n propertyName = \"\";\n oldValue = \"\";\n newValue = \"\";\n}\n", "extension": "jexl", "putLocalsBackIntoScope": true }, @@ -39,7 +39,7 @@ "hops": [ { "type": "runScript", - "code": "/*\n The inputXPath file should be in the form ;; ex.:\n propertyName;/jcr:root/content/swisscom/de//*[@sling:resourceType='foundation/components/parsys']/*[not(@sling:resourceType)];newVal\n propertyName1;/jcr:root/content/swisscom/de//*[(jcr:like(@sling:resourceType, 'swisscom/components/content/text'))];newVal1\n*/\n\nsplitted = str:split(vals, ';');\n\nif(arr:getLength(splitted) == 3) {\n propertyName = splitted[0];\n xPathQuery = splitted[1];\n newValue = splitted[2];\n} else {\n propertyName = \"\";\n xPathQuery = \"\";\n newValue = \"\";\n}\n", + "code": "/*\n The inputXPath file should be in the form ;; ex.:\n propertyName;/jcr:root/content/swisscom/de//*[@sling:resourceType='foundation/components/parsys']/*[not(@sling:resourceType)];newVal\n propertyName1;/jcr:root/content/swisscom/de//*[(jcr:like(@sling:resourceType, 'swisscom/components/content/text'))];newVal1\n*/\n\nsplit = str:split(vals, ';');\n\nif(arr:getLength(split) == 3) {\n propertyName = split[0];\n xPathQuery = split[1];\n newValue = split[2];\n} else {\n propertyName = \"\";\n xPathQuery = \"\";\n newValue = \"\";\n}\n", "extension": "jexl", "putLocalsBackIntoScope": true }, From 09f14acf8ff43475365a8fa7be4ada472ed32a2d Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 14:07:45 +0100 Subject: [PATCH 06/12] feat(editor): split script, move declaration to parameters --- src/main/frontend/model/samples/index.ts | 5 +++ .../model/samples/migrate-page-template.json | 32 ++++++++++++++ .../model/samples/migrate-resource-type.json | 42 +++++++------------ 3 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 src/main/frontend/model/samples/migrate-page-template.json diff --git a/src/main/frontend/model/samples/index.ts b/src/main/frontend/model/samples/index.ts index d6edd53..0920d2d 100644 --- a/src/main/frontend/model/samples/index.ts +++ b/src/main/frontend/model/samples/index.ts @@ -5,6 +5,7 @@ import updateBuildTimestamp from './update-build-timestamp.json'; import findComponentAndPage from './find-component-and-page.json'; import createMissingJcrContentNodes from './create-missing-jcr-content-nodes.json'; import migrateResourceType from './migrate-resource-type.json'; +import migratePageTemplate from './migrate-page-template.json'; import batchSearchAndReplace from './batch-search-and-replace.json'; import checkHardcodedUrls from './check-hardcoded-urls.json'; import removeDeprecatedLegacyUrls from './remove-deprecated-legacy-urls.json'; @@ -60,6 +61,10 @@ export const SAMPLES: Sample[] = [ config: migrateResourceType as Script, label: 'Sample: Migrate Resource Type', }, + { + config: migratePageTemplate as Script, + label: 'Sample: Migrate Page Template', + }, { config: batchSearchAndReplace as Script, label: 'Sample: Batch search and replace', diff --git a/src/main/frontend/model/samples/migrate-page-template.json b/src/main/frontend/model/samples/migrate-page-template.json new file mode 100644 index 0000000..08370d1 --- /dev/null +++ b/src/main/frontend/model/samples/migrate-page-template.json @@ -0,0 +1,32 @@ +{ + "logLevel": "info", + "hops": [ + { + "type": "nodeQuery", + "query": "SELECT * FROM [cq:PageContent] AS page WHERE [cq:template] = \"${args.sourceTemplate}\"", + "queryType": "JCR-SQL2", + "hops": [ + { + "type": "setProperty", + "conflict": "force", + "propertyName": "cq:template", + "value": "args.destinationTemplate" + } + ] + } + ], + "parameters": [ + { + "name": "sourceTemplate", + "defaultValue": "/conf/project/settings/wcm/templates/page", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "destinationTemplate", + "defaultValue": "/conf/project/settings/wcm/templates/page-new", + "type": "text", + "evaluation": "STRING" + } + ] +} diff --git a/src/main/frontend/model/samples/migrate-resource-type.json b/src/main/frontend/model/samples/migrate-resource-type.json index afcb41f..2093abf 100644 --- a/src/main/frontend/model/samples/migrate-resource-type.json +++ b/src/main/frontend/model/samples/migrate-resource-type.json @@ -1,46 +1,32 @@ { "logLevel": "info", "hops": [ - { - "type": "declare", - "declarations": { - "sourceResourceType": "\"swisscom/components/content/accordion\"", - "destinationResourceType": "\"swisscom/components/content/accordion-new\"" - } - }, { "type": "nodeQuery", - "query": "SELECT * FROM [nt:unstructured] as component WHERE component.[sling:resourceType] = \"${sourceResourceType}\"", + "query": "SELECT * FROM [nt:unstructured] as component WHERE component.[sling:resourceType] = \"${args.sourceResourceType}\"", "queryType": "JCR-SQL2", "hops": [ { "type": "setProperty", "conflict": "force", "propertyName": "sling:resourceType", - "value": "destinationResourceType" + "value": "args.destinationResourceType" } ] - }, + } + ], + "parameters": [ { - "type": "declare", - "declarations": { - "sourceTemplate": "\"/conf/swisscom/settings/wcm/templates/swisscom-content-page\"", - "destinationTemplate": "\"/conf/swisscom/settings/wcm/templates/swisscom-content-page-new\"" - } + "name": "destinationResourceType", + "defaultValue": "project/components/content/accordion-new", + "type": "text", + "evaluation": "STRING" }, { - "type": "nodeQuery", - "query": "SELECT * FROM [cq:PageContent] AS page WHERE [cq:template] = \"${sourceTemplate}\"", - "queryType": "JCR-SQL2", - "hops": [ - { - "type": "setProperty", - "conflict": "force", - "propertyName": "cq:template", - "value": "destinationTemplate" - } - ] + "name": "sourceResourceType", + "defaultValue": "project/components/content/accordion", + "type": "text", + "evaluation": "STRING" } - ], - "parameters": [] + ] } From 2f8c4117464c5115d8de18ab4c85f0fcbe0a9ee3 Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 14:38:21 +0100 Subject: [PATCH 07/12] feat(editor): move declaration to parameters --- .../model/samples/check-hardcoded-urls.json | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/model/samples/check-hardcoded-urls.json b/src/main/frontend/model/samples/check-hardcoded-urls.json index 14febae..a2b6744 100644 --- a/src/main/frontend/model/samples/check-hardcoded-urls.json +++ b/src/main/frontend/model/samples/check-hardcoded-urls.json @@ -1,17 +1,9 @@ { "logLevel": "info", "hops": [ - { - "type": "declare", - "declarations": { - "path": "\"/content/swisscom/de\"", - "phrase": "\"https://www.swisscom.ch/content/de\"", - "extension": "\".html\"" - } - }, { "type": "runScript", - "code": "xPathQuery = str:join([\"/jcr:root\", path, \"//*[jcr:contains(., '\", phrase, \"') and jcr:contains(., '\", extension, \"') ]\"]);\n\n", + "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[jcr:contains(., '\", args.phrase, \"') and jcr:contains(., '\", args.extension, \"') ]\"]);\n\n", "extension": "jexl", "putLocalsBackIntoScope": true }, @@ -26,7 +18,7 @@ "hops": [ { "type": "filterNode", - "expression": "property.type == 1 && !property.multiple && str:contains(jcr:val(node, property.name), phrase ) && str:contains(jcr:val(node, property.name), extension) ", + "expression": "property.type == 1 && !property.multiple && str:contains(jcr:val(node, property.name), args.phrase ) && str:contains(jcr:val(node, property.name), args.extension) ", "hops": [ { "type": "runScript", @@ -48,7 +40,7 @@ }, { "type": "filterNode", - "expression": "str:contains(joinedProperty, phrase) && str:contains(joinedProperty, extension)", + "expression": "str:contains(joinedProperty, args.phrase) && str:contains(joinedProperty, args.extension)", "hops": [ { "type": "runScript", @@ -66,5 +58,24 @@ ] } ], - "parameters": [] + "parameters": [ + { + "name": "phrase", + "defaultValue": "https://www.project.ch/content/de", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "extension", + "defaultValue": ".html", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "path", + "defaultValue": "/content/project/de", + "type": "text", + "evaluation": "STRING" + } + ] } From 105e90d6ac0f582cbc7a7a459e8c756f03711bb2 Mon Sep 17 00:00:00 2001 From: marcofra Date: Tue, 17 Dec 2024 16:00:54 +0100 Subject: [PATCH 08/12] feat(editor): simplified script by merging single/multiple value property type --- .../model/samples/check-hardcoded-urls.json | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/main/frontend/model/samples/check-hardcoded-urls.json b/src/main/frontend/model/samples/check-hardcoded-urls.json index a2b6744..c8def1b 100644 --- a/src/main/frontend/model/samples/check-hardcoded-urls.json +++ b/src/main/frontend/model/samples/check-hardcoded-urls.json @@ -16,9 +16,15 @@ "type": "each", "expression": "node.properties", "hops": [ + { + "type": "declare", + "declarations": { + "joinedProperty": "str:join(jcr:vals(node, property.name))" + } + }, { "type": "filterNode", - "expression": "property.type == 1 && !property.multiple && str:contains(jcr:val(node, property.name), args.phrase ) && str:contains(jcr:val(node, property.name), args.extension) ", + "expression": "str:contains(joinedProperty, args.phrase) && str:contains(joinedProperty, args.extension)", "hops": [ { "type": "runScript", @@ -27,30 +33,6 @@ "putLocalsBackIntoScope": true } ] - }, - { - "type": "filterNode", - "expression": "property.type == 1 && property.multiple", - "hops": [ - { - "type": "declare", - "declarations": { - "joinedProperty": "str:join(jcr:vals(node, property.name))" - } - }, - { - "type": "filterNode", - "expression": "str:contains(joinedProperty, args.phrase) && str:contains(joinedProperty, args.extension)", - "hops": [ - { - "type": "runScript", - "code": "log.info(property.path)", - "extension": "js", - "putLocalsBackIntoScope": true - } - ] - } - ] } ], "iterator": "property" From 41fccfb3506e8eddb797255bb737b3f87d8bcd93 Mon Sep 17 00:00:00 2001 From: marcofra Date: Thu, 19 Dec 2024 21:45:26 +0100 Subject: [PATCH 09/12] feat(editor): replace logging with file output --- src/main/frontend/model/samples/check-hardcoded-urls.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/model/samples/check-hardcoded-urls.json b/src/main/frontend/model/samples/check-hardcoded-urls.json index c8def1b..8dc285f 100644 --- a/src/main/frontend/model/samples/check-hardcoded-urls.json +++ b/src/main/frontend/model/samples/check-hardcoded-urls.json @@ -3,7 +3,7 @@ "hops": [ { "type": "runScript", - "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[jcr:contains(., '\", args.phrase, \"') and jcr:contains(., '\", args.extension, \"') ]\"]);\n\n", + "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[jcr:contains(., '\", args.phrase, \"') and jcr:contains(., '\", args.extension, \"') ]\"]);\noutput = utils.file.txt(\"hardcoded_urls\");\n\n", "extension": "jexl", "putLocalsBackIntoScope": true }, @@ -28,8 +28,8 @@ "hops": [ { "type": "runScript", - "code": "log.info(property.path)", - "extension": "js", + "code": "output.append(property.path);\noutput.append(\"\\n\");", + "extension": "jexl", "putLocalsBackIntoScope": true } ] From 5be490ef2caba81bf1abaeb7181b9e5a868ac209 Mon Sep 17 00:00:00 2001 From: marcofra Date: Fri, 20 Dec 2024 11:53:28 +0100 Subject: [PATCH 10/12] feat(editor): file rename --- src/main/frontend/model/samples/check-hardcoded-urls.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/model/samples/check-hardcoded-urls.json b/src/main/frontend/model/samples/check-hardcoded-urls.json index 8dc285f..5ac1e44 100644 --- a/src/main/frontend/model/samples/check-hardcoded-urls.json +++ b/src/main/frontend/model/samples/check-hardcoded-urls.json @@ -3,7 +3,7 @@ "hops": [ { "type": "runScript", - "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[jcr:contains(., '\", args.phrase, \"') and jcr:contains(., '\", args.extension, \"') ]\"]);\noutput = utils.file.txt(\"hardcoded_urls\");\n\n", + "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[jcr:contains(., '\", args.phrase, \"') and jcr:contains(., '\", args.extension, \"') ]\"]);\noutput = utils.file.txt(\"properties_containing_hardcoded_urls\");\n\n", "extension": "jexl", "putLocalsBackIntoScope": true }, From a2e36c68b3a27bcccd9874481ff218bd493f1ffc Mon Sep 17 00:00:00 2001 From: marcofra Date: Thu, 9 Jan 2025 17:50:20 +0100 Subject: [PATCH 11/12] feat(editor): replace variables with parameters --- .../model/samples/rename-property.json | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/model/samples/rename-property.json b/src/main/frontend/model/samples/rename-property.json index 7666b55..68e10af 100644 --- a/src/main/frontend/model/samples/rename-property.json +++ b/src/main/frontend/model/samples/rename-property.json @@ -1,17 +1,9 @@ { "logLevel": "info", "hops": [ - { - "type": "declare", - "declarations": { - "path": "\"/content/swisscom/de\"", - "sourcePropertyName": "\"navTitle\"", - "destinationPropertyName": "\"navTitle-new\"" - } - }, { "type": "runScript", - "code": "xPathQuery = str:join([\"/jcr:root\", path, \"//*[@\", sourcePropertyName, \"]\"]);", + "code": "xPathQuery = str:join([\"/jcr:root\", args.path, \"//*[@\", args.sourcePropertyName, \"]\"]);", "extension": "jexl", "putLocalsBackIntoScope": true }, @@ -22,11 +14,30 @@ "hops": [ { "type": "renameProperty", - "newName": "${destinationPropertyName}", - "propertyName": "${sourcePropertyName}" + "newName": "${args.destinationPropertyName}", + "propertyName": "${args.sourcePropertyName}" } ] } ], - "parameters": [] + "parameters": [ + { + "name": "sourcePropertyName", + "defaultValue": "navTitle", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "destinationPropertyName", + "defaultValue": "navTitle-new", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "path", + "defaultValue": "/content/project/de", + "type": "text", + "evaluation": "STRING" + } + ] } From bf8cb13049b827e8d906ac142211368296e26c68 Mon Sep 17 00:00:00 2001 From: marcofra Date: Thu, 9 Jan 2025 18:04:15 +0100 Subject: [PATCH 12/12] feat(editor): replace declarations with parameters, changed query path --- .../frontend/model/samples/rename-node.json | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/frontend/model/samples/rename-node.json b/src/main/frontend/model/samples/rename-node.json index f9eb103..97ce0ef 100644 --- a/src/main/frontend/model/samples/rename-node.json +++ b/src/main/frontend/model/samples/rename-node.json @@ -1,30 +1,23 @@ { "logLevel": "info", "hops": [ - { - "type": "declare", - "declarations": { - "nodeOldName": "\"oldName\"", - "nodeNewName": "\"newName\"" - } - }, { "type": "each", "expression": "['de', 'fr', 'it', 'en']", "hops": [ { "type": "nodeQuery", - "query": "/* The search query has to return the parent nodes we want to act on. */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/swisscom/${lang}/res/_/aaaaaaaaaaaaaaaaaaaaaaaa])", + "query": "/* The search query has to return the parent nodes we want to act on. */\nSELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/project/${lang}])", "queryType": "JCR-SQL2", "hops": [ { "type": "childNodes", - "namePattern": "${nodeOldName}", + "namePattern": "${args.nodeOldName}", "hops": [ { "type": "moveNode", "conflict": "force", - "newName": "${nodeNewName}" + "newName": "${args.nodeNewName}" } ] } @@ -34,5 +27,18 @@ "iterator": "lang" } ], - "parameters": [] + "parameters": [ + { + "name": "nodeOldName", + "defaultValue": "oldName", + "type": "text", + "evaluation": "STRING" + }, + { + "name": "nodeNewName", + "defaultValue": "newName", + "type": "text", + "evaluation": "STRING" + } + ] }