Project

General

Profile

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("user") @ApiParam(value = "User email", required = true) String user,
34
                                    @RequestParam(value = "jobType", required = false)
35
                                    @ApiParam(value = "Equals to filter job type on validation history page") String jobType,
36
                                    @RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
37
                                    @RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
38
                                    @RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
39
                                    @RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
40
                                    @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
41
                                    @RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
42
        user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
43
        return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
44
    }
45

    
46
    @RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
47
    @ResponseBody
48
    @PreAuthorize("hasRole('ROLE_USER')")
49
    public int getJobsOfUserPerValidationStatus(@RequestBody String user,
50
                                                @RequestBody String jobType,
51
                                                @RequestBody String validationStatus) throws JSONException {
52
        user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
53
        return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus);
54
    }
55

    
56
    @RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
57
    @ResponseBody
58
    public StoredJob getJobSummary(@RequestParam String jobId,
59
                                   @RequestParam String groupBy) throws JSONException {
60
        return monitorService.getJobSummary(jobId, groupBy);
61
    }
62

    
63
}
(4-4/11)