How to clean up the growing repo? How to safely delete all the unwanted assets and pages.
Requirement:
Find the references of all the assets and pages and clean up unreferenced assets and unwanted pages.
Introduction:
You can call the below process as asset, pages references report.
Usually, with growing repo size, we usually do logs rotation and archiving, we also do some compactions (Revision cleanup).
What if we could remove some of the deactivated and unreferenced assets or pages?
How to find references of assets or pages?
Go to the following url https://{domain}/apps/acs-commons/content/manage-controlled-processes.html and click on Start Process and select Renovator process as shown below:
Start ProcessRenovator Process
I am trying to check the references of all the assets under the following path:
Source path: /content/dam/wknd/en/activities
And select some random path into the Destination path: /content/dam/wknd/en/magazine
And please do make sure to check the Dry run and Detailed Report checkboxes, if not checked all the assets will be moved to the new folder i.e, /content/dam/wknd/en/magazine
Process fields selections
Once you start the process you would see the process take some time to run and you can click on the process and open the view or download the excel report as shown:
Process result pageView the results popup
Once downloaded delete the following columns:
Remove unwanted columns
You can see some of the rows have empty references and if you think these assets are no more required then you can remove them
Unreferenced rows
How to remove the unreferenced assets or pages safely?
You can run through the above steps on any of the folders and please make sure to avoid running on root folders or pages like: /content/dam or /content or home pages because would slow down the servers
For more information on how to use the renovator process for
How to track Text component using ACDL? How to track the links inside a text component using ACDL? Can I add the custom ID to the links?
Requirement:
Track all the hyperlinks inside the text component using ACDL and add also provide a custom ID to track the links.
Introduction:
The goal of the Adobe Client Data Layer is to reduce the effort to instrument websites by providing a standardized method to expose and access any kind of data for any script.
The Adobe Client Data Layer is platform agnostic, but is fully integrated into the Core Components for use with AEM.
You can also learn more about the OOTB core text component here and also you can learn more about the Adobe Client data layerhere. You can also learn about how to create tracking for the custom component here.
In the following example, we are going to use component delegation to delegate the OOTB text component and enable custom tracking on the text component, you can learn more about component delegation here.
Add a JSOUP and Lombok dependency to your project.
Add a service called JSONConverter as shown below:
package com.adobe.aem.guides.wknd.core.service;
import com.fasterxml.jackson.databind.util.JSONPObject;
/**
* Interface to deal with Json.
*/
public interface JSONConverter {
/**
* Convert Json Object to given object
*
* @param jsonpObject
* @param clazz type of class
* @return @{@link Object}
*/
@SuppressWarnings("rawtypes")
Object convertToObject(JSONPObject jsonpObject, Class clazz);
/**
* Convert Json Object to given object
*
* @param jsonString
* @param clazz type of class
* @return @{@link Object}
*/
@SuppressWarnings("rawtypes")
Object convertToObject(String jsonString, Class clazz);
/**
* Convert Json Object to given object
*
* @param object
* @return @{@link String}
*/
String convertToJsonString(Object object);
/**
* Convert Json Object to given object
*
* @param object
* @return @{@link JSONPObject}
*/
JSONPObject convertToJSONPObject(Object object);
}
Add a Service implementation JSONConverterImpl to convert object to JSON String using Object Mapper API
package com.adobe.aem.guides.wknd.core.service.impl;
import com.adobe.aem.guides.wknd.core.service.JSONConverter;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@Component(service = JSONConverter.class)
public class JSONConverterImpl implements JSONConverter {
private static final Logger LOG = LoggerFactory.getLogger(JSONConverterImpl.class);
@SuppressWarnings("unchecked")
@Override
public Object convertToObject(JSONPObject jsonpObject, @SuppressWarnings("rawtypes") Class clazz) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(jsonpObject.toString(), clazz);
} catch (IOException e) {
LOG.debug("IOException while converting JSON to {} class {}", clazz.getName(), e.getMessage());
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public Object convertToObject(String jsonString, @SuppressWarnings("rawtypes") Class clazz) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(jsonString, clazz);
} catch (IOException e) {
LOG.debug("IOException while converting JSON to {} class {}", clazz.getName(), e.getMessage());
}
return null;
}
@Override
public String convertToJsonString(Object object) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.setSerializationInclusion(Include.NON_EMPTY).writerWithDefaultPrettyPrinter().writeValueAsString(object);
} catch (IOException e) {
LOG.debug("IOException while converting object {} to Json String {}", object.getClass().getName(),
e.getMessage());
}
return null;
}
@Override
public JSONPObject convertToJSONPObject(Object object) {
ObjectMapper mapper = new ObjectMapper();
try {
String jsonString = mapper.writeValueAsString(object);
return mapper.readValue(jsonString, JSONPObject.class);
} catch (IOException e) {
LOG.debug("IOException while converting object {} to Json String {}", object.getClass().getName(),
e.getMessage());
}
return null;
}
}
Create TexModelImpl Sling model class which will be extending OOTB Text component and add delegate to override default getText() method.
Create a custom method called addLinkTracking and JSOUP API to read the text and get all the hyperlinks, once you have all the hyperlinks you can add custom tracking code by calling getLinkData method and this method should take care of custom ID tracking or generating default ID for all the links.
package com.adobe.aem.guides.wknd.core.models.impl;
import com.adobe.aem.guides.wknd.core.service.JSONConverter;
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.wcm.core.components.models.Text;
import com.adobe.cq.wcm.core.components.util.ComponentUtils;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.components.ComponentContext;
import lombok.experimental.Delegate;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.*;
import org.apache.sling.models.annotations.injectorspecific.*;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@Model(adaptables = SlingHttpServletRequest.class, adapters = {Text.class, ComponentExporter.class}, resourceType = TextModelImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class TextModelImpl implements Text {
public static final String RESOURCE_TYPE = "wknd/components/text";
@SlingObject
protected Resource resource;
@ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL)
private ComponentContext componentContext;
@ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL)
private Page currentPage;
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Default(values=StringUtils.EMPTY)
protected String id;
@OSGiService
private JSONConverter jsonConverter;
@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private Text text;
@Override
public String getText() {
return addLinkTracking(text.getText());
}
private String addLinkTracking(String text) {
if(StringUtils.isNotEmpty(text) && (ComponentUtils.isDataLayerEnabled(resource) || resource.getPath().contains("/content/experience-fragments"))) {
Document doc = Jsoup.parse(text);
Elements anchors = doc.select("a");
AtomicInteger counter = new AtomicInteger(1);
anchors.stream().forEach(anch -> {
anch.attr("data-cmp-clickable", true);
anch.attr("data-cmp-data-layer", getLinkData(anch, counter.getAndIncrement()));
});
return doc.body().html();
}
return text;
}
public String getLinkData(Element anchor, int count) {
//Create a map of properties we want to expose
Map<String, Object> textLinkProperties = new HashMap<>();
textLinkProperties.put("@type", resource.getResourceType()+"/link");
textLinkProperties.put("dc:title", anchor.text());
textLinkProperties.put("xdm:linkURL", anchor.attr("href"));
//Use AEM Core Component utils to get a unique identifier for the Byline component (in case multiple are on the page)
String textLinkID;
if(StringUtils.isEmpty(id)) {
textLinkID = ComponentUtils.getId(resource, this.currentPage, this.componentContext) + ComponentUtils.ID_SEPARATOR + ComponentUtils.generateId("link", resource.getPath()+anchor.text());
} else {
textLinkID = ComponentUtils.getId(resource, this.currentPage, this.componentContext) + ComponentUtils.ID_SEPARATOR + "link-" + count;
}
// Return the bylineProperties as a JSON String with a key of the bylineResource's ID
return String.format("{\"%s\":%s}",
textLinkID,
jsonConverter.convertToJsonString(textLinkProperties));
}
private interface DelegationExclusion {
String getText();
}
}
Check the default tracking for hyperlinks inside the text component
auto generated link tracking
Add a custom ID to the component as shown below:
tracking ID field
In the below screenshot, we can see a custom tracking ID added to the link and each link will be called has 1, 2, 3 …
custom tracking ID for each linkclick event getting captured
What is ACDL? How to use ACDL within AEM? How to add custom ID for component tracking
Requirement:
Enable ACDL on the project and track the events and add provide ID for component tracking instead of using auto generated HEX value
Introduction:
The Adobe Client Data Layer introduces a standard method to collect and store data about a visitors experience on a webpage and then make it easy to access this data. The Adobe Client Data Layer is platform agnostic but is fully integrated into the Core Components for use with AEM.
You can also visit the article to enable ACDL on your project, you can go through the document to understand its usage.
After enabling on the site you can see the datalayer for each component:
Enter adobeDataLayer.getState() in browser console
component datalayer
You can paste the following JS script on the console to test button clicks on the page
Create a package for a list of paths using the ACS commons query package tool
Introduction:
Usually, when we try to create a package of content from the lowers or prod environment, we provide a list of pages we are trying to create a package for by going into the edit.
Add filters
What about the assets related to those pages? Again, you need to get the list of assets and edit the package.
Is there a way we can create a package using the ACS Commons tool?
How to bulk replicate (Publish/Unpublish) pages in AEM using MCP?
Requirement:
Use bulk replication other than the OOTB tree activation tool and using MCP add a different replication agent instead of the default agent.
Introduction:
Usually for bulk replication we usually use the OOTB tree activation page and select the path to start the bulk replication i.e, activation only.
Activation Treestart path and activate
MCP provides an easier way and with better UI to run bulk activation. You can also create a separate replication agent other than default agent so that existing authoring replication or existing schedulers won’t be blocked.
You can use the MCP queue to replicate synchronously and the default queue to replicate asynchronously. For pages more than 10K its recommended to use MCP 10k Queue
Select the Tree Activation:
Go to MCP page url: http://{domain}/apps/acs-commons/content/manage-controlled-processes.html
Select Tree Activation process
Provide the path of the page and select all for “What to Publish” and MCP Queue based on your requirement.
Provide an agent if you are using a different agent for bulk replication and select action to bulk publish or unpublish the pages.
AEM doesn’t support the move option for bulk selection of pages. Hence, there is a need to find a way to bulk move pages from one location to another location and update their references.
Requirement:
This article discusses the problem of bulk moving pages from one location to another location in Adobe Experience Manager (AEM) and introduces the MCP Renovator process as a solution. It also provides step-by-step instructions on how to use an Excel sheet and the Renovator process to move pages, update references, deactivate and delete moved pages, and publish moved references and pages.
Bulk move some of the pages from one location to another location
Update the references on the page.
Deactivate moved pages and delete
Publish moved references
Publish moved pages
Introduction:
Out of the box, AEM doesn’t support the move option/operation for more than one selection of pages. However, we can use the MCP renovator process to bulk move the existing pages from one location to another location.
Create an Excel sheet containing the following columns:
Source – source path of the page
Destination – destination path and if you want to rename the page you do as well
In the above example, the magazine page will be renamed to revenue
Go to the MCP process path http://{domain}}/apps/acs-commons/content/manage-controlled-processes.html, select Renovator process upload the Excel sheet and use the following options as per your needs. If you select replication MCP queue will activate only references but won’t activate the moved pages.
Renovator process
Dry run the process to validate for any errors in the Excel sheet and select the detailed report to view complete move-related changes.
Renovator satisfy all 5 requirements but for the 6th requirement, you can use the below process to activate all the moved pages and you upload the same excel sheet and below process will only look into the destination column AEM Publish / UnPublish / Delete List of pages – MCP Process
Can we Publish / Un Publish / Delete the list of pages mentioned in an Excel sheet?
Requirement:
This article discusses how to use the Manage Controlled Processes (MCP) dashboard in Adobe Experience Manager (AEM) to create a process for publishing, unpublishing, and deleting a list of pages in AEM based on an Excel sheet. The article provides code snippets for creating the ListTreeReplicationFactory service and implementation class called ListTreeReplication that reads the Excel sheet and performs the desired actions on the specified pages.
Create an MCP process to Publish / Un Publish / Delete the list of pages mentioned in an Excel sheet.
Introduction:
Usually, product owners or authors would like to Publish certain pages like offer/product/article pages based on business requirements and also would like to unpublish and delete to clean up the pages which are unnecessary.
This process will be really helpful during Excel sheet based migration.
MCP (Manage Controlled Processes) is both a dashboard for performing complex tasks and a rich API for defining these tasks as process definitions. In addition to kicking off new processes, users can also monitor running tasks, retrieve information about completed tasks, halt work, and so on.
Add the following maven dependency to your pom to extend MCP
How can I update an existing template with a new template without moving child pages or reactivation it?
Requirement:
This article discusses how to update an existing template with a new template in AEM without moving child pages or reactivation. The article provides two methods to achieve this goal: a manual method and a programmatic method. The programmatic method uses Manage Controlled Processes (MCP), which is both a dashboard and a rich API for defining complex tasks as process definitions. The article provides a step-by-step guide to updating the template type programmatically.
Update the Adventures page template from the landing page template to the Adventure page template.
Avoid moving child pages from the current adventure page to the new staging location
Avoid bulk activation of child pages due to movement
Create duplicate page
Introduction:
Let’s try to solve the above issue manually:
Create a new page called adventures (which will be created as adventures0) using the adventure page template.
Copy all the child pages or move page by page from the current adventures page to the new adventure page.
Copy the child pages from source to destination
Delete the current adventures page and move the adventures0 page and rename it by removing the 0
Move the page and rename
Finally, click on manage publication to publish the new adventures page and select all child pages to reactivate.
Include child pages before publishing
Let’s try to solve the above issue programmatically:
MCP (Manage Controlled Processes) is both a dashboard for performing complex tasks and a rich API for defining these tasks as process definitions. In addition to kicking off new processes, users can also monitor running tasks, retrieve information about completed tasks, halt work, and so on.
Add the following maven dependency to your pom to extend MCP
With increasing security and safety concerns, AEM Groovy Console is not allowed to be installed in the author/publish environment in Production. As a result, users require an alternative tool to execute short scripts for content updates.
Requirement:
The Groovy Console has been a preferred tool for executing short scripts for content updates in Adobe Experience Manager (AEM), but due to security and safety concerns, the console is not installed in the author/publish environment in Production. This article explores using the ACS Commons Managed Control Process (MCP) as a better alternative for running bulk updates with the provided console. It provides an introduction to MCP and explains how to extend it in a current project structure and make relevant POM changes. It also covers tools that come out of the box with MCP, how to use and maintain them, and how to create a new process and form fields with MCP.
Extend MCP in your current project structure and add the relevant POM changes
Introduction:
MCP (Manage Controlled Processes) is both a dashboard for performing complex tasks and also a rich API for defining these tasks as process definitions. In addition to kicking off new processes, users can also monitor running tasks, retrieve information about completed tasks, halt work, and so on.
The Groovy console is an awesome tool to write short scripts to execute some of the content updates but due to increase security and safety issues, the AMS team is not allowing to install Groovy Console in the author/publish environment in Production and there is no other way we can run the groovy console on pubs. Hence ACS Commons MCP would be the better replacement for running these kinds of bulk updates using the beautiful console provided by ACS Commons.
How to use MCP?
Process Manager: How to navigate and access ACS Commons MCP process manager
Tools: Tools that come to OOTB when you use MCP tools
Operations: How to use and maintain the MCP process
In order to extend the MCP process, create a separate module called MCP under your project directory and add the following dependencies as shown below:
Add the following code into all module pom.xml to embed this new module
For the MCP process to pick up your new process, you need to create a service that implements ProcessDefinitionFactory and override the getName method to provide the process name to show under the list of processes.
MCP process list
createProcessDefinitionInstance to create a new instance of this process.
package com.mysite.mcp.process;
import org.osgi.service.component.annotations.Component;
import com.adobe.acs.commons.mcp.ProcessDefinitionFactory;
@Component(service = ProcessDefinitionFactory.class, immediate = true)
public class ExampleProcessFactory extends ProcessDefinitionFactory<ExampleProcess> {
@Override
public String getName() {
return "Example PRocess";
}
@Override
protected ExampleProcess createProcessDefinitionInstance() {
return new ExampleProcess();
}
}
You can learn more regarding process definition here
Create Process Implementation:
The process implementation class extends ProcessDefinition and you can have multiple form fields to accept the author’s input.