Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kuckmc01
kuckmc01 / gist:e1a05ac4179289c98cb6d0d402f52973
Created January 12, 2023 18:30
Example set permissions for AEM Dam Asset Reports using Repo Init
create group dam-reports with path /home/groups/dam-reports
set ACL for dam-reports
allow jcr:read on /libs/dam/gui/content/reports
allow jcr:read on /libs/dam/gui/content/nav/tools/assets/assetreports
allow jcr:read on /var/dam
allow jcr:read,rep:write,jcr:removeChildNodes on /var/dam/reports
allow jcr:read on /libs/dam/gui/content/reports/generatereport
allow jcr:read on /libs/cq/core/content/nav/tools/assets
end
@kuckmc01
kuckmc01 / remove-nodes.groovy
Created October 27, 2022 20:32
Simple groovy console script to delete all child nodes using resource resolver
def path ="/content/cq:tags/parent"
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
def children = resource.getChildren();
children.each { child ->
resourceResolver.delete(child);
println "removed:"+child
@kuckmc01
kuckmc01 / string-replacement.js
Last active June 19, 2022 02:39
String replacement in javascript for {0}, {2}...{n} values in string
//Using string replace
const x = 'hello {0}, my name is {1}';
const y = ['world','guy'];
const z = x.replace(/\{\d+\}/g, (match) => (y[match.replace(/\{|\}/g,'')]));
console.log(z);
// Using for each
let s = 'hello {0}, my name is {1}';
y.forEach((value,index) => { s = s.replace('{'+index+'}',value)})
console.log(s);
@kuckmc01
kuckmc01 / nested-multifield.xml
Last active January 11, 2022 14:34
AEM 6.5 or AEMAACS Ready Nested Multifield
<outer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
composite="{Boolean}true"
fieldLabel="outer">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
name="./outerName">
<items jcr:primaryType="nt:unstructured">
package datasources.staticstyles.v1;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.wcm.api.designer.Designer;
import org.apache.commons.collections.iterators.TransformIterator;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
@kuckmc01
kuckmc01 / gist:7a3d20361b22af4dacdf9aca715c6c61
Created July 25, 2019 21:41
Example datasource servlet
Example servlet datasource tied to resourceType located originaly in wcm core components at https://github.com/adobe/aem-core-wcm-components/blob/c15f3a23025322f4b2783da6c257c4e79abb22c9/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/servlets/AllowedHeadingElementsDataSourceServlet.java
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2019 Adobe Systems Incorporated
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
@kuckmc01
kuckmc01 / gist:ddc19654c745e4a3a0cb553450f461db
Created June 28, 2019 14:43
Multfield 6.5 compatible example
<attrMap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
composite="{Boolean}true"
fieldDescription="x"
fieldLabel="Attribute Map">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
name="./attrMap">
select page.* from [cq:Page] as page
inner join [cq:PageContent] as pageContent
on isChildNode(pageContent, page)
inner join [nt:base] as carousel
on isDescendantNode(carousel, pageContent)
inner join [nt:base] as list
on isDescendantNode(list, pageContent)
where isDescendantNode(pageContent, '/content')
and name(pageContent) = 'jcr:content'
and carousel.[sling:resourceType] = 'COMPONENT_ONE'
@kuckmc01
kuckmc01 / gist:c4049d18d7e6669ce9ec16c28c2e3445
Created May 24, 2019 17:37
SQL2 dam:Asset query specific sub metadata node has property
SELECT * FROM [dam:Asset] AS s WHERE ISDESCENDANTNODE([/content/dam/abc]) and s.[jcr:content/metadata/thing/textfield1] is not null
@kuckmc01
kuckmc01 / gist:dccdcc0367e8cea3a73f7f88f0a46844
Created May 16, 2019 17:06
xpath get PageContent that has child component with sling:resourceType
/jcr:root/content//element(*,cq:PageContent)[*/*/@sling:resourceType="the/resource/type"]