1
|
package eu.dnetlib.validator.service.impls;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.HashSet;
|
5
|
import java.util.List;
|
6
|
import java.util.Set;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.transaction.annotation.Propagation;
|
10
|
import org.springframework.transaction.annotation.Transactional;
|
11
|
|
12
|
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
13
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
14
|
import eu.dnetlib.validator.commons.dao.jobs.JobsDAO;
|
15
|
import eu.dnetlib.validator.commons.dao.rules.RulesetsDAO;
|
16
|
import eu.dnetlib.validator.engine.ValidatorException;
|
17
|
import eu.dnetlib.validator.service.impl.ValidatorManager;
|
18
|
|
19
|
@Transactional(propagation = Propagation.REQUIRED)
|
20
|
public class ValidatorRestore {
|
21
|
|
22
|
private JobsDAO jobsDao;
|
23
|
private RulesetsDAO rulesetsDao;
|
24
|
private ValidatorManager valManager;
|
25
|
private boolean autoRestoreOnStartup;
|
26
|
|
27
|
private static Logger logger = Logger.getLogger(ValidatorRestore.class);
|
28
|
|
29
|
public List<StoredJob> deleteUncompleted() {
|
30
|
List<StoredJob> unCompletedJobs = new ArrayList<StoredJob>();
|
31
|
try {
|
32
|
logger.info("Checking for uncompleted jobs");
|
33
|
unCompletedJobs = jobsDao.getUncompletedJobs();
|
34
|
logger.info("Uncompleted jobs found: "+unCompletedJobs.size());
|
35
|
if(unCompletedJobs.size() > 0 ) {
|
36
|
logger.info("deleting uncompleted jobs..");
|
37
|
jobsDao.deleteUncompletedJobs();
|
38
|
}
|
39
|
} catch (Exception e) {
|
40
|
logger.error("Error deleting uncompleted jobs", e);
|
41
|
}
|
42
|
return unCompletedJobs;
|
43
|
}
|
44
|
|
45
|
public void restartJobs(List<StoredJob> jobs) {
|
46
|
try {
|
47
|
for (StoredJob job : jobs) {
|
48
|
try {
|
49
|
if (job.getUserEmail().equalsIgnoreCase("workflow service"))
|
50
|
continue;
|
51
|
logger.debug("Restarting job: "+job.getId());
|
52
|
Set<Integer> contentRules = new HashSet<Integer>();
|
53
|
Set<Integer> usageRules = new HashSet<Integer>();
|
54
|
for (RuleSet ruleset : rulesetsDao.getRuleSets()) {
|
55
|
if (ruleset.getGuidelinesAcronym().equals(job.getDesiredCompatibilityLevel())) {
|
56
|
for (int ruleId : job.getRules()) {
|
57
|
if (ruleset.getContentRulesIds().contains(ruleId))
|
58
|
contentRules.add(ruleId);
|
59
|
else if (ruleset.getUsageRulesIds().contains(ruleId))
|
60
|
usageRules.add(ruleId);
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
if (!contentRules.isEmpty())
|
65
|
job.setSelectedContentRules(contentRules);
|
66
|
if (!usageRules.isEmpty())
|
67
|
job.setSelectedUsageRules(usageRules);
|
68
|
valManager.submitJob(job);
|
69
|
} catch (Exception e) {
|
70
|
logger.error("error Re-Submitting validation job", e);
|
71
|
throw new ValidatorException(e);
|
72
|
}
|
73
|
}
|
74
|
} catch (Exception e) {
|
75
|
logger.error("error while restarting uncompleted jobs", e);
|
76
|
}
|
77
|
}
|
78
|
|
79
|
public ValidatorManager getValManager() {
|
80
|
return valManager;
|
81
|
}
|
82
|
|
83
|
public void setValManager(ValidatorManager valManager) {
|
84
|
this.valManager = valManager;
|
85
|
}
|
86
|
|
87
|
public JobsDAO getJobsDao() {
|
88
|
return jobsDao;
|
89
|
}
|
90
|
|
91
|
public void setJobsDao(JobsDAO jobsDao) {
|
92
|
this.jobsDao = jobsDao;
|
93
|
}
|
94
|
|
95
|
public RulesetsDAO getRulesetsDao() {
|
96
|
return rulesetsDao;
|
97
|
}
|
98
|
public void setRulesetsDao(RulesetsDAO rulesetsDao) {
|
99
|
this.rulesetsDao = rulesetsDao;
|
100
|
}
|
101
|
public boolean isAutoRestoreOnStartup() {
|
102
|
return autoRestoreOnStartup;
|
103
|
}
|
104
|
|
105
|
public void setAutoRestoreOnStartup(boolean autoRestoreOnStartup) {
|
106
|
this.autoRestoreOnStartup = autoRestoreOnStartup;
|
107
|
}
|
108
|
|
109
|
|
110
|
}
|