Project

General

Profile

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