1
|
package gr.uoa.di.validator.api;
|
2
|
|
3
|
import gr.uoa.di.validator.dao.JobSubmitted;
|
4
|
import gr.uoa.di.validator.dao.JobSubmittedDAO;
|
5
|
import gr.uoa.di.validator.impls.providers.OAIPMHRecordProvider;
|
6
|
import gr.uoa.di.validator.impls.providers.OAIPMHSinglePageVerbProvider;
|
7
|
|
8
|
import java.util.ArrayList;
|
9
|
import java.util.List;
|
10
|
import java.util.Properties;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.springframework.transaction.annotation.Propagation;
|
14
|
import org.springframework.transaction.annotation.Transactional;
|
15
|
|
16
|
@Transactional(propagation = Propagation.REQUIRED)
|
17
|
public class ValidatorRestore {
|
18
|
|
19
|
private OpenAIREValidator openAIREValidator;
|
20
|
private JobSubmittedDAO jobSubmittedDao;
|
21
|
|
22
|
private static Logger logger = Logger.getLogger(ValidatorRestore.class);
|
23
|
|
24
|
public List<JobSubmitted> deleteUncompleted() {
|
25
|
logger.debug("Checking for uncompleted jobs");
|
26
|
List<JobSubmitted> unCompletedJobs = jobSubmittedDao.getUncompletedJobs();
|
27
|
logger.debug("Uncompleted jobs found: "+unCompletedJobs.size());
|
28
|
if(unCompletedJobs.size()>0)
|
29
|
jobSubmittedDao.deleteUncompletedJobs();
|
30
|
return unCompletedJobs;
|
31
|
}
|
32
|
|
33
|
public void restore( List<JobSubmitted> unCompletedJobs) {
|
34
|
Properties pros = null;
|
35
|
List<String> unCompletedRegJobs = new ArrayList<String>();
|
36
|
for (JobSubmitted job : unCompletedJobs) {
|
37
|
logger.debug("Restarting job: "+job.getId());
|
38
|
try {
|
39
|
if (job.getRuleset().equalsIgnoreCase("Custom")) {
|
40
|
logger.debug("restoring compatibility test job");
|
41
|
if(job.getType().equals("OAI Content Validation")) {
|
42
|
pros = new Properties();
|
43
|
pros.setProperty(OAIPMHRecordProvider.BASEURL, job.getRepo());
|
44
|
pros.setProperty(OAIPMHRecordProvider.METADATA_PREFIX, "oai_dc");
|
45
|
pros.setProperty(OAIPMHRecordProvider.TIMEOUT, "360000");
|
46
|
pros.setProperty(OAIPMHRecordProvider.DELAY, "1000");
|
47
|
pros.setProperty(OAIPMHRecordProvider.RETRY_DELAY, "60000");
|
48
|
pros.setProperty(OAIPMHRecordProvider.RETRY_EFFORTS, "3");
|
49
|
pros.setProperty(OAIPMHRecordProvider.RECORDS, job.getRecords());
|
50
|
pros.setProperty(OAIPMHRecordProvider.SET, job.getSet());
|
51
|
getOpenAIREValidator().submitContentJob(pros, job.getRules(), job.getUser(), job. getGroupBy_xpath(), null);
|
52
|
} else if (job.getType().equals("OAI Usage Validation")) {
|
53
|
pros = new Properties();
|
54
|
pros.setProperty(OAIPMHSinglePageVerbProvider.BASEURL, job.getRepo());
|
55
|
pros.setProperty(OAIPMHSinglePageVerbProvider.TIMEOUT, "60000");
|
56
|
pros.setProperty(OAIPMHSinglePageVerbProvider.DELAY, "1000");
|
57
|
pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_DELAY, "60000");
|
58
|
pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_EFFORTS, "3");
|
59
|
getOpenAIREValidator().submitUsageJob(pros, job.getRules(), job.getUser(), null);
|
60
|
}
|
61
|
} else if (job.getRuleset().equalsIgnoreCase("Registration Request")) {
|
62
|
logger.debug("restoring registration request job");
|
63
|
String activationId = job.getActivation_id();
|
64
|
if (unCompletedRegJobs.contains(activationId)) {
|
65
|
logger.debug("registration job already restored");
|
66
|
} else {
|
67
|
jobSubmittedDao.deleteSemiCompletedRegistrationJobs(activationId);
|
68
|
unCompletedRegJobs.add(activationId);
|
69
|
List<String> inputs = getOpenAIREValidator().getJobForRegistration(activationId);
|
70
|
if (inputs != null) {
|
71
|
List<String> admin_emails = new ArrayList<String>();
|
72
|
admin_emails.add(inputs.get(4));
|
73
|
|
74
|
this.getOpenAIREValidator().preRegistrationValidations(inputs.get(2), inputs.get(1), activationId, inputs.get(3),admin_emails, inputs.get(5), inputs.get(8), inputs.get(6), inputs.get(7));
|
75
|
} else {
|
76
|
logger.debug("Activation-Id is wrong or Repository is already registered.");
|
77
|
}
|
78
|
|
79
|
}
|
80
|
|
81
|
}
|
82
|
|
83
|
|
84
|
} catch (OpenAIREValidatorException e) {
|
85
|
logger.error("Error adding job", e);
|
86
|
}
|
87
|
|
88
|
}
|
89
|
}
|
90
|
|
91
|
public OpenAIREValidator getOpenAIREValidator() {
|
92
|
return openAIREValidator;
|
93
|
}
|
94
|
|
95
|
public void setOpenAIREValidator(OpenAIREValidator openAIREValidator) {
|
96
|
this.openAIREValidator = openAIREValidator;
|
97
|
}
|
98
|
|
99
|
public JobSubmittedDAO getJobSubmittedDao() {
|
100
|
return jobSubmittedDao;
|
101
|
}
|
102
|
|
103
|
public void setJobSubmittedDao(JobSubmittedDAO jobSubmittedDao) {
|
104
|
this.jobSubmittedDao = jobSubmittedDao;
|
105
|
}
|
106
|
|
107
|
}
|