Project

General

Profile

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

    
3
import eu.dnetlib.domain.functionality.validator.JobForValidation;
4
import eu.dnetlib.domain.functionality.validator.RuleSet;
5
import eu.dnetlib.domain.functionality.validator.StoredJob;
6
import eu.dnetlib.gwt.server.service.SpringGwtRemoteServiceServlet;
7
import eu.dnetlib.repo.manager.client.services.ValidationService;
8
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
9
import eu.dnetlib.repo.manager.service.controllers.MonitorApi;
10
import eu.dnetlib.repo.manager.service.controllers.ValidatorApi;
11
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
12
import eu.dnetlib.repo.manager.shared.JobsOfUser;
13
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
14
import org.apache.log4j.Logger;
15
import org.json.JSONException;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Value;
18
import org.springframework.stereotype.Service;
19

    
20
import javax.annotation.PostConstruct;
21
import javax.servlet.ServletConfig;
22
import javax.servlet.ServletException;
23
import java.util.List;
24

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

    
31
    private static final Logger LOGGER = Logger
32
            .getLogger(ValidationServiceImpl.class);
33

    
34
    @Autowired
35
    private EmailUtils emailUtils;
36

    
37
    @Value("${services.repo-manager.deploy.environment}")
38
    private String deployEnvironment;
39

    
40
    //private ServiceLocator<ValidatorService> validatorServiceLocator;
41

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

    
44
    public void init(ServletConfig config) throws ServletException {
45

    
46
        LOGGER.info("initializing validation service impl ");
47
        super.init(config);
48
    }
49

    
50
    @Autowired
51
    private ValidatorApi validatorApi;
52
    @Autowired
53
    private MonitorApi monitorApi;
54

    
55
    @PostConstruct
56
    public void initRulesets() {
57
        //this.loadRulesets();
58
    }
59

    
60
    @Override
61
    public List<String> getSets(String baseUrl) throws ValidationServiceException {
62
        return validatorApi.getSetsOfRepository(baseUrl);
63
    }
64

    
65
    @Override
66
    public Boolean identifyRepository(String baseUrl) throws ValidationServiceException {
67
        return validatorApi.identifyRepo(baseUrl);
68
    }
69

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

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

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

    
98
    @Override
99
    public RuleSet getRuleSet(String acronym) throws ValidationServiceException {
100
        return validatorApi.getRuleSet(acronym);
101
    }
102

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

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

    
126
    @Override
127
    public StoredJob getJobSummary(int jobId, String groupBy)
128
            throws ValidationServiceException {
129

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

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

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

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

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

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

    
193

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

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

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