journal api

This commit is contained in:
Michele Artini 2023-12-01 07:52:05 +01:00
parent 8df4c71cbf
commit 8457481c0a
5 changed files with 28 additions and 28 deletions

View File

@ -1,5 +1,6 @@
package eu.dnetlib.wfs.manager.controller;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
@ -35,8 +36,8 @@ public class ApiController extends DnetRestController {
@GetMapping("/history")
public List<WfJournalEntry> history(
@RequestParam(required = true) final int total,
@RequestParam(required = false) final Long from,
@RequestParam(required = false) final Long to) {
@RequestParam(required = false) final LocalDate from,
@RequestParam(required = false) final LocalDate to) {
return wfManagerService.findHistory(total, from, to);
}

View File

@ -1,12 +1,11 @@
package eu.dnetlib.wfs.manager.service;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.TimeZone;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
@ -165,17 +164,13 @@ public class WorkflowManagerService {
return wfJournalEntryRepository.findByDsIdOrderByEndDateDesc(dsId, PageRequest.of(0, MAX_HISTORY_SIZE)).getContent();
}
public List<WfJournalEntry> findHistory(final int total, final Long from, final Long to) {
public List<WfJournalEntry> findHistory(final int total, final LocalDate from, final LocalDate to) {
final int max = ((total > 0) || (total < MAX_HISTORY_SIZE)) ? total : MAX_HISTORY_SIZE;
if ((from == null) && (to == null)) { return wfJournalEntryRepository.findAll(PageRequest.of(0, max, Sort.by("endDate").descending())).toList(); }
final LocalDateTime fromTime = from != null ? LocalDateTime.ofInstant(Instant.ofEpochMilli(from), TimeZone
.getDefault()
.toZoneId()) : LocalDateTime.MIN;
final LocalDateTime toTime = to != null ? LocalDateTime.ofInstant(Instant.ofEpochMilli(to), TimeZone
.getDefault()
.toZoneId()) : LocalDateTime.MAX;
final LocalDateTime fromTime = from != null ? from.atTime(0, 0, 0) : LocalDateTime.MIN;
final LocalDateTime toTime = to != null ? to.atTime(23, 59, 59) : LocalDateTime.MAX;
return wfJournalEntryRepository.findByEndDateBetweenOrderByEndDateDesc(fromTime, toTime, PageRequest.of(0, max)).getContent();
}

View File

@ -6,13 +6,11 @@
</mat-form-field>
<p>
<span *ngIf="from < 0 && to < 0"><b>Recent workflows</b> (max {{total}})</span>
<span *ngIf="from >= 0 && to >= 0"><b>Workflows from </b>{{from | date:"yyyy-MM-dd HH:mm:ss"}} <b>to</b> {{to |
date:"yyyy-MM-dd HH:mm:ss"}}</span>
<span *ngIf="from >= 0 && to < 0"><b>Workflows from </b>{{from | date:"yyyy-MM-dd HH:mm:ss"}} <b>to</b>
<span *ngIf="from && to"><b>Recent workflows</b> (max {{total}})</span>
<span *ngIf="from && to"><b>Workflows from </b>{{from}} <b>to</b> {{to}}</span>
<span *ngIf="from && !to"><b>Workflows from </b>{{from}} <b>to</b>
<i>undefined</i></span>
<span *ngIf="from < 0 && to >= 0"><b>Workflows from </b><i>undefined</i> <b>to</b> {{to | date:"yyyy-MM-dd
HH:mm:ss"}}</span>
<span *ngIf="!from && to"><b>Workflows from </b><i>undefined</i> <b>to</b> {{to}}</span>
<br />
<span><b>Count :</b> {{historyDatasource.filteredData.length}}</span>
</p>
@ -48,8 +46,10 @@
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef style="width: 10%;" mat-sort-header sortActionDescription="Sort by Status">
Status </th>
<td mat-cell *matCellDef="let element"><span class="badge-label"
[ngClass]="{'badge-success' : element.status === 'success', 'badge-failure' : element.status === 'failure'}">{{element.status}}</span>
<td mat-cell *matCellDef="let element"><span class="badge-label" [ngClass]="{
'badge-success' : element.status === 'success',
'badge-failure' : element.status === 'failure',
'badge-pending' : element.status === 'pending'}">{{element.status}}</span>
</td>
</ng-container>

View File

@ -20,8 +20,8 @@ export class WfHistoryComponent implements AfterViewInit, OnInit {
colums: string[] = ['processId', 'name', 'family', 'dsName', 'status', 'startDate', 'endDate'];
total: number = 100
from: number = -1
to: number = -1
from?: Date;
to?: Date;
constructor(public client: WfHistoryClient, public route: ActivatedRoute, public dialog: MatDialog) {
}
@ -36,8 +36,8 @@ export class WfHistoryComponent implements AfterViewInit, OnInit {
let toP = queryParams['to'];
if (totalP) { this.total = parseInt(totalP); }
if (fromP) { this.from = parseInt(fromP); }
if (toP) { this.to = parseInt(toP); }
if (fromP) { this.from = new Date(fromP); }
if (toP) { this.to = new Date(toP) }
this.client.loadWfHistory(this.total, this.from, this.to, (data: WfHistoryEntry[]) => this.historyDatasource.data = data);
});
@ -155,12 +155,12 @@ export class WfHistoryDialog {
})
export class WfHistoryClient extends ISClient {
loadWfHistory(total: number, from: number, to: number, onSuccess: Function): void {
loadWfHistory(total: number, from: Date | undefined, to: Date | undefined, onSuccess: Function): void {
let params = new HttpParams();
if (total && total > 0) { params = params.append('total', total); }
if (from && from > 0) { params = params.append('from', from); }
if (to && to > 0) { params = params.append('to', to); }
if (from) { params = params.append('from', from.toLocaleDateString()); }
if (to) { params = params.append('to', to.toLocaleDateString()); }
this.httpGetWithOptions<WfHistoryEntry[]>('/proxy/byType/wf-manager/history/', { params: params }, onSuccess);
this.httpGetWithOptions<WfHistoryEntry[]>('/proxy/byType/wf_manager/api/history', { params: params }, onSuccess);
}
}

View File

@ -88,7 +88,7 @@ a:not([href]):hover {
padding-left: 1em;
padding-right: 1em;
border-radius: 0.4em;
font-size: 0.9em;
font-size: 1em;
font-variant: small-caps;
color: #fff;
text-align: center;
@ -100,6 +100,10 @@ a:not([href]):hover {
background-color: #336699;
}
.badge-pending {
background-color: darkgrey;
}
.badge-success {
background-color: darkgreen;
}