I'm trying to update metadata with user id through workflow, when I was run the workflow on the particular that asset metadata should be update with the user id.
Write a workflow to save the name/id of the user on the metadata of the asset on which the workflow was run on in the field- "user id".
I need java code for this.
Solved! Go to Solution.
Views
Replies
Total Likes
I hope this article might help you.
I hope you are aware of wring custom work flow process (Java which implements WorkflowProcess). Here, you need to write the actual logic.
Views
Replies
Total Likes
I hope this article might help you.
I hope you are aware of wring custom work flow process (Java which implements WorkflowProcess). Here, you need to write the actual logic.
Views
Replies
Total Likes
Hi @Nandigama_Vamsi
how to update the metadata of an asset with the user ID using a workflow
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import org.apache.sling.api.resource.ResourceResolver;
public class UpdateMetadataWorkflowProcess {
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
try {
// Get the user ID
String userId = workItem.getWorkflow().getInitiator();
// Get the asset path
String assetPath = workItem.getWorkflowData().getPayload().toString();
// Get the resource resolver
ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
// Update the metadata of the asset
Resource assetResource = resourceResolver.getResource(assetPath);
ModifiableValueMap metadata = assetResource.adaptTo(ModifiableValueMap.class);
metadata.put("user id", userId);
resourceResolver.commit();
// Log the success message
workflowSession.getWorkflowData().getMetaDataMap().put("success", "Metadata updated successfully");
} catch (Exception e) {
// Log the error message
workflowSession.getWorkflowData().getMetaDataMap().put("error", "Failed to update metadata: " + e.getMessage());
}
}
}
Views
Replies
Total Likes
Hi @Raja_Reddy @Nandigama_Vamsi
I have checked above logic by implementing WorkflowProcess .
public class UpdateMetadataWorkflowProcess implements WorkflowProcess { ...}
String userId = workitem.getWorkflow().getInitiator();
// value of userId: workflow-service
Session session = worksession.adaptTo(Session.class);
String userId = session.getUserID();
// value of userId: workflow-process-service
@Nandigama_Vamsi are you expecting this user ID? or the logged in user ID (the guy has uploaded the DAM asset).
Views
Replies
Total Likes
Thank you for the reply.
when I'm run the workflow the asset metadata property user id field as to create and fill with my userid that logging.
Example if I login with admin, when I run the workflow the metadata property of user id field updated with admin.
Views
Replies
Total Likes