Questetra-Addon-XML file, Extract Configs

Questetra-Addon-XML file, Extract Configs

Questetra-Addon-XML file, Extract Configs
Extracts the configs of the automatic step. The Addon-XML file (for Questetra BPMS automatic task) is parsed and information such as summary, last-modified, config etc. are extracted (XML escape is not decoded).
Configs
  • A: Select FILES DATA for Addon-XML (Multiple not supported) *
  • B: Set Which Language to Extract (e.g. “de”, “”)#{EL}
  • C: Select STRING DATA for Label (update)
  • C2: Select STRING DATA for English Label (update)
  • D: Select STRING DATA for Summary (update)
  • E: Select STRING DATA for HelpPageUrl (update)
  • F: Select STRING DATA for LastModified (update)
  • G: Select STRING DATA for EngineType (update)
  • H: Select STRING DATA for License (update)
  • I: Select STRING DATA for Script (update)
  • J: Select STRING DATA for Configs HTML (update)
  • K: Select STRING DATA for Base64 image (update)
Script (click to open)

// GraalJS Script (engine type: 2)

/*
Notes:
- Ends with an error, if the number of files is not one.
- Element without locale attribute is required for all definition-elements
- EngineType: "0" = Rhino (deprecated), "1" = Nashorn, "2" = GraalJS
- Configs definition with multiple child elements outputs LI-HTML with fontawesome5
- Escape processing and template processing are required for website HTML code.
    - M227: Auto Executing Data Binding, Arithmetic Operations
    - https://questetra.zendesk.com/hc/en-us/articles/360002260571-M227
        - HTML Escape: "#{#escapeXml(#q_xml_data)}"
        - https://questetra.zendesk.com/hc/en-us/articles/360024292872-R2272
 
Notes(ja):
- ファイルの数が1でない場合、エラー終了します
- 全ての定義(XML要素)につきデフォルト設定(locale 属性をもたない要素)が必須です
- EngineType: "0"= Rhino (deprecated), "1"= Nashorn, "2"= GraalJS
- 複数子要素を持つConfigs定義については箇条書HTMLを出力します(fontawesome5 icons)
- 抽出情報をもとにWebサイト原稿を生成したい場合、エスケープやテンプレ挿入を後置します
    - M227: 業務データの結合や四則演算が自動実行されるように設定する
    - https://questetra.zendesk.com/hc/ja/articles/360002260571-M227
        - HTMLエスケープ: "#{#escapeXml(#q_xml_data)}"
        - https://questetra.zendesk.com/hc/ja/articles/360024292872-R2272
*/

//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const filesPocketAddon  = configs.getObject( "SelectConfA" ); // required
const strLocaleCode     = configs.get      ( "StrConfB" ) + "";
const strPocketLabel    = configs.getObject( "SelectConfC" );
const strPocketLabelEn  = configs.getObject( "SelectConfC2");
const strPocketSummary  = configs.getObject( "SelectConfD" );
const strPocketHelpUrl  = configs.getObject( "SelectConfE" );
const strPocketLastMod  = configs.getObject( "SelectConfF" );
const strPocketEngine   = configs.getObject( "SelectConfG" );
const strPocketLicense  = configs.getObject( "SelectConfH" );
const strPocketScript   = configs.getObject( "SelectConfI" );
const strPocketConfigs  = configs.getObject( "SelectConfJ" );
const strPocketImage    = configs.getObject( "SelectConfK" );


//// == Data Retrieving / ワークフローデータの参照 ==
let fileAddon = engine.findData( filesPocketAddon ); 
// java.util.ArrayList
if( fileAddon === null ) {
  throw new Error( "\n AutomatedTask UnexpectedFilesError:" + 
                   " Files {A} not found \n" );
}
if ( fileAddon.size() > 1) {
  throw new Error( "\n AutomatedTask UnexpectedFilesError:" + 
                   " Files {A} must be single: " + 
                     fileAddon.size() + " files attached \n" );
}


