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.service.ValidatorServiceImpl;
|
6
|
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
|
7
|
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
|
8
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
9
|
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
10
|
|
11
|
import java.util.*;
|
12
|
|
13
|
import io.swagger.annotations.Api;
|
14
|
import io.swagger.annotations.ApiParam;
|
15
|
import org.json.JSONException;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.http.MediaType;
|
18
|
import org.springframework.http.ResponseEntity;
|
19
|
import org.springframework.security.access.prepost.PreAuthorize;
|
20
|
import org.springframework.web.bind.annotation.*;
|
21
|
|
22
|
|
23
|
@RestController
|
24
|
@RequestMapping(value = "/validator")
|
25
|
@Api(description = "Validator API", tags = {"validator"})
|
26
|
public class ValidatorController {
|
27
|
|
28
|
@Autowired
|
29
|
private ValidatorServiceImpl validatorService;
|
30
|
|
31
|
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
|
32
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
33
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
34
|
@ResponseBody
|
35
|
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
|
36
|
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException {
|
37
|
return validatorService.submitJobForValidation(jobForValidation);
|
38
|
}
|
39
|
|
40
|
@RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST,
|
41
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
42
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
43
|
@ResponseBody
|
44
|
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
|
45
|
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
|
46
|
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
|
47
|
return validatorService.reSubmitJobForValidation(email, jobId);
|
48
|
}
|
49
|
|
50
|
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
51
|
@ResponseBody
|
52
|
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
|
53
|
return validatorService.getRuleSets(mode);
|
54
|
}
|
55
|
|
56
|
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
57
|
@ResponseBody
|
58
|
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) {
|
59
|
return validatorService.getSetsOfRepository(url);
|
60
|
}
|
61
|
|
62
|
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
63
|
@ResponseBody
|
64
|
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) {
|
65
|
return validatorService.identifyRepo(url);
|
66
|
}
|
67
|
|
68
|
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
69
|
@ResponseBody
|
70
|
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
|
71
|
return validatorService.getRuleSet(acronym);
|
72
|
}
|
73
|
|
74
|
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
75
|
@ResponseBody
|
76
|
@PreAuthorize("hasRole('ROLE_USER')")
|
77
|
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
|
78
|
@RequestParam(value = "jobType", required = false)
|
79
|
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
|
80
|
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
|
81
|
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
|
82
|
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
|
83
|
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
|
84
|
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
|
85
|
) throws ValidatorServiceException {
|
86
|
return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
|
87
|
}
|
88
|
|
89
|
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
90
|
@ResponseBody
|
91
|
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
92
|
return validatorService.getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
93
|
}
|
94
|
|
95
|
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
96
|
@ResponseBody
|
97
|
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException {
|
98
|
return validatorService.getInterfaceInformation(baseUrl);
|
99
|
}
|
100
|
|
101
|
|
102
|
}
|