1
|
package eu.dnetlib.data.oai.store.actions;
|
2
|
|
3
|
import java.util.concurrent.Callable;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
7
|
|
8
|
import eu.dnetlib.data.information.oai.utils.OAIParameterNames;
|
9
|
import org.apache.commons.logging.Log;
|
10
|
import org.apache.commons.logging.LogFactory;
|
11
|
import org.dom4j.io.SAXReader;
|
12
|
import org.springframework.core.io.ClassPathResource;
|
13
|
|
14
|
import com.google.common.base.Function;
|
15
|
import com.google.common.collect.Iterables;
|
16
|
|
17
|
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo;
|
18
|
import eu.dnetlib.data.oai.store.sync.OAIStoreSynchronizer;
|
19
|
import eu.dnetlib.enabling.resultset.client.IterableResultSetClient;
|
20
|
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
|
21
|
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
|
22
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
23
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
24
|
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
|
25
|
|
26
|
public class SyncAction extends AbstractOAIStoreAction {
|
27
|
|
28
|
private static final Log log = LogFactory.getLog(SyncAction.class); // NOPMD by marko on 11/24/08 5:02 PM
|
29
|
|
30
|
@Resource
|
31
|
private OAIStoreSynchronizer synchronizer;
|
32
|
@Resource
|
33
|
private ResultSetClientFactory resultSetClientFactory;
|
34
|
org.springframework.core.io.Resource dmfXsltResource = new ClassPathResource("/eu/dnetlib/data/oai/store/xslt/addDMFBlock.xslt");
|
35
|
private final SAXReader saxReader = new SAXReader();
|
36
|
|
37
|
@Override
|
38
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
|
39
|
EPRUtils eprUtils = new EPRUtils();
|
40
|
W3CEndpointReference epr = eprUtils.getEpr(job.getParameters().get(OAIParameterNames.OAI_SYNC_EPR));
|
41
|
String recordSource = job.getParameters().get(OAIParameterNames.OAI_SOURCE);
|
42
|
String formatName = job.getParameters().get(OAIParameterNames.OAI_FORMAT_NAME);
|
43
|
String formatLayout = job.getParameters().get(OAIParameterNames.OAI_FORMAT_LAYOUT);
|
44
|
String formatInterpretation = job.getParameters().get(OAIParameterNames.OAI_FORMAT_INTERPRETATION);
|
45
|
boolean alwaysNewRecord = Boolean.valueOf(job.getParameters().get(OAIParameterNames.OAI_ALWAYS_NEW_RECORD));
|
46
|
final String dbName = job.getParameters().get(OAIParameterNames.OAI_DB);
|
47
|
MDFInfo mdf = new MDFInfo("", "", "", formatName, formatLayout, formatInterpretation, "", true);
|
48
|
IterableResultSetClient client = resultSetClientFactory.getClient(epr);
|
49
|
Iterable<String> records = client;
|
50
|
// in case of DMF there is no "hat element" after oai:metadata: we must add it or the OAI-PMH export will only contain the first
|
51
|
// element inside oai:metadata.
|
52
|
if (formatName.equalsIgnoreCase("DMF")) {
|
53
|
records = addDMFBlock(client);
|
54
|
}
|
55
|
this.synchronizer.synchronize(records, mdf, recordSource, dbName, alwaysNewRecord, new Callable<Object>() {
|
56
|
|
57
|
@Override
|
58
|
public Object call() {
|
59
|
handler.done(job);
|
60
|
return null;
|
61
|
}
|
62
|
}, new Callable<Object>() {
|
63
|
|
64
|
@Override
|
65
|
public Object call() {
|
66
|
handler.failed(job, new Exception("Error during OAI synchronization on db " + dbName));
|
67
|
return null;
|
68
|
}
|
69
|
});
|
70
|
|
71
|
}
|
72
|
|
73
|
protected Iterable<String> addDMFBlock(final Iterable<String> input) {
|
74
|
final ApplyXslt addDMFBlockXslt = new ApplyXslt(dmfXsltResource);
|
75
|
return Iterables.transform(input, new Function<String, String>() {
|
76
|
|
77
|
@Override
|
78
|
public String apply(final String dmfRecord) {
|
79
|
return addDMFBlockXslt.evaluate(dmfRecord);
|
80
|
}
|
81
|
});
|
82
|
}
|
83
|
|
84
|
public OAIStoreSynchronizer getSynchronizer() {
|
85
|
return synchronizer;
|
86
|
}
|
87
|
|
88
|
public void setSynchronizer(final OAIStoreSynchronizer synchronizer) {
|
89
|
this.synchronizer = synchronizer;
|
90
|
}
|
91
|
|
92
|
public ResultSetClientFactory getRsClientFactory() {
|
93
|
return resultSetClientFactory;
|
94
|
}
|
95
|
|
96
|
public void setRsClientFactory(final ResultSetClientFactory rsClientFactory) {
|
97
|
this.resultSetClientFactory = rsClientFactory;
|
98
|
}
|
99
|
|
100
|
}
|