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
|
|
36
|
public static boolean isValidDate(final String date) {
|
37
|
return date.matches("\\d{4}-\\d{2}-\\d{2}");
|
38
|
}
|
39
|
|
40
|
public static FieldTypeProtos.StructuredProperty getPid(final JsonObject localIdentifier, final Map<String, ScholExplorerConfiguration> conf) {
|
41
|
final String pidType = getStringValue(localIdentifier, "type");
|
42
|
final ScholExplorerConfiguration configuration = conf.get(pidType);
|
43
|
if (configuration.getCleandPidType() == null) {
|
44
|
return null;
|
45
|
}
|
46
|
final String pid = getStringValue(localIdentifier, "id");
|
47
|
return FieldTypeProtos.StructuredProperty.newBuilder()
|
48
|
.setValue(pid)
|
49
|
.setQualifier(getQualifier(configuration.getCleandPidType(), "dnet:pid_types"))
|
50
|
.build();
|
51
|
}
|
52
|
public static FieldTypeProtos.Qualifier getQualifier(final String classValue, final String schemeValue) {
|
53
|
|
54
|
return FieldTypeProtos.Qualifier.newBuilder()
|
55
|
.setSchemeid(schemeValue)
|
56
|
.setSchemename(schemeValue)
|
57
|
.setClassname(classValue)
|
58
|
.setClassid(classValue)
|
59
|
.build();
|
60
|
}
|
61
|
|
62
|
public static String getDefaultResulttype(final String cobjcategory) {
|
63
|
switch (cobjcategory) {
|
64
|
case "0029":
|
65
|
return "software";
|
66
|
case "0021":
|
67
|
case "0024":
|
68
|
case "0025":
|
69
|
case "0030":
|
70
|
return "dataset";
|
71
|
case "0000":
|
72
|
case "0010":
|
73
|
case "0018":
|
74
|
case "0020":
|
75
|
case "0022":
|
76
|
case "0023":
|
77
|
case "0026":
|
78
|
case "0027":
|
79
|
case "0028":
|
80
|
case "0037":
|
81
|
return "other";
|
82
|
case "0001":
|
83
|
case "0002":
|
84
|
case "0004":
|
85
|
case "0005":
|
86
|
case "0006":
|
87
|
case "0007":
|
88
|
case "0008":
|
89
|
case "0009":
|
90
|
case "0011":
|
91
|
case "0012":
|
92
|
case "0013":
|
93
|
case "0014":
|
94
|
case "0015":
|
95
|
case "0016":
|
96
|
case "0017":
|
97
|
case "0019":
|
98
|
case "0031":
|
99
|
case "0032":
|
100
|
return "publication";
|
101
|
default:
|
102
|
return "publication";
|
103
|
}
|
104
|
}
|
105
|
|
106
|
}
|