Project

General

Profile

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.JobResultEntry;
6
import eu.dnetlib.domain.functionality.validator.StoredJob;
7
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
8
import eu.dnetlib.repo.manager.service.EmailUtils;
9
import eu.dnetlib.repo.manager.service.RepositoryService;
10
import eu.dnetlib.repo.manager.service.ValidatorServiceImpl;
11
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
12
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
13
import eu.dnetlib.domain.functionality.validator.JobForValidation;
14
import eu.dnetlib.domain.functionality.validator.RuleSet;
15

    
16
import java.util.*;
17

    
18
import io.swagger.annotations.Api;
19
import io.swagger.annotations.ApiParam;
20
import org.json.JSONException;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.http.MediaType;
23
import org.springframework.http.ResponseEntity;
24
import org.springframework.security.access.prepost.PreAuthorize;
25
import org.springframework.web.bind.annotation.*;
26

    
27
import javax.ws.rs.Path;
28

    
29

    
30
@RestController
31
@RequestMapping(value = "/validator")
32
@Api(description = "Validator API",  tags = {"validator"})
33
public class ValidatorController {
34

    
35
    @Autowired
36
    private ValidatorServiceImpl validatorService;
37

    
38
    @Autowired
39
    private EmailUtils emailUtils;
40

    
41
    @RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
42
            consumes = MediaType.APPLICATION_JSON_VALUE,
43
            produces = MediaType.APPLICATION_JSON_VALUE)
44
    @ResponseBody
45
    @PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
46
    public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException {
47
        return validatorService.submitJobForValidation(jobForValidation);
48
    }
49

    
50
    @RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST,
51
            consumes = MediaType.APPLICATION_JSON_VALUE,
52
            produces = MediaType.APPLICATION_JSON_VALUE)
53
    @ResponseBody
54
    @PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
55
    public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
56
                                                           @PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
57
        return validatorService.reSubmitJobForValidation(email, jobId);
58
    }
59

    
60
    @RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
61
    @ResponseBody
62
    public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
63
        return validatorService.getRuleSets(mode);
64
    }
65

    
66
    @RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
67
    @ResponseBody
68
    public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) {
69
        return validatorService.getSetsOfRepository(url);
70
    }
71

    
72
    @RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
73
    @ResponseBody
74
    public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) {
75
        return validatorService.identifyRepo(url);
76
    }
77

    
78
    @RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
79
    @ResponseBody
80
    public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
81
        return validatorService.getRuleSet(acronym);
82
    }
83

    
84
    @RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
85
    @ResponseBody
86
    @PreAuthorize("hasRole('ROLE_USER')")
87
    public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
88
                                            @RequestParam(value = "jobType", required = false)
89
                                            @ApiParam(value = "Equals to filter job type on validation history page") String jobType,
90
                                            @RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
91
                                            @RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
92
                                            @RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
93
                                            @RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
94
                                            @RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
95
                                            ) throws ValidatorServiceException {
96
        return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
97
    }
98

    
99
    @RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
100
    @ResponseBody
101
    public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws  ValidatorServiceException {
102
        return validatorService.getStoredJobsTotalNumberNew(user, jobType, validationStatus);
103
    }
104

    
105
    @RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
106
    @ResponseBody
107
    public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl") String baseUrl) throws ValidationServiceException {
108
        return validatorService.getInterfaceInformation(baseUrl);
109
    }
110

    
111
    @RequestMapping(value = "/validationSummary/{repoId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
112
    @ResponseBody
113
    public List<StoredJob> getInterfaceInformation(@PathVariable(value = "repoId") String repoId, @RequestParam(name = "size", defaultValue = "20") int size ) throws ValidatorServiceException, ResourceNotFoundException, JSONException {
114
        return validatorService.getJobsSummary(repoId,size);
115
    }
116

    
117

    
118
    @RequestMapping(value = "/complete" , method = RequestMethod.POST,  produces = MediaType.APPLICATION_JSON_VALUE)
119
    @ResponseBody
120
    public void validationCompleted(
121
        @RequestParam(value = "interfaceId") String interfaceId,
122
        @RequestParam(value = "repoId") String repoId,
123
        @RequestParam(value = "jobId") String jobId,
124
        @RequestParam(value = "issuerEmail") String issuerEmail,
125
        @RequestParam(value = "isUpdate") boolean isUpdate,
126
        @RequestParam(value = "isSuccess") boolean isSuccess,
127
        @RequestParam(value = "scoreUsage") int scoreUsage,
128
        @RequestParam(value = "scoreContent") int scoreContent) throws Exception {
129

    
130
        emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
131
    }
132

    
133

    
134
}
(11-11/11)