1
|
package eu.dnetlib.data.mdstore.modular;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.beans.factory.annotation.Required;
|
9
|
|
10
|
import eu.dnetlib.data.mdstore.MDStoreServiceException;
|
11
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
12
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
13
|
|
14
|
public class FeedAction extends AbstractMDStoreAction {
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(FeedAction.class);
|
17
|
|
18
|
private MDStoreFeeder feeder;
|
19
|
|
20
|
@Autowired
|
21
|
private MDStoreUtils mdstoreUtils;
|
22
|
|
23
|
@Override
|
24
|
public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
|
25
|
|
26
|
final String mdId = job.getParameters().get("mdId");
|
27
|
if (mdId == null || mdId.isEmpty()) { throw new MDStoreServiceException("Blackboard param (mdId) is empty"); }
|
28
|
|
29
|
final String epr = job.getParameters().get("epr");
|
30
|
if (epr == null || epr.isEmpty()) { throw new MDStoreServiceException("Blackboard param (mdId) is empty"); }
|
31
|
|
32
|
String storingType = job.getParameters().get("storingType");
|
33
|
if (storingType == null || storingType.isEmpty()) {
|
34
|
storingType = "REFRESH";
|
35
|
}
|
36
|
|
37
|
final String layoutIndex = job.getParameters().get("layoutIndex");
|
38
|
String format = feeder.getDao().getMDStore(mdId).getFormat();
|
39
|
|
40
|
List<MDFormatDescription> mdformats = mdstoreUtils.getField(format, layoutIndex);
|
41
|
if (mdformats != null) {
|
42
|
for (MDFormatDescription desc : mdformats) {
|
43
|
log.info("name: " + desc.getName());
|
44
|
log.info("xpath: " + desc.getXpath());
|
45
|
}
|
46
|
}
|
47
|
|
48
|
feeder.feed(mdId, epr, storingType, true, mdformats, new FeedDoneCallback() {
|
49
|
|
50
|
@Override
|
51
|
public void call(final int size) {
|
52
|
job.getParameters().put("total", "" + size);
|
53
|
completeWithSuccess(handler, job);
|
54
|
}
|
55
|
}, new FeedFailedCallback() {
|
56
|
|
57
|
@Override
|
58
|
public void call(final Throwable e) {
|
59
|
log.error("Error feeding mdstore: " + mdId, e);
|
60
|
completeWithFail(handler, job, e);
|
61
|
}
|
62
|
});
|
63
|
}
|
64
|
|
65
|
public MDStoreFeeder getFeeder() {
|
66
|
return feeder;
|
67
|
}
|
68
|
|
69
|
@Required
|
70
|
public void setFeeder(final MDStoreFeeder feeder) {
|
71
|
this.feeder = feeder;
|
72
|
}
|
73
|
|
74
|
}
|