Revision 52957
Added by Sandro La Bruzzo over 5 years ago
modules/dnet-mapreduce-jobs/branches/beta/src/main/java/eu/dnetlib/data/mapreduce/hbase/dataimport/CrossRefToActions.java | ||
---|---|---|
14 | 14 |
import java.util.List; |
15 | 15 |
import java.util.Objects; |
16 | 16 |
|
17 |
import static eu.dnetlib.data.mapreduce.hbase.dataimport.ScholixToActions.*;
|
|
17 |
import static eu.dnetlib.data.mapreduce.hbase.dataimport.DumpToActionsUtility.*;
|
|
18 | 18 |
import static eu.dnetlib.data.proto.FieldTypeProtos.*; |
19 | 19 |
import static eu.dnetlib.data.proto.KindProtos.Kind; |
20 | 20 |
import static eu.dnetlib.data.proto.OafProtos.Oaf; |
... | ... | |
261 | 261 |
|
262 | 262 |
} |
263 | 263 |
|
264 |
private static String getDefaultResulttype(final String cobjcategory) { |
|
265 |
switch (cobjcategory) { |
|
266 |
case "0029": |
|
267 |
return "software"; |
|
268 |
case "0021": |
|
269 |
case "0024": |
|
270 |
case "0025": |
|
271 |
case "0030": |
|
272 |
return "dataset"; |
|
273 |
case "0000": |
|
274 |
case "0010": |
|
275 |
case "0018": |
|
276 |
case "0020": |
|
277 |
case "0022": |
|
278 |
case "0023": |
|
279 |
case "0026": |
|
280 |
case "0027": |
|
281 |
case "0028": |
|
282 |
case "0037": |
|
283 |
return "other"; |
|
284 |
case "0001": |
|
285 |
case "0002": |
|
286 |
case "0004": |
|
287 |
case "0005": |
|
288 |
case "0006": |
|
289 |
case "0007": |
|
290 |
case "0008": |
|
291 |
case "0009": |
|
292 |
case "0011": |
|
293 |
case "0012": |
|
294 |
case "0013": |
|
295 |
case "0014": |
|
296 |
case "0015": |
|
297 |
case "0016": |
|
298 |
case "0017": |
|
299 |
case "0019": |
|
300 |
case "0031": |
|
301 |
case "0032": |
|
302 |
return "publication"; |
|
303 |
default: |
|
304 |
return "publication"; |
|
305 |
} |
|
306 |
} |
|
307 | 264 |
|
308 | 265 |
|
309 | 266 |
|
modules/dnet-mapreduce-jobs/branches/beta/src/main/java/eu/dnetlib/data/mapreduce/hbase/dataimport/DumpToActionsUtility.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.hbase.dataimport; |
|
2 |
|
|
3 |
import com.google.gson.JsonArray; |
|
4 |
import com.google.gson.JsonObject; |
|
5 |
import eu.dnetlib.data.proto.FieldTypeProtos; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
10 |
import java.util.Map; |
|
11 |
|
|
12 |
public class DumpToActionsUtility { |
|
13 |
|
|
14 |
public static String getStringValue(final JsonObject root, final String key) { |
|
15 |
if (root.has(key) && !root.get(key).isJsonNull()) |
|
16 |
return root.get(key).getAsString(); |
|
17 |
return null; |
|
18 |
} |
|
19 |
|
|
20 |
public static List<String> getArrayValues(final JsonObject root, final String key) { |
|
21 |
if (root.has(key) && root.get(key).isJsonArray()) { |
|
22 |
final JsonArray asJsonArray = root.get(key).getAsJsonArray(); |
|
23 |
final List<String> result = new ArrayList<>(); |
|
24 |
|
|
25 |
|
|
26 |
asJsonArray.forEach(it -> { |
|
27 |
if (StringUtils.isNotBlank(it.getAsString())) { |
|
28 |
result.add(it.getAsString()); |
|
29 |
} |
|
30 |
}); |
|
31 |
return result; |
|
32 |
} |
|
33 |
return new ArrayList<>(); |
|
34 |
} |
|
35 |
public static FieldTypeProtos.StructuredProperty getPid(final JsonObject localIdentifier, final Map<String, ScholExplorerConfiguration> conf) { |
|
36 |
final String pidType = getStringValue(localIdentifier, "type"); |
|
37 |
final ScholExplorerConfiguration configuration = conf.get(pidType); |
|
38 |
if (configuration.getCleandPidType() == null) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
final String pid = getStringValue(localIdentifier, "id"); |
|
42 |
return FieldTypeProtos.StructuredProperty.newBuilder() |
|
43 |
.setValue(pid) |
|
44 |
.setQualifier(getQualifier(configuration.getCleandPidType(), "dnet:pid_types")) |
|
45 |
.build(); |
|
46 |
} |
|
47 |
public static FieldTypeProtos.Qualifier getQualifier(final String classValue, final String schemeValue) { |
|
48 |
|
|
49 |
return FieldTypeProtos.Qualifier.newBuilder() |
|
50 |
.setSchemeid(schemeValue) |
|
51 |
.setSchemename(schemeValue) |
|
52 |
.setClassname(classValue) |
|
53 |
.setClassid(classValue) |
|
54 |
.build(); |
|
55 |
} |
|
56 |
|
|
57 |
public static String getDefaultResulttype(final String cobjcategory) { |
|
58 |
switch (cobjcategory) { |
|
59 |
case "0029": |
|
60 |
return "software"; |
|
61 |
case "0021": |
|
62 |
case "0024": |
|
63 |
case "0025": |
|
64 |
case "0030": |
|
65 |
return "dataset"; |
|
66 |
case "0000": |
|
67 |
case "0010": |
|
68 |
case "0018": |
|
69 |
case "0020": |
|
70 |
case "0022": |
|
71 |
case "0023": |
|
72 |
case "0026": |
|
73 |
case "0027": |
|
74 |
case "0028": |
|
75 |
case "0037": |
|
76 |
return "other"; |
|
77 |
case "0001": |
|
78 |
case "0002": |
|
79 |
case "0004": |
|
80 |
case "0005": |
|
81 |
case "0006": |
|
82 |
case "0007": |
|
83 |
case "0008": |
|
84 |
case "0009": |
|
85 |
case "0011": |
|
86 |
case "0012": |
|
87 |
case "0013": |
|
88 |
case "0014": |
|
89 |
case "0015": |
|
90 |
case "0016": |
|
91 |
case "0017": |
|
92 |
case "0019": |
|
93 |
case "0031": |
|
94 |
case "0032": |
|
95 |
return "publication"; |
|
96 |
default: |
|
97 |
return "publication"; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
} |
modules/dnet-mapreduce-jobs/branches/beta/src/main/java/eu/dnetlib/data/mapreduce/hbase/dataimport/ScholixToActions.java | ||
---|---|---|
25 | 25 |
import static eu.dnetlib.data.proto.ResultProtos.Result.*; |
26 | 26 |
import static eu.dnetlib.data.proto.ResultResultProtos.ResultResult; |
27 | 27 |
import static eu.dnetlib.data.proto.TypeProtos.Type; |
28 |
import static eu.dnetlib.data.mapreduce.hbase.dataimport.DumpToActionsUtility.*; |
|
28 | 29 |
|
29 | 30 |
public class ScholixToActions { |
30 | 31 |
|
... | ... | |
319 | 320 |
return result; |
320 | 321 |
} |
321 | 322 |
|
322 |
public static Qualifier getQualifier(final String classValue, final String schemeValue) { |
|
323 | 323 |
|
324 |
return Qualifier.newBuilder() |
|
325 |
.setSchemeid(schemeValue) |
|
326 |
.setSchemename(schemeValue) |
|
327 |
.setClassname(classValue) |
|
328 |
.setClassid(classValue) |
|
329 |
.build(); |
|
330 |
} |
|
331 | 324 |
|
332 |
private static StructuredProperty getPid(final JsonObject localIdentifier, final Map<String, ScholExplorerConfiguration> conf) { |
|
333 |
final String pidType = getStringValue(localIdentifier, "type"); |
|
334 |
final ScholExplorerConfiguration configuration = conf.get(pidType); |
|
335 |
if (configuration.getCleandPidType() == null) { |
|
336 |
return null; |
|
337 |
} |
|
338 |
final String pid = getStringValue(localIdentifier, "id"); |
|
339 |
return StructuredProperty.newBuilder() |
|
340 |
.setValue(pid) |
|
341 |
.setQualifier(getQualifier(configuration.getCleandPidType(), "dnet:pid_types")) |
|
342 |
.build(); |
|
343 |
} |
|
344 | 325 |
|
345 |
public static String getStringValue(final JsonObject root, final String key) { |
|
346 |
if (root.has(key) && !root.get(key).isJsonNull()) |
|
347 |
return root.get(key).getAsString(); |
|
348 |
return null; |
|
349 |
} |
|
350 | 326 |
|
351 |
public static List<String> getArrayValues(final JsonObject root, final String key) { |
|
352 |
if (root.has(key) && root.get(key).isJsonArray()) { |
|
353 |
final JsonArray asJsonArray = root.get(key).getAsJsonArray(); |
|
354 |
final List<String> result = new ArrayList<>(); |
|
355 | 327 |
|
356 | 328 |
|
357 |
asJsonArray.forEach(it -> { |
|
358 |
if (StringUtils.isNotBlank(it.getAsString())) { |
|
359 |
result.add(it.getAsString()); |
|
360 |
} |
|
361 |
}); |
|
362 |
return result; |
|
363 |
} |
|
364 |
return new ArrayList<>(); |
|
365 |
} |
|
366 |
|
|
367 | 329 |
} |
Also available in: Unified diff
refactored Action