1
|
package eu.dnetlib.oai.actions;
|
2
|
|
3
|
import java.util.concurrent.Callable;
|
4
|
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
|
7
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
8
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
9
|
import eu.dnetlib.oai.conf.OAISetsCounter;
|
10
|
|
11
|
public class CountSetsAction extends AbstractOAIStoreAction {
|
12
|
|
13
|
@Autowired
|
14
|
private OAISetsCounter setsCounter;
|
15
|
|
16
|
@Override
|
17
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
|
18
|
final String configuredOnly = job.getParameters().get("configuredOnly");
|
19
|
final String storeId = job.getParameters().get("collection");
|
20
|
final String dbName = job.getParameters().get("oai_dbName");
|
21
|
|
22
|
if (configuredOnly.equalsIgnoreCase("false")) {
|
23
|
this.executeForAll(storeId, handler, job, dbName);
|
24
|
} else {
|
25
|
this.executeForConfiguredSetsOnly(storeId, handler, job, dbName);
|
26
|
}
|
27
|
|
28
|
}
|
29
|
|
30
|
private void executeForAll(final String storeId, final BlackboardServerHandler handler, final BlackboardJob job, final String dbName) {
|
31
|
|
32
|
this.setsCounter.updateCounts(storeId, dbName, new Callable<Object>() {
|
33
|
|
34
|
@Override
|
35
|
public Object call() {
|
36
|
handler.done(job);
|
37
|
return null;
|
38
|
}
|
39
|
}, new Callable<Object>() {
|
40
|
|
41
|
@Override
|
42
|
public Object call() {
|
43
|
handler.failed(job, new Exception("Error during OAI sets count on db " + dbName));
|
44
|
return null;
|
45
|
}
|
46
|
});
|
47
|
}
|
48
|
|
49
|
private void executeForConfiguredSetsOnly(final String storeId, final BlackboardServerHandler handler, final BlackboardJob job, final String dbName) {
|
50
|
this.setsCounter.updateConfigurationCounts(storeId, dbName, new Callable<Object>() {
|
51
|
|
52
|
@Override
|
53
|
public Object call() {
|
54
|
handler.done(job);
|
55
|
return null;
|
56
|
}
|
57
|
}, new Callable<Object>() {
|
58
|
|
59
|
@Override
|
60
|
public Object call() {
|
61
|
handler.failed(job, new Exception("Error during OAI sets count on db " + dbName));
|
62
|
return null;
|
63
|
}
|
64
|
});
|
65
|
}
|
66
|
|
67
|
public OAISetsCounter getSetsCounter() {
|
68
|
return this.setsCounter;
|
69
|
}
|
70
|
|
71
|
public void setSetsCounter(final OAISetsCounter setsCounter) {
|
72
|
this.setsCounter = setsCounter;
|
73
|
}
|
74
|
}
|