1
|
package eu.dnetlib.data.mapreduce.hbase.dataimport;
|
2
|
|
3
|
import com.google.common.base.Joiner;
|
4
|
import com.google.gson.JsonObject;
|
5
|
import com.google.gson.JsonParser;
|
6
|
import eu.dnetlib.actionmanager.actions.ActionFactory;
|
7
|
import eu.dnetlib.actionmanager.actions.AtomicAction;
|
8
|
import eu.dnetlib.actionmanager.common.Agent;
|
9
|
import org.apache.hadoop.io.LongWritable;
|
10
|
import org.apache.hadoop.io.Text;
|
11
|
import org.apache.hadoop.mapreduce.Mapper;
|
12
|
|
13
|
import java.io.IOException;
|
14
|
import java.util.List;
|
15
|
|
16
|
public class DOIBoostImportMapper extends Mapper<LongWritable, Text, Text, Text> {
|
17
|
|
18
|
private String setName;
|
19
|
private Agent agent;
|
20
|
private Text keyout;
|
21
|
private Text valueOut;
|
22
|
private JsonParser parser;
|
23
|
private ActionFactory factory;
|
24
|
private boolean invisible;
|
25
|
private boolean onlyOrganization;
|
26
|
|
27
|
private static final String SEPARATOR = "@";
|
28
|
|
29
|
@Override
|
30
|
protected void setup(Context context) throws IOException, InterruptedException {
|
31
|
setName = context.getConfiguration().get("setName");
|
32
|
agent = new Agent(context.getConfiguration().get("agentId"), context.getConfiguration().get("agentName"), Agent.AGENT_TYPE.service);
|
33
|
keyout = new Text("");
|
34
|
valueOut = new Text("");
|
35
|
factory = new ActionFactory();
|
36
|
parser = new JsonParser();
|
37
|
invisible = context.getConfiguration().getBoolean("invisible", false);
|
38
|
onlyOrganization= context.getConfiguration().getBoolean("onlyOrganization", false);
|
39
|
}
|
40
|
|
41
|
@Override
|
42
|
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
|
43
|
final String inputJson = value.toString();
|
44
|
final JsonObject rootElement = parser.parse(inputJson).getAsJsonObject();
|
45
|
try {
|
46
|
List<AtomicAction> atomicActions = DOIBoostToActions.generatePublicationActionsFromDump(rootElement, factory, setName, agent, invisible, onlyOrganization);
|
47
|
if (atomicActions!= null) {
|
48
|
for (AtomicAction action: atomicActions){
|
49
|
keyout.set(Joiner.on(SEPARATOR).join(action.getTargetRowKey(), action.getTargetColumnFamily(), action.getTargetColumn()));
|
50
|
valueOut.set(action.toJSON());
|
51
|
context.write(keyout, valueOut);
|
52
|
context.getCounter(this.getClass().getSimpleName(), action.getTargetColumnFamily()).increment(1);
|
53
|
}
|
54
|
}
|
55
|
} catch (Throwable e) {
|
56
|
System.err.println(inputJson);
|
57
|
throw e;
|
58
|
}
|
59
|
}
|
60
|
}
|