1 |
52951
|
sandro.lab
|
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 |
52955
|
sandro.lab
|
import eu.dnetlib.actionmanager.common.Agent;
|
8 |
52951
|
sandro.lab
|
import eu.dnetlib.data.mapreduce.hbase.dataimport.CrossRefToActions;
|
9 |
|
|
import org.apache.commons.lang3.StringUtils;
|
10 |
52955
|
sandro.lab
|
import org.junit.Before;
|
11 |
53592
|
sandro.lab
|
import org.junit.Ignore;
|
12 |
52951
|
sandro.lab
|
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 |
|
|
|
19 |
|
|
public class CrossRefToActionTest {
|
20 |
|
|
|
21 |
52955
|
sandro.lab
|
private String setName;
|
22 |
|
|
private Agent agent;
|
23 |
52951
|
sandro.lab
|
|
24 |
52955
|
sandro.lab
|
@Before
|
25 |
|
|
public void setup() {
|
26 |
|
|
setName = "DLI";
|
27 |
|
|
agent= new Agent("agentId","agentName", Agent.AGENT_TYPE.service);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
|
31 |
53592
|
sandro.lab
|
@Ignore
|
32 |
52951
|
sandro.lab
|
@Test
|
33 |
|
|
public void testSingleScholixAction2() throws IOException {
|
34 |
52956
|
sandro.lab
|
doTestSingleCrossRefAction("/eu/dnetlib/data/mapreduce/actions/broken");
|
35 |
52951
|
sandro.lab
|
}
|
36 |
|
|
|
37 |
|
|
@Test
|
38 |
|
|
public void testAllScholixAction() throws IOException {
|
39 |
|
|
doTestAllCrossRefAction("/eu/dnetlib/data/mapreduce/actions/part-06036");
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
private void doTestSingleCrossRefAction(final String filePath) throws IOException {
|
44 |
|
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
45 |
|
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
46 |
|
|
|
47 |
|
|
String line = in.readLine();
|
48 |
|
|
System.out.println(line);
|
49 |
|
|
final JsonParser parser = new JsonParser();
|
50 |
|
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
51 |
52958
|
sandro.lab
|
AtomicAction actions = CrossRefToActions.generateActionsFromDump(root, new ActionFactory(), setName, agent, false);
|
52 |
52955
|
sandro.lab
|
System.out.println(actions.toJSON());
|
53 |
52951
|
sandro.lab
|
}
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
private void doTestAllCrossRefAction(final String filePath) throws IOException {
|
59 |
|
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
60 |
|
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
61 |
|
|
|
62 |
|
|
String line = in.readLine();
|
63 |
|
|
while(StringUtils.isNotBlank(line)) {
|
64 |
|
|
|
65 |
|
|
final JsonParser parser = new JsonParser();
|
66 |
|
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
67 |
|
|
try {
|
68 |
52959
|
sandro.lab
|
CrossRefToActions.generateActionsFromDump(root, new ActionFactory(), setName, agent, false);
|
69 |
52951
|
sandro.lab
|
} catch (Throwable e) {
|
70 |
|
|
System.out.println(line);
|
71 |
|
|
throw new RuntimeException(e);
|
72 |
|
|
}
|
73 |
|
|
line= in.readLine();
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
}
|