Revision 49879
Added by Antonis Lempesis over 6 years ago
ValidationServiceImpl.java | ||
---|---|---|
9 | 9 |
import eu.dnetlib.repo.manager.client.services.ValidationService; |
10 | 10 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils; |
11 | 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; |
|
12 | 14 |
import eu.dnetlib.repo.manager.shared.*; |
13 | 15 |
import gr.uoa.di.driver.util.ServiceLocator; |
14 | 16 |
import org.apache.log4j.Logger; |
17 |
import org.json.JSONException; |
|
15 | 18 |
import org.springframework.beans.factory.annotation.Autowired; |
16 | 19 |
import org.springframework.beans.factory.annotation.Value; |
17 | 20 |
import org.springframework.stereotype.Service; |
... | ... | |
39 | 42 |
|
40 | 43 |
private ServiceLocator<ValidatorService> validatorServiceLocator; |
41 | 44 |
|
42 |
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>(); |
|
45 |
//private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
|
|
43 | 46 |
|
44 | 47 |
public void init(ServletConfig config) throws ServletException { |
45 | 48 |
|
... | ... | |
47 | 50 |
super.init(config); |
48 | 51 |
} |
49 | 52 |
|
53 |
@Autowired |
|
54 |
private ValidatorApi validatorApi; |
|
55 |
@Autowired |
|
56 |
private MonitorApi monitorApi; |
|
57 |
|
|
50 | 58 |
@PostConstruct |
51 | 59 |
public void initRulesets() { |
52 |
this.loadRulesets(); |
|
60 |
//this.loadRulesets();
|
|
53 | 61 |
} |
54 | 62 |
|
55 | 63 |
@Override |
56 | 64 |
public List<String> getSets(String baseUrl) throws ValidationServiceException { |
57 |
try { |
|
58 |
LOGGER.debug("Getting sets of repository with url: " + baseUrl); |
|
59 |
return OaiTools.getSetsOfRepo(baseUrl); |
|
60 |
} catch (Exception e) { |
|
61 |
LOGGER.error("Error while getting sets of repository with url: " + baseUrl, e); |
|
62 |
// emailUtils.reportException(e); |
|
63 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.NOT_VALID_SET); |
|
64 |
} |
|
65 |
return validatorApi.getSetsOfRepository(baseUrl); |
|
65 | 66 |
} |
66 | 67 |
|
67 | 68 |
@Override |
68 | 69 |
public Boolean identifyRepository(String baseUrl) throws ValidationServiceException { |
69 |
try { |
|
70 |
LOGGER.debug("Identifying repository with url: " + baseUrl); |
|
71 |
return OaiTools.identifyRepository(baseUrl); |
|
72 |
} catch (Exception e) { |
|
73 |
LOGGER.error("Error while identifying repository with url: " + baseUrl, e); |
|
74 |
// emailUtils.reportException(e); |
|
75 |
return false; |
|
76 |
// throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.NOT_VALID_BASEURL); |
|
77 |
} |
|
70 |
return validatorApi.identifyRepo(baseUrl); |
|
78 | 71 |
} |
79 | 72 |
|
80 | 73 |
@Override |
... | ... | |
96 | 89 |
|
97 | 90 |
@Override |
98 | 91 |
public List<RuleSet> getRuleSets(String validationMode) throws ValidationServiceException { |
99 |
LOGGER.info("Getting rulesets for mode: " + validationMode); |
|
100 | 92 |
try { |
101 |
if (!rulesetMap.containsKey(validationMode)) |
|
102 |
this.loadRulesets(); |
|
103 |
|
|
104 |
return this.rulesetMap.get(validationMode); |
|
93 |
return validatorApi.getRuleSets(validationMode); |
|
105 | 94 |
} catch (Exception e) { |
106 | 95 |
LOGGER.error("Error getting rulesets", e); |
107 | 96 |
emailUtils.reportException(e); |
... | ... | |
111 | 100 |
|
112 | 101 |
@Override |
113 | 102 |
public RuleSet getRuleSet(String acronym) throws ValidationServiceException { |
114 |
LOGGER.info("Getting ruleset with acronym: " + acronym); |
|
115 |
RuleSet ruleSet = null; |
|
116 |
try { |
|
117 |
for (List<RuleSet> ruleSets : this.rulesetMap.values()) { |
|
118 |
for (RuleSet rSet : ruleSets) |
|
119 |
if (rSet.getGuidelinesAcronym().equals(acronym)) { |
|
120 |
ruleSet = rSet; |
|
121 |
break; |
|
122 |
} |
|
123 |
} |
|
124 |
return ruleSet; |
|
125 |
} catch (Exception e) { |
|
126 |
LOGGER.error("Error getting ruleset", e); |
|
127 |
emailUtils.reportException(e); |
|
128 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); |
|
129 |
} |
|
103 |
return validatorApi.getRuleSet(acronym); |
|
130 | 104 |
} |
131 | 105 |
|
132 | 106 |
@Override |
133 | 107 |
public void submitValidationJob(JobForValidation job) throws ValidationServiceException { |
134 | 108 |
try { |
135 |
LOGGER.info("Submitting validation job"); |
|
136 |
this.getValidationService().submitValidationJob(job); |
|
109 |
validatorApi.submitJobForValidation(job); |
|
137 | 110 |
} catch (Exception e) { |
138 | 111 |
LOGGER.error("Error while submitting validation job", e); |
139 | 112 |
emailUtils.reportException(e); |
... | ... | |
145 | 118 |
public void reSubmitValidationJob(int jobId) |
146 | 119 |
throws ValidationServiceException { |
147 | 120 |
try { |
148 |
LOGGER.info("re-Submitting validation job"); |
|
149 |
StoredJob job = this.getJobSummary(jobId, "all"); |
|
150 |
Set<Integer> contentRules = new HashSet<Integer>(); |
|
151 |
Set<Integer> usageRules = new HashSet<Integer>(); |
|
152 |
RuleSet ruleSet = this.getRuleSet(job.getDesiredCompatibilityLevel()); |
|
153 |
for (int ruleId : job.getRules()) { |
|
154 |
if (ruleSet.getContentRulesIds().contains(ruleId)) |
|
155 |
contentRules.add(ruleId); |
|
156 |
else if (ruleSet.getUsageRulesIds().contains(ruleId)) |
|
157 |
usageRules.add(ruleId); |
|
158 |
} |
|
159 |
if (!contentRules.isEmpty()) |
|
160 |
job.setSelectedContentRules(contentRules); |
|
161 |
if (!usageRules.isEmpty()) |
|
162 |
job.setSelectedUsageRules(usageRules); |
|
163 |
this.submitValidationJob(job); |
|
164 |
} catch (Exception e) { |
|
121 |
validatorApi.reSubmitJobForValidation(String.valueOf(jobId)); |
|
122 |
} catch (JSONException e) { |
|
165 | 123 |
LOGGER.error("Error while re-submitting validation job", e); |
166 | 124 |
emailUtils.reportException(e); |
167 | 125 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); |
... | ... | |
171 | 129 |
@Override |
172 | 130 |
public StoredJob getJobSummary(int jobId, String groupBy) |
173 | 131 |
throws ValidationServiceException { |
132 |
|
|
174 | 133 |
try { |
175 |
LOGGER.info("getting job summary for id: " + jobId); |
|
176 |
return getValidationService().getStoredJob(jobId, groupBy); |
|
177 |
} catch (ValidatorServiceException e) { |
|
134 |
return monitorApi.getJobSummary(String.valueOf(jobId),groupBy); |
|
135 |
} catch (Exception e) { |
|
178 | 136 |
LOGGER.error("Error getting job summary for id: " + jobId, e); |
179 | 137 |
emailUtils.reportException(e); |
180 | 138 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); |
... | ... | |
192 | 150 |
// else |
193 | 151 |
jobs = getValidationService().getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus); |
194 | 152 |
return jobs; |
153 |
// return monitorApi.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus); |
|
195 | 154 |
} catch (Exception e) { |
196 | 155 |
LOGGER.error("Error getting jobs of user " + user, e); |
197 | 156 |
emailUtils.reportException(e); |
... | ... | |
222 | 181 |
try { |
223 | 182 |
LOGGER.debug("getting jobs of user " + user + " totalJobs included: " + includeJobsTotal); |
224 | 183 |
JobsOfUser retJobs = new JobsOfUser(); |
225 |
List<StoredJob> jobs; |
|
226 |
//TODO update after declaring roles |
|
227 |
// if (this.userOverridesRepoRegistration(user)) |
|
228 |
// jobs = getValidationService().getStoredJobs(null, jobType, offset, limit, null, null); |
|
229 |
// else |
|
230 |
retJobs.setJobs(this.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus)); |
|
231 |
if (includeJobsTotal) { |
|
232 |
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null)); |
|
233 |
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL)); |
|
234 |
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED)); |
|
235 |
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_ONGOING)); |
|
236 |
} |
|
237 |
return retJobs; |
|
238 | 184 |
|
185 |
return monitorApi.getJobsOfUser(user, jobType, String.valueOf(offset), String.valueOf(limit), |
|
186 |
dateFrom, dateTo, validationStatus, String.valueOf(includeJobsTotal)); |
|
187 |
|
|
239 | 188 |
} catch (Exception e) { |
240 | 189 |
LOGGER.error("getting jobs of user " + user + " totalJobs included: " + includeJobsTotal, e); |
241 |
emailUtils.reportException(e); |
|
242 | 190 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); |
243 | 191 |
} |
244 | 192 |
} |
245 | 193 |
|
246 | 194 |
private void loadRulesets() { |
247 |
try { |
|
195 |
/* try {
|
|
248 | 196 |
LOGGER.debug("loading rulesets"); |
249 | 197 |
for (RuleSet ruleSet : getValidationService().getRuleSets()) { |
250 | 198 |
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains(deployEnvironment)) { |
... | ... | |
268 | 216 |
} catch (Exception e) { |
269 | 217 |
LOGGER.error("Error getting rulesets", e); |
270 | 218 |
emailUtils.reportException(e); |
271 |
} |
|
219 |
}*/
|
|
272 | 220 |
} |
273 | 221 |
|
274 | 222 |
private ValidatorService getValidationService() { |
Also available in: Unified diff
merged newAPI branch