Project

General

Profile

1
package eu.dnetlib.functionality.index.action;
2

    
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5
import org.springframework.beans.factory.annotation.Autowired;
6

    
7
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
8
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
9
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction;
10
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
11
import eu.dnetlib.functionality.index.IndexCollection;
12
import eu.dnetlib.functionality.index.IndexServerDAOMap;
13
import eu.dnetlib.functionality.index.utils.MetadataReference;
14

    
15
/**
16
 * The Class DeleteIndexAction.
17
 */
18
public class DeleteIndexAction extends AbstractIndexAction implements BlackboardServerAction<IndexAction> {
19

    
20
	/**
21
	 * logger.
22
	 */
23
	private static final Log log = LogFactory.getLog(DeleteIndexAction.class);
24

    
25
	/** The index server dao map. */
26
	@Autowired
27
	private IndexServerDAOMap indexServerDAOMap;
28

    
29
	/**
30
	 * {@inheritDoc}
31
	 * 
32
	 * @see eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction#execute(eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler,
33
	 *      eu.dnetlib.enabling.tools.blackboard.BlackboardJob)
34
	 */
35
	@Override
36
	public void execute(final BlackboardServerHandler handler, final BlackboardJob job) throws IndexServiceException {
37
		final String dsId = getIndexDSId(job);
38
		if (dsId == null) throw new IndexServiceException("some Blackboard parameter is missing in DELETE message");
39
		MetadataReference mdRef = getMetadataReference(dsId);
40
		final String backendId = getBackend(job);
41
		if (backendId == null) throw new IndexServiceException("No backend identifier information in CREATE message");
42
		IndexCollection indexCollection = indexServerDAOMap.getIndexServerDAO(backendId).getIndexCollection(mdRef);
43
		if (indexCollection.deleteIndex(dsId) == false)
44
			throw new IndexServiceException("Error to delete collection the index response for the delete action is not OK");
45
		if (indexCollection.commit() == false)
46
			throw new IndexServiceException("Error to delete collection the index response for the delete action is not OK");
47
		if (!serviceTools.deleteIndexDS(dsId)) {
48
			log.warn("couldn't delete IndexDS: " + dsId);
49
		}
50
		log.info("\n\nDELETE report:" + "\n- dsId: " + dsId);
51
		indexCollection.shutdown();
52
		handler.done(job);
53
	}
54

    
55
}
(5-5/8)