1
|
package eu.dnetlib.repo.manager.controllers;
|
2
|
|
3
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
4
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
5
|
import eu.dnetlib.repo.manager.domain.JobsOfUser;
|
6
|
import eu.dnetlib.repo.manager.service.MonitorServiceImpl;
|
7
|
import io.swagger.annotations.Api;
|
8
|
import io.swagger.annotations.ApiParam;
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.json.JSONException;
|
11
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.http.MediaType;
|
14
|
import org.springframework.security.access.prepost.PreAuthorize;
|
15
|
import org.springframework.security.core.context.SecurityContextHolder;
|
16
|
import org.springframework.web.bind.annotation.*;
|
17
|
|
18
|
@RestController
|
19
|
@RequestMapping(value = "/monitor")
|
20
|
@Api(description = "Monitor API", tags = {"monitor"})
|
21
|
public class MonitorController {
|
22
|
|
23
|
private static final Logger LOGGER = Logger
|
24
|
.getLogger(MonitorController.class);
|
25
|
|
26
|
@Autowired
|
27
|
private MonitorServiceImpl monitorService;
|
28
|
|
29
|
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
|
30
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
31
|
@ResponseBody
|
32
|
@PreAuthorize("hasRole('ROLE_USER')")
|
33
|
public JobsOfUser getJobsOfUser(@RequestParam(value = "jobType", required = false)
|
34
|
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
|
35
|
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
|
36
|
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
|
37
|
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
|
38
|
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
|
39
|
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
|
40
|
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
41
|
return monitorService.getJobsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
|
42
|
}
|
43
|
|
44
|
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
45
|
@ResponseBody
|
46
|
@PreAuthorize("hasRole('ROLE_USER')")
|
47
|
public int getJobsOfUserPerValidationStatus(@RequestBody String jobType,
|
48
|
@RequestBody String validationStatus) throws JSONException {
|
49
|
return monitorService.getJobsOfUserPerValidationStatus(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), jobType, validationStatus);
|
50
|
}
|
51
|
|
52
|
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
53
|
@ResponseBody
|
54
|
public StoredJob getJobSummary(@RequestParam String jobId,
|
55
|
@RequestParam String groupBy) throws JSONException {
|
56
|
return monitorService.getJobSummary(jobId, groupBy);
|
57
|
}
|
58
|
|
59
|
}
|