1
|
package eu.dnetlib.data.mdstore.modular.action;
|
2
|
|
3
|
import eu.dnetlib.data.mdstore.modular.MDStoreFeeder;
|
4
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
5
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
6
|
import eu.dnetlib.rmi.common.ResultSet;
|
7
|
import eu.dnetlib.rmi.data.MDStoreServiceException;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.springframework.beans.factory.annotation.Required;
|
11
|
|
12
|
public class FeedAction extends AbstractMDStoreAction {
|
13
|
|
14
|
private static final Log log = LogFactory.getLog(FeedAction.class);
|
15
|
|
16
|
private MDStoreFeeder feeder;
|
17
|
|
18
|
@Override
|
19
|
public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
|
20
|
|
21
|
final String mdId = job.getParameters().get("mdId");
|
22
|
if ((mdId == null) || mdId.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
|
23
|
|
24
|
final String epr = job.getParameters().get("epr");
|
25
|
if ((epr == null) || epr.isEmpty()) throw new MDStoreServiceException("Blackboard param (mdId) is empty");
|
26
|
|
27
|
ResultSet<?> resultSet = ResultSet.fromJson(epr);
|
28
|
|
29
|
String storingType = job.getParameters().get("storingType");
|
30
|
if ((storingType == null) || storingType.isEmpty()) {
|
31
|
storingType = "REFRESH";
|
32
|
}
|
33
|
|
34
|
feeder.feed(mdId, resultSet, storingType, params -> {
|
35
|
job.getParameters().put("total", "" + params.get("size"));
|
36
|
completeWithSuccess(handler, job);
|
37
|
}, e -> {
|
38
|
log.error("Error feeding mdstore: " + mdId, e);
|
39
|
completeWithFail(handler, job, e);
|
40
|
});
|
41
|
}
|
42
|
|
43
|
public MDStoreFeeder getFeeder() {
|
44
|
return feeder;
|
45
|
}
|
46
|
|
47
|
@Required
|
48
|
public void setFeeder(final MDStoreFeeder feeder) {
|
49
|
this.feeder = feeder;
|
50
|
}
|
51
|
|
52
|
}
|