Project

General

Profile

1 52913 sandro.lab
package eu.dnetlib.msro.openaireplus.workflows.nodes.actions;
2
3
import com.google.gson.Gson;
4
import com.googlecode.sarasvati.Arc;
5
import com.googlecode.sarasvati.NodeToken;
6
import eu.dnetlib.msro.rmi.MSROException;
7
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
8
import org.apache.commons.lang3.StringUtils;
9
10
import java.util.List;
11
import java.util.Map;
12
13
public class ExtractOutputPathJobNode extends SimpleJobNode {
14
15
    private String hdfsOutputPathParam;
16
17
18
    @Override
19
    protected String execute(NodeToken token) throws Exception {
20
        final String sets = token.getEnv().getAttribute("sets");
21
        if (StringUtils.isBlank(sets))
22
            throw  new MSROException("¯\\\\_(ツ)_/¯ cannot find sets on env");
23
24
        final List<Map<String, String>> setsMap = new Gson().fromJson(sets, List.class);
25
        if (setsMap== null || setsMap.size() !=1)  {
26
            throw  new MSROException("¯\\\\_(ツ)_/¯ Sets map from json is wrong!");
27
        }
28
29
30
        final String path = setsMap.get(0).get("path");
31
        if (StringUtils.isEmpty(path)){
32
            throw new MSROException("Path is empty");
33
        }
34
        token.getEnv().setAttribute(getHdfsOutputPathParam(), path);
35
        return Arc.DEFAULT_ARC;
36
    }
37
38
39
    public String getHdfsOutputPathParam() {
40
        return hdfsOutputPathParam;
41
    }
42
43
    public void setHdfsOutputPathParam(String hdfsOutputPathParam) {
44
        this.hdfsOutputPathParam = hdfsOutputPathParam;
45
    }
46
}