|
336 | 336 | } |
337 | 337 | |
338 | 338 | function processData(historyData, logData) { |
339 | | - |
340 | | - const historyRows = buildHistoryRows(historyData[0]); |
341 | | - const logRows = buildLogRows(logData[0]); |
342 | | - |
343 | | - renderSet(historyRows.concat(logRows)); |
| 339 | + const historyRows = buildHistoryRows(historyData); |
344 | 340 | |
345 | | - // Get rest of log data (if exists) |
346 | | - getMoreLogData(logData[0]._scroll_id); |
| 341 | + // Check if logData is valid and contains hits (Elasticsearch is enabled) |
| 342 | + if (logData && logData.hits && logData.hits.hits && logData.hits.hits.length > 0) { |
| 343 | + const logRows = buildLogRows(logData); |
| 344 | + renderSet(historyRows.concat(logRows)); |
| 345 | + |
| 346 | + // Get rest of log data (if exists) |
| 347 | + getMoreLogData(logData._scroll_id); |
| 348 | + } else { |
| 349 | + // Elasticsearch is disabled or no log data available, only show history |
| 350 | + renderSet(historyRows); |
| 351 | + $(".ajax-spinner").hide(); |
| 352 | + var table = $("#logData").DataTable(); |
| 353 | + table.draw(); |
| 354 | + } |
347 | 355 | } |
348 | 356 | |
349 | 357 | function processFailed(historyError, logError) { |
|
352 | 360 | |
353 | 361 | console.log("Errors", historyError, logError); |
354 | 362 | |
355 | | - alert("Error retrieving history data."); |
| 363 | + // If only log error (Elasticsearch disabled), try to process history data alone |
| 364 | + if (historyError && historyError.status === 200) { |
| 365 | + const historyRows = buildHistoryRows(historyError); |
| 366 | + renderSet(historyRows); |
| 367 | + var table = $("#logData").DataTable(); |
| 368 | + table.draw(); |
| 369 | + } else { |
| 370 | + alert("Error retrieving history data."); |
| 371 | + } |
356 | 372 | } |
357 | 373 |
|
358 | 374 | function downloadLogCSV() { |
|
523 | 539 | |
524 | 540 | esReq.query.bool.must.push({"query_string":{"fields":["procInstId"],"query" : "\"" + decodeURIComponent(params.procInstId) + "\""}}); |
525 | 541 | |
526 | | - // Get history and log data (first scroll) in parallel |
527 | | - $.when( $.getJSON("/${base}/rest/history/" + params.procInstId), |
528 | | - $.getJSON("/${base}/rest/logs/get?source=" + encodeURIComponent(JSON.stringify(esReq))) ).then(processData, processFailed); |
| 542 | + // Get history data |
| 543 | + var historyPromise = $.getJSON("/${base}/rest/history/" + params.procInstId); |
| 544 | + |
| 545 | + // Get log data (may fail if Elasticsearch is disabled) |
| 546 | + var logPromise = $.getJSON("/${base}/rest/logs/get?source=" + encodeURIComponent(JSON.stringify(esReq))) |
| 547 | + .fail(function() { |
| 548 | + // Silently ignore log errors (Elasticsearch may be disabled) |
| 549 | + return $.Deferred().resolve(null); |
| 550 | + }); |
| 551 | + |
| 552 | + // Process data when both complete (or log fails gracefully) |
| 553 | + $.when(historyPromise, logPromise).then( |
| 554 | + function(historyResult, logResult) { |
| 555 | + // Handle successful responses |
| 556 | + var historyData = historyResult[0]; |
| 557 | + var logData = logResult ? logResult[0] : null; |
| 558 | + processData(historyData, logData); |
| 559 | + }, |
| 560 | + function(historyError, logError) { |
| 561 | + // Handle errors |
| 562 | + processFailed(historyError, logError); |
| 563 | + } |
| 564 | + ); |
529 | 565 | |
530 | 566 | // In case of unknown problems, just hide spinner |
531 | 567 | setTimeout(function() { |
|
972 | 1008 | dataType: "json", |
973 | 1009 | async: false, |
974 | 1010 | success: function(data) { |
975 | | - var finished = false; |
976 | | - scrollId = data._scroll_id; |
977 | | - if (data.hits) { |
978 | | - for (const hit of data.hits.hits) { |
979 | | - const source = hit._source; |
980 | | - const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, "<br/>") + "</p>"]; |
981 | | - logLines.push(row); |
982 | | - |
983 | | - } |
984 | | - } |
985 | | - while (!finished) { |
986 | | - $.ajax({ |
987 | | - type: "POST", |
988 | | - url: "/${base}/rest/logs/get/scroll", |
989 | | - data: "scrollId=" + scrollId, |
990 | | - async: false, |
991 | | - success: function(data) { |
992 | | - if (data.hits) { |
993 | | - |
994 | | - if (data.hits.hits.length > 0) { |
995 | | - for (const hit of data.hits.hits) { |
996 | | - const source = hit._source; |
997 | | - const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, "<br/>") + "</p>"]; |
998 | | - logLines.push(row); |
999 | | - } |
1000 | | - scrollId = data._scroll_id; |
1001 | | - } |
1002 | | - else { |
1003 | | - finished = true; |
1004 | | - } |
1005 | | - } |
1006 | | - }, |
1007 | | - error: function(e) { |
1008 | | - alert("Error retrieving history data."); |
1009 | | - } |
1010 | | - }); |
1011 | | - } |
| 1011 | + // Check if data is valid (Elasticsearch enabled) |
| 1012 | + if (data && data.hits) { |
| 1013 | + var finished = false; |
| 1014 | + scrollId = data._scroll_id; |
| 1015 | + if (data.hits) { |
| 1016 | + for (const hit of data.hits.hits) { |
| 1017 | + const source = hit._source; |
| 1018 | + const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, "<br/>") + "</p>"]; |
| 1019 | + logLines.push(row); |
| 1020 | + |
| 1021 | + } |
| 1022 | + } |
| 1023 | + while (!finished) { |
| 1024 | + $.ajax({ |
| 1025 | + type: "POST", |
| 1026 | + url: "/${base}/rest/logs/get/scroll", |
| 1027 | + data: "scrollId=" + scrollId, |
| 1028 | + async: false, |
| 1029 | + success: function(data) { |
| 1030 | + if (data.hits) { |
| 1031 | + |
| 1032 | + if (data.hits.hits.length > 0) { |
| 1033 | + for (const hit of data.hits.hits) { |
| 1034 | + const source = hit._source; |
| 1035 | + const row = [source["@timestamp"], "Log", source.actInstId.split(':')[0], "<p>" + source.msgBody.replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, "<br/>") + "</p>"]; |
| 1036 | + logLines.push(row); |
| 1037 | + } |
| 1038 | + scrollId = data._scroll_id; |
| 1039 | + } |
| 1040 | + else { |
| 1041 | + finished = true; |
| 1042 | + } |
| 1043 | + } |
| 1044 | + }, |
| 1045 | + error: function(e) { |
| 1046 | + console.log("Error retrieving more log data - Elasticsearch may be disabled"); |
| 1047 | + finished = true; |
| 1048 | + } |
| 1049 | + }); |
| 1050 | + } |
| 1051 | + } |
1012 | 1052 | } |
1013 | 1053 | }).fail(function(xhr, err) { |
1014 | | - console.error("Error getting instance JSON: " + xhr.responseText); |
| 1054 | + console.log("Error getting log data for JSON export - Elasticsearch may be disabled: " + xhr.responseText); |
1015 | 1055 | }); |
1016 | 1056 | logLines.sort(function(a, b) { |
1017 | 1057 | var aDate = moment(a[0].trim()); |
|
0 commit comments