Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!
SOLVED

How to Update Language Copy Using Java workflows?

Avatar

Level 3

I have customized my translations and I use below code to create language copy, I am not sure what will be the similar code for update language copy? I tried String workflowName = "/var/workflow/models/wcm-translation/update_language_copy"; but it ends up throwing "Failed to load master language from payload."

 

 

WorkflowSession wfSession = workflowService.getWorkflowSession(session);

// We can have any workflow model here - For creating language copy I am using create_language_copy workflow.

String workflowName = "/var/workflow/models/wcm-translation/create_language_copy";

// Get the workflow model

WorkflowModel wfModel = wfSession.getModel(workflowName);

 

String languageEnMasterPath = "master page path";

// Get the workflow data

// Workflow Data - Provide the master language page path from where the language copy to be created 

WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", languageEnMasterPath);

// Add meta data values

final Map<String, Object> workflowMetadata = new HashMap<>();

workflowMetadata.put("model", "/etc/workflow/models/wcm-translation/create_language_copy/jcr:content/model");

// If parent pages to be auto created when not present - false to not create

workflowMetadata.put("createNonEmptyAncestors", true);

// Pass true if child pages to be created

workflowMetadata.put("deep", false);

workflowMetadata.put("projectFolderLanguageRefCount", "Count of total language masters available");

// Pass comma separated languages list like en,fr,es etc. For only 1 language pass workflowMetadata.put("language", "fr")

workflowMetadata.put("languageList", "comma separated language list");

//Pass project type - add_structure_only will create only structure no translation will happen

workflowMetadata.put("projectType", "add_structure_only");

workflowMetadata.put("projectTitle", "");

 

// Run the Workflow.

wfSession.startWorkflow(wfModel, wfData, workflowMetadata);

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @troubleshooter3,

The exception is thrown from below:

final String masterLanguage = (String)metaData.get("language", (Class)String.class);
if (StringUtils.isEmpty((CharSequence)masterLanguage)) {
    throw new WorkflowException("Failed to load master language from payload.");
}


Please make sure that the master language is populated in metadata as below:

 

String languageEnMasterPath = "master page path";
String workflowName = "/var/workflow/models/wcm-translation/update_language_copy";

WorkflowSession wfSession = workflowService.getWorkflowSession(session);
WorkflowModel wfModel = wfSession.getModel(workflowName);
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", languageEnMasterPath);

//Below contains list of items to add to wfData
wfData.getMetaDataMap().put("language", "Value");

Map<String, Object> metaDataMap = new HashMap<String, Object>();
metaDataMap.put(workflowTitle, "WCM: Update Language Copy");

wfSession.startWorkflow(wfModel, wfData, metaDataMap);
session.save();

 

 

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hello @troubleshooter3,

The exception is thrown from below:

final String masterLanguage = (String)metaData.get("language", (Class)String.class);
if (StringUtils.isEmpty((CharSequence)masterLanguage)) {
    throw new WorkflowException("Failed to load master language from payload.");
}


Please make sure that the master language is populated in metadata as below:

 

String languageEnMasterPath = "master page path";
String workflowName = "/var/workflow/models/wcm-translation/update_language_copy";

WorkflowSession wfSession = workflowService.getWorkflowSession(session);
WorkflowModel wfModel = wfSession.getModel(workflowName);
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", languageEnMasterPath);

//Below contains list of items to add to wfData
wfData.getMetaDataMap().put("language", "Value");

Map<String, Object> metaDataMap = new HashMap<String, Object>();
metaDataMap.put(workflowTitle, "WCM: Update Language Copy");

wfSession.startWorkflow(wfModel, wfData, metaDataMap);
session.save();

 

 

 

Avatar

Level 3
That code is still using create language copy and not update language copy, however I have also tried adding language list attribute to metadata.

Avatar

Community Advisor
I have edited my response, please check my answer above again. Let me know if still this doesn't work.