How to Update Language Copy Using Java workflows?

Avatar

Avatar

troubleshooter3

Avatar

troubleshooter3

troubleshooter3

03-11-2020

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);

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jineet_Vora

Avatar

Jineet_Vora

Jineet_Vora

03-11-2020

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();

 

 

 

Answers (0)