Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ESIPFed/Geoweaver
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Aug 31, 2024
2 parents e87137d + b38cba1 commit 39ea6ee
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/gw/GeoweaverApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class GeoweaverApplication {
private static String workspace;

public static void main(String[] args) {

// if we have a command line argument, we assume it is a command
if (args.length > 0) {

Expand Down Expand Up @@ -74,6 +73,7 @@ public static void main(String[] args) {

addLocalhost();


System.out.println("GeoWeaver is started and ready for use..");
System.out.println("URL: http://localhost:"+BaseTool.get_current_port()+"/Geoweaver");
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/gw/database/HistoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collection;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
Expand Down Expand Up @@ -163,4 +164,8 @@ public interface HistoryRepository extends JpaRepository<History, String> {
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_id = ?1 AND history.history_process = gwprocess.id", nativeQuery = true)
List<Object[]> findOneHistoryofProcess(String history_id);


@Modifying
@Query(value = "DELETE FROM history WHERE history_process = ?1 AND indicator = ?2", nativeQuery = true)
void deleteByProcessAndIndicator(String historyProcess, String indicator);
}
5 changes: 5 additions & 0 deletions src/main/java/com/gw/tools/HistoryTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ public void stop(String history_id) {
}
}


public void deleteFailedHistory(String processId) {
historyrepository.deleteByProcessAndIndicator(processId, ExecutionStatus.FAILED);
}

public void saveSkippedHisotry(String historyid, String workflow_process_id, String hostid) {

try {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/gw/web/GeoweaverController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import javax.annotation.PreDestroy;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -64,6 +59,7 @@
import org.springframework.core.io.Resource;
import org.springframework.data.repository.query.Param;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -1638,4 +1634,16 @@ public ResponseEntity<String> authenticateUser(ModelMap model, WebRequest reques

return resp;
}

@DeleteMapping("/delete-failed")
public ResponseEntity<Map<String, Boolean>> deleteFailedProcesses(@RequestParam(required = false) String processId) {
Map<String, Boolean> response = new HashMap<>();
if (processId == null || processId.trim().isEmpty()) {
response.put("failed", false);
return new ResponseEntity<>(response, HttpStatus.FORBIDDEN);
}
hist.deleteFailedHistory(processId);
response.put("success", true);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
14 changes: 14 additions & 0 deletions src/main/resources/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@
display: inline-block;
margin: 10px;
}

.history-remove-failed {
background: indianred;
border: 0;
margin-right: 15px;
padding: 4px 10px;
border-radius: 8px;
transition: transform 0.3s ease, background 0.3s ease;
}

.history-remove-failed:hover {
cursor: pointer;
transform: scale(1.05);
}
56 changes: 43 additions & 13 deletions src/main/resources/static/js/gw.history.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,29 @@ GW.history = {
},



removeFailedHistory: function(processId) {
const formData = new FormData();
formData.append('processId', processId);
const options = {
method: 'DELETE',
body: formData,
}
fetch("delete-failed", options)
// GW.process.sidepanel.history(processId, 'testing_data_integration');
},
/**
* Generates an HTML table with process execution history data.
*
* @param {Array} msg - Array of process history data.
* @returns {string} - HTML content of the process execution history table.
*/
getProcessHistoryTable: function(msg){
let hasFailedProcess;
if (msg.length > 0) {
hasFailedProcess = msg.some((item) => item.indicator === "Failed");
} else {
hasFailedProcess = false;
}

let content = `
<div style="display: flex; flex-direction: row; justify-content: space-between;">
Expand All @@ -214,9 +229,19 @@ GW.history = {
</select>
<input type="number" id="durationValue" placeholder="Enter duration" style="color: black;">
</div>
<div id="statusFilterContainer">
<label for="statusFilter">Status:</label>
<div id="statusFilterContainer">`;

if (msg.length && hasFailedProcess) {

content += `<button id="failed-history-rm"
onclick="(function(){ GW.history.removeFailedHistory('${msg[0]['history_process']}');
window.alert('Actions will reflect on next page load. Processing.') })()"
class="history-remove-failed"
data-history-process="` + msg[0]['history_process'] + `"
>
Remove Failed History</button>`;
}
content += `<label for="statusFilter">Status:</label>
<select id="statusFilter" style="color: black;">
<option value="">All</option> <!-- Changed to "All" -->
<option value="Done">Done</option>
Expand Down Expand Up @@ -279,8 +304,8 @@ GW.history = {
"')\">View Changes</a> &nbsp;";


content += " <a href=\"javascript: GW.process.deleteHistory('"+
msg[i].history_id+"')\">Delete</a> &nbsp;";
content += ` <a href="javascript: GW.process.deleteHistory('`+
msg[i].history_id+`')">Delete</a> &nbsp;`;

if(msg[i].indicator == "Running"){
content += " <a href=\"javascript: void(0)\" id=\"stopbtn_"+msg[i].history_id+"\" onclick=\"GW.process.stop('"+msg[i].history_id+"')\">Stop</a>";
Expand All @@ -293,12 +318,6 @@ GW.history = {

content += "</tbody>";

$('#statusFilter').on('change', function () {

var value = $(this).val();
console.log(value);
});

// create an interactive chart to show all the data

content =
Expand All @@ -307,8 +326,9 @@ GW.history = {
"<canvas id=\"process-history-chart\"></canvas>"+
"</div>" + content ;

return content;


return content;
},

/**
Expand Down Expand Up @@ -446,6 +466,16 @@ GW.history = {


$(document).ready(function() {

$(document).on('click', '#failed-history-rm', function () {
const historyProcess = $(this).data("history-remove-failed");
if (historyProcess) {
GW.history.removeFailedHistory(historyProcess);
} else {
console.error('Error: history-remove-failed attribute is missing or undefined.');
}
});

// Function to apply search filter
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
const selectedStatus = $('#statusFilter').val().toLowerCase();
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/static/js/gw.process.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,10 @@ GW.process = {
alert("Cannot find the process history in the database.");
return;
}
alert("History deleted successfully.");
$("#history-row-" + history_id).remove();
console.log("History "+history_id+" is deleted successfully.");
var row = $('tr[id="history-row-' + history_id + '"]');
var table = $('#process_history_table').DataTable();
table.row(row).remove().draw(); // remove the row from the table completely without refresh
})
.fail(function(jxr, status) {
console.error("Fail to Delete History.");
Expand Down
9 changes: 4 additions & 5 deletions src/main/resources/static/js/gw.process.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,10 @@ GW.process.util = {

GW.history.stopAllTimers();

$(process_history_container_id).html(
GW.history.getProcessHistoryTable(msg),
);

GW.history.startActiveTimer();
$(process_history_container_id).html(
GW.history.getProcessHistoryTable(msg),
);
GW.history.startActiveTimer();

var table_selector = `${process_history_container_id} ${process_history_table_id}`;
GW.history.applyBootstrapTable(table_selector);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/fragments/config/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
<script src="../js/gw.menu.js"></script>
<script src="../js/gw.home.js"></script>
<script src="../js/gw.main.js"></script>

<link rel="stylesheet" href="../css/common.css" />

0 comments on commit 39ea6ee

Please sign in to comment.