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