Expand my Community achievements bar.

SOLVED

Workflow to Rename an updated asset

Avatar

Level 2

I'm looking to create a workflow in Adobe Assets CS to update the name of modified assets.
I see on posts people referring to the Update Asset model but when I look in the existing Models I don't see it Nor can I find processes that match.

Any help is appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @Civison 

 

In AEM as a Cloud Service (AEMaaCS), the traditional DAM Update Asset workflow is not available because AEMaaCS relies more on microservices and out-of-the-box automated processes for asset processing but for your use case you can use an event listener to capture and respond to asset updates.
Below is a similar code example with title update:

import com.day.cq.dam.api.Asset;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

@Component(
        service = EventHandler.class,
        immediate = true,
        property = {
                "event.topics=org/apache/sling/api/resource/Resource/CHANGED",
                "event.filter=(path=/content/dam/*)"
        }
)
public class AssetTitleUpdateListener implements EventHandler {

    private static final Logger LOG = LoggerFactory.getLogger(AssetTitleUpdateListener.class);

    @Reference
    private ResourceResolverFactory resourceResolverFactory;

    @Reference
    private JobManager jobManager;

    @Override
    public void handleEvent(Event event) {
        try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(Map.of(ResourceResolverFactory.SUBSERVICE, "dataWrite"))) {
            String path = (String) event.getProperty("path");
            Resource resource = resolver.getResource(path);

            if (resource != null && resource.isResourceType("dam:Asset")) {
                Asset asset = resource.adaptTo(Asset.class);
                if (asset != null) {
                    String newTitle = asset.getMetadataValue("dc:title");

                    // Custom logic on title change
                    LOG.info("Asset title updated to: {}", newTitle);

                    // Here you can add further processing logic if needed
                }
            }
        } catch (Exception e) {
            LOG.error("Error handling asset title update event: ", e);
        }
    }
}

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 7

Hi @Civison 

 

In AEM as a Cloud Service (AEMaaCS), the traditional DAM Update Asset workflow is not available because AEMaaCS relies more on microservices and out-of-the-box automated processes for asset processing but for your use case you can use an event listener to capture and respond to asset updates.
Below is a similar code example with title update:

import com.day.cq.dam.api.Asset;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.event.jobs.JobManager;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

@Component(
        service = EventHandler.class,
        immediate = true,
        property = {
                "event.topics=org/apache/sling/api/resource/Resource/CHANGED",
                "event.filter=(path=/content/dam/*)"
        }
)
public class AssetTitleUpdateListener implements EventHandler {

    private static final Logger LOG = LoggerFactory.getLogger(AssetTitleUpdateListener.class);

    @Reference
    private ResourceResolverFactory resourceResolverFactory;

    @Reference
    private JobManager jobManager;

    @Override
    public void handleEvent(Event event) {
        try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(Map.of(ResourceResolverFactory.SUBSERVICE, "dataWrite"))) {
            String path = (String) event.getProperty("path");
            Resource resource = resolver.getResource(path);

            if (resource != null && resource.isResourceType("dam:Asset")) {
                Asset asset = resource.adaptTo(Asset.class);
                if (asset != null) {
                    String newTitle = asset.getMetadataValue("dc:title");

                    // Custom logic on title change
                    LOG.info("Asset title updated to: {}", newTitle);

                    // Here you can add further processing logic if needed
                }
            }
        } catch (Exception e) {
            LOG.error("Error handling asset title update event: ", e);
        }
    }
}