//// == Calculating / 演算 ==
/// load text (XML)
let strAddonXml = '';
let numLineCounter = 0;
fileRepository.readFile( fileAddon.get(0), "UTF-8", function(line) {
// com.questetra.bpms.core.event.scripttask.FileRepositoryWrapper
// https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#FileRepositoryWrapper
    strAddonXml += line + '\n';
    numLineCounter ++;
});
engine.log( " AutomatedTask FileLoaded: Number of lines = " + numLineCounter );

/// parse XML
// com.questetra.bpms.core.event.scripttask.XPathWrapper
// - https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#XPathWrapper
// com.questetra.bpms.core.event.scripttask.XPathWrapper.NodeWrapper
// com.questetra.bpms.core.event.scripttask.XPathWrapper.NodeListWrapper
//   /label  /help-page-url  /summary  /license  /engine-type  /last-modified
//   /script  /configs  /configs/config  /icon

/// extract Label (Addon title)
let xpathLabel   = "/service-task-definition/label[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathLabel ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'label' " );
    xpathLabel   = "/service-task-definition/label[not(@locale)]";
}
const strLabel   = xpath.findNodeText( strAddonXml, xpathLabel );

/// extract default-Label (Addon english title)
let xpathLabelEn = "/service-task-definition/label[not(@locale)]";
const strLabelEn = xpath.findNodeText( strAddonXml, xpathLabelEn );

/// extract Summary
let xpathSummary = "/service-task-definition/summary[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathSummary ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'summary' " );
    xpathSummary = "/service-task-definition/summary[not(@locale)]";
}
const strSummary = xpath.findNodeText( strAddonXml, xpathSummary );

/// extract HelpPageUrl
let xpathHelpUrl = "/service-task-definition/help-page-url[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathHelpUrl ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'help-page-url' " );
    xpathHelpUrl = "/service-task-definition/help-page-url[not(@locale)]";
}
const strHelpUrl = xpath.findNodeText( strAddonXml, xpathHelpUrl );

/// extract LastModified
let xpathLastMod = "/service-task-definition/last-modified[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathLastMod ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'last-modified' " );
    xpathLastMod = "/service-task-definition/last-modified[not(@locale)]";
}
const strLastMod = xpath.findNodeText( strAddonXml, xpathLastMod );

/// extract EngineType
let xpathEngine = "/service-task-definition/engine-type[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathEngine ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'engine-type' " );
    xpathEngine = "/service-task-definition/engine-type[not(@locale)]";
}
const strEngine = xpath.findNodeText( strAddonXml, xpathEngine );

/// extract License
let xpathLicense = "/service-task-definition/license[@locale='" + strLocaleCode + "']";
if( xpath.findNodeList( strAddonXml, xpathLicense ).getLength() == 0 ){
    engine.log( "  XPATH: 'locale=\"" + strLocaleCode + "\"' not found in 'license' " );
    xpathLicense = "/service-task-definition/license[not(@locale)]";
}
const strLicense = xpath.findNodeText( strAddonXml, xpathLicense );

/// extract Script (not escaped)
let xpathScript = "/service-task-definition/script";
const strScript = xpath.findNodeText( strAddonXml, xpathScript );


/// extract ConfigsHTML (not escaped)
let strConfigs = "";
const xmlNodesConfig = xpath.findNodeList( strAddonXml,
                                           '/service-task-definition/configs/config');
