// GraalJS Script (engine type: 2)
//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const strTsv = configs.get( "StrConfA1" ); /// REQUIRED /////////////
if( strTsv === "" ){
throw new Error( "\n AutomatedTask ConfigError:" +
" Config {A1: Tsv} is empty \n" );
}
const arr2dTsv = parseAsRectangular( strTsv );
const strPocketOutput = configs.getObject( "SelectConfB1" ); // NotRequired /////
const numPocketNumOfRows = configs.getObject( "SelectConfB2" ); // NotRequired /////
const numPocketNumOfColumns = configs.getObject( "SelectConfB3" ); // NotRequired /////
//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)
//// == Calculating / 演算 ==
// output TSV
let strOutput = "";
for( let i = 0; i < arr2dTsv.length; i++ ){
strOutput += arr2dTsv[i].join("\t") + "\n";
}
strOutput = strOutput.slice( 0, -1 ); // delete last "\n"
//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketOutput !== null ){
engine.setData( strPocketOutput, strOutput );
}
if( numPocketNumOfRows !== null ){
engine.setData( numPocketNumOfRows, new java.math.BigDecimal( arr2dTsv.length ) );
}
if( numPocketNumOfColumns !== null ){
engine.setData( numPocketNumOfColumns, new java.math.BigDecimal( arr2dTsv[0].length ) );
}
} //////// END "main()" /////////////////////////////////////////////////////////////////
// Parses TSV string as two-dimensional rectangular data matrix and creates a 2D array.
function parseAsRectangular( strTsv ){
const arrTsv = strTsv.split("\n");
/// Get numMinWidth and numMaxWidth (blank lines are excluded)
let numMinWidth = Infinity; // cf. String-Type Max: 1 million
let numMaxWidth = 0;
let numBlanklines = 0;
for( let i = 0; i < arrTsv.length; i++ ){
if( arrTsv[i] === "" ){ // Skip blank lines
numBlanklines += 1;
continue;
}
let arrCells = arrTsv[i].split("\t");
if( numMinWidth > arrCells.length ){ numMinWidth = arrCells.length; }
if( numMaxWidth < arrCells.length ){ numMaxWidth = arrCells.length; }
}
engine.log( " AutomatedTask TsvDataCheck:" +
" MinWidth:" + numMinWidth +
" MaxWidth:" + numMaxWidth +
" Lines:" + arrTsv.length +
" (BlankLines:" + numBlanklines + ")" );
/// Get numMinWidth and numMaxWidth (blank lines are excluded)
let arr2dTsv = [];
for( let i = 0; i < arrTsv.length; i++ ){
if( arrTsv[i] === "" ){ // Skip blank lines
continue;
}
let arrTmp = [];
let arrCells = arrTsv[i].split("\t");
for( let j = 0; j < numMaxWidth; j++ ){
if( j < arrCells.length ){
arrTmp[j] = arrCells[j];
}else{
arrTmp[j] = "";
}
}
arr2dTsv.push( arrTmp );
}
return arr2dTsv;
}
/*
Notes:
- When the process reaches this automated task, TSV is automatically read.
- TSV: Monthly sales, monthly access log, etc.
- If there is a blank line in the input TSV text, it will be skipped.
- The output TSV is rectangular data. There are no blank lines.
- No line feed code is added to the last line of the output TSV.
APPENDIX:
- TSV data that is not rectangular is automatically formatted with an empty string.
- Tabs are added according to the row with the largest number of columns.
- However, lines with only line breaks (blank lines) are skipped.
Notes-ja:
- 案件が自動処理工程に到達した際、文字列型データに保存されているTSVが自動的に読み込まれます。
- TSV: 月次売上、月次アクセスログ、など
- 入力TSVテキストに空行がある場合、スキップされます。
- 出力TSVは矩形データとなります。空行は存在しません。
- 出力TSVの最終行に改行コードは付与されません。
APPENDIX-ja:
- 矩形でないTSVデータは、空文字によって自動整形されます。
- もっとも列数(タブ数)が多い行にあわせて、タブが追加されます。
- ただし、改行のみの行(空行)は、スキップされます。
*/