AEM 6.5 Workflow Launcher Conditions to set dc:title property to filename or another property value | Adobe Higher Education
Skip to main content
nviswanathareddy
Level 2
August 3, 2023

AEM 6.5 Workflow Launcher Conditions to set dc:title property to filename or another property value

Hi Community,

I am working with AEM 6.5

I have written a custom workflow process step to add metadata properties under the asset metadata node

for Ex: add property title to metadata node with value filename

 

when I Start the Workflow Model on an asset having metadata property dc:title the workflow process is successfully updating the dc:title property with the filename

 

But when I trigger the Workflow Launcher (attached the screenshot) with the same Workflow Model it is unable to override the property dc:title

 

Is there any way or any condition to override the dc:title property while using Workflow Launcher

Ce sujet a été fermé aux réponses.

3 commentaires

VictorToledo_
Level 3
August 3, 2023

Hi,

could you share the workflow step code? how are you getting the metadata node?

nviswanathareddy
Level 2
August 4, 2023

Hi @victortoledo_ 
please find the requested code

 

public class AAWKNDCustomAssetMetadataProcess implements WorkflowProcess { @Reference private ResourceResolverFactory resourceResolverFactory; @Override public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { try { WorkflowData workflowData = workItem.getWorkflowData(); // Check if the payload is an asset (JCR_PATH) if ("JCR_PATH".equals(workflowData.getPayloadType())) { String assetPath = workflowData.getPayload().toString(); String metadataPath = getMetadataPath(assetPath); if (StringUtils.isNotEmpty(metadataPath)) { LOGGER.info("Asset Path: {}", assetPath); LOGGER.info("Metadata Node Path: {}", metadataPath); // Get the filename without extension String filename = getProcessedTitle(assetPath); // Add the filename as properties to the metadata node addFilenameToMetadata(metadataPath, workflowSession.adaptTo(Session.class), filename); } else { } } } catch (Exception e) { throw new WorkflowException("Error processing asset metadata", e); } } private void addFilenameToMetadata(String metadataPath, Session session, String filename) { try { Node metadataNode = session.getNode(metadataPath); // Add the filename as the new dc:title property metadataNode.setProperty("dc:title", filename); LOGGER.info("DC Title property value is: {}", filename); // Save the changes to the session session.save(); } } private String getMetadataPath(String assetPath) { try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(getServiceUserMap())) { Resource assetResource = resourceResolver.getResource(assetPath); if (assetResource != null) { Resource metadataResource = assetResource.getChild("jcr:content/metadata"); if (metadataResource != null) { return metadataResource.getPath(); } } } catch (Exception e) { } return null; } private String getProcessedTitle(String assetPath) { // Extract the filename from the assetPath and remove the extension return assetPath.substring(assetPath.lastIndexOf('/') + 1); } private Map<String, Object> getServiceUserMap() { Map<String, Object> serviceUserMap = new HashMap<>(); // Set the service user mapping according to your AEM setup serviceUserMap.put(ResourceResolverFactory.SUBSERVICE, "my-subservice"); return serviceUserMap; } }
VictorToledo_
Level 3
August 4, 2023

Hi @nviswanathareddy 

looks good to me. I was doing some tests with your code and launcher and it is working fine on my local.

(if the launcher is executing the workflow you can debug it and see where is the issue.)

Make sure that your resource resolver has the right permissions for the launchers path and dam path.

 

for me understanding you are able to execute the workflow using the launcher. But it is not working as you expected. Please add more details where you have the issue

 

 

nviswanathareddy
Level 2
August 4, 2023

.

SivakumarKanoori
Community Advisor
Community Advisor
August 4, 2023

@nviswanathareddy :  I think, Your idea is to trigger the workflow whenever there is an asset upload under /content/dam/wknd right.

In this situation i think, your workflow is not getting triggered itself.

 

Can you change the path as below (as the below path states that  upload anything under the wknd folder you workflow gets triggered.)

/content/dam/wknd(/.*/)

 

Let me know if still didnt work.

 

Thanks 

Siva

Thanks,Siva
nviswanathareddy
Level 2
August 4, 2023

Hi @sivakumarkanoori 

Thanks for your response, your understanding was right

I am trying to update dc:title property on an asset, when I trigger the workflow model it was able to update the dc:title successfully
But when I use the same workflow model with a launcher my dc:title property was unable to update, it is taking the title of the asset as the dc:title only, if an asset doesn't have the title the workflow launcher can successfully update the property

SivakumarKanoori
Community Advisor
Community Advisor
August 4, 2023

@nviswanathareddy : As stated in the previous comment, try to edit the launcher and change the path to /content/dam/wknd(/.*/)

 

Thanks,Siva