Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.dataimport;
2

    
3
import com.google.gson.JsonObject;
4
import com.google.gson.JsonParser;
5
import eu.dnetlib.actionmanager.actions.ActionFactory;
6
import eu.dnetlib.actionmanager.actions.AtomicAction;
7
import eu.dnetlib.actionmanager.common.Agent;
8
import org.apache.hadoop.io.LongWritable;
9
import org.apache.hadoop.io.Text;
10
import org.apache.hadoop.mapreduce.Mapper;
11

    
12
import java.io.IOException;
13

    
14
public class CrossRefImportMapper extends Mapper<LongWritable, Text, Text, Text> {
15

    
16
    private String setName;
17
    private Agent agent;
18
    private Text keyout;
19
    private Text valueOut;
20
    private JsonParser parser;
21
    private ActionFactory factory;
22
    private boolean invisible;
23

    
24
    @Override
25
    protected void setup(Context context) throws IOException, InterruptedException {
26
        setName = context.getConfiguration().get("setName");
27
        agent = new Agent(context.getConfiguration().get("agentId"), context.getConfiguration().get("agentName"), Agent.AGENT_TYPE.service);
28
        keyout = new Text("");
29
        valueOut = new Text("");
30
        factory = new ActionFactory();
31
        parser = new JsonParser();
32
        invisible = context.getConfiguration().getBoolean("invisible", false);
33
    }
34

    
35
    @Override
36
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
37
        final String inputJson = value.toString();
38
        final JsonObject rootElement = parser.parse(inputJson).getAsJsonObject();
39
        try {
40
            final AtomicAction action = CrossRefToActions.generateActionsFromDump(rootElement, factory, setName, agent, invisible);
41

    
42
            keyout.set(action.getRowKey());
43
            valueOut.set(action.toJSON());
44
            context.write(keyout, valueOut);
45

    
46
        } catch (Throwable e) {
47
            System.err.println(inputJson);
48
            throw e;
49
        }
50

    
51

    
52
    }
53

    
54

    
55
}
(1-1/11)