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