1
|
package eu.dnetlib.data.mapreduce.actions;
|
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.data.mapreduce.hbase.dataimport.CrossRefToActions;
|
8
|
import eu.dnetlib.data.mapreduce.hbase.dataimport.ScholixToActions;
|
9
|
import eu.dnetlib.data.mapreduce.util.StreamUtils;
|
10
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
import org.junit.Test;
|
13
|
|
14
|
import java.io.BufferedReader;
|
15
|
import java.io.IOException;
|
16
|
import java.io.InputStream;
|
17
|
import java.io.InputStreamReader;
|
18
|
import java.util.List;
|
19
|
|
20
|
public class CrossRefToActionTest {
|
21
|
|
22
|
|
23
|
@Test
|
24
|
public void testSingleScholixAction2() throws IOException {
|
25
|
doTestSingleCrossRefAction("/eu/dnetlib/data/mapreduce/actions/part-06036");
|
26
|
}
|
27
|
|
28
|
@Test
|
29
|
public void testAllScholixAction() throws IOException {
|
30
|
doTestAllCrossRefAction("/eu/dnetlib/data/mapreduce/actions/part-06036");
|
31
|
}
|
32
|
|
33
|
|
34
|
private void doTestSingleCrossRefAction(final String filePath) throws IOException {
|
35
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
36
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
37
|
|
38
|
String line = in.readLine();
|
39
|
System.out.println(line);
|
40
|
final JsonParser parser = new JsonParser();
|
41
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
42
|
List<AtomicAction> actions = CrossRefToActions.generateActionsFromDump(root, new ActionFactory());
|
43
|
}
|
44
|
|
45
|
|
46
|
|
47
|
|
48
|
private void doTestAllCrossRefAction(final String filePath) throws IOException {
|
49
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
50
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
51
|
|
52
|
String line = in.readLine();
|
53
|
while(StringUtils.isNotBlank(line)) {
|
54
|
|
55
|
final JsonParser parser = new JsonParser();
|
56
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
57
|
try {
|
58
|
List<AtomicAction> actions = CrossRefToActions.generateActionsFromDump(root, new ActionFactory());
|
59
|
} catch (Throwable e) {
|
60
|
System.out.println(line);
|
61
|
throw new RuntimeException(e);
|
62
|
}
|
63
|
line= in.readLine();
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
|
69
|
}
|