#Questetra-Addon-XML_file: Extract Configs

Questetra-Addon-XML file, Extract Configs

Questetra-Addon-XML file, Extract Configs

Questetra-Addon-XMLファイル, コンフィグ情報の抽出

Extracts the configs of the Auto Step (automated task). The Addon-XML file (for Questetra BPMS automatic task) is parsed and information such as summary, last-modified, config etc. are extracted.

Auto Step icon
Configs for this Auto Step
SelectConfA
A: Select FILES DATA for Addon-XML (Multiple not supported) *
StrConfB
B: Set Which Language to Extract (e.g. “de”, “”)#{EL}
SelectConfC
C: Select STRING DATA for Label (update)
SelectConfC2
C2: Select STRING DATA for English Label (update)
SelectConfD
D: Select STRING DATA for Summary (update)
SelectConfE
E: Select STRING DATA for HelpPageUrl (update)
SelectConfF
F: Select STRING DATA for LastModified (update)
SelectConfG
G: Select STRING DATA for EngineType (update)
SelectConfH
H: Select STRING DATA for License (update)
SelectConfI
I: Select STRING DATA for Script (update)
SelectConfJ
J: Select STRING DATA for Configs HTML (update)
SelectConfK
K: Select STRING DATA for Base64 image (update)
Script (click to open)
// GraalJS Script (engine type: 2)

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

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


//// == 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)  //// ★★★ Updated in ver 2022 (dt,dd) ★★★
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) + "]";

  // "dt"
  strConfigs += '<dt style="font-weight: 300; font-size: 50%; margin: -1em 0 0 0; color: #C3C3C3;">';
  strConfigs += xpath.findNodeText( strAddonXml, xpathTmp + "/@name" );
  strConfigs += '</dt>';
  // "dd"
  strConfigs += '<dd style="margin: -0.5em 0 0.1em 1em">';
  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 );
  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 += "</dd>\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()" /////////////////////////////////////////////////////////////////

/*
Notes:
- Element without locale attribute is required for all definition-elements
- Configs definition with multiple child elements outputs LI-HTML
- Ends with an error, if the number of files is not one.
- 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
Appendix:
- EngineType: "0"
    - Engine Name: "Rhino" (obsolete)
    - v9.7 (2013-10-07)
    - v11.1 (2016-09-05)
    - v13.1 (2021-07-12)
        - https://support.questetra.com/versions/version-131/
- EngineType: "1"
    - Engine Name: "Nashorn" (obsolete)
    - v11.7 (2018-06-11)
        - https://support.questetra.com/versions/version-1170/
    - v12.0 (2020-05-11)
    - v14.0 (2022-04-11)
        - https://support.questetra.com/versions/version-140/
- EngineType: "2"
    - Engine Name: "GraalJS"
    - v12.2 (2020-10-12)

Notes-ja:
- 全ての定義(XML要素)につきデフォルト設定(locale 属性をもたない要素)が必須です
- 複数子要素を持つConfigs定義については箇条書HTMLを出力します
- ファイルの数が1でない場合、エラー終了します
- 抽出情報をもとに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
Appendix-ja:
- EngineType: "0"
    - Engine Name: "Rhino" (obsolete)
    - v9.7 (2013-10-07) にて登場
        - "新しい自動処理設定 『スクリプトタスク』 を追加しました"
        - https://japan.zdnet.com/release/30054194/
    - v11.1 (2016-09-05)
        - "[サービスタスク (Add-on)]を追加"
    - v13.1 (2021-07-12) にて廃止
        - "スクリプトタスク:スクリプトエンジンが「GraalJS」に置き換えられます"
        - https://support.questetra.com/ja/versions/version-131/
- EngineType: "1"
    - Engine Name: "Nashorn" (obsolete)
    - v11.7 (2018-06-11) にて登場
        - https://support.questetra.com/ja/versions/version-1170/
        - "スクリプト実行エンジンとして「Nashorn」を使用できるように"
    - v12.0 (2020-05-11)
        - `configs.getObject()` が登場
    - v14.0 (2022-04-11) にて廃止
        - "スクリプトタスク:「Nashorn」が強制的に「GraalJS」に変更されます"
        - https://support.questetra.com/ja/versions/version-140/
- EngineType: "2"
    - Engine Name: "GraalJS"
    - v12.2 (2020-10-12) にて登場
        - "スクリプト実行エンジンとして「GraalJS」を使用できるように"
        - https://support.questetra.com/ja/versions/version-1220/
*/

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

Capture

Extracts the configs of the Auto Step (automated task). The Addon-XML file (for Questetra BPMS automatic task) is parsed and information such as summary, last-modified, config etc. are extracted.

Appendix

See Also

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