1
|
package eu.dnetlib.index.action;
|
2
|
|
3
|
import eu.dnetlib.clients.index.utils.MetadataReference;
|
4
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
5
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
|
6
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
7
|
import eu.dnetlib.index.IndexCollection;
|
8
|
import eu.dnetlib.index.IndexServerDAOMap;
|
9
|
import eu.dnetlib.rmi.provision.IndexServiceException;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
|
14
|
/**
|
15
|
* The Delete by Query Action. It expects the query to be in Solr/Lucene format.
|
16
|
*/
|
17
|
public class DeleteByQueryAction extends AbstractIndexAction implements BlackboardServerAction<IndexAction> {
|
18
|
|
19
|
/**
|
20
|
* logger.
|
21
|
*/
|
22
|
private static final Log log = LogFactory.getLog(DeleteByQueryAction.class);
|
23
|
|
24
|
/**
|
25
|
* The index server dao map.
|
26
|
*/
|
27
|
@Autowired
|
28
|
private IndexServerDAOMap indexServerDAOMap;
|
29
|
|
30
|
/**
|
31
|
* {@inheritDoc}
|
32
|
*
|
33
|
* @see BlackboardServerAction#execute(BlackboardServerHandler,
|
34
|
* BlackboardJob)
|
35
|
*/
|
36
|
@Override
|
37
|
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws IndexServiceException {
|
38
|
final String dsId = getIndexDSId(job);
|
39
|
if (dsId == null) throw new IndexServiceException("dsId Blackboard parameter is missing in DELETE BY QUERY message");
|
40
|
final MetadataReference mdRef = getMetadataReference(dsId);
|
41
|
final String backendId = getBackend(job);
|
42
|
if (backendId == null) throw new IndexServiceException("No backend identifier information in DELETE BY QUERY message");
|
43
|
final IndexCollection indexCollection = indexServerDAOMap.getIndexServerDAO(backendId).getIndexCollection(mdRef);
|
44
|
|
45
|
// TODO The query should be passed in CQL format
|
46
|
final String query = getQuery(job);
|
47
|
|
48
|
log.info("DELETE BY QUERY: '" + query + "' on index '" + mdRef + "'");
|
49
|
|
50
|
// here we pass the query as it is, no dsId.
|
51
|
if (indexCollection.deleteByQuery(query, null) == false)
|
52
|
throw new IndexServiceException(String.format("Error to delete on index '%s', query '%s'", mdRef, query));
|
53
|
if (indexCollection.commit() == false)
|
54
|
throw new IndexServiceException(String.format("Error to commit on index '%s'", mdRef));
|
55
|
|
56
|
log.info("DELETE BY QUERY done");
|
57
|
indexCollection.shutdown();
|
58
|
handler.done(job);
|
59
|
}
|
60
|
|
61
|
}
|