1
|
package eu.dnetlib.repo.manager.service.controllers;
|
2
|
|
3
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
4
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
5
|
import eu.dnetlib.repo.manager.service.utils.OaiTools;
|
6
|
import gr.uoa.di.driver.util.ServiceLocator;
|
7
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
8
|
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
9
|
import eu.dnetlib.repo.manager.service.shared.Constants;
|
10
|
|
11
|
import java.util.*;
|
12
|
import java.util.concurrent.ConcurrentHashMap;
|
13
|
import eu.dnetlib.api.functionality.ValidatorService;
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.json.JSONException;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
import org.springframework.web.bind.annotation.PathVariable;
|
19
|
|
20
|
import javax.annotation.PostConstruct;
|
21
|
import javax.annotation.Resource;
|
22
|
|
23
|
|
24
|
@Component
|
25
|
public class ValidatorApiImpl implements ValidatorApi{
|
26
|
|
27
|
@Autowired
|
28
|
private MonitorApiImpl monitorApi;
|
29
|
|
30
|
@Resource(name = "validatorServiceLocator")
|
31
|
private ServiceLocator<ValidatorService> validatorServiceLocator;
|
32
|
|
33
|
private ValidatorService getValidationService() {
|
34
|
return this.validatorServiceLocator.getService();
|
35
|
}
|
36
|
|
37
|
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
|
38
|
return validatorServiceLocator;
|
39
|
}
|
40
|
|
41
|
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
|
42
|
this.validatorServiceLocator = validatorServiceLocator;
|
43
|
}
|
44
|
|
45
|
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
|
46
|
|
47
|
private static final Logger LOGGER = Logger
|
48
|
.getLogger(ValidatorApiImpl.class);
|
49
|
|
50
|
@PostConstruct
|
51
|
private void loadRules(){
|
52
|
|
53
|
try {
|
54
|
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
|
55
|
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
|
56
|
String key = "";
|
57
|
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
|
58
|
key = Constants.VALIDATION_MODE_DATA;
|
59
|
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
|
60
|
key = Constants.VALIDATION_MODE_LITERATURE;
|
61
|
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
|
62
|
key = Constants.VALIDATION_MODE_CRIS;
|
63
|
|
64
|
if (rulesetMap.containsKey(key))
|
65
|
rulesetMap.get(key).add(ruleSet);
|
66
|
else {
|
67
|
List<RuleSet> ruleSets = new ArrayList<RuleSet>();
|
68
|
ruleSets.add(ruleSet);
|
69
|
rulesetMap.put(key, ruleSets);
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
} catch (ValidatorServiceException e) {
|
74
|
e.printStackTrace();
|
75
|
}
|
76
|
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
public void submitJobForValidation(JobForValidation jobForValidation) {
|
81
|
try {
|
82
|
this.getValidationService().submitValidationJob(jobForValidation);
|
83
|
} catch (ValidatorServiceException e) {
|
84
|
e.printStackTrace();
|
85
|
}
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public void reSubmitJobForValidation(String jobId) throws JSONException {
|
90
|
|
91
|
StoredJob job = monitorApi.getJobSummary(jobId,"all");
|
92
|
Set<Integer> contentRules = new HashSet<Integer>();
|
93
|
Set<Integer> usageRules = new HashSet<Integer>();
|
94
|
|
95
|
RuleSet ruleSet = null;
|
96
|
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
|
97
|
for (RuleSet rSet : ruleSets)
|
98
|
if (rSet.getGuidelinesAcronym().equals(job.getDesiredCompatibilityLevel())) {
|
99
|
ruleSet = rSet;
|
100
|
break;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
for (int ruleId : job.getRules()) {
|
105
|
if (ruleSet.getContentRulesIds().contains(ruleId))
|
106
|
contentRules.add(ruleId);
|
107
|
else if (ruleSet.getUsageRulesIds().contains(ruleId))
|
108
|
usageRules.add(ruleId);
|
109
|
}
|
110
|
if (!contentRules.isEmpty())
|
111
|
job.setSelectedContentRules(contentRules);
|
112
|
if (!usageRules.isEmpty())
|
113
|
job.setSelectedUsageRules(usageRules);
|
114
|
this.submitJobForValidation(job);
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
|
119
|
return rulesetMap.get(mode);
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public List<String> getSetsOfRepository(String url) {
|
124
|
try {
|
125
|
return OaiTools.getSetsOfRepo(url);
|
126
|
} catch (Exception e) {
|
127
|
e.printStackTrace();
|
128
|
}
|
129
|
return null;
|
130
|
}
|
131
|
|
132
|
}
|