Project

General

Profile

1
package eu.dnetlib.repo.manager.server.services;
2

    
3
import eu.dnetlib.api.functionality.ValidatorService;
4
import eu.dnetlib.api.functionality.ValidatorServiceException;
5
import eu.dnetlib.domain.functionality.validator.JobForValidation;
6
import eu.dnetlib.domain.functionality.validator.RuleSet;
7
import eu.dnetlib.domain.functionality.validator.StoredJob;
8
import eu.dnetlib.gwt.server.service.SpringGwtRemoteServiceServlet;
9
import eu.dnetlib.repo.manager.client.services.ValidationService;
10
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
11
import eu.dnetlib.repo.manager.server.utils.OaiTools;
12
import eu.dnetlib.repo.manager.service.controllers.MonitorApi;
13
import eu.dnetlib.repo.manager.service.controllers.ValidatorApi;
14
import eu.dnetlib.repo.manager.shared.*;
15
import gr.uoa.di.driver.util.ServiceLocator;
16
import org.apache.log4j.Logger;
17
import org.json.JSONException;
18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.beans.factory.annotation.Value;
20
import org.springframework.stereotype.Service;
21

    
22
import javax.annotation.PostConstruct;
23
import javax.servlet.ServletConfig;
24
import javax.servlet.ServletException;
25
import java.util.*;
26
import java.util.concurrent.ConcurrentHashMap;
27

    
28
/**
29
 * Created by nikonas on 22/12/15.
30
 */
31
@Service("validationService")
32
public class ValidationServiceImpl extends SpringGwtRemoteServiceServlet implements ValidationService {
33

    
34
    private static final Logger LOGGER = Logger
35
            .getLogger(ValidationServiceImpl.class);
36

    
37
    @Autowired
38
    private EmailUtils emailUtils;
39

    
40
    @Value("${services.repo-manager.deploy.environment}")
41
    private String deployEnvironment;
42

    
43
    private ServiceLocator<ValidatorService> validatorServiceLocator;
44

    
45
    //private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
46

    
47
    public void init(ServletConfig config) throws ServletException {
48

    
49
        LOGGER.info("initializing validation service impl ");
50
        super.init(config);
51
    }
52

    
53
    @Autowired
54
    private ValidatorApi validatorApi;
55
    @Autowired
56
    private MonitorApi monitorApi;
57

    
58
    @PostConstruct
59
    public void initRulesets() {
60
        //this.loadRulesets();
61
    }
62

    
63
    @Override
64
    public List<String> getSets(String baseUrl) throws ValidationServiceException {
65
        return validatorApi.getSetsOfRepository(baseUrl);
66
    }
67

    
68
    @Override
69
    public Boolean identifyRepository(String baseUrl) throws ValidationServiceException {
70
        return validatorApi.identifyRepo(baseUrl);
71
    }
72

    
73
    @Override
74
    public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
75
        try {
76
            LOGGER.debug("Getting interface information with url: " + baseUrl);
77
            InterfaceInformation interfaceInformation = new InterfaceInformation();
78
            interfaceInformation.setIdentified(this.identifyRepository(baseUrl));
79
            if (interfaceInformation.isIdentified())
80
                interfaceInformation.setSets(this.getSets(baseUrl));
81

    
82
            return interfaceInformation;
83
        } catch (Exception e) {
84
            LOGGER.error("Error getting interface information with url: " + baseUrl, e);
85
//            emailUtils.reportException(e);
86
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
87
        }
88
    }
89

    
90
    @Override
91
    public List<RuleSet> getRuleSets(String validationMode) throws ValidationServiceException {
92
        try {
93
            return validatorApi.getRuleSets(validationMode);
94
        } catch (Exception e) {
95
            LOGGER.error("Error getting rulesets", e);
96
            emailUtils.reportException(e);
97
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
98
        }
99
    }
100

    
101
    @Override
102
    public RuleSet getRuleSet(String acronym) throws ValidationServiceException {
103
        return validatorApi.getRuleSet(acronym);
104
    }
105

    
106
    @Override
107
    public void submitValidationJob(JobForValidation job) throws ValidationServiceException {
108
        try {
109
            validatorApi.submitJobForValidation(job);
110
        } catch (Exception e) {
111
            LOGGER.error("Error while submitting validation job", e);
112
            emailUtils.reportException(e);
113
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
114
        }
115
    }
116

    
117
    @Override
118
    public void reSubmitValidationJob(int jobId)
119
            throws ValidationServiceException {
120
        try {
121
            validatorApi.reSubmitJobForValidation(String.valueOf(jobId));
122
        } catch (JSONException e) {
123
            LOGGER.error("Error while re-submitting validation job", e);
124
            emailUtils.reportException(e);
125
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
126
        }
127
    }
128

    
129
    @Override
130
    public StoredJob getJobSummary(int jobId, String groupBy)
131
            throws ValidationServiceException {
132

    
133
        try {
134
            return monitorApi.getJobSummary(String.valueOf(jobId),groupBy);
135
        } catch (Exception e) {
136
            LOGGER.error("Error getting job summary for id: " + jobId, e);
137
            emailUtils.reportException(e);
138
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
139
        }
140
    }
141

    
142
    @Override
143
    public List<StoredJob> getJobsOfUser(String user, String jobType, Integer offset, Integer limit, String dateFrom, String dateTo, String validationStatus) throws ValidationServiceException {
144
        try {
145
            LOGGER.debug("getting jobs of user " + user);
146
            List<StoredJob> jobs;
147
            //TODO update after declaring roles
148
//            if (this.userOverridesRepoRegistration(user))
149
//                jobs = getValidationService().getStoredJobs(null, jobType, offset, limit, null, null);
150
//            else
151
            jobs = getValidationService().getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
152
            return jobs;
153
//            return monitorApi.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
154
        } catch (Exception e) {
155
            LOGGER.error("Error getting jobs of user " + user, e);
156
            emailUtils.reportException(e);
157
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
158
        }
159
    }
160

    
161
    @Override
162
    public int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidationServiceException {
163
        try {
164
            LOGGER.debug("getting jobs of user " + user);
165
            int sum;
166
            //TODO update after declaring roles
167
//            if (this.userOverridesRepoRegistration(user))
168
//                sum = getValidationService().getStoredJobsTotalNumber(null, jobType);
169
//            else
170
            sum = getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
171
            return sum;
172
        } catch (Exception e) {
173
            LOGGER.error("Error getting jobs of user " + user, e);
174
            emailUtils.reportException(e);
175
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
176
        }
177
    }
178

    
179
    @Override
180
    public JobsOfUser getJobsOfUser(String user, String jobType, Integer offset, Integer limit, String dateFrom, String dateTo, String validationStatus, boolean includeJobsTotal) throws ValidationServiceException {
181
        try {
182
            LOGGER.debug("getting jobs of user " + user + " totalJobs included: " + includeJobsTotal);
183
            JobsOfUser retJobs = new JobsOfUser();
184

    
185
            return monitorApi.getJobsOfUser(user, jobType, String.valueOf(offset), String.valueOf(limit),
186
                    dateFrom, dateTo, validationStatus, String.valueOf(includeJobsTotal));
187

    
188
        } catch (Exception e) {
189
            LOGGER.error("getting jobs of user " + user + " totalJobs included: " + includeJobsTotal, e);
190
            throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
191
        }
192
    }
193

    
194

    
195
    private ValidatorService getValidationService() {
196
        return this.validatorServiceLocator.getService();
197
    }
198

    
199
    public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
200
        return validatorServiceLocator;
201
    }
202

    
203
    public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
204
        this.validatorServiceLocator = validatorServiceLocator;
205
    }
206
}
(6-6/6)