1
|
package eu.dnetlib.data.oai.store.actions;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
|
7
|
import eu.dnetlib.data.information.oai.utils.OAIParameterNames;
|
8
|
import org.apache.commons.lang3.StringUtils;
|
9
|
|
10
|
import eu.dnetlib.data.information.oai.publisher.OaiPublisherRuntimeException;
|
11
|
import eu.dnetlib.data.oai.store.mongo.MongoPublisherStore;
|
12
|
import eu.dnetlib.data.oai.store.mongo.MongoPublisherStoreDAO;
|
13
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
14
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
15
|
|
16
|
public class CreateOAIIndexAction extends AbstractOAIStoreAction {
|
17
|
|
18
|
@Resource
|
19
|
private MongoPublisherStoreDAO mongoPublisherStoreDAO;
|
20
|
|
21
|
@Override
|
22
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception {
|
23
|
String storeId = job.getParameters().get(OAIParameterNames.OAI_COLLECTON);
|
24
|
String dbName = job.getParameters().get(OAIParameterNames.OAI_DB);
|
25
|
// Examples: field1,field2 -- one compound index on the given two fields
|
26
|
// field1,field2;field3,field4 -- two compound indices: one on field1 and field2, the other on field3 and field4
|
27
|
String fieldNames = job.getParameters().get(OAIParameterNames.OAI_INDEXES);
|
28
|
if (StringUtils.isBlank(dbName) || StringUtils.isBlank(storeId) || StringUtils.isBlank(fieldNames)) throw new IllegalArgumentException(
|
29
|
"Job parameters oai_dbName, oai_collection and oai_index_fieldNames are mandatory");
|
30
|
else {
|
31
|
MongoPublisherStore store = this.mongoPublisherStoreDAO.getStore(storeId, dbName);
|
32
|
if (store != null) {
|
33
|
String[] indexFieldList = fieldNames.replaceAll(" ", "").split(";");
|
34
|
for (String idx : indexFieldList) {
|
35
|
String[] fields = idx.split(",");
|
36
|
store.createCompoundIndex(Arrays.asList(fields));
|
37
|
}
|
38
|
handler.done(job);
|
39
|
} else throw new OaiPublisherRuntimeException("store " + storeId + " does not exist on db " + dbName + ": can't create compound indices");
|
40
|
}
|
41
|
}
|
42
|
|
43
|
public MongoPublisherStoreDAO getMongoPublisherStoreDAO() {
|
44
|
return mongoPublisherStoreDAO;
|
45
|
}
|
46
|
|
47
|
public void setMongoPublisherStoreDAO(final MongoPublisherStoreDAO mongoPublisherStoreDAO) {
|
48
|
this.mongoPublisherStoreDAO = mongoPublisherStoreDAO;
|
49
|
}
|
50
|
|
51
|
}
|