Converter (JigyosyoZipCsv to JigyosyoZipXml)
Generates a postal code master. The business zip “JIGYOSYO.CSV” (20k lines) by Japan Post Co., Ltd. is converted to “Jigyosyo-Zip.xml”. If “Japan-Zip.xml” (120k lines) is specified, “Jigyosyo-Zip.xml” (140k lines) will be created.
Configs
  • A: Select FILES DATA for JIGYOSYO.CSV (Multiple not supported) *
  • Ax: Select FILES DATA for Japan-Zip.xml (Multiple not supported)
  • B: Select FILES DATA for Jigyosyo-Zip.xml (update) *
  • Bx: Set the file name if you want to save as a different name#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
//////// START "main()" ////////
main();
function main(){ 


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + "";
const dataIdAx = configs.get( "conf_DataIdAx" ) + "";
const dataIdB = configs.get( "conf_DataIdB" ) + "";
const saveAs  = configs.get( "conf_SaveAs" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'

let fileName = "";
if( saveAs === "" ){
  fileName = "Jigyosyo-Zip.xml";
}else{
  fileName = saveAs;
}


//// == Data Retrieving / ワークフローデータの参照 ==
const myFiles = engine.findDataByNumber( dataIdA ); 
let   upFiles = engine.findDataByNumber( dataIdB ); 
// java.util.ArrayList
if (myFiles === null || myFiles.size() != 1) {
  throw new Error( '\n One-file attachment is only valid. \n' );
}
if (upFiles === null ) {
  upFiles = new java.util.ArrayList();
}


//// == Calculating / 演算 ==
/// Read Lines
let myLineCounter = 0;
let arrCodeAddr   = [];
fileRepository.readFile(myFiles.get(0), "Shift_JIS", function(line) {
  const lineVals = line.split(",");
  const zipCode  = lineVals[7].replace(/"/g, '');
  const zipAddr  = (lineVals[3] + lineVals[4] + lineVals[5] + lineVals[6]).replace(/"/g, '');
  const zipCorp  = lineVals[2].replace(/"/g, '');
  const codeAddr = [zipCode, zipAddr, zipCorp];
  arrCodeAddr.push( codeAddr );
  myLineCounter++;
});
engine.log( "#Line of Text-File: " + myLineCounter );

/// Generate XML
// '<item value="6068501" display="606-8501 京都府京都市左京区吉田本町 京都大学" />'
// https://www.post.japanpost.jp/zipcode/dl/jigyosyo/readme.html

let xmlFileText = '';
for( var i = 0; i < myLineCounter; i++ ){
  xmlFileText += '<item value="';
  xmlFileText += arrCodeAddr[i][0];
  xmlFileText += '" display="';
  xmlFileText += arrCodeAddr[i][0].substring(0,3) + '-' + arrCodeAddr[i][0].substring(3,7);
  xmlFileText += ' ';
  xmlFileText += arrCodeAddr[i][1];
  xmlFileText += ' ';
  xmlFileText += arrCodeAddr[i][2];
  xmlFileText += '" />\n';
}

/// Append Japan-Zip.xml
/// Read Lines
if( dataIdAx !== "" ){
  const cfFiles = engine.findDataByNumber( dataIdAx ); 
  if( cfFiles !== null && cfFiles.size() == 1 ){
    let cfLineCounter = 0;
    fileRepository.readFile(cfFiles.get(0), "UTF-8", function(line) {
      if( line.startsWith('<item') ){
        xmlFileText += line + '\n';
      }
      cfLineCounter++;
    });
    engine.log( "#Line of Text-File: " + cfLineCounter );
  }
}

/// Add XML Declaration etc
xmlFileText = '<?xml version="1.0" encoding="UTF-8"?><items>\n' + xmlFileText + '</items>';

/// Add to Files Array
upFiles.add( new com.questetra.bpms.core.event.scripttask.NewQfile(
  fileName, "application/xml", xmlFileText ));


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdB, upFiles );

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

Download

2021-07-08 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-jigyosyozipcsv-to-jigyosyozipxml-2021/
The Add-on import feature is available with Professional edition.

Capture

See also

%d bloggers like this: