Revision 52931
Added by Claudio Atzori over 5 years ago
ScholixToActions.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mapreduce.hbase.dataimport; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Objects; |
|
7 |
|
|
3 | 8 |
import com.google.gson.JsonArray; |
4 | 9 |
import com.google.gson.JsonObject; |
5 |
import com.googlecode.protobuf.format.JsonFormat; |
|
6 | 10 |
import eu.dnetlib.actionmanager.actions.ActionFactory; |
7 | 11 |
import eu.dnetlib.actionmanager.actions.AtomicAction; |
8 | 12 |
import eu.dnetlib.actionmanager.common.Agent; |
... | ... | |
11 | 15 |
import eu.dnetlib.data.transform.xml.AbstractDNetXsltFunctions; |
12 | 16 |
import org.apache.commons.lang3.StringUtils; |
13 | 17 |
|
14 |
import java.util.ArrayList; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Objects; |
|
18 |
|
|
19 | 18 |
import static eu.dnetlib.data.proto.FieldTypeProtos.*; |
20 | 19 |
import static eu.dnetlib.data.proto.KindProtos.Kind; |
21 | 20 |
import static eu.dnetlib.data.proto.OafProtos.*; |
... | ... | |
26 | 25 |
|
27 | 26 |
public class ScholixToActions { |
28 | 27 |
|
29 |
public static List<AtomicAction> generateActionsFromScholix(final JsonObject rootElement, final Map<String, ScholExplorerConfiguration> configurationMap,
|
|
28 |
public static List<AtomicAction> generateActionsFromScholix(final JsonObject rootElement, final Map<String, ScholExplorerConfiguration> conf, |
|
30 | 29 |
final String setName, final Agent agent, ActionFactory factory, String nsPrefix, final String dsName, |
31 | 30 |
final String dsId, String dateOfCollection) { |
32 | 31 |
|
... | ... | |
40 | 39 |
final JsonObject localIdentifier = rootElement.getAsJsonArray("localIdentifier").get(0).getAsJsonObject(); |
41 | 40 |
final String dnetId = getStringValue(rootElement, "id").substring(17); |
42 | 41 |
|
43 |
|
|
44 |
String title; |
|
42 |
String title = ""; |
|
45 | 43 |
if (rootElement.has("title") && rootElement.get("title").isJsonArray()) { |
46 | 44 |
StringBuilder ttl = new StringBuilder(); |
47 | 45 |
getArrayValues(rootElement, "title").forEach(ttl::append); |
... | ... | |
50 | 48 |
title = getStringValue(rootElement, "title"); |
51 | 49 |
} |
52 | 50 |
|
53 |
if (title != null && title.charAt(0) == '"' && title.charAt(title.length() - 1) == '"') |
|
51 |
if (title != null && title.charAt(0) == '"' && title.charAt(title.length() - 1) == '"') {
|
|
54 | 52 |
title = title.substring(1, title.length() - 1); |
53 |
} |
|
55 | 54 |
|
56 |
|
|
57 | 55 |
final Oaf.Builder oafBuilder = Oaf.newBuilder(); |
58 |
final boolean isVisible = title != null && configurationMap.get(getStringValue(localIdentifier, "type")).isVisible();
|
|
56 |
final boolean isVisible = StringUtils.isNotBlank(title) && conf.get(getStringValue(localIdentifier, "type")).isVisible();
|
|
59 | 57 |
oafBuilder.setDataInfo( |
60 | 58 |
DataInfo.newBuilder() |
61 | 59 |
.setInvisible(!isVisible) |
... | ... | |
65 | 63 |
.setProvenanceaction(getQualifier("sysimport:actionset", "dnet:provenanceActions")) |
66 | 64 |
.build()); |
67 | 65 |
oafBuilder.setKind(Kind.entity); |
68 |
final OafEntity.Builder oafEntityBuilder = OafEntity.newBuilder(); |
|
69 |
oafEntityBuilder.setType(Type.result); |
|
70 | 66 |
final String sourceId = String.format("50|%s::%s", nsPrefix, dnetId); |
71 |
oafEntityBuilder.setId(sourceId); |
|
72 |
final StructuredProperty pid = getPid(localIdentifier, configurationMap); |
|
73 |
if (pid != null) |
|
67 |
final KeyValue collectedFrom = KeyValue.newBuilder() |
|
68 |
.setValue(dsName) |
|
69 |
.setKey("10|openaire____::" + AbstractDNetXsltFunctions.md5(dsId)) |
|
70 |
.build(); |
|
71 |
final OafEntity.Builder oafEntityBuilder = OafEntity.newBuilder() |
|
72 |
.setType(Type.result) |
|
73 |
.setDateofcollection(dateOfCollection) |
|
74 |
.addCollectedfrom(collectedFrom) |
|
75 |
.setId(sourceId); |
|
76 |
|
|
77 |
final StructuredProperty pid = getPid(localIdentifier, conf); |
|
78 |
if (pid != null) { |
|
74 | 79 |
oafEntityBuilder.addPid(pid); |
80 |
} |
|
75 | 81 |
final Result.Builder result = Result.newBuilder(); |
76 |
final Metadata.Builder metadata = Metadata.newBuilder(); |
|
77 |
metadata.setResulttype(getQualifier(typology, "dnet:result_typologies")); |
|
78 |
metadata.setLanguage(Qualifier.newBuilder() |
|
82 |
|
|
83 |
final Metadata.Builder metadata = Metadata.newBuilder() |
|
84 |
.setResulttype(getQualifier(typology, "dnet:result_typologies")) |
|
85 |
.setLanguage(Qualifier.newBuilder() |
|
79 | 86 |
.setClassid("und") |
80 | 87 |
.setClassname("Undetermined") |
81 | 88 |
.setSchemeid("dent:languages") |
82 | 89 |
.setSchemename("dent:languages") |
83 | 90 |
.build()); |
84 |
if (title!= null) |
|
85 |
metadata.addTitle(StructuredProperty.newBuilder() |
|
86 |
.setValue(title) |
|
87 |
.setQualifier(getQualifier("main title", "dnet:dataCite_title")) |
|
88 |
.build()); |
|
91 |
if (title != null) { |
|
92 |
metadata.addTitle(StructuredProperty.newBuilder() |
|
93 |
.setValue(title) |
|
94 |
.setQualifier(getQualifier("main title", "dnet:dataCite_title")) |
|
95 |
.build()); |
|
96 |
} |
|
89 | 97 |
if (publisher.size() > 0) |
90 | 98 |
metadata.setPublisher(StringField.newBuilder().setValue(publisher.get(0)).build()); |
91 | 99 |
if (StringUtils.isNotEmpty(abstractValue)) { |
... | ... | |
127 | 135 |
} |
128 | 136 |
result.setMetadata(metadata.build()); |
129 | 137 |
|
130 |
KeyValue collectedFrom = KeyValue.newBuilder() |
|
131 |
.setValue(dsName) |
|
132 |
.setKey("10|openaire____::" + AbstractDNetXsltFunctions.md5(dsId)) |
|
133 |
.build(); |
|
134 |
oafEntityBuilder.addCollectedfrom(collectedFrom); |
|
135 |
|
|
136 |
oafEntityBuilder.setDateofcollection(dateOfCollection); |
|
137 |
|
|
138 | 138 |
final String pidType = getStringValue(localIdentifier, "type"); |
139 |
final ScholExplorerConfiguration currentConfiguration = configurationMap.get(pidType);
|
|
140 |
if (currentConfiguration.getGeneratedUrl() != null) {
|
|
139 |
final ScholExplorerConfiguration currentConf = conf.get(pidType);
|
|
140 |
if (currentConf.getGeneratedUrl() != null) { |
|
141 | 141 |
final Instance.Builder instance = Instance.newBuilder(); |
142 | 142 |
final String pidValue = getStringValue(localIdentifier, "id"); |
143 |
instance.addUrl(String.format(currentConfiguration.getGeneratedUrl(), pidValue));
|
|
143 |
instance.addUrl(String.format(currentConf.getGeneratedUrl(), pidValue)); |
|
144 | 144 |
instance.setAccessright(Qualifier.newBuilder() |
145 | 145 |
.setClassid("UNKNOWN") |
146 | 146 |
.setClassname("not available") |
... | ... | |
214 | 214 |
ResultResult.Builder resultInverseRel = ResultResult.newBuilder(); |
215 | 215 |
String relClass; |
216 | 216 |
String inverseRelClass; |
217 |
|
|
217 | 218 |
switch (relationSemantic) { |
218 | 219 |
case "isSupplementedBy": { |
219 | 220 |
cfRelation = "resultResult_supplement_isSupplementedBy"; |
... | ... | |
264 | 265 |
} |
265 | 266 |
} |
266 | 267 |
|
267 |
List<AtomicAction> actions = new ArrayList<>(); |
|
268 |
final List<AtomicAction> actions = new ArrayList<>();
|
|
268 | 269 |
actions.add(createResultResultRelation(sourceId, targetId, collectedFrom, resultRel.build(), relClass, cfRelation, factory, setName, agent)); |
269 | 270 |
actions.add(createResultResultRelation(targetId, sourceId, collectedFrom, resultInverseRel.build(), inverseRelClass, cfInverseRelation, factory, setName, agent)); |
270 | 271 |
|
... | ... | |
293 | 294 |
return result; |
294 | 295 |
} |
295 | 296 |
|
296 |
|
|
297 | 297 |
private static List<JsonObject> extractRelations(final JsonObject rootElement, final String fieldType) { |
298 | 298 |
final List<JsonObject> result = new ArrayList<>(); |
299 | 299 |
if (rootElement.has(fieldType) && rootElement.get(fieldType).isJsonArray()) { |
... | ... | |
303 | 303 |
return result; |
304 | 304 |
} |
305 | 305 |
|
306 |
|
|
307 | 306 |
private static Qualifier getQualifier(final String classValue, final String schemeValue) { |
308 | 307 |
|
309 | 308 |
return Qualifier.newBuilder() |
Also available in: Unified diff
small fixes