1
|
package eu.dnetlib.index.action;
|
2
|
|
3
|
import eu.dnetlib.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 Class DeleteIndexAction.
|
16
|
*/
|
17
|
public class DeleteIndexAction extends AbstractIndexAction implements BlackboardServerAction<IndexAction> {
|
18
|
|
19
|
/**
|
20
|
* logger.
|
21
|
*/
|
22
|
private static final Log log = LogFactory.getLog(DeleteIndexAction.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("some Blackboard parameter is missing in DELETE message");
|
40
|
MetadataReference mdRef = getMetadataReference(dsId);
|
41
|
final String backendId = getBackend(job);
|
42
|
if (backendId == null) throw new IndexServiceException("No backend identifier information in CREATE message");
|
43
|
IndexCollection indexCollection = indexServerDAOMap.getIndexServerDAO(backendId).getIndexCollection(mdRef);
|
44
|
if (indexCollection.deleteIndex(dsId) == false)
|
45
|
throw new IndexServiceException("Error to delete collection the index response for the delete action is not OK");
|
46
|
if (indexCollection.commit() == false)
|
47
|
throw new IndexServiceException("Error to delete collection the index response for the delete action is not OK");
|
48
|
if (!serviceTools.deleteIndexDS(dsId)) {
|
49
|
log.warn("couldn't delete IndexDS: " + dsId);
|
50
|
}
|
51
|
log.info("\n\nDELETE report:" + "\n- dsId: " + dsId);
|
52
|
indexCollection.shutdown();
|
53
|
handler.done(job);
|
54
|
}
|
55
|
|
56
|
}
|