Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to Update Language Copy Using Java workflows?

Avatar

Avatar
Level 1
troubleshooter3
Level 1

Likes

0 likes

Total Posts

14 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
troubleshooter3
Level 1

Likes

0 likes

Total Posts

14 posts

Correct Reply

0 solutions
View profile
troubleshooter3
Level 1

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

View Entire Topic

Avatar

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Give Back
Level 4
Jineet_Vora
Level 4

Likes

42 likes

Total Posts

45 posts

Correct Reply

22 solutions
Top badges earned
Give Back
Ignite 1
Boost 5
Boost 3
Boost 25
View profile
Jineet_Vora
Level 4

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