Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes.dedup;
2

    
3
import java.util.List;
4
import java.util.Map;
5

    
6
import com.google.common.collect.Lists;
7
import com.google.common.collect.Maps;
8
import com.google.gson.Gson;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
10
import eu.dnetlib.miscutils.datetime.DateUtils;
11
import eu.dnetlib.msro.workflows.graph.Arc;
12
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
13
import eu.dnetlib.msro.workflows.procs.Env;
14
import eu.dnetlib.rmi.data.hadoop.actionmanager.RawSet;
15
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
16
import eu.dnetlib.rmi.enabling.ISLookUpService;
17
import eu.dnetlib.rmi.manager.MSROException;
18
import org.apache.commons.lang3.StringUtils;
19
import org.apache.commons.logging.Log;
20
import org.apache.commons.logging.LogFactory;
21
import org.springframework.beans.factory.annotation.Autowired;
22

    
23
/**
24
 * The Class PrepareConfiguredActionSetJobNode.
25
 */
26
public class PrepareConfiguredActionSetJobNode extends SimpleJobNode {
27

    
28
	/**
29
	 * logger.
30
	 */
31
	private static final Log log = LogFactory.getLog(PrepareConfiguredActionSetJobNode.class);
32

    
33
	/**
34
	 * The dedup config sequence param.
35
	 */
36
	private String dedupConfigSequence;
37

    
38
	/**
39
	 * The job property.
40
	 */
41
	private String jobProperty;
42

    
43
	/**
44
	 * The action set path param name.
45
	 */
46
	private String actionSetPathParam;
47

    
48
	private String setsParam;
49

    
50
	/**
51
	 * The service locator.
52
	 */
53
	@Autowired
54
	private UniqueServiceLocator serviceLocator;
55

    
56
	/*
57
	 * (non-Javadoc)
58
	 *
59
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
60
	 */
61
	@Override
62
	protected String execute(final Env env) throws Exception {
63

    
64
		final List<Map<String, String>> setList = Lists.newArrayList();
65

    
66
		final Map<String, String> set = Maps.newHashMap();
67

    
68
		final String actionSetId = getDedupConfigSequence();
69
		final ISLookUpService isLookUpService = serviceLocator.getService(ISLookUpService.class);
70
		final String basePath = isLookUpService.getResourceProfileByQuery(
71
				"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerServiceResourceType']//SERVICE_PROPERTIES/PROPERTY[@key='basePath']/@value/string()");
72
		if (StringUtils.isBlank(basePath)) {
73
			throw new IllegalStateException("missing basePath in ActionManagerService");
74
		}
75

    
76
		String actionSetDirectory;
77
		try {
78
			actionSetDirectory = isLookUpService.getResourceProfileByQuery(
79
					"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerSetDSResourceType' and .//SET/@id = '" + actionSetId
80
							+ "']//SET/@ directory/string()");
81
		} catch (ISLookUpDocumentNotFoundException e) {
82
			throw new MSROException("missing directory in ActionSet profile: " + actionSetId);
83
		}
84

    
85
		final String rawSetId = RawSet.newInstance().getId();
86
		set.put("rawset", rawSetId);
87
		set.put("creationDate", DateUtils.now_ISO8601());
88
		set.put("set", actionSetId);
89
		set.put("enabled", "true");
90
		set.put("jobProperty", getJobProperty());
91

    
92
		env.setAttribute(set.get("jobProperty"), set.get("rawset"));
93

    
94
		final String path = basePath + "/" + actionSetDirectory + "/" + rawSetId;
95
		log.info("using action set path: " + path);
96
		env.setAttribute(getActionSetPathParam(), path);
97

    
98
		setList.add(set);
99
		final String sets = new Gson().toJson(setList);
100
		log.debug("built set: " + sets);
101

    
102
		env.setAttribute(getSetsParam(), sets);
103

    
104
		return Arc.DEFAULT_ARC;
105
	}
106

    
107
	/**
108
	 * Gets the job property.
109
	 *
110
	 * @return the job property
111
	 */
112
	public String getJobProperty() {
113
		return jobProperty;
114
	}
115

    
116
	/**
117
	 * Sets the job property.
118
	 *
119
	 * @param jobProperty the new job property
120
	 */
121
	public void setJobProperty(final String jobProperty) {
122
		this.jobProperty = jobProperty;
123
	}
124

    
125
	public String getActionSetPathParam() {
126
		return actionSetPathParam;
127
	}
128

    
129
	public void setActionSetPathParam(final String actionSetPathParam) {
130
		this.actionSetPathParam = actionSetPathParam;
131
	}
132

    
133
	public String getDedupConfigSequence() {
134
		return dedupConfigSequence;
135
	}
136

    
137
	public void setDedupConfigSequence(final String dedupConfigSequence) {
138
		this.dedupConfigSequence = dedupConfigSequence;
139
	}
140

    
141
	public String getSetsParam() {
142
		return setsParam;
143
	}
144

    
145
	public void setSetsParam(final String setsParam) {
146
		this.setsParam = setsParam;
147
	}
148
}
(10-10/13)