// (c) 2019, Questetra, Inc. (the MIT License)
//////// START "main()" ////////
main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const groupA = configs.get( "conf_GroupA" ) + ""; // config required
const timesA = configs.get( "conf_TimesA" ) + ""; // config required
const groupB = configs.get( "conf_GroupB" ) + ""; // config not required
const timesB = configs.get( "conf_TimesB" ) + ""; // config not required
const groupC = configs.get( "conf_GroupC" ) + ""; // config not required
const timesC = configs.get( "conf_TimesC" ) + ""; // config not required
const groupD = configs.get( "conf_GroupD" ) + ""; // config not required
const timesD = configs.get( "conf_TimesD" ) + ""; // config not required
const dataIdE = configs.get( "conf_DataIdE" ) + ""; // config required
// Design-time Config Format Check
let numA = 0;
let numB = 0;
let numC = 0;
let numD = 0;
const positiveInt = /^([1-9]\d*)$/; // RegExp
if( groupA === "" ){
throw new Error( "\n AutomatedTask ConfigError:" +
" Config {Group A} is empty \n" );
}
if( positiveInt.test( timesA ) ){
numA = parseInt(timesA, 10);
}else{
throw new Error( "\n AutomatedTask ConfigError:" +
" Config Number {a} is not a positive integer \n" );
}
if( groupB !== "" ){
if( positiveInt.test( timesB ) ){
numB = parseInt(timesB, 10);
}else{
engine.log( " AutomatedTask ConfigWarning:" +
" Config Number {b} is not a positive integer" );
}
}
if( groupC !== "" ){
if( positiveInt.test( timesC ) ){
numC = parseInt(timesC, 10);
}else{
engine.log( " AutomatedTask ConfigWarning:" +
" Config Number {c} is not a positive integer" );
}
}
if( groupD !== "" ){
if( positiveInt.test( timesD ) ){
numD = parseInt(timesD, 10);
}else{
engine.log( " AutomatedTask ConfigWarning:" +
" Config Number {d} is not a positive integer" );
}
}
//// == Data Retrieving / ワークフローデータの参照 ==
// nothing (This Service Task is a CREATE type)
//// == Calculating / 演算 ==
let tmpPassword = "";
engine.log( " AutomatedTask Number of A-Characters: " + numA );
for( let i = 0; i < numA; i++ ){
tmpPassword += groupA.charAt( Math.floor( Math.random() * groupA.length ) );
}
engine.log( " AutomatedTask Number of B-Characters: " + numB );
for( let i = 0; i < numB; i++ ){
tmpPassword += groupB.charAt( Math.floor( Math.random() * groupB.length ) );
}
engine.log( " AutomatedTask Number of C-Characters: " + numC );
for( let i = 0; i < numC; i++ ){
tmpPassword += groupC.charAt( Math.floor( Math.random() * groupC.length ) );
}
engine.log( " AutomatedTask Number of D-Characters: " + numD );
for( let i = 0; i < numD; i++ ){
tmpPassword += groupD.charAt( Math.floor( Math.random() * groupD.length ) );
}
// shuffle (Fisher-Yates)
let tmpArray = tmpPassword.split("");
let j = tmpArray.length;
while ( j > 1 ) {
let k = Math.floor( Math.random() * j );
j = j - 1;
if (j == k) continue;
let tmp = tmpArray[j];
tmpArray[j] = tmpArray[k];
tmpArray[k] = tmp;
}
//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdE, tmpArray.join("") );
} //////// END "main()" ////////
Pingback: Random Password Generator – Questetra Support
Pingback: Number, Generate Random – Questetra Support