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