wf history by date

This commit is contained in:
Michele Artini 2022-07-08 15:08:50 +02:00
parent 14d7110b1d
commit 78bda245f2
4 changed files with 41 additions and 12 deletions

View File

@ -3,12 +3,17 @@ package eu.dnetlib.is.wfs;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller @Controller
public class WfHistoryController { public class WfHistoryController {
@GetMapping("/wf_history") @GetMapping("/wf_history")
public void wfHistory(final ModelMap map) { public void wfHistory(final ModelMap map,
@RequestParam(required = false, defaultValue = "-1") final Long from,
@RequestParam(required = false, defaultValue = "-1") final Long to) {
map.put("maxNumberOfRecentWfs", WfHistoryRestController.MAX_NUMBER_OF_RECENT_WFS);
map.put("fromDate", from);
map.put("toDate", to);
} }
} }

View File

@ -26,16 +26,18 @@ public class WfHistoryRestController {
@Autowired @Autowired
private WfHistoryImporter wfHistoryImporter; private WfHistoryImporter wfHistoryImporter;
public static final int MAX_NUMBER_OF_RECENT_WFS = 100;
@GetMapping("/") @GetMapping("/")
public List<WfProcessExecution> history(@RequestParam(required = false) final Date from, @RequestParam(required = false) final Date to) { public List<WfProcessExecution> history(@RequestParam(required = false) final Long from, @RequestParam(required = false) final Long to) {
if (from == null && to == null) { if (from == null && to == null) {
return wfProcessExecutionRepository.findAll(PageRequest.of(0, 100, Sort.by("endDate").descending())).toList(); return wfProcessExecutionRepository.findAll(PageRequest.of(0, MAX_NUMBER_OF_RECENT_WFS, Sort.by("endDate").descending())).toList();
} else if (from == null) { } else if (from == null) {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(0), to); return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(0), new Date(to));
} else if (to == null) { } else if (to == null) {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(from, new Date()); return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(from), new Date());
} else { } else {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(from, to); return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(from), new Date(to));
} }
} }

View File

@ -1,6 +1,11 @@
var app = angular.module('wfHistoryApp', []); var app = angular.module('wfHistoryApp', []);
app.controller('wfHistoryController', function($scope, $http) { app.controller('wfHistoryController', function($scope, $http) {
$scope.fromDate = fromDate();
$scope.toDate = toDate();
$scope.maxNumberOfRecentWfs = maxNumberOfRecentWfs();
$scope.workflows = []; $scope.workflows = [];
$scope.currentWf = {}; $scope.currentWf = {};
$scope.currDetailsKey = ''; $scope.currDetailsKey = '';
@ -8,8 +13,12 @@ app.controller('wfHistoryController', function($scope, $http) {
$scope.sortField = 'processId'; $scope.sortField = 'processId';
$scope.sortReverse = false; $scope.sortReverse = false;
$scope.reload = function() { $scope.reload = function() {
$http.get('./api/wfs/?' + $.now()).then(function successCallback(res) { var url = './api/wfs/?' + $.now();
if ($scope.fromDate > 0) { url += "&from=" + $scope.fromDate; }
if ($scope.toDate > 0) { url += "&to=" + $scope.toDate; }
$http.get(url).then(function successCallback(res) {
$scope.workflows = res.data; $scope.workflows = res.data;
}, function errorCallback(res) { }, function errorCallback(res) {
alert('ERROR: ' + res.data.message); alert('ERROR: ' + res.data.message);

View File

@ -3,6 +3,14 @@
<head th:replace="fragments/mainParts.html :: htmlHeader('Workflow history')"></head> <head th:replace="fragments/mainParts.html :: htmlHeader('Workflow history')"></head>
<script th:inline="javascript">
/*<![CDATA[*/
function maxNumberOfRecentWfs() { return /*[[${maxNumberOfRecentWfs}]]*/ -1; }
function fromDate() { return /*[[${fromDate}]]*/ -1; }
function toDate() { return /*[[${toDate}]]*/ -1; }
/*]]>*/
</script>
<body ng-app="wfHistoryApp" ng-controller="wfHistoryController"> <body ng-app="wfHistoryApp" ng-controller="wfHistoryController">
<nav th:replace="fragments/mainParts.html :: mainMenu('Workflow history')"></nav> <nav th:replace="fragments/mainParts.html :: mainMenu('Workflow history')"></nav>
@ -14,8 +22,13 @@
<p ng-show="workflows.length > 0"> <p ng-show="workflows.length > 0">
<input type="text" class="form-control form-control-sm" ng-model="wfFilter" placeholder="Filter..."/> <input type="text" class="form-control form-control-sm" ng-model="wfFilter" placeholder="Filter..."/>
</p> </p>
<p> <p class="text-muted">
<span class="text-muted"><b>Total workflows :</b> {{(workflows | filter:wfFilter).length}}</span> <span ng-show="fromDate < 0 && toDate < 0"><b>Recent workflows</b> (max {{maxNumberOfRecentWfs}})</span>
<span ng-show="fromDate >= 0 && toDate >= 0"><b>Workflows from </b>{{fromDate | date:"yyyy-MM-dd HH:mm:ss"}} <b>to</b> {{toDate | date:"yyyy-MM-dd HH:mm:ss"}}</span>
<span ng-show="fromDate >= 0 && toDate < 0"><b>Workflows from </b>{{fromDate | date:"yyyy-MM-dd HH:mm:ss"}} <b>to</b> <i>undefined</i></span>
<span ng-show="fromDate < 0 && toDate >= 0"><b>Workflows from </b><i>undefined</i> <b>to</b> {{toDate | date:"yyyy-MM-dd HH:mm:ss"}}</span>
<br />
<span><b>Count :</b> {{(workflows | filter:wfFilter).length}}</span>
</p> </p>
<table class="table table-sm table-striped small"> <table class="table table-sm table-striped small">
<thead> <thead>