1
|
package eu.dnetlib.oai.actions;
|
2
|
|
3
|
import com.google.common.collect.Iterables;
|
4
|
import eu.dnetlib.enabling.resultset.client.ResultSetClient;
|
5
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
6
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
7
|
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
|
8
|
import eu.dnetlib.oai.sync.OAIStoreSynchronizer;
|
9
|
import eu.dnetlib.rmi.common.ResultSet;
|
10
|
import eu.dnetlib.rmi.provision.MDFInfo;
|
11
|
import eu.dnetlib.utils.MetadataReference;
|
12
|
import eu.dnetlib.utils.MetadataReferenceFactory;
|
13
|
import org.apache.commons.logging.Log;
|
14
|
import org.apache.commons.logging.LogFactory;
|
15
|
import org.dom4j.io.SAXReader;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.core.io.ClassPathResource;
|
18
|
|
19
|
public class SyncAction extends AbstractOAIStoreAction {
|
20
|
|
21
|
private static final Log log = LogFactory.getLog(SyncAction.class); // NOPMD by marko on 11/24/08 5:02 PM
|
22
|
private final SAXReader saxReader = new SAXReader();
|
23
|
org.springframework.core.io.Resource dmfXsltResource = new ClassPathResource("/eu/dnetlib/oai/xslt/addDMFBlock.xslt");
|
24
|
@Autowired
|
25
|
private OAIStoreSynchronizer synchronizer;
|
26
|
@Autowired
|
27
|
private ResultSetClient resultSetClient;
|
28
|
|
29
|
@Override
|
30
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
|
31
|
String epr = job.getParameters().get("oai_syncEpr");
|
32
|
String recordSource = job.getParameters().get("oai_recordSource");
|
33
|
boolean alwaysNewRecord = Boolean.valueOf(job.getParameters().get("oai_alwaysNewRecord"));
|
34
|
final String dbName = job.getParameters().get("oai_dbName");
|
35
|
|
36
|
final String collectionName = job.getParameters().get("oai_collectionName");
|
37
|
final MetadataReference mdRef = MetadataReferenceFactory.decode(collectionName, MDREF_SEPARATOR);
|
38
|
|
39
|
final ResultSet<?> rs = ResultSet.fromJson(epr);
|
40
|
log.info("Syncronizing content for oai on db " + dbName + "for metadata format: " + mdRef);
|
41
|
Iterable<String> records = resultSetClient.iter(rs, String.class);
|
42
|
// 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
|
43
|
// element inside oai:metadata.
|
44
|
if (mdRef.getFormat().equalsIgnoreCase("DMF")) {
|
45
|
records = addDMFBlock(records);
|
46
|
}
|
47
|
this.synchronizer.synchronize(records, mdRef, recordSource, dbName, alwaysNewRecord, () -> {
|
48
|
handler.done(job);
|
49
|
return null;
|
50
|
}, () -> {
|
51
|
handler.failed(job, new Exception("Error during OAI synchronization on db " + dbName));
|
52
|
return null;
|
53
|
});
|
54
|
|
55
|
}
|
56
|
|
57
|
protected Iterable<String> addDMFBlock(final Iterable<String> input) {
|
58
|
final ApplyXslt addDMFBlockXslt = new ApplyXslt(dmfXsltResource);
|
59
|
return Iterables.transform(input, addDMFBlockXslt::apply);
|
60
|
}
|
61
|
|
62
|
public OAIStoreSynchronizer getSynchronizer() {
|
63
|
return synchronizer;
|
64
|
}
|
65
|
|
66
|
public void setSynchronizer(final OAIStoreSynchronizer synchronizer) {
|
67
|
this.synchronizer = synchronizer;
|
68
|
}
|
69
|
|
70
|
}
|