const processInstanceDatas = engine.findDataByVarName("q_extract_processInstance_records").replace(/\n$/,"");
const rows = processInstanceDatas.split("\n");
const itemLists = itemDao.findAll("test-m1549.xml", true);
const itemIdLists = new Array();
const itemLabelLists = new Array();
main();
function main(){
let updateCount = 0;
let executionList = "";
let cols;
// cols[0]: Kind("request" or "execution"), [1]: CRUD("追加","変更","削除"),[2]: URL,
// [3]: Title,[4]: Author,[5]: Publish Date, [6]: Request Process API Key,
// [7]:Request Date ,[8]: Process Id, [9]: Request Process Status
// check update count
for (var i=0; i < rows.length; i++){
cols = rows[i].split("\t");
if ((cols[0] === "request")&&(cols[6] !== "")&&(cols[9] === "更新中")){
updateCount++;
executionList += rows[i] + "\n";
}
}
engine.setDataByVarName("q_getting_rows_count", new java.math.BigDecimal(Number(updateCount)));
engine.setDataByVarName("q_extract_processInstance_records", executionList.replace(/\n$/,""));
// master add
for (var i=0; i < rows.length; i++){
cols = rows[i].split("\t");
if ((cols[1] === "追加")&&(cols[6] !== "")&&(cols[9] === "更新中")){
itemIdLists.push(cols[2]);
itemLabelLists.push("[" + cols[2] + "],[" + cols[3] + "],[" + cols[4] + "],[" + cols[5] + "]");
}
}
// master update or delete
let execKind;
let updateLabel = "";
for (var i=0; i < itemLists.size(); i++){
execKind = "stay";
for (var j=1; j < rows.length; j++){
cols = rows[j].split("\t");
if ((cols[2] === itemLists.get(i).getValue())&&(cols[1] === "変更")&&(cols[9] === "更新中")){
execKind = "update";
updateLabel = "[" + cols[2] + "],[" + cols[3] + "],[" + cols[4] + "],[" + cols[5] + "]";
break;
}
if ((cols[2] === itemLists.get(i).getValue())&&(cols[1] === "削除")&&(cols[9] === "更新中")){
execKind = "delete";
break;
}
}
if (execKind === "update"){
itemIdLists.push(itemLists.get(i).getValue());
itemLabelLists.push(updateLabel);
}else{
if (execKind === "stay"){
itemIdLists.push(itemLists.get(i).getValue());
itemLabelLists.push(itemLists.get(i).getDisplay());
}
}
}
let ids = "";
let labels = "";
for (var i=0; i < itemIdLists.length; i++){
ids += itemIdLists[i] + "\n";
labels += itemLabelLists[i] + "\n";
}
engine.setDataByVarName("q_ids_for_update_master",ids.replace(/\n$/,""));
engine.setDataByVarName("q_labels_for_update_master",labels.replace(/\n$/,""));
}