Revision 45455
Added by Alessia Bardi over 7 years ago
CreateOAIIndexAction.java | ||
---|---|---|
6 | 6 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
7 | 7 |
import eu.dnetlib.oai.mongo.MongoPublisherStore; |
8 | 8 |
import eu.dnetlib.oai.mongo.MongoPublisherStoreDAO; |
9 |
import eu.dnetlib.oai.utils.OAIParameterNames; |
|
9 | 10 |
import eu.dnetlib.rmi.provision.OaiPublisherRuntimeException; |
10 | 11 |
import org.apache.commons.lang3.StringUtils; |
11 | 12 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
25 | 26 |
|
26 | 27 |
@Override |
27 | 28 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws Exception { |
28 |
final String storeId = job.getParameters().get("oai_collectionName"); |
|
29 |
final String dbName = job.getParameters().get("oai_dbName"); |
|
30 |
final String fieldNames = job.getParameters().get("oai_index_fieldNames"); |
|
31 |
if (StringUtils.isBlank(storeId) || StringUtils.isBlank(fieldNames)) { |
|
32 |
throw new IllegalArgumentException( |
|
33 |
"Job parameters collection and oai_index_fieldNames are mandatory"); |
|
34 |
} else { |
|
35 |
final MongoPublisherStore store = this.mongoPublisherStoreDAO.getStore(storeId, dbName); |
|
29 |
String storeId = job.getParameters().get(OAIParameterNames.OAI_COLLECTON); |
|
30 |
String dbName = job.getParameters().get(OAIParameterNames.OAI_DB); |
|
31 |
// Examples: field1,field2 -- one compound index on the given two fields |
|
32 |
// field1,field2;field3,field4 -- two compound indices: one on field1 and field2, the other on field3 and field4 |
|
33 |
String fieldNames = job.getParameters().get(OAIParameterNames.OAI_INDEXES); |
|
34 |
if (StringUtils.isBlank(dbName) || StringUtils.isBlank(storeId) || StringUtils.isBlank(fieldNames)) |
|
35 |
throw new IllegalArgumentException(String.format( |
|
36 |
"Job parameters %s, %s and %s are mandatory", OAIParameterNames.OAI_DB, OAIParameterNames.OAI_COLLECTON, OAIParameterNames.OAI_INDEXES)); |
|
37 |
else { |
|
38 |
MongoPublisherStore store = this.mongoPublisherStoreDAO.getStore(storeId, dbName); |
|
36 | 39 |
if (store != null) { |
37 |
final String[] indexFieldList = fieldNames.replaceAll(" ", "").split(";");
|
|
38 |
for (final String idx : indexFieldList) {
|
|
39 |
final String[] fields = idx.split(",");
|
|
40 |
store.createIndex(Arrays.asList(fields)); |
|
40 |
String[] indexFieldList = fieldNames.replaceAll(" ", "").split(";"); |
|
41 |
for (String idx : indexFieldList) { |
|
42 |
String[] fields = idx.split(","); |
|
43 |
store.createCompoundIndex(Arrays.asList(fields));
|
|
41 | 44 |
} |
42 | 45 |
handler.done(job); |
43 |
} else { |
|
44 |
throw new OaiPublisherRuntimeException("store " + storeId + " does not exist on db " + dbName + ": can't create indices"); |
|
45 |
} |
|
46 |
} else throw new OaiPublisherRuntimeException("store " + storeId + " does not exist on db " + dbName + ": can't create compound indices"); |
|
46 | 47 |
} |
47 | 48 |
} |
48 | 49 |
|
Also available in: Unified diff
Included changes about the CQL translation as in most recent version of cnr-cql-utils of DNet40 + refactoring of OAI parameters