Skip to content

Commit

Permalink
feat(editor): add additional sample scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofra committed Dec 16, 2024
1 parent 6e3064e commit 5516e12
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/frontend/model/samples/add-node.json
Original file line number Diff line number Diff line change
@@ -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": []
}
33 changes: 33 additions & 0 deletions src/main/frontend/model/samples/add-or-replace-property.json
Original file line number Diff line number Diff line change
@@ -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": []
}
77 changes: 77 additions & 0 deletions src/main/frontend/model/samples/batch-search-and-replace.json
Original file line number Diff line number Diff line change
@@ -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 <propertyName>,<oldValue>,<newValue> 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 <propertyName>;<xPathQuery>;<propertyValue> 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"
}
]
}
70 changes: 70 additions & 0 deletions src/main/frontend/model/samples/check-hardcoded-urls.json
Original file line number Diff line number Diff line change
@@ -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": []
}
26 changes: 26 additions & 0 deletions src/main/frontend/model/samples/delete-nodes.json
Original file line number Diff line number Diff line change
@@ -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": []
}
45 changes: 45 additions & 0 deletions src/main/frontend/model/samples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
},
];
46 changes: 46 additions & 0 deletions src/main/frontend/model/samples/migrate-resource-type.json
Original file line number Diff line number Diff line change
@@ -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": []
}
Loading

0 comments on commit 5516e12

Please sign in to comment.