1 |
34342
|
nikon.gasp
|
package eu.dnetlib.validator.service.impl;
|
2 |
21870
|
nikon.gasp
|
|
3 |
41972
|
nikon.gasp
|
import eu.dnetlib.domain.functionality.validator.CustomProperties;
|
4 |
34342
|
nikon.gasp
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
5 |
|
|
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
6 |
|
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
7 |
|
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
8 |
|
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler;
|
9 |
|
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
10 |
37040
|
nikon.gasp
|
import eu.dnetlib.validator.commons.dao.DaoException;
|
11 |
34342
|
nikon.gasp
|
import eu.dnetlib.validator.commons.dao.jobs.JobsDAO;
|
12 |
|
|
import eu.dnetlib.validator.commons.dao.rules.RulesDAO;
|
13 |
|
|
import eu.dnetlib.validator.commons.dao.rules.RulesetsDAO;
|
14 |
55423
|
andreas.cz
|
import eu.dnetlib.validator.commons.email.Emailer;
|
15 |
34342
|
nikon.gasp
|
import eu.dnetlib.validator.engine.Validator;
|
16 |
|
|
import eu.dnetlib.validator.engine.ValidatorException;
|
17 |
|
|
import eu.dnetlib.validator.engine.data.Rule;
|
18 |
|
|
import eu.dnetlib.validator.engine.execution.Job;
|
19 |
|
|
import eu.dnetlib.validator.service.impls.ValidatorRestore;
|
20 |
41622
|
nikon.gasp
|
import eu.dnetlib.validator.service.impls.listeners.*;
|
21 |
34342
|
nikon.gasp
|
import eu.dnetlib.validator.service.impls.providers.DnetProvider;
|
22 |
|
|
import eu.dnetlib.validator.service.impls.providers.OAIPMHRecordProvider;
|
23 |
|
|
import eu.dnetlib.validator.service.impls.providers.OAIPMHSinglePageVerbProvider;
|
24 |
|
|
import eu.dnetlib.validator.service.impls.rules.ChainRule;
|
25 |
|
|
import eu.dnetlib.validator.service.impls.rules.RuleTypes;
|
26 |
41622
|
nikon.gasp
|
import org.apache.log4j.Logger;
|
27 |
|
|
import org.springframework.transaction.annotation.Propagation;
|
28 |
|
|
import org.springframework.transaction.annotation.Transactional;
|
29 |
34342
|
nikon.gasp
|
|
30 |
41622
|
nikon.gasp
|
import java.util.*;
|
31 |
|
|
|
32 |
36698
|
nikon.gasp
|
@Transactional
|
33 |
34342
|
nikon.gasp
|
public class ValidatorManagerImpl implements ValidatorManager {
|
34 |
21870
|
nikon.gasp
|
|
35 |
56962
|
ioannis.di
|
private Emailer emailer;
|
36 |
|
|
private Validator validator;
|
37 |
34342
|
nikon.gasp
|
private JobsDAO jobsDao;
|
38 |
|
|
private RulesetsDAO rulesetsDao;
|
39 |
|
|
private RulesDAO rulesDao;
|
40 |
|
|
private ValidatorRestore valRestore;
|
41 |
|
|
|
42 |
37040
|
nikon.gasp
|
|
43 |
21870
|
nikon.gasp
|
private static Logger logger = Logger.getLogger(ValidatorManagerImpl.class);
|
44 |
|
|
|
45 |
34342
|
nikon.gasp
|
private ListenersManager listenersManager;
|
46 |
21870
|
nikon.gasp
|
public void start() {
|
47 |
36698
|
nikon.gasp
|
logger.info("Initializing Validator Manager module");
|
48 |
37040
|
nikon.gasp
|
if (valRestore.isAutoRestoreOnStartup()) {
|
49 |
|
|
logger.info("auto-restoring OpenAire Validator is enabled..");
|
50 |
|
|
List<StoredJob> jobs = valRestore.deleteUncompleted();
|
51 |
|
|
valRestore.restartJobs(jobs);
|
52 |
|
|
logger.info("finished restoring OpenAire Validator..");
|
53 |
|
|
} else {
|
54 |
|
|
logger.info("auto-restoring OpenAire Validator is disabled..");
|
55 |
|
|
}
|
56 |
21870
|
nikon.gasp
|
}
|
57 |
30662
|
nikon.gasp
|
|
58 |
34342
|
nikon.gasp
|
public StoredJob getStoredJob(int jobId, String groupBy)
|
59 |
|
|
throws ValidatorException {
|
60 |
|
|
try {
|
61 |
36698
|
nikon.gasp
|
logger.info("Getting job summary for job " + jobId +" with groupBy: "+groupBy);
|
62 |
34342
|
nikon.gasp
|
return jobsDao.getJobSummary(jobId,groupBy);
|
63 |
|
|
} catch (Exception e) {
|
64 |
|
|
logger.error("error getting job summary for job " + jobId, e);
|
65 |
|
|
throw new ValidatorException(e);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
35380
|
nikon.gasp
|
public List<StoredJob> getStoredJobs(String userMail, String jobType,
|
70 |
35734
|
nikon.gasp
|
Integer offset, Integer limit, String dateFrom, String dateTo)
|
71 |
34342
|
nikon.gasp
|
throws ValidatorException {
|
72 |
41901
|
nikon.gasp
|
return this.getStoredJobs(userMail, jobType, offset, limit, dateFrom, dateTo, null);
|
73 |
|
|
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
public List<StoredJob> getStoredJobs(String userMail, String jobType,
|
77 |
|
|
Integer offset, Integer limit, String dateFrom, String dateTo, String jobStatus)
|
78 |
|
|
throws ValidatorException {
|
79 |
34342
|
nikon.gasp
|
try {
|
80 |
37040
|
nikon.gasp
|
logger.debug("Getting jobs of user " + userMail);
|
81 |
41901
|
nikon.gasp
|
return jobsDao.getJobs(userMail, jobType, offset, limit, dateFrom, dateTo, jobStatus);
|
82 |
34342
|
nikon.gasp
|
} catch (Exception e) {
|
83 |
|
|
logger.error("error Getting jobs of user " + userMail, e);
|
84 |
|
|
throw new ValidatorException(e);
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
35380
|
nikon.gasp
|
|
88 |
|
|
public int getStoredJobsTotalNumber(String userMail, String jobType)
|
89 |
|
|
throws ValidatorException {
|
90 |
41901
|
nikon.gasp
|
return this.getStoredJobsTotalNumber(userMail, jobType, null);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
public int getStoredJobsTotalNumber(String userMail, String jobType, String jobStatus)
|
94 |
|
|
throws ValidatorException {
|
95 |
35380
|
nikon.gasp
|
try {
|
96 |
37040
|
nikon.gasp
|
logger.debug("Getting jobs total sum of user " + userMail);
|
97 |
41901
|
nikon.gasp
|
return jobsDao.getJobsTotalNumber(userMail, jobType, jobStatus);
|
98 |
35380
|
nikon.gasp
|
} catch (Exception e) {
|
99 |
|
|
logger.error("error Getting jobs sum of user " + userMail, e);
|
100 |
|
|
throw new ValidatorException(e);
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
36208
|
nikon.gasp
|
|
104 |
34342
|
nikon.gasp
|
public List<RuleSet> getRuleSets() throws ValidatorException {
|
105 |
|
|
try {
|
106 |
36698
|
nikon.gasp
|
logger.info("Getting rulesets");
|
107 |
34342
|
nikon.gasp
|
return rulesetsDao.getRuleSets();
|
108 |
|
|
} catch (Exception e) {
|
109 |
|
|
logger.error("error Getting rulesets ", e);
|
110 |
|
|
throw new ValidatorException(e);
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
35734
|
nikon.gasp
|
|
114 |
36208
|
nikon.gasp
|
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
|
115 |
41622
|
nikon.gasp
|
public StoredJob beginDataJobForWorkflow(String mdstoreId, String guidelines, String groupBy, int records, int workers, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler, int jobStatusUpdateInterval, boolean outputEpr, boolean blacklistedRecords, String blacklistGuidelines) throws ValidatorException{
|
116 |
30662
|
nikon.gasp
|
try {
|
117 |
36698
|
nikon.gasp
|
logger.info("Submitting data job for workflow");
|
118 |
31252
|
nikon.gasp
|
// String desiredCompatibility = "openaire3.0";
|
119 |
41622
|
nikon.gasp
|
Set<Integer> ruleIdsForBlacklist = new HashSet<Integer>();
|
120 |
30662
|
nikon.gasp
|
Set<Integer> ruleIdsContent = new HashSet<Integer>();
|
121 |
34342
|
nikon.gasp
|
for (RuleSet ruleset : rulesetsDao.getRuleSets()) {
|
122 |
30662
|
nikon.gasp
|
if (ruleset.getGuidelinesAcronym().equals(guidelines)) {
|
123 |
34342
|
nikon.gasp
|
ruleIdsContent = ruleset.getContentRulesIds();
|
124 |
30662
|
nikon.gasp
|
}
|
125 |
41622
|
nikon.gasp
|
if (blacklistedRecords && ruleset.getGuidelinesAcronym().equals(blacklistGuidelines)) {
|
126 |
|
|
ruleIdsForBlacklist = ruleset.getContentRulesIds();
|
127 |
|
|
ruleIdsContent.addAll(ruleIdsForBlacklist);
|
128 |
|
|
}
|
129 |
30662
|
nikon.gasp
|
}
|
130 |
34342
|
nikon.gasp
|
|
131 |
|
|
Properties props = new Properties();
|
132 |
21870
|
nikon.gasp
|
|
133 |
34342
|
nikon.gasp
|
props.setProperty(DnetProvider.MDSTORE_ID, mdstoreId);
|
134 |
|
|
props.setProperty(DnetProvider.BATCH_SIZE, "50");
|
135 |
38323
|
nikon.gasp
|
if (bJob.getParameters().get("batchSize") != null )
|
136 |
|
|
props.setProperty(DnetProvider.BATCH_SIZE, bJob.getParameters().get("batchSize"));
|
137 |
30662
|
nikon.gasp
|
|
138 |
35734
|
nikon.gasp
|
props.setProperty(DnetProvider.RECORDS, Integer.toString(records));
|
139 |
|
|
|
140 |
34342
|
nikon.gasp
|
StoredJob newJob = new StoredJob();
|
141 |
|
|
newJob.setUserEmail("Workflow Service");
|
142 |
41901
|
nikon.gasp
|
newJob.setValidationType("C");
|
143 |
34342
|
nikon.gasp
|
newJob.setDesiredCompatibilityLevel(guidelines);
|
144 |
|
|
newJob.setContentJobStatus("ongoing");
|
145 |
|
|
newJob.setUsageJobStatus("none");
|
146 |
|
|
newJob.setJobType("Workflow Request");
|
147 |
|
|
newJob.setDuration("--");
|
148 |
|
|
newJob.setBaseUrl(mdstoreId);
|
149 |
|
|
newJob.setRules(ruleIdsContent);
|
150 |
35734
|
nikon.gasp
|
newJob.setRecords(records);
|
151 |
34342
|
nikon.gasp
|
newJob.setValidationSet("dnet-workflow");
|
152 |
|
|
newJob.setGroupByXpath(groupBy);
|
153 |
|
|
newJob.setMetadataPrefix("oai_dc");
|
154 |
|
|
newJob.setId(-1);
|
155 |
|
|
|
156 |
|
|
int jobIdStored = jobsDao.save(newJob);
|
157 |
|
|
|
158 |
|
|
Set<Rule> rulesContent = new HashSet<Rule>();
|
159 |
31252
|
nikon.gasp
|
|
160 |
34342
|
nikon.gasp
|
logger.debug("Selected content rules number: " + ruleIdsContent.size());
|
161 |
|
|
for (Integer ruleId : ruleIdsContent){
|
162 |
30662
|
nikon.gasp
|
|
163 |
34342
|
nikon.gasp
|
eu.dnetlib.domain.functionality.validator.Rule tempRule=rulesDao.get(ruleId);
|
164 |
|
|
|
165 |
30662
|
nikon.gasp
|
//special behaviour type of rule is chain
|
166 |
|
|
if(tempRule.getType().equals("ChainRule")) {
|
167 |
|
|
ChainRule<Rule> chainRule = this.handleChain(tempRule);
|
168 |
34342
|
nikon.gasp
|
rulesContent.add(chainRule);
|
169 |
30662
|
nikon.gasp
|
}
|
170 |
|
|
else {
|
171 |
34342
|
nikon.gasp
|
rulesContent.add((Rule) this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), tempRule.getId()));
|
172 |
30662
|
nikon.gasp
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
34342
|
nikon.gasp
|
Job jobContent = new Job(jobIdStored, 3, rulesContent, props);
|
176 |
32474
|
nikon.gasp
|
|
177 |
34342
|
nikon.gasp
|
ValidatorJobListener listenerContent = listenersManager.createListener();
|
178 |
|
|
listenerContent.setJobSubmittedId(jobIdStored);
|
179 |
|
|
listenerContent.setJobSubmittedUser("Workflow Service");
|
180 |
|
|
listenerContent.setGroupBy_xpath(groupBy);
|
181 |
|
|
listenerContent.setValidationType("content");
|
182 |
|
|
listenerContent.setInternalJobsSum(workers);
|
183 |
41622
|
nikon.gasp
|
listenerContent.setBlacklistRuleIds(ruleIdsForBlacklist);
|
184 |
32474
|
nikon.gasp
|
|
185 |
34342
|
nikon.gasp
|
DnetListener dnetListener = listenersManager.createDnetListener();
|
186 |
31427
|
nikon.gasp
|
dnetListener.setJob(bJob);
|
187 |
|
|
dnetListener.setBlackboardHandler(blackboardHandler);
|
188 |
35423
|
nikon.gasp
|
dnetListener.setInternalJobsSum(workers);
|
189 |
35734
|
nikon.gasp
|
dnetListener.setValidationJobId(jobIdStored);
|
190 |
|
|
dnetListener.setJobStatusUpdateInterval(jobStatusUpdateInterval);
|
191 |
55394
|
antonis.le
|
|
192 |
|
|
dnetListener.setValidatorManager(this);
|
193 |
|
|
dnetListener.setGroupBy(groupBy);
|
194 |
|
|
|
195 |
41622
|
nikon.gasp
|
if (blacklistedRecords) {
|
196 |
38323
|
nikon.gasp
|
dnetListener.setEnableOutputToDisk(true);
|
197 |
41622
|
nikon.gasp
|
|
198 |
|
|
}
|
199 |
38323
|
nikon.gasp
|
if (outputEpr)
|
200 |
|
|
dnetListener.setEnableOutputToRS(true);
|
201 |
30662
|
nikon.gasp
|
|
202 |
55394
|
antonis.le
|
dnetListener.initOutputs();
|
203 |
|
|
|
204 |
34342
|
nikon.gasp
|
validator.submitJob(jobContent, workers, listenerContent, dnetListener);
|
205 |
38323
|
nikon.gasp
|
|
206 |
30662
|
nikon.gasp
|
return newJob;
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
} catch (Exception e) {
|
210 |
|
|
logger.error("Error Submitting content job", e);
|
211 |
|
|
throw new ValidatorException(e);
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
34342
|
nikon.gasp
|
|
215 |
36208
|
nikon.gasp
|
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
|
216 |
34342
|
nikon.gasp
|
public void submitJob(JobForValidation job) throws ValidatorException {
|
217 |
30662
|
nikon.gasp
|
|
218 |
21870
|
nikon.gasp
|
try {
|
219 |
36698
|
nikon.gasp
|
logger.info("Submiting validation job requested by user: " + job.getUserEmail());
|
220 |
34342
|
nikon.gasp
|
|
221 |
57006
|
ioannis.di
|
|
222 |
57070
|
ioannis.di
|
if (job.isRegistration()) {
|
223 |
34342
|
nikon.gasp
|
logger.debug("initiating preregistration validations on repo " + job.getBaseUrl() + " for user " + job.getUserEmail() + "and desired compatibility: " + job.getDesiredCompatibilityLevel());
|
224 |
57006
|
ioannis.di
|
|
225 |
|
|
for (RuleSet ruleset : rulesetsDao.getRuleSets(job.getDesiredCompatibilityLevel())) {
|
226 |
|
|
job.setSelectedContentRules(ruleset.getContentRulesIds());
|
227 |
|
|
job.setSelectedUsageRules(ruleset.getUsageRulesIds());
|
228 |
|
|
}
|
229 |
21870
|
nikon.gasp
|
}
|
230 |
34342
|
nikon.gasp
|
|
231 |
55423
|
andreas.cz
|
if ( job.getDesiredCompatibilityLevel().toLowerCase().matches("^openaire4.0$") ) {
|
232 |
|
|
logger.debug("Chosen set: OpenAIRE For Thematic + Institutional Repositories");
|
233 |
|
|
logger.debug("Setting METADATA_PREFIX to: oai_openaire");
|
234 |
|
|
job.setMetadataPrefix("oai_openaire");
|
235 |
|
|
} else if (
|
236 |
55394
|
antonis.le
|
// job.getDesiredCompatibilityLevel().equalsIgnoreCase("openaire2.0") ||
|
237 |
|
|
job.getDesiredCompatibilityLevel().toLowerCase().matches("^openaire\\d.\\d$") ||
|
238 |
|
|
// job.getDesiredCompatibilityLevel().equalsIgnoreCase("openaire3.0") ||
|
239 |
|
|
// job.getDesiredCompatibilityLevel().equalsIgnoreCase("openaire4.0") ||
|
240 |
34342
|
nikon.gasp
|
job.getDesiredCompatibilityLevel().equalsIgnoreCase("driver") ) {
|
241 |
|
|
logger.debug("Chosen set: OpenAIRE For Literature Repositories");
|
242 |
|
|
logger.debug("Setting METADATA_PREFIX to: oai_dc");
|
243 |
|
|
job.setMetadataPrefix("oai_dc");
|
244 |
55394
|
antonis.le
|
} else if ( job.getDesiredCompatibilityLevel().toLowerCase().matches("^openaire\\d.\\d_data$")) {
|
245 |
|
|
// job.getDesiredCompatibilityLevel().equalsIgnoreCase("openaire2.0_data")) {
|
246 |
34342
|
nikon.gasp
|
logger.debug("Chosen set: OpenAIRE For Data Archives");
|
247 |
|
|
logger.debug("Setting METADATA_PREFIX to: oai_datacite");
|
248 |
|
|
job.setMetadataPrefix("oai_datacite");
|
249 |
55394
|
antonis.le
|
} else if ( job.getDesiredCompatibilityLevel().toLowerCase().matches("^openaire\\d.\\d(.\\d)?_cris$")) {
|
250 |
|
|
// job.getDesiredCompatibilityLevel().equalsIgnoreCase("openaire3.0_cris")) {
|
251 |
34342
|
nikon.gasp
|
logger.debug("Chosen set: OpenAIRE For Cris");
|
252 |
|
|
logger.debug("Setting METADATA_PREFIX to: oai_CERIF_openaire");
|
253 |
|
|
job.setMetadataPrefix("oai_CERIF_openaire");
|
254 |
57006
|
ioannis.di
|
} else {
|
255 |
|
|
logger.error("Cannot set metadata prefx for " + job.getDesiredCompatibilityLevel() + " guidelines");
|
256 |
34342
|
nikon.gasp
|
}
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
StoredJob newJob = new StoredJob(job);
|
260 |
21870
|
nikon.gasp
|
|
261 |
34342
|
nikon.gasp
|
int usageJobs = 0;
|
262 |
|
|
int contentJobs = 0;
|
263 |
|
|
Set<Integer> totalRules = new HashSet<Integer>();
|
264 |
|
|
Map<String,Set<Integer>> verbRuleMap = null;
|
265 |
|
|
String validationType = "";
|
266 |
31252
|
nikon.gasp
|
|
267 |
34342
|
nikon.gasp
|
if (job.getSelectedContentRules() != null) {
|
268 |
|
|
contentJobs = 1;
|
269 |
57006
|
ioannis.di
|
validationType += "C";
|
270 |
34342
|
nikon.gasp
|
totalRules.addAll(job.getSelectedContentRules());
|
271 |
|
|
newJob.setContentJobStatus("ongoing");
|
272 |
|
|
} else {
|
273 |
|
|
newJob.setContentJobStatus("none");
|
274 |
|
|
}
|
275 |
57006
|
ioannis.di
|
|
276 |
34342
|
nikon.gasp
|
if (job.getSelectedUsageRules() != null) {
|
277 |
|
|
logger.debug("Creating map for provider information");
|
278 |
|
|
verbRuleMap= new HashMap<String,Set<Integer>>();
|
279 |
|
|
Set<Integer> old,temp = null;
|
280 |
57006
|
ioannis.di
|
|
281 |
34342
|
nikon.gasp
|
for (Integer id : job.getSelectedUsageRules()){
|
282 |
|
|
eu.dnetlib.domain.functionality.validator.Rule ruleStored = rulesDao.get(id);
|
283 |
|
|
logger.debug("Checking for verb : "+ruleStored.getProvider_information());
|
284 |
|
|
if((old=verbRuleMap.get(ruleStored.getProvider_information())) == null){
|
285 |
|
|
logger.debug("Verb doesn't exist");
|
286 |
|
|
temp = new HashSet<Integer>();
|
287 |
|
|
temp.add(ruleStored.getId());
|
288 |
|
|
verbRuleMap.put(ruleStored.getProvider_information(),temp);
|
289 |
|
|
}else{
|
290 |
|
|
logger.debug("Verb exists");
|
291 |
|
|
old.add(ruleStored.getId());
|
292 |
|
|
}
|
293 |
21870
|
nikon.gasp
|
}
|
294 |
34342
|
nikon.gasp
|
usageJobs = verbRuleMap.size();
|
295 |
|
|
validationType +="U";
|
296 |
|
|
totalRules.addAll(job.getSelectedUsageRules());
|
297 |
|
|
newJob.setUsageJobStatus("ongoing");
|
298 |
|
|
} else {
|
299 |
|
|
newJob.setUsageJobStatus("none");
|
300 |
21870
|
nikon.gasp
|
}
|
301 |
34342
|
nikon.gasp
|
|
302 |
|
|
|
303 |
|
|
Map<String, Set<Rule>> entityChosenRulesMap = null;
|
304 |
|
|
Map<String, Set<Rule>> entityChosenRulesMapReferential = null;
|
305 |
|
|
|
306 |
|
|
if (job.isCris()) {
|
307 |
56962
|
ioannis.di
|
entityChosenRulesMap = new HashMap<>();
|
308 |
|
|
entityChosenRulesMapReferential = new HashMap<>();
|
309 |
34342
|
nikon.gasp
|
this.prepareCrisJobs(job, entityChosenRulesMap, entityChosenRulesMapReferential);
|
310 |
|
|
newJob.setGroupByXpath("//header/setSpec");
|
311 |
|
|
contentJobs = entityChosenRulesMap.keySet().size() + entityChosenRulesMapReferential.keySet().size();
|
312 |
38323
|
nikon.gasp
|
//TODO move in uoa-domain
|
313 |
|
|
newJob.setCris(true);
|
314 |
|
|
newJob.setSelectedCrisEntities(job.getSelectedCrisEntities());
|
315 |
|
|
newJob.setCrisReferentialChecks(job.isCrisReferentialChecks());
|
316 |
34342
|
nikon.gasp
|
}
|
317 |
57006
|
ioannis.di
|
|
318 |
34342
|
nikon.gasp
|
newJob.setValidationType(validationType);
|
319 |
57006
|
ioannis.di
|
|
320 |
57070
|
ioannis.di
|
if (job.isRegistration()) {
|
321 |
34342
|
nikon.gasp
|
newJob.setJobType("Registration Request");
|
322 |
38323
|
nikon.gasp
|
//TODO move in uoa-domain
|
323 |
34342
|
nikon.gasp
|
newJob.setActivationId(job.getActivationId());
|
324 |
38323
|
nikon.gasp
|
newJob.setRegistration(true);
|
325 |
|
|
newJob.setUpdateExisting(job.isUpdateExisting());
|
326 |
|
|
newJob.setOfficialName(job.getOfficialName());
|
327 |
|
|
newJob.setAdminEmails(job.getAdminEmails());
|
328 |
|
|
newJob.setDatasourceId(job.getDatasourceId());
|
329 |
|
|
newJob.setInterfaceId(job.getInterfaceId());
|
330 |
|
|
newJob.setInterfaceIdOld(job.getInterfaceIdOld());
|
331 |
|
|
newJob.setRepoType(job.getRepoType());
|
332 |
34342
|
nikon.gasp
|
} else
|
333 |
|
|
newJob.setJobType("Compatibility Test");
|
334 |
|
|
|
335 |
21870
|
nikon.gasp
|
newJob.setDuration("--");
|
336 |
34342
|
nikon.gasp
|
newJob.setRules(totalRules);
|
337 |
|
|
newJob.setId(-1);
|
338 |
|
|
|
339 |
|
|
int jobIdStored = jobsDao.save(newJob);
|
340 |
|
|
|
341 |
|
|
RegistrationListener regListener = null;
|
342 |
57070
|
ioannis.di
|
if (job.isRegistration()) {
|
343 |
34342
|
nikon.gasp
|
regListener = listenersManager.createRegListener();
|
344 |
|
|
regListener.setUserMail(job.getUserEmail());
|
345 |
|
|
regListener.setDatasourceId(job.getDatasourceId());
|
346 |
|
|
regListener.setInterfaceId(job.getInterfaceId());
|
347 |
57006
|
ioannis.di
|
regListener.setUpdateExisting(job.isUpdateExisting());
|
348 |
34342
|
nikon.gasp
|
regListener.setTotalJobs(usageJobs + contentJobs);
|
349 |
21870
|
nikon.gasp
|
}
|
350 |
34342
|
nikon.gasp
|
|
351 |
|
|
CompatibilityTestListener compTestListener = listenersManager.createCompTestListener();
|
352 |
|
|
compTestListener.setValidationSet(job.getValidationSet());
|
353 |
|
|
compTestListener.setGuidelines(job.getDesiredCompatibilityLevel());
|
354 |
|
|
compTestListener.setTotalJobs(usageJobs + contentJobs);
|
355 |
|
|
|
356 |
57006
|
ioannis.di
|
//CONTENT
|
357 |
34342
|
nikon.gasp
|
if (job.getSelectedContentRules() != null) {
|
358 |
|
|
Set<Rule> rulesContent = new HashSet<Rule>();
|
359 |
|
|
Properties props = new Properties();
|
360 |
57006
|
ioannis.di
|
|
361 |
34342
|
nikon.gasp
|
props.setProperty(OAIPMHRecordProvider.BASEURL, job.getBaseUrl());
|
362 |
|
|
props.setProperty(OAIPMHRecordProvider.METADATA_PREFIX, newJob.getMetadataPrefix());
|
363 |
|
|
props.setProperty(OAIPMHRecordProvider.RECORDS,Integer.toString(job.getRecords()));
|
364 |
|
|
props.setProperty(OAIPMHRecordProvider.SET,job.getValidationSet());
|
365 |
|
|
|
366 |
|
|
Job jobContent = null;
|
367 |
|
|
|
368 |
|
|
ValidatorJobListener listenerContent = listenersManager.createListener();
|
369 |
57006
|
ioannis.di
|
|
370 |
34342
|
nikon.gasp
|
listenerContent.setJobSubmittedId(jobIdStored);
|
371 |
|
|
listenerContent.setJobSubmittedUser(job.getUserEmail());
|
372 |
|
|
listenerContent.setGroupBy_xpath(newJob.getGroupByXpath());
|
373 |
|
|
listenerContent.setValidationType("content");
|
374 |
|
|
listenerContent.setInternalJobsSum(contentJobs);
|
375 |
21870
|
nikon.gasp
|
|
376 |
34342
|
nikon.gasp
|
if (job.isCris()) {
|
377 |
|
|
logger.debug("Submiting job for cris.");
|
378 |
|
|
logger.debug("Total content jobs: " + contentJobs);
|
379 |
|
|
jobContent = new Job(jobIdStored, 4, rulesContent, props);
|
380 |
57006
|
ioannis.di
|
// acz
|
381 |
|
|
// validator.submitJobForCris(jobContent, entityChosenRulesMap, entityChosenRulesMapReferential, listenerContent, compTestListener);
|
382 |
|
|
// send cris validation to Guideline team member. Could be moved into MemoryThreadValidator.submitJobForCris method
|
383 |
|
|
List<String> recipientsMailAddr = new ArrayList<String>();
|
384 |
|
|
recipientsMailAddr.add("andreas.czerniak@uni-bielefeld.de");
|
385 |
|
|
emailer.sendMail( recipientsMailAddr, "CrisJob submitting", "baseUrl: " + job.getBaseUrl() , false, recipientsMailAddr);
|
386 |
|
|
} else {
|
387 |
34342
|
nikon.gasp
|
logger.debug("Selected content rules number: " + job.getSelectedContentRules().size());
|
388 |
|
|
for (Integer ruleId : job.getSelectedContentRules()){
|
389 |
57006
|
ioannis.di
|
eu.dnetlib.domain.functionality.validator.Rule tempRule= rulesDao.get(ruleId);
|
390 |
34342
|
nikon.gasp
|
|
391 |
|
|
//special behaviour type of rule is chain
|
392 |
57006
|
ioannis.di
|
if (tempRule.getType().equals("ChainRule")) {
|
393 |
34342
|
nikon.gasp
|
ChainRule<Rule> chainRule = this.handleChain(tempRule);
|
394 |
|
|
rulesContent.add(chainRule);
|
395 |
57006
|
ioannis.di
|
} else
|
396 |
34342
|
nikon.gasp
|
rulesContent.add((Rule) this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), tempRule.getId()));
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
jobContent = new Job(jobIdStored, 1, rulesContent, props);
|
400 |
|
|
|
401 |
57070
|
ioannis.di
|
if (job.isRegistration()) {
|
402 |
34342
|
nikon.gasp
|
validator.submitJob(jobContent, 1, listenerContent, regListener);
|
403 |
|
|
} else {
|
404 |
|
|
validator.submitJob(jobContent, 1, listenerContent, compTestListener);
|
405 |
|
|
}
|
406 |
21870
|
nikon.gasp
|
}
|
407 |
|
|
}
|
408 |
34342
|
nikon.gasp
|
|
409 |
36208
|
nikon.gasp
|
//USAGE
|
410 |
|
|
if (job.getSelectedUsageRules() != null) {
|
411 |
|
|
|
412 |
|
|
ValidatorJobListener listenerUsage = listenersManager.createListener();
|
413 |
|
|
listenerUsage.setJobSubmittedId(jobIdStored);
|
414 |
|
|
listenerUsage.setValidationType("usage");
|
415 |
|
|
listenerUsage.setJobSubmittedUser(job.getUserEmail());
|
416 |
|
|
listenerUsage.setInternalJobsSum(usageJobs);
|
417 |
|
|
List <Job> jobsUsage = new ArrayList<Job>();
|
418 |
|
|
for (Map.Entry<String, Set<Integer>> entry : verbRuleMap.entrySet()) {
|
419 |
|
|
Properties pros = new Properties();
|
420 |
|
|
pros.setProperty(OAIPMHSinglePageVerbProvider.VERB,entry.getKey());
|
421 |
|
|
pros.setProperty(OAIPMHSinglePageVerbProvider.BASEURL, job.getBaseUrl());
|
422 |
|
|
Set<Rule> rulesUsage = new HashSet<Rule>();
|
423 |
|
|
for (Integer ruleId : entry.getValue()){
|
424 |
|
|
eu.dnetlib.domain.functionality.validator.Rule tempRule = rulesDao.get(ruleId);
|
425 |
|
|
logger.debug("prepare to add rule to registry with regexp: "+tempRule.getConfiguration().getProperty("regexp"));
|
426 |
|
|
rulesUsage.add((Rule)this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), tempRule.getId()));
|
427 |
|
|
}
|
428 |
|
|
jobsUsage.add(new Job(jobIdStored, 2, rulesUsage, pros));
|
429 |
|
|
}
|
430 |
|
|
for (Job jobUsage : jobsUsage ) {
|
431 |
57070
|
ioannis.di
|
if (job.isRegistration()) {
|
432 |
36208
|
nikon.gasp
|
validator.submitJob(jobUsage, 1, listenerUsage, regListener);
|
433 |
|
|
} else {
|
434 |
|
|
validator.submitJob(jobUsage, 1, listenerUsage, compTestListener);
|
435 |
|
|
}
|
436 |
|
|
}
|
437 |
|
|
}
|
438 |
|
|
|
439 |
|
|
|
440 |
21870
|
nikon.gasp
|
} catch (Exception e) {
|
441 |
34342
|
nikon.gasp
|
logger.error("error submitting job ", e);
|
442 |
21870
|
nikon.gasp
|
throw new ValidatorException(e);
|
443 |
|
|
}
|
444 |
34342
|
nikon.gasp
|
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
private void prepareCrisJobs(JobForValidation job,
|
448 |
|
|
Map<String, Set<Rule>> entityChosenRulesMap,
|
449 |
37040
|
nikon.gasp
|
Map<String, Set<Rule>> entityChosenRulesMapReferential) throws ValidatorException, DaoException {
|
450 |
34342
|
nikon.gasp
|
//getting rules per entity and leave only chosen ones
|
451 |
|
|
logger.debug("Selected Entities: " + job.getSelectedCrisEntities());
|
452 |
|
|
for (String entity : RuleTypes.getEntities().keySet()) {
|
453 |
|
|
|
454 |
|
|
logger.debug("checking entity: " + entity);
|
455 |
|
|
Set<Rule> rulesBasic = new HashSet<Rule>();
|
456 |
|
|
Set<Rule> rulesReferential = new HashSet<Rule>();
|
457 |
|
|
if (job.getSelectedCrisEntities().contains(entity)) {
|
458 |
|
|
logger.debug("entity: " + entity + " is selected");
|
459 |
|
|
for (eu.dnetlib.domain.functionality.validator.Rule rule : rulesDao.getAllRulesByJobTypeEntityType("content", entity)) {
|
460 |
|
|
if (job.getSelectedContentRules().contains(rule.getId())) {
|
461 |
|
|
eu.dnetlib.domain.functionality.validator.Rule tempRule=rulesDao.get(rule.getId());
|
462 |
|
|
if (rule.getName().contains("Relationship")) {
|
463 |
|
|
if (job.isCrisReferentialChecks()) {
|
464 |
|
|
rulesReferential.add((Rule) this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), tempRule.getId()));
|
465 |
|
|
}
|
466 |
|
|
} else {
|
467 |
|
|
rulesBasic.add((Rule) this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), tempRule.getId()));
|
468 |
|
|
}
|
469 |
|
|
}
|
470 |
|
|
}
|
471 |
|
|
logger.debug("Basic rules: " + rulesBasic.size());
|
472 |
|
|
logger.debug("Referential rules: " + rulesReferential.size());
|
473 |
|
|
entityChosenRulesMap.put(RuleTypes.getSetOfEntity(entity), rulesBasic);
|
474 |
|
|
if (job.isCrisReferentialChecks() && !rulesReferential.isEmpty())
|
475 |
|
|
entityChosenRulesMapReferential.put(RuleTypes.getSetOfEntity(entity), rulesReferential);
|
476 |
|
|
} else {
|
477 |
|
|
logger.debug("entity: " + entity + " is not selected");
|
478 |
|
|
}
|
479 |
|
|
}
|
480 |
|
|
logger.debug("Return entities: " + entityChosenRulesMap.keySet());
|
481 |
21870
|
nikon.gasp
|
|
482 |
34342
|
nikon.gasp
|
|
483 |
21870
|
nikon.gasp
|
}
|
484 |
|
|
|
485 |
34342
|
nikon.gasp
|
|
486 |
41972
|
nikon.gasp
|
public Rule getRuleClassInstanceByType(String type, CustomProperties pros, int id) throws ValidatorException {
|
487 |
34342
|
nikon.gasp
|
logger.debug("getting rule object of type "+type);
|
488 |
21870
|
nikon.gasp
|
String classname = RuleTypes.getClassOfType(type);
|
489 |
34342
|
nikon.gasp
|
if (classname == null){
|
490 |
|
|
logger.debug("error getting rule object of type "+type+" classname=null");
|
491 |
21870
|
nikon.gasp
|
return null;
|
492 |
34342
|
nikon.gasp
|
}
|
493 |
|
|
else {
|
494 |
21870
|
nikon.gasp
|
try {
|
495 |
|
|
Class<?> clazz = Class.forName(classname);
|
496 |
34342
|
nikon.gasp
|
logger.debug("classname: "+clazz.getName());
|
497 |
41985
|
nikon.gasp
|
Properties properties = new Properties();
|
498 |
|
|
properties.putAll(pros.getProperties());
|
499 |
|
|
return (Rule) clazz.getConstructor(new Class[]{Properties.class,Integer.TYPE}).newInstance(properties,id);
|
500 |
34342
|
nikon.gasp
|
|
501 |
|
|
} catch (Exception e) {
|
502 |
|
|
logger.debug("error getting rule object: "+e);
|
503 |
21870
|
nikon.gasp
|
return null;
|
504 |
34342
|
nikon.gasp
|
}
|
505 |
21870
|
nikon.gasp
|
}
|
506 |
|
|
}
|
507 |
30662
|
nikon.gasp
|
|
508 |
34342
|
nikon.gasp
|
|
509 |
37040
|
nikon.gasp
|
private ChainRule<Rule> handleChain(eu.dnetlib.domain.functionality.validator.Rule tempRule) throws ValidatorException, DaoException {
|
510 |
30662
|
nikon.gasp
|
logger.debug("chain rule found");
|
511 |
|
|
List<Rule> rules_chain = new ArrayList<Rule>();
|
512 |
34342
|
nikon.gasp
|
eu.dnetlib.domain.functionality.validator.Rule tempRuleChain1=rulesDao.get(Integer.parseInt(tempRule.getConfiguration().getProperty("rule_1")));
|
513 |
30662
|
nikon.gasp
|
if(tempRuleChain1.getType().equals("ChainRule")) {
|
514 |
|
|
ChainRule<Rule> chainRule1 = this.handleChain(tempRuleChain1);
|
515 |
|
|
rules_chain.add(chainRule1);
|
516 |
|
|
} else {
|
517 |
34342
|
nikon.gasp
|
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(),tempRuleChain1.getId()));
|
518 |
30662
|
nikon.gasp
|
}
|
519 |
34342
|
nikon.gasp
|
eu.dnetlib.domain.functionality.validator.Rule tempRuleChain2=rulesDao.get(Integer.parseInt(tempRule.getConfiguration().getProperty("rule_2")));
|
520 |
30662
|
nikon.gasp
|
if(tempRuleChain2.getType().equals("ChainRule")) {
|
521 |
|
|
ChainRule<Rule> chainRule2 = this.handleChain(tempRuleChain2);
|
522 |
|
|
rules_chain.add(chainRule2);
|
523 |
|
|
} else {
|
524 |
34342
|
nikon.gasp
|
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), tempRuleChain2.getId()));
|
525 |
30662
|
nikon.gasp
|
}
|
526 |
|
|
Properties chainPros = new Properties();
|
527 |
|
|
chainPros.setProperty(ChainRule.TYPE,tempRule.getConfiguration().getProperty(ChainRule.TYPE));
|
528 |
34342
|
nikon.gasp
|
ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, tempRule.getId(), rules_chain);
|
529 |
30662
|
nikon.gasp
|
return chainRule;
|
530 |
|
|
}
|
531 |
21870
|
nikon.gasp
|
|
532 |
|
|
public Validator getValidator() {
|
533 |
|
|
return validator;
|
534 |
|
|
}
|
535 |
34342
|
nikon.gasp
|
|
536 |
|
|
public ListenersManager getListenersManager() {
|
537 |
|
|
return listenersManager;
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
public void setListenersManager(ListenersManager listenersManager) {
|
541 |
|
|
this.listenersManager = listenersManager;
|
542 |
|
|
}
|
543 |
|
|
|
544 |
21870
|
nikon.gasp
|
public void setValidator(Validator validator) {
|
545 |
|
|
this.validator = validator;
|
546 |
|
|
}
|
547 |
34342
|
nikon.gasp
|
|
548 |
|
|
public JobsDAO getJobsDao() {
|
549 |
|
|
return jobsDao;
|
550 |
21870
|
nikon.gasp
|
}
|
551 |
34342
|
nikon.gasp
|
|
552 |
|
|
public void setJobsDao(JobsDAO jobsDao) {
|
553 |
|
|
this.jobsDao = jobsDao;
|
554 |
21870
|
nikon.gasp
|
}
|
555 |
34342
|
nikon.gasp
|
|
556 |
|
|
public RulesetsDAO getRulesetsDao() {
|
557 |
|
|
return rulesetsDao;
|
558 |
21870
|
nikon.gasp
|
}
|
559 |
34342
|
nikon.gasp
|
|
560 |
|
|
public void setRulesetsDao(RulesetsDAO rulesetsDao) {
|
561 |
|
|
this.rulesetsDao = rulesetsDao;
|
562 |
21870
|
nikon.gasp
|
}
|
563 |
34342
|
nikon.gasp
|
|
564 |
|
|
public RulesDAO getRulesDao() {
|
565 |
|
|
return rulesDao;
|
566 |
21870
|
nikon.gasp
|
}
|
567 |
34342
|
nikon.gasp
|
|
568 |
|
|
public void setRulesDao(RulesDAO rulesDao) {
|
569 |
|
|
this.rulesDao = rulesDao;
|
570 |
21870
|
nikon.gasp
|
}
|
571 |
34342
|
nikon.gasp
|
|
572 |
37040
|
nikon.gasp
|
public ValidatorRestore getValRestore() {
|
573 |
|
|
return valRestore;
|
574 |
|
|
}
|
575 |
|
|
|
576 |
|
|
public void setValRestore(ValidatorRestore valRestore) {
|
577 |
|
|
this.valRestore = valRestore;
|
578 |
|
|
}
|
579 |
|
|
|
580 |
30052
|
antonis.le
|
}
|