Project

General

Profile

1
package eu.dnetlib.data.actionmanager;
2

    
3
import java.util.List;
4
import javax.jws.WebParam;
5

    
6
import eu.dnetlib.data.hadoop.HadoopIsClient;
7
import eu.dnetlib.data.hadoop.HadoopServiceCore;
8

    
9
import eu.dnetlib.rmi.data.hadoop.ClusterName;
10
import eu.dnetlib.rmi.data.hadoop.HadoopServiceException;
11
import eu.dnetlib.enabling.tools.AbstractBaseService;
12
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
13
import eu.dnetlib.rmi.data.hadoop.actionmanager.ActionManagerException;
14
import eu.dnetlib.rmi.data.hadoop.actionmanager.ActionManagerService;
15
import eu.dnetlib.rmi.data.hadoop.actionmanager.ActionManagerSet;
16
import org.apache.hadoop.fs.Path;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Required;
19

    
20
public class ActionManagerServiceImpl extends AbstractBaseService implements ActionManagerService {
21

    
22
	@Autowired
23
	private HadoopIsClient isClient;
24

    
25
	private NotificationHandler notificationHandler;
26

    
27
	@Autowired
28
	private HadoopServiceCore hadoopServiceCore;
29

    
30
	@Override
31
	public String createSet(@WebParam(name = "set") final ActionManagerSet set) throws ActionManagerException {
32
		try {
33
			final String basePath = isClient.getBasePathHDFS();
34
			final Path actionSetPath = new Path(basePath + "/" + set.getId());
35
			hadoopServiceCore.createHdfsDir(ClusterName.DM, actionSetPath.toString(), true);
36
			return isClient.registerSetProfile(set);
37
		} catch (HadoopServiceException e) {
38
			throw new ActionManagerException(e);
39
		}
40
	}
41

    
42
	@Override
43
	public boolean deleteSet(@WebParam(name = "set") final String setId) throws ActionManagerException {
44
		try {
45
			final String basePath = isClient.getBasePathHDFS();
46
			final Path actionSetPath = new Path(basePath + "/" + setId);
47
			hadoopServiceCore.deleteFromHdfs(ClusterName.DM, actionSetPath.toString());
48
			return isClient.deleteSetProfile(setId);
49
		} catch (HadoopServiceException e) {
50
			throw new ActionManagerException(e);
51
		}
52
	}
53

    
54
	@Override
55
	public List<ActionManagerSet> ListSets() throws ActionManagerException {
56
		return isClient.listSets();
57
	}
58

    
59
	@Override
60
	public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
61
		getNotificationHandler().notified(subscriptionId, topic, isId, message);
62
	}
63

    
64
	public NotificationHandler getNotificationHandler() {
65
		return notificationHandler;
66
	}
67

    
68
	@Required
69
	public void setNotificationHandler(final NotificationHandler notificationHandler) {
70
		this.notificationHandler = notificationHandler;
71
	}
72

    
73
}
    (1-1/1)