Solved! Go to Solution.
Views
Replies
Total Likes
Based on my understanding from your previous questions, you import metadata using the Asset console. Afterward, you manually initiate the workflow by choosing an asset as the payload. In this scenario, the "photoshop:State" is not accessible directly in the workflow metadata; instead, you need to retrieve it from the asset metadata.
final String path = workItem.getWorkflowData().getPayload().toString();
try(ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class)) {
Resource assetResource = resourceResolver.getResource(path);
if(assetResource != null) {
Asset asset = assetResource.adaptTo(Asset.class);
String commentDescription = asset.getMetadataValue("photoshop:State");
Session jcrSession = resourceResolver.adaptTo(Session.class);
Node assetNode = assetResource.adaptTo(Node.class);
Node collectionNode;
if (assetNode.hasNode("jcr:content/comments")) {
collectionNode = assetNode.getNode ("jcr:content/comments");
} else {
collectionNode = assetNode.addNode("jcr:content/comments");
collectionNode.setPrimaryType ("nt:unstructured");
collectionNode.addMixin("mix:lastModified");
collectionNode.setProperty ("sling:resourceType",
"granite/comments/component/collection");
}
Node commentNode = collectionNode.addNode ("Comment3");
commentNode.setPrimaryType("nt:unstructured");
commentNode.addMixin( "mix:lastModified");
commentNode.setProperty("sling:resourceType",
"granite/comments/components/comment");
commentDescription = commentDescription != null && !commentDescription.isEmpty()
? commentDescription : "cant match the metadata";
commentNode.setProperty("jcr:description", commentDescription);
jcrSession.save();
}
} catch(RepositoryException e) {
e.printStackTrace ();
}
It looks like the issue is because the "commentDescription" is null, so the issue is in this line, are you sure the "metaDataMap" object should contain the property "photoshop:state" attribute?
String commentDescription = metaDataMap.get("photoshop:State", String.class);
Can you try this?
String commentDescription= workItem.getWorkflowData().getMetaDataMap().get("photoshop:State", String.class);
no still not working
and yeah by default it has photoshop:state you can check this
Hi,
The code attempts to import comments from asset metadata into AEM assets via a workflow. If it always falls back to "can't match the metadata," here are some steps:
Check Metadata Key: Ensure the metadata key "photoshop:State" matches exactly, considering case sensitivity.
Logging: Add logging to print the values of commentDescription and assetPaths. This helps debug what's retrieved from metadata.
Metadata Structure: Confirm the metadata structure in assets matches expectations, especially the presence of "photoshop:State."
Fallback Value: Ensure the fallback value ("cant match the metadata") doesn't inadvertently overwrite actual metadata.
Asset Paths: Verify that the assetPath in metadata is correctly formatted and contains the paths of the assets you want to update.
Permissions: Check that the workflow user has the necessary permissions to read metadata and modify assets.
is there away to debug the workflow to check if the map really working
Based on my understanding from your previous questions, you import metadata using the Asset console. Afterward, you manually initiate the workflow by choosing an asset as the payload. In this scenario, the "photoshop:State" is not accessible directly in the workflow metadata; instead, you need to retrieve it from the asset metadata.
final String path = workItem.getWorkflowData().getPayload().toString();
try(ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class)) {
Resource assetResource = resourceResolver.getResource(path);
if(assetResource != null) {
Asset asset = assetResource.adaptTo(Asset.class);
String commentDescription = asset.getMetadataValue("photoshop:State");
Session jcrSession = resourceResolver.adaptTo(Session.class);
Node assetNode = assetResource.adaptTo(Node.class);
Node collectionNode;
if (assetNode.hasNode("jcr:content/comments")) {
collectionNode = assetNode.getNode ("jcr:content/comments");
} else {
collectionNode = assetNode.addNode("jcr:content/comments");
collectionNode.setPrimaryType ("nt:unstructured");
collectionNode.addMixin("mix:lastModified");
collectionNode.setProperty ("sling:resourceType",
"granite/comments/component/collection");
}
Node commentNode = collectionNode.addNode ("Comment3");
commentNode.setPrimaryType("nt:unstructured");
commentNode.addMixin( "mix:lastModified");
commentNode.setProperty("sling:resourceType",
"granite/comments/components/comment");
commentDescription = commentDescription != null && !commentDescription.isEmpty()
? commentDescription : "cant match the metadata";
commentNode.setProperty("jcr:description", commentDescription);
jcrSession.save();
}
} catch(RepositoryException e) {
e.printStackTrace ();
}
Views
Likes
Replies