1
|
package eu.dnetlib.oai.actions;
|
2
|
|
3
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
4
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
5
|
import eu.dnetlib.oai.sets.OAISetsCounter;
|
6
|
import eu.dnetlib.oai.utils.OAIParameterNames;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
|
9
|
public class CountSetsAction extends AbstractOAIStoreAction {
|
10
|
|
11
|
@Autowired
|
12
|
private OAISetsCounter setsCounter;
|
13
|
|
14
|
@Override
|
15
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
|
16
|
String configuredOnly = job.getParameters().get(OAIParameterNames.OAI_CONFIGURED_SETS_ONLY);
|
17
|
String storeId = job.getParameters().get(OAIParameterNames.OAI_COLLECTON);
|
18
|
String dbName = job.getParameters().get(OAIParameterNames.OAI_DB);
|
19
|
|
20
|
if (configuredOnly.equalsIgnoreCase("false")) {
|
21
|
this.executeForAll(storeId, dbName, handler, job);
|
22
|
} else {
|
23
|
this.executeForConfiguredSetsOnly(storeId, dbName, handler, job);
|
24
|
}
|
25
|
|
26
|
}
|
27
|
|
28
|
private void executeForAll(final String storeId, final String dbName, final BlackboardServerHandler handler, final BlackboardJob job) {
|
29
|
|
30
|
this.setsCounter.updateCounts(storeId, dbName, () -> {
|
31
|
handler.done(job);
|
32
|
return null;
|
33
|
}, () -> {
|
34
|
handler.failed(job, new Exception("Error during OAI sets count on db " + dbName));
|
35
|
return null;
|
36
|
});
|
37
|
}
|
38
|
|
39
|
private void executeForConfiguredSetsOnly(final String storeId, final String dbName, final BlackboardServerHandler handler, final BlackboardJob job) {
|
40
|
this.setsCounter.updateConfigurationCounts(storeId, dbName, () -> {
|
41
|
handler.done(job);
|
42
|
return null;
|
43
|
}, () -> {
|
44
|
handler.failed(job, new Exception("Error during OAI sets count on db " + dbName));
|
45
|
return null;
|
46
|
});
|
47
|
}
|
48
|
|
49
|
public OAISetsCounter getSetsCounter() {
|
50
|
return this.setsCounter;
|
51
|
}
|
52
|
|
53
|
public void setSetsCounter(final OAISetsCounter setsCounter) {
|
54
|
this.setsCounter = setsCounter;
|
55
|
}
|
56
|
}
|