Expand my Community achievements bar.

Dynamic Media publishing images before ONTime

Avatar

Community Advisor

Hi Team,

 

We have integrated our AEM instance with Dynamic media for image serving capabilities. Some of our images will have onTime associated and these assets should be visible only from that time . We use the OOTB ontime/offtime capabilties but when the images are published ontime is not honored in DM  it goes live through dynamic media immediately .

This is the existing product behavior https://experienceleague.adobe.com/docs/experience-cloud-kcs/kbarticles/KA-21180.html?lang=en

 

Any suggestions on preventing these assets from getting synced before onTime is reached to avoid accidental publishing or any possibilities of introducing a pre processor before asset published to scene7/dynamic media.

 

From what i could find in the OOTB methods AEM uses an eventhandler and does the syncing to DM through a job in case of activation of an asset .

Please let me know your thoughts on the same

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Community Advisor

Hi @sherinregi ,

You can try to implement an onTime event handler for requirement. This will trigger On change in Validity status (onTime) of a page, this handler service will publish all referenced assets on the page. This service is meant to run in author instance only you can set configuration policy as require for this purpose.

You can further tweak this logic as per your need based on only on assets if you want to trigger it.

@Component(immediate = true, service = EventHandler.class, property = {
		EventConstants.EVENT_TOPIC + "=" + PageEvent.EVENT_TOPIC }, configurationPolicy = ConfigurationPolicy.REQUIRE)
public class OnTimeEventHandler implements EventHandler {

@Override
	public void handleEvent(final Event event) {
		final PageEvent pgEvent = PageEvent.fromEvent(event);
		final Iterator<PageModification> modifications = pgEvent.getModifications();
		while (modifications.hasNext()) {
			final PageModification modification = modifications.next();
			final ModificationType modType = modification.getType();
			if (modType.equals(PageModification.ModificationType.VALID)) {
				LOGGER.info(
						"OnTimeEventHandler : handleEvent() : Page Valid Event captured for page : {} : Starting Referenced Assets Replication",
						modification.getPath());
				startAssetReplication(modification.getPath());
			}
		}
	}


private void startAssetReplication(final String pagePath) {
		ResourceResolver resolver = Utils.getResourceResolver(resolverFactory, "subservice");
		try {
			final Set<com.day.cq.wcm.api.reference.Reference> referencesSet = new HashSet<com.day.cq.wcm.api.reference.Reference>();
			if (null != resolver) {
				final Resource pageResource = resolver
						.getResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
				if (null != pageResource) {
					for (ReferenceProvider referenceProvider : this.referenceProviders) {
						referencesSet.addAll(referenceProvider.findReferences(pageResource));
					}
					replicateReferences(referencesSet, resolver.adaptTo(Session.class), pagePath);
				} else {
					LOGGER.warn(
							"OnTimeEventHandler : startAssetReplication() : Could not get resource for page path : {}",
							pagePath);
				}
			} else {
				LOGGER.warn(
						"OnTimeEventHandler : startAssetReplication() : Getting {} Resource Resolver as NULL while getting references assets for page path : {}",
						, pagePath);
			}
		} finally {
			if (resolver != null && resolver.isLive()) {
				resolver.close();
			}
		}
	}

}






Thanks
Tarun 

Avatar

Community Advisor

Hi @TarunKumar 

Thanks for the suggestion . Just wanted to highlight one thing the problem is when this asset is replicated by an author before onTime is reached, In this case aem honors' the onTime and if we access the asset on publish it will not display but Dynamic media will update the asset status to publish and will be available from scene7 server . We specifically wanted to prevent this scenario . Once the OnTime reaches then we are good with asset live on PROD.  Basically here we want to prevent this asset from going to dynamic media server before it reaches onTime.