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