Files, Duplicate

Files, Duplicate
Files, Duplicate

Duplicates Files-type data. All files stored in Files-type data A is copied over Files-type data B.

2020-02-21 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/files-duplicate/

Configs
  • A: Select FILE DATA *
  • B: Select FILE DATA (update)
  • B2: Select FILE DATA (append)
  • C: Set File Names to Save-as (eg “apple.png,orange.jpeg”) #{EL}
Script
// Notes:
// Use the standard function for duplication of string, numeric, date, etc.
// - Automated Step (BPMN Icons): "Service Task (Data Assignment)"
// - M227: Auto Executing Data Binding, Arithmetic Operations
// If you want to add files without erasing already stored files, use B2.
// If no setting to save as, the file names will not be changed.
// For rename purposes, set A and B to the same data item and set names at C.
//
// Notes (ja):
// 文字列型・数値型・日付型などのデータ複製には、標準機能をご活用ください。
// - 自動処理工程(BPMNアイコン): [サービスタスク(データ設定)]
// - M227: 業務データの結合や四則演算が自動実行されるように設定する
// 既に格納されているファイルを消さずにファイル追加したい場合は、B2をご利用ください。
// 別名保存の設定が無い場合(足りない場合)は、既存のファイル名のまま保存されます。
// AとBを同じデータ項目に設定し、Cをセットすれば、リネームの用途にもご利用いただけます。

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


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA   = configs.get( "conf_DataIdA" ) + ""; // required
const dataIdB   = configs.get( "conf_DataIdB" ) + ""; // not required
const dataIdB2  = configs.get( "conf_DataIdB2") + ""; // not required
const csvSaveAs = configs.get( "conf_CsvSaveAs"  ) + ""; // not required
// 'java.lang.String' to javascript primitive 'string'

if( csvSaveAs === "" ){
  engine.log( " AutomatedTask Config:" +
              " File Names to Save-as {C} is empty" );
}else{
  engine.log( " AutomatedTask Config:" +
              " File Names to Save-as: " + csvSaveAs );
}
const arrSaveAs = csvSaveAs.split(",");


//// == Data Retrieving / ワークフローデータの参照 ==
const inputFiles = engine.findDataByNumber( dataIdA ); 
// java.util.ArrayList
// - com.questetra.bpms.core.event.scripttask.QfileView
if( inputFiles === null ){
  throw new Error( "\n AutomatedTask UnexpectedFilesError:" + 
                   " Files {A} is empty \n" );
}
let originalFiles = new java.util.ArrayList();
if( dataIdB2 !== "" ){
  if( engine.findDataByNumber( dataIdB2 ) !== null ){
    originalFiles = engine.findDataByNumber( dataIdB2 ); 
    // java.util.ArrayList
  }
}


//// == Calculating / 演算 ==
let outputFiles1 = new java.util.ArrayList();
if( dataIdB !== "" ){
  for( let i = 0; i < inputFiles.size() - 0; i++){
    let tmpName = inputFiles.get(i).getName();
    if( i < arrSaveAs.length ){
      if( arrSaveAs[i] !== "" ){
        tmpName = arrSaveAs[i];
      }
    }
    outputFiles1.add(
      new com.questetra.bpms.core.event.scripttask.NewQfile(
        tmpName,
        inputFiles.get(i).getContentType(), 
        inputFiles.get(i)
      )
    );
    engine.log( " AutomatedTask:" +
                " Add to B[" + i + "]: " + tmpName );
  }
}

let outputFiles2 = new java.util.ArrayList();
if( dataIdB2 !== "" ){
  for( let i = 0; i < originalFiles.size() - 0; i++){
    let tmpName = originalFiles.get(i).getName();
    outputFiles2.add(
      new com.questetra.bpms.core.event.scripttask.NewQfile(
        tmpName,
        originalFiles.get(i).getContentType(), 
        originalFiles.get(i)
      )
    );
    engine.log( " AutomatedTask:" +
                " Add to B2[" + i + "]: " + tmpName );
  }
  for( let i = 0; i < inputFiles.size() - 0; i++){
    let tmpName = inputFiles.get(i).getName();
    if( i < arrSaveAs.length){
      if( arrSaveAs[i] !== "" ){
        tmpName = arrSaveAs[i];
      }
    }
    outputFiles2.add(
      new com.questetra.bpms.core.event.scripttask.NewQfile(
        tmpName,
        inputFiles.get(i).getContentType(), 
        inputFiles.get(i)
      )
    );
    engine.log( " AutomatedTask:" +
                " Add to B2[" + (i + originalFiles.size()) + "]: " + tmpName );
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdB !== "" ){
  engine.setDataByNumber( dataIdB, outputFiles1 );
}
if( dataIdB2 !== "" ){
  engine.setDataByNumber( dataIdB2, outputFiles2 );
}

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

Download

Capture

Duplicates Files-type data. All files stored in Files-type data A is copied over Files-type data B.

Notes

  1. Use the standard function for duplication of string, numeric, date, etc.
    1. – Automated Step (BPMN Icons): “Service Task (Data Assignment)”
    2. – M227: Auto Executing Data Binding, Arithmetic Operations
  2. If you want to add files without erasing already stored files, use B2.
  3. If no setting to save as, the file names will not be changed.
  4. For rename purposes, set A and B to the same data item and set names at C.

See also

1 thought on “Files, Duplicate”

  1. Pingback: Data Duplicator (Files) – Questetra Support

Leave a Reply

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

%d bloggers like this: