2 |
2 |
|
3 |
3 |
import eu.dnetlib.api.functionality.ValidatorService;
|
4 |
4 |
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
|
5 |
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
5 |
6 |
import eu.dnetlib.repo.manager.client.services.ValidationService;
|
6 |
7 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
|
7 |
8 |
import eu.dnetlib.repo.manager.server.utils.OaiTools;
|
|
9 |
import eu.dnetlib.repo.manager.shared.Constants;
|
8 |
10 |
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
|
9 |
11 |
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
|
10 |
12 |
import gr.uoa.di.driver.util.ServiceLocator;
|
11 |
13 |
import org.apache.log4j.Logger;
|
12 |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
13 |
16 |
import org.springframework.stereotype.Service;
|
14 |
17 |
|
|
18 |
import javax.annotation.PostConstruct;
|
15 |
19 |
import javax.servlet.ServletConfig;
|
16 |
20 |
import javax.servlet.ServletException;
|
|
21 |
import java.util.ArrayList;
|
17 |
22 |
import java.util.List;
|
|
23 |
import java.util.Map;
|
|
24 |
import java.util.concurrent.ConcurrentHashMap;
|
18 |
25 |
|
19 |
26 |
/**
|
20 |
27 |
* Created by nikonas on 22/12/15.
|
... | ... | |
28 |
35 |
@Autowired
|
29 |
36 |
private EmailUtils emailUtils;
|
30 |
37 |
|
|
38 |
@Value("${services.repo-manager.deploy.environment}")
|
|
39 |
private String deployEnvironment;
|
|
40 |
|
31 |
41 |
private ServiceLocator<ValidatorService> validatorServiceLocator;
|
32 |
42 |
|
|
43 |
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
|
|
44 |
|
33 |
45 |
public void init(ServletConfig config) throws ServletException {
|
34 |
46 |
|
35 |
47 |
LOGGER.info("initializing validation service impl ");
|
36 |
48 |
super.init(config);
|
|
49 |
}
|
37 |
50 |
|
|
51 |
@PostConstruct
|
|
52 |
public void initRulesets() {
|
|
53 |
this.loadRulesets();
|
38 |
54 |
}
|
39 |
55 |
|
40 |
56 |
@Override
|
... | ... | |
80 |
96 |
}
|
81 |
97 |
|
82 |
98 |
@Override
|
|
99 |
public List<RuleSet> getRuleSets(String validationMode) throws ValidationServiceException {
|
|
100 |
LOGGER.info("Getting rulesets for mode: " + validationMode);
|
|
101 |
try {
|
|
102 |
if (!rulesetMap.containsKey(validationMode))
|
|
103 |
this.loadRulesets();
|
|
104 |
|
|
105 |
return this.rulesetMap.get(validationMode);
|
|
106 |
} catch (Exception e) {
|
|
107 |
LOGGER.error("Error getting rulesets", e);
|
|
108 |
emailUtils.reportException(e);
|
|
109 |
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
@Override
|
83 |
114 |
public void submitValidationJob(JobForValidation job) throws ValidationServiceException {
|
84 |
115 |
try {
|
85 |
116 |
LOGGER.info("Submitting validation job");
|
... | ... | |
90 |
121 |
}
|
91 |
122 |
}
|
92 |
123 |
|
|
124 |
private void loadRulesets() {
|
|
125 |
try {
|
|
126 |
LOGGER.debug("loading rulesets");
|
|
127 |
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
|
|
128 |
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains(deployEnvironment)) {
|
|
129 |
String key = "";
|
|
130 |
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
|
|
131 |
key = Constants.VALIDATION_MODE_DATA;
|
|
132 |
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
|
|
133 |
key = Constants.VALIDATION_MODE_LITERATURE;
|
|
134 |
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
|
|
135 |
key = Constants.VALIDATION_MODE_CRIS;
|
|
136 |
|
|
137 |
if (rulesetMap.containsKey(key))
|
|
138 |
rulesetMap.get(key).add(ruleSet);
|
|
139 |
else {
|
|
140 |
List<RuleSet> ruleSets = new ArrayList<RuleSet>();
|
|
141 |
ruleSets.add(ruleSet);
|
|
142 |
rulesetMap.put(key, ruleSets);
|
|
143 |
}
|
|
144 |
}
|
|
145 |
}
|
|
146 |
} catch (Exception e) {
|
|
147 |
LOGGER.error("Error getting rulesets", e);
|
|
148 |
emailUtils.reportException(e);
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
93 |
152 |
private ValidatorService getValidationService() {
|
94 |
153 |
return this.validatorServiceLocator.getService();
|
95 |
154 |
}
|
added method to get Rulesets
fixed a bug while loading Guidelines