Questetra-Model-XML Extract Definition
Extracts the definition summary of Business Process. Process-data-definitions (“number”, “data-type”, “name”) and Node (“number”, “name”, “nodeType”) are extracted from Model-XML file in QAR archive. TSV and/or HTML for WordPress are generated.
https://support.questetra.com/addons/questetra-model-xml-extract-definition/
2019-01-18 (C) Questetra, Inc. (MIT License)
Configs
  • A: Select FILES DATA for Model-XML (Multiple not supported) *
  • a1: Select STRING DATA for QAR-Title
  • a2: Select STRING DATA for QAR-Description
  • a3: Set URL for Qar File (e.g. “https://example.com/foo/”) #{EL}
  • a4: Set LICENSE for Qar File (e.g. “(C) Questetra, Inc.”) #{EL}
  • B: Select STRING DATA for TSV of Nodes-Definition (update)
  • C: Select STRING DATA for TSV of Data-Definition (update)
  • D: Select STRING DATA for Digest HTML (update)
Script
// Rhino engine (engine type: 0) to use E4X

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


//// == Config Retrieving / 工程コンフィグの参照 ==
var dataIdA = configs.get( "conf_DataIdA" ) + "";
var dataIdA1 = configs.get( "conf_DataIdA1" ) + "";
var dataIdA2 = configs.get( "conf_DataIdA2" ) + "";
var qarUrl   = configs.get( "conf_QarUrl" ) + "";
var qarLicense = configs.get( "conf_QarLicense" ) + "";
var dataIdB = configs.get( "conf_DataIdB" ) + "";
var dataIdC = configs.get( "conf_DataIdC" ) + "";
var dataIdD = configs.get( "conf_DataIdD" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'

if(dataIdB === "" && dataIdC === "" && dataIdD === "" ){
  throw new Error( '\n B/C/D is required at least one. \n' );
}


//// == Data Retrieving / ワークフローデータの参照 ==
var qarTitle = "";
if( dataIdA1 !== ""){
  qarTitle = engine.findDataByNumber( dataIdA1 ) + "";
}
var qarDescr = "";
if( dataIdA2 !== ""){
  qarDescr = engine.findDataByNumber( dataIdA2 ) + "";
}

var myFiles = engine.findDataByNumber( dataIdA ); 
// java.util.ArrayList
if (myFiles === null || myFiles.size() != 1) {
  throw new Error( '\n One-file attachment is only valid. \n' );
}
var myFileText = '';
var myLineCounter = 0;
fileRepository.readFile(myFiles.get(0), "UTF-8", function(line) {
    myFileText += line + '\n';
    myLineCounter++;
});
engine.log( "#Line of Text-File: " + myLineCounter );
// engine.log( myFileText ); // debug


//// == Calculating / 演算 ==
/// parse XML (ECMAScript for XML (E4X))
myFileText = myFileText
//  .replace(/<\?xml\s.*?\?>/, "") // E4X bug 336551
  .replace(/<\?xml[^>]*\?>/, "") // E4X bug 336551
  .trim(); // Removes space, tab, no-break space, etc. and LF, CR
//engine.log( myFileText ); //debug
var xmlObj = new XML( myFileText );
engine.log( "Parcing XML is completed." );

var numData = xmlObj["process-data-definitions"]["process-data-definition"].length() - 0;
engine.log( " #Data: " + numData );
var numNode = xmlObj.nodes.node.length() - 0;
engine.log( " #Node: " + numNode );

/// Extracts Node Def
var i;
var nodeObjects = new Array(numNode);
for(i = 0; i < numNode ; i++){
  nodeObjects[i] = {};
  nodeObjects[i].name   = xmlObj.nodes.node[i].name + "";
  nodeObjects[i].type   = xmlObj.nodes.node[i].nodeType + "";
  nodeObjects[i].number = xmlObj.nodes.node[i].attribute("number") + "";
}
nodeObjects.sort(function(a, b){ // name sort
	if (a.name > b.name) return 1;
	if (a.name < b.name) return -1;
	return 0;
});
var nodeDefTsv  = '';
for(i = 0; i < numNode ; i++){
  nodeDefTsv  += nodeObjects[i].name + "\t";
  nodeDefTsv  += nodeObjects[i].type + "\t";
  nodeDefTsv  += nodeObjects[i].number;
  if( i !== numData ){
    nodeDefTsv  += "\n";
  }
}
engine.log( nodeDefTsv );

/// Extracts Data Def
var dataObjects = new Array(numData);
for(i = 0; i < numData ; i++){
  var order = xmlObj["process-data-definitions"]["process-data-definition"][i]["view-order"] - 1; // "order" start 1
  dataObjects[order] = {};
  dataObjects[order].type   = xmlObj["process-data-definitions"]["process-data-definition"][i]["data-type"] + "";
  dataObjects[order].form   = "";
  if( dataObjects[order].type === "0" || dataObjects[order].type === "11" || dataObjects[order].type === "8" ){
    dataObjects[order].form = xmlObj["process-data-definitions"]["process-data-definition"][i]["form-type"] + "";
  } // STRING or SELECT or USER type
  if( dataObjects[order].type === "5" ){
    dataObjects[order].form = xmlObj["process-data-definitions"]["process-data-definition"][i]["sub-type"] + "";
  } // DATE type
  dataObjects[order].name   = xmlObj["process-data-definitions"]["process-data-definition"][i].name + "";
  dataObjects[order].number = xmlObj["process-data-definitions"]["process-data-definition"][i].attribute("number") + "";
}
var dataDefTsv  = '';
for(i = 0; i < numData ; i++){
  dataDefTsv  += dataObjects[i].type + "\t";
  dataDefTsv  += dataObjects[i].form + "\t";
  dataDefTsv  += dataObjects[i].name + "\t";
  dataDefTsv  += dataObjects[i].number;
  if( i !== numData ){
    dataDefTsv  += "\n";
  }
}
engine.log( dataDefTsv );

/// Generates HTML (Qar Title Descr Url License)
var myHtml = '';
myHtml += '<!-- wp:html -->\n';
myHtml += '[su_box title="' + qarTitle;
myHtml += '" style="soft" box_color="#77eeee" title_color="#000000" radius="0"]';
myHtml += qarDescr + '<br><a href="' + qarUrl + '">';
myHtml += qarUrl + '</a><br><span style="float: right;">';
myHtml += qarLicense + '</span>[/su_box]\n';
myHtml += '<!-- /wp:html -->\n';
myHtml += '\n';

/// Generates HTML (Qar Node)
myHtml += '<!-- wp:html -->\n';
myHtml += '[su_spoiler title="Nodes" open="yes" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="source"]';
myHtml += '<div style="line-height:2.5em;font-size:0.8em;">\n';
for(i = 0; i < numNode; i++ ){
  if(nodeObjects[i].type === "0"){
    myHtml += '<span style="padding:0.2em 0.5em;margin:1em 0.2em;';
    myHtml += 'border:solid 1px #053769;border-radius:8px;';
    myHtml += 'background-color:#8AF2FF;" ';
    myHtml += 'title="NodeNumber: ';
    myHtml += nodeObjects[i].number;
    myHtml += '">';
    myHtml += nodeObjects[i].name;
    myHtml += '</span>\n';
  }else if(nodeObjects[i].type === "3"){
    myHtml += '<span style="padding:0.2em 0.5em;margin:1em 0.2em;';
    myHtml += 'border:solid 1px #686868;border-radius:8px;';
    myHtml += 'background-color:#EEEEEE;" ';
    myHtml += 'title="NodeNumber: ';
    myHtml += nodeObjects[i].number;
    myHtml += '">';
    myHtml += nodeObjects[i].name;
    myHtml += '</span>\n';
  }
}
myHtml += '</div>[/su_spoiler]\n';
myHtml += '<!-- /wp:html -->\n';
myHtml += '\n';

/// Generates HTML (Qar DataItems)
myHtml += '<!-- wp:html -->\n';
myHtml += '[su_spoiler title="Data" open="yes" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="source"]';
myHtml += '<div style="font-size:0.9em;">\n';
myHtml += '<table style="width:100%;">\n';
for(i = 0; i < numData; i++ ){
/// 0-f0 String (Text Box single line) 文字(単一行)
/// 0-f1 String (Text Box multiple lines) 文字(複数行)-
/// 12 Numeric 数値-
/// 11-f2 Select (Radio Button) 選択(ラジオボタン)
/// 11-f4 Select (Select Box) 選択(セレクトボックス)
/// 11-f3 Select (Check Box) 選択(チェックボックス)
/// 11-f5 Select (Search Select Box) 選択(検索セレクトボックス)-
/// 5-s0 Date (Y/M/D) 日付(年月日)
/// 5-s1 Date (Y/M) 日付(年月)
/// 5-s2 Date (M/D) 日付(月日)
/// 5-s3 Date (Y) 日付(年)
/// 10 Datetime 日時-
/// 14 File ファイル-
/// 8-f4 User (Select Box) ユーザ(セレクトボックス)
/// 8-f5 User (Search Select Box) ユーザ(検索セレクトボックス)-
/// 16 Organization 組織-
/// 9 Discussion 掲示板-
/// 13 Table テーブル-
/// 15 Guide Panel ガイドパネル-

  myHtml += '<tr>\n';
  if( dataObjects[i].type === "0" && dataObjects[i].form === "0" ){
    myHtml += '<td style="padding:1px 5px;" title="String (Text Box single line)">';
    myHtml += '<span style="color:#B40404"><i class="fal fa-font"></i> single</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "0" && dataObjects[i].form === "1" ){
    myHtml += '<td style="padding:1px 5px;" title="String (Text Box multiple lines)">';
    myHtml += '<span style="color:#B40404"><i class="fal fa-font"></i> multiple</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "12"){
    myHtml += '<td style="padding:1px 5px;" title="Numeric">';
    myHtml += '<span style="color:#B45F04"><i class="fal fa-percent"></i> number</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "11" && dataObjects[i].form === "2" ){
    myHtml += '<td style="padding:1px 5px;" title="Select (Radio Button)">';
    myHtml += '<span style="color:#AEB404"><i class="fal fa-list-alt"></i> radio</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "11" && dataObjects[i].form === "4" ){
    myHtml += '<td style="padding:1px 5px;" title="Select (Select Box)">';
    myHtml += '<span style="color:#AEB404"><i class="fal fa-list-alt"></i> select</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "11" && dataObjects[i].form === "3" ){
    myHtml += '<td style="padding:1px 5px;" title="Select (Check Box)">';
    myHtml += '<span style="color:#AEB404"><i class="fal fa-list-alt"></i> check</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "11" && dataObjects[i].form === "5" ){
    myHtml += '<td style="padding:1px 5px;" title="Select (Search Select Box)">';
    myHtml += '<span style="color:#AEB404"><i class="fal fa-list-alt"></i> search</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "5" && dataObjects[i].form === "0" ){
    myHtml += '<td style="padding:1px 5px;" title="Date (Y/M/D)">';
    myHtml += '<span style="color:#5FB404"><i class="fal fa-calendar-alt"></i> yyyy-mm-dd</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "5" && dataObjects[i].form === "1" ){
    myHtml += '<td style="padding:1px 5px;" title="Date (Y/M)">';
    myHtml += '<span style="color:#5FB404"><i class="fal fa-calendar-alt"></i> yyyy-mm</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "5" && dataObjects[i].form === "2" ){
    myHtml += '<td title="Date (M/D)">';
    myHtml += '<span style="padding:1px 5px;" style="color:#5FB404"><i class="fal fa-calendar-alt"></i> mm-dd</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "5" && dataObjects[i].form === "3" ){
    myHtml += '<td style="padding:1px 5px;" title="Date (Y)">';
    myHtml += '<span style="color:#5FB404"><i class="fal fa-calendar-alt"></i> yyyy</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "10" ){
    myHtml += '<td style="padding:1px 5px;" title="Datetime">';
    myHtml += '<span style="color:#5FB404"><i class="fal fa-clock"></i> datetime</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "14" ){
    myHtml += '<td style="padding:1px 5px;" title="File">';
    myHtml += '<span style="color:#04B404"><i class="fal fa-copy"></i> files</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "8" && dataObjects[i].form === "4" ){
    myHtml += '<td style="padding:1px 5px;" title="User (Select Box)">';
    myHtml += '<span style="color:#04B45F"><i class="fal fa-user"></i> select</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "8" && dataObjects[i].form === "5" ){
    myHtml += '<td style="padding:1px 5px;" title="User (Search Select Box)">';
    myHtml += '<span style="color:#04B45F"><i class="fal fa-user"></i> search</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "16" ){
    myHtml += '<td style="padding:1px 5px;" title="Organization">';
    myHtml += '<span style="color:#04B4AE"><i class="fal fa-sitemap"></i> org</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "9" ){
    myHtml += '<td style="padding:1px 5px;" title="Discussion">';
    myHtml += '<span style="color:#045FB4"><i class="fal fa-comments"></i> discuss</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "13" ){
    myHtml += '<td style="padding:1px 5px;" title="Table">';
    myHtml += '<span style="color:#0404B4"><i class="fal fa-table"></i> table</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else if( dataObjects[i].type === "15" ){
    myHtml += '<td style="padding:1px 5px;" title="Guide Panel">';
    myHtml += '<span style="color:#5F04B4"><i class="fal fa-info"></i> guide</span></td>\n';
    myHtml += '<td style="padding:1px 10px;" title="DataNumber: ';
    myHtml += dataObjects[i].number;
    myHtml += '">';
    myHtml += dataObjects[i].name;
    myHtml += '</td>\n';
  }else{
    engine.log( "unknown data type" );
  }
  myHtml += '</tr>\n';
}
myHtml += '</table>\n';
myHtml += '</div>[/su_spoiler]\n';
myHtml += '<!-- /wp:html -->\n';
myHtml += '\n';


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdB !== "" ){
  engine.setDataByNumber( dataIdB, nodeDefTsv );
}
if( dataIdC !== "" ){
  engine.setDataByNumber( dataIdC, dataDefTsv );
}
if( dataIdD !== "" ){
  engine.setDataByNumber( dataIdD, myHtml );
}

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

// Methods of the XML object (E4X)
// - https://wso2.com/project/mashup/0.2/docs/e4xquickstart.html
// - Objects marked with a * are also available on XML List objects.
// appendChild(child), attribute(attributeName) *, attributes() *,
// child(propertyName) *, childIndex(), children() *,
// comments() *, contains(value) *, copy() *, descendants([name]) *,
// elements([name]) *, hasComplexContent() *, hasSimpleContent() *,
// inScopeNamespaces(), insertChildAfter(child1, child2),
// insertChildBefore(child1, child2), length() *, localName(), name(),
// namespace([prefix]), namespaceDeclarations(), nodeKind(),
// normalize() *, parent() *, processingInstructions([name]) *,
// prependChild(value), removeNamespace(namespace),
// replace(propertyName, value), setChildren(value), 
// setLocalName(name), setName(name), setNamespace(ns)
// text() *, toString() *, toXMLString() *, valueOf() *

Download

Questetra-Model-Xml-Extract-Definition.xml

Capture

See also

1 thought on “Questetra-Model-XML Extract Definition”

  1. Pingback: Questetra-Addon-XML Generate Digest-HTML – Questetra Support

Leave a Reply

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