engine.log( " AutomatedTask XmlParsed: NumOf 'Config' = " + xmlNodesConfig.getLength() );
for( let i = 0; i < xmlNodesConfig.getLength(); i++ ){
  let xpathTmp = "/service-task-definition/configs/config[" + (i+1) + "]";

  // "li" prefix
  strConfigs += '<li><span class="fa-li">';
  if( xpath.findNodeText( strAddonXml, xpathTmp + "/@form-type" ) == "SELECT" ){
    if( xpath.findNodeList( strAddonXml, xpathTmp + "[@editable='true']" )
             .getLength() == 1 ){
      strConfigs += '<i class="far fa-caret-square-down fa-lg"></i>';
    }else{
      strConfigs += '<i class="fal fa-caret-square-down fa-lg"></i>';
    }
  }else if( xpath.findNodeText( strAddonXml, xpathTmp + "/@form-type" ) == "TEXTFIELD" ){
    strConfigs += '<i class="far fa-pen-square fa-lg"></i>';
  }else if( xpath.findNodeText( strAddonXml, xpathTmp + "/@form-type" ) == "TEXTAREA" ){
    strConfigs += '<i class="far fa-edit fa-lg"></i>';
  }else if( xpath.findNodeText( strAddonXml, xpathTmp + "/@form-type" ) == "QUSER" ){
    strConfigs += '<i class="fal fa-user fa-lg"></i>';
  }else{ // "OAUTH2"
    strConfigs += '<i class="fal fa-badge-check fa-lg"></i>';
  }
  strConfigs += '</span> ';

  // "li" body
  let xpathTmp2 = xpathTmp + "/label[@locale='" + strLocaleCode + "']";
  if( xpath.findNodeList( strAddonXml, xpathTmp2 ).getLength() == 0 ){
      engine.log( "  XPATH: 'locale=\"" + strLocaleCode +
                                   "\"' not found in 'config[" + (i+1) + "]' " );
      xpathTmp2 = xpathTmp + "/label[not(@locale)]";
  }
  strConfigs += xpath.findNodeText( strAddonXml, xpathTmp2 );

  // "li" postfix
  if( xpath.findNodeList( strAddonXml, xpathTmp + "[@required='true']" )
           .getLength() == 1 ){
    strConfigs += '<span style="color:#990000;"> *</span>';
  }
  if( xpath.findNodeList( strAddonXml, xpathTmp + "[@el-enabled='true']" )
           .getLength() == 1 ){
    strConfigs += '<span style="color:#000099;"><sup style="font-style:italic;">#{EL}</sup></span>';
  }
  strConfigs += "</li>\n";
}

/// extract Base64 Encoded Image
let xpathImage = "/service-task-definition/icon";
const strImage = xpath.findNodeText( strAddonXml, xpathImage );


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketLabel !== null ){
  engine.setData( strPocketLabel, strLabel );
}
if( strPocketLabelEn !== null ){
  engine.setData( strPocketLabelEn, strLabelEn );
}
if( strPocketSummary !== null ){
  engine.setData( strPocketSummary, strSummary );
}
if( strPocketHelpUrl !== null ){
  engine.setData( strPocketHelpUrl, strHelpUrl );
}
if( strPocketLastMod !== null ){
  engine.setData( strPocketLastMod, strLastMod );
}
if( strPocketEngine !== null ){
  engine.setData( strPocketEngine, strEngine );
}
if( strPocketLicense !== null ){
  engine.setData( strPocketLicense, strLicense );
}
if( strPocketScript !== null ){
  engine.setData( strPocketScript, strScript );
}
if( strPocketConfigs !== null ){
  engine.setData( strPocketConfigs, strConfigs );
}
if( strPocketImage !== null ){
  engine.setData( strPocketImage, strImage );
}

} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

2020-09-04 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/questetra-addon-xml-file-extract-configs/
The Addon-import feature is available with Professional edition.

Notes

  • Ends with an error, if the number of files is not one.
  • Element without locale attribute is required for all definition-elements
  • EngineType: “0” = Rhino (deprecated), “1” = Nashorn, “2” = GraalJS
  • Configs definition with multiple child elements outputs LI-HTML with fontawesome5
  • Escape processing and template processing are required for website HTML code.

Capture

Extracts the configs of the automatic step. The Addon-XML file (for Questetra BPMS automatic task) is parsed and information such as summary, last-modified, config etc. are extracted (XML escape is not decoded). And simple HTML code is generated.

See also

3 thoughts on “Questetra-Addon-XML file, Extract Configs”

  1. Pingback: Questetra-Addon-XML Extract Configs – Questetra Support

  2. Pingback: Questetra-Model-XML file, Extract Definitions – Questetra Support

  3. Pingback: JSON String, Extract Value using JSON-Path – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading