cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Initiating a Translation Package Creation from a Java workflow expression robot

AdamElkins
12-Amethyst

Initiating a Translation Package Creation from a Java workflow expression robot

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?

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3
plutsky
14-Alexandrite
(To:AdamElkins)

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

 

 

AdamElkins
12-Amethyst
(To:plutsky)

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

Top Tags