Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Version: Windchill 12.1
Use Case: I am looking for a way to initiate the creation of a translation package from a workflow. Is that possible? Are there any Java API's I can use to potentially do this in an expression robot?
Description:
I am looking for a way to initiate the creation of a translation package from a workflow. Is that possible? Are there any Java API's I can use to potentially do this in an expression robot?
Solved! Go to Solution.
There is an OTB workflow that does this already. A custom process can be implemented that initiates a translation package as follows.
org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger("com.ptc.tml.workflow.CoreWorkflow");
logger.trace("Build Translation Package - entered");
String oldUser = null;
wt.inf.container.WTContainer container = null;
String targetLang = "";
com.ptc.tml.collection.TranslationCollection collection = com.ptc.tml.collection.TranslationCollection.fromOidString(collectionOid);
try {
wt.workflow.engine.WfProcess main = (wt.workflow.engine.WfProcess)self.getObject();
final String wfCreator = com.ptc.tml.utils.TMLUtils.getUserName(main.getCreator());
oldUser = com.ptc.tml.utils.TMLUtils.switchSessionPrincipal(wfCreator);
userName = collection.getUserName();
outputDir = collection.getOutputDirectory();
container = collection.getContainer();
targetLang = collection.getTargetLanguage();
containerOid = collection.getContainerRef().getKey().toString();
final String sourceLang = collection.getSourceLanguage();
wt.vc.baseline.ManagedBaseline baseline = com.ptc.tml.utils.WorkflowAdapter.createBaseline(collection, log);
if (baseline == null) {
baselineOid = null;
log.addErrorNoDocsToTranslate();
logger.trace("Collection " + collection.getName() + ": " + errorMsg);
} else {
log = new com.ptc.tml.log.TmlPackageLog(baseline, collection.getSourceLanguage(), targetLang, log);
baselineOid = com.ptc.tml.utils.TMLUtils.getReference(baseline);
logger.trace("Collection " + collection.getName() + " -> Baseline " + baselineOid);
newTranslationPackageName = com.ptc.tml.utils.WorkflowAdapter.
createTranslationPackage(baseline, collection.getSourceOid(), sourceLang, targetLang, userName, outputDir, container, log).getAbsolutePath();
if (log.numErrors() == 0) {
//Store notification messages
successMessage = new StringBuilder(log.toHtmlSummaryString());
warningMessage = new StringBuilder(log.toHtmlWarningString());
}
logger.trace("Baseline " + baselineOid + " -> Package " + newTranslationPackageName);
}
} catch(java.lang.Throwable t) {
log.addError("Build Translation Package", t);
} finally {
if (log.numErrors() > 0) {
log.writeErrorLog();
errorMsg = log.toHtmlSummaryString();
}
com.ptc.tml.utils.TMLUtils.switchSessionPrincipal(oldUser);
}
logger.trace("Build Translation Package - exiting");
There is a public class called TranslationProcess which includes public methods for initiating a translation. The general idea is that you would need to first call an api to create the objects and the baseline, and then call an api "exportTranslationPackage"
com.ptc.tml.utils.TranslationProcess
Thanks! I will look into this and mark it as the solution if it pans out.
There is an OTB workflow that does this already. A custom process can be implemented that initiates a translation package as follows.
org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger("com.ptc.tml.workflow.CoreWorkflow");
logger.trace("Build Translation Package - entered");
String oldUser = null;
wt.inf.container.WTContainer container = null;
String targetLang = "";
com.ptc.tml.collection.TranslationCollection collection = com.ptc.tml.collection.TranslationCollection.fromOidString(collectionOid);
try {
wt.workflow.engine.WfProcess main = (wt.workflow.engine.WfProcess)self.getObject();
final String wfCreator = com.ptc.tml.utils.TMLUtils.getUserName(main.getCreator());
oldUser = com.ptc.tml.utils.TMLUtils.switchSessionPrincipal(wfCreator);
userName = collection.getUserName();
outputDir = collection.getOutputDirectory();
container = collection.getContainer();
targetLang = collection.getTargetLanguage();
containerOid = collection.getContainerRef().getKey().toString();
final String sourceLang = collection.getSourceLanguage();
wt.vc.baseline.ManagedBaseline baseline = com.ptc.tml.utils.WorkflowAdapter.createBaseline(collection, log);
if (baseline == null) {
baselineOid = null;
log.addErrorNoDocsToTranslate();
logger.trace("Collection " + collection.getName() + ": " + errorMsg);
} else {
log = new com.ptc.tml.log.TmlPackageLog(baseline, collection.getSourceLanguage(), targetLang, log);
baselineOid = com.ptc.tml.utils.TMLUtils.getReference(baseline);
logger.trace("Collection " + collection.getName() + " -> Baseline " + baselineOid);
newTranslationPackageName = com.ptc.tml.utils.WorkflowAdapter.
createTranslationPackage(baseline, collection.getSourceOid(), sourceLang, targetLang, userName, outputDir, container, log).getAbsolutePath();
if (log.numErrors() == 0) {
//Store notification messages
successMessage = new StringBuilder(log.toHtmlSummaryString());
warningMessage = new StringBuilder(log.toHtmlWarningString());
}
logger.trace("Baseline " + baselineOid + " -> Package " + newTranslationPackageName);
}
} catch(java.lang.Throwable t) {
log.addError("Build Translation Package", t);
} finally {
if (log.numErrors() > 0) {
log.writeErrorLog();
errorMsg = log.toHtmlSummaryString();
}
com.ptc.tml.utils.TMLUtils.switchSessionPrincipal(oldUser);
}
logger.trace("Build Translation Package - exiting");