Hello All - I am looking for Curl command to add a property in all the pages under the specific folder in JCR. if the property exists, it should ignore it else it should add it.
Path:/content/test/en
Property: testprop = true
Also is there any utility provided by ACS to add a specific property without using CURL command?
Solved! Go to Solution.
Views
Replies
Total Likes
There is no AEM out of the box curl command that allows you to update a sling resource inside of the crx/de, however, you can create a Sling Servlet that can accept specific parameters, which allows you to manipulate and change properties using the Sling CRUD API.
Sling CRUD API - https://sling.apache.org/documentation/the-sling-engine/sling-api-crud-support.html
The servlet will accept parameters as "resourcePath", "prop", "val".
example: [POST] /bin/my-site/update-resource [REQUEST-BODY]resourcePath=/content/dam/my-site/folder;prop=testprop;value=true
Servlet doPost example:
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
ResourceResolver resourceResolver = getResourceResolver();
String path = extractPostRequestBody("resourcePath");
String propName = extractPostRequestBody("prop");
String propVal = extractPostRequestBody("val");
Resource myResource = resourceResolver.getResource(path);
ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
properties.put(propName, propVal);
resourceResolver.commit();
}
Hi @aemninja
Unfortunately there is no such utility available that can update any additional property to all the pages under a specific folder.
How frequently you need this property to be updated?
Hope this helps!
Thanks
There is no AEM out of the box curl command that allows you to update a sling resource inside of the crx/de, however, you can create a Sling Servlet that can accept specific parameters, which allows you to manipulate and change properties using the Sling CRUD API.
Sling CRUD API - https://sling.apache.org/documentation/the-sling-engine/sling-api-crud-support.html
The servlet will accept parameters as "resourcePath", "prop", "val".
example: [POST] /bin/my-site/update-resource [REQUEST-BODY]resourcePath=/content/dam/my-site/folder;prop=testprop;value=true
Servlet doPost example:
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
ResourceResolver resourceResolver = getResourceResolver();
String path = extractPostRequestBody("resourcePath");
String propName = extractPostRequestBody("prop");
String propVal = extractPostRequestBody("val");
Resource myResource = resourceResolver.getResource(path);
ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
properties.put(propName, propVal);
resourceResolver.commit();
}