Revision 52935
Added by Claudio Atzori over 5 years ago
ScholixToActions.java | ||
---|---|---|
6 | 6 |
import java.util.Objects; |
7 | 7 |
|
8 | 8 |
import com.google.gson.JsonArray; |
9 |
import com.google.gson.JsonElement; |
|
9 | 10 |
import com.google.gson.JsonObject; |
11 |
import com.googlecode.protobuf.format.JsonFormat; |
|
10 | 12 |
import eu.dnetlib.actionmanager.actions.ActionFactory; |
11 | 13 |
import eu.dnetlib.actionmanager.actions.AtomicAction; |
12 | 14 |
import eu.dnetlib.actionmanager.common.Agent; |
15 |
import eu.dnetlib.data.mapreduce.util.StreamUtils; |
|
13 | 16 |
import eu.dnetlib.data.proto.RelMetadataProtos; |
14 | 17 |
import eu.dnetlib.data.proto.RelTypeProtos; |
15 | 18 |
import eu.dnetlib.data.transform.xml.AbstractDNetXsltFunctions; |
... | ... | |
36 | 39 |
final String abstractValue = getStringValue(rootElement, "abstract"); |
37 | 40 |
final List<String> authors = getArrayValues(rootElement, "author"); |
38 | 41 |
final List<String> dates = getArrayValues(rootElement, "date"); |
39 |
final JsonObject localIdentifier = rootElement.getAsJsonArray("localIdentifier").get(0).getAsJsonObject(); |
|
42 |
|
|
43 |
final JsonArray localIdentifiers = rootElement.getAsJsonArray("localIdentifier"); |
|
40 | 44 |
final String dnetId = getStringValue(rootElement, "id").substring(17); |
41 | 45 |
|
42 | 46 |
String title = ""; |
... | ... | |
53 | 57 |
} |
54 | 58 |
|
55 | 59 |
final Oaf.Builder oafBuilder = Oaf.newBuilder(); |
56 |
final boolean isVisible = StringUtils.isNotBlank(title) && conf.get(getStringValue(localIdentifier, "type")).isVisible(); |
|
60 |
|
|
61 |
final boolean isVisible = StringUtils.isNotBlank(title) && StreamUtils.toStream(localIdentifiers.iterator()) |
|
62 |
.map(JsonElement::getAsJsonObject) |
|
63 |
.anyMatch(o -> { |
|
64 |
final String type = getStringValue(o, "type"); |
|
65 |
return StringUtils.isNotBlank(type) && conf.containsKey(type) && conf.get(type).isVisible(); |
|
66 |
}); |
|
57 | 67 |
oafBuilder.setDataInfo( |
58 | 68 |
DataInfo.newBuilder() |
59 | 69 |
.setInvisible(!isVisible) |
... | ... | |
74 | 84 |
.addCollectedfrom(collectedFrom) |
75 | 85 |
.setId(sourceId); |
76 | 86 |
|
77 |
final StructuredProperty pid = getPid(localIdentifier, conf); |
|
78 |
if (pid != null) { |
|
79 |
oafEntityBuilder.addPid(pid); |
|
80 |
} |
|
87 |
StreamUtils.toStream(localIdentifiers.iterator()) |
|
88 |
.map(JsonElement::getAsJsonObject) |
|
89 |
.map(localIdentifier -> getPid(localIdentifier, conf)) |
|
90 |
.filter(Objects::nonNull) |
|
91 |
.forEach(oafEntityBuilder::addPid); |
|
92 |
|
|
81 | 93 |
final Result.Builder result = Result.newBuilder(); |
82 | 94 |
|
83 | 95 |
final Metadata.Builder metadata = Metadata.newBuilder() |
... | ... | |
88 | 100 |
.setSchemeid("dent:languages") |
89 | 101 |
.setSchemename("dent:languages") |
90 | 102 |
.build()); |
91 |
if (title != null) {
|
|
103 |
if (StringUtils.isNotBlank(title)) {
|
|
92 | 104 |
metadata.addTitle(StructuredProperty.newBuilder() |
93 | 105 |
.setValue(title) |
94 | 106 |
.setQualifier(getQualifier("main title", "dnet:dataCite_title")) |
... | ... | |
115 | 127 |
|
116 | 128 |
if (rootElement.has("subject")) { |
117 | 129 |
JsonArray subject = rootElement.getAsJsonArray("subject"); |
118 |
subject.forEach(it -> |
|
119 |
{ |
|
120 |
final JsonObject item = it.getAsJsonObject(); |
|
121 |
final String scheme = getStringValue(item, "scheme"); |
|
122 |
metadata.addSubject(StructuredProperty.newBuilder() |
|
123 |
.setValue(Objects.requireNonNull(getStringValue(item, "value"))) |
|
124 |
.setQualifier(getQualifier(scheme, "dnet:subject")) |
|
125 |
.build()); |
|
126 |
} |
|
130 |
subject.forEach(it -> { |
|
131 |
final JsonObject item = it.getAsJsonObject(); |
|
132 |
final String scheme = getStringValue(item, "scheme"); |
|
133 |
metadata.addSubject(StructuredProperty.newBuilder() |
|
134 |
.setValue(Objects.requireNonNull(getStringValue(item, "value"))) |
|
135 |
.setQualifier(getQualifier(scheme, "dnet:subject")) |
|
136 |
.build()); |
|
137 |
} |
|
127 | 138 |
); |
128 | 139 |
} |
129 | 140 |
int i = 1; |
... | ... | |
135 | 146 |
} |
136 | 147 |
result.setMetadata(metadata.build()); |
137 | 148 |
|
138 |
final String pidType = getStringValue(localIdentifier, "type"); |
|
139 |
final ScholExplorerConfiguration currentConf = conf.get(pidType); |
|
140 |
if (currentConf.getGeneratedUrl() != null) { |
|
141 |
final Instance.Builder instance = Instance.newBuilder(); |
|
142 |
final String pidValue = getStringValue(localIdentifier, "id"); |
|
143 |
instance.addUrl(String.format(currentConf.getGeneratedUrl(), pidValue)); |
|
144 |
instance.setAccessright(Qualifier.newBuilder() |
|
145 |
.setClassid("UNKNOWN") |
|
146 |
.setClassname("not available") |
|
147 |
.setSchemeid("dnet:access_modes") |
|
148 |
.setSchemename("dnet:access_modes") |
|
149 |
.build()); |
|
149 |
localIdentifiers.forEach(it -> { |
|
150 | 150 |
|
151 |
instance.setInstancetype(Qualifier.newBuilder() |
|
152 |
.setClassid("0000") |
|
153 |
.setClassname("Unknown") |
|
154 |
.setSchemeid("dnet:publication_resource") |
|
155 |
.setSchemename("dnet:publication_resource") |
|
156 |
.build()); |
|
157 |
instance.setHostedby(KeyValue.newBuilder() |
|
158 |
.setKey("10|openaire____::55045bd2a65019fd8e6741a755395c8c") |
|
159 |
.setValue("Unknown Repository") |
|
160 |
.build()); |
|
151 |
final JsonObject localIdentifier = it.getAsJsonObject(); |
|
152 |
final String pidType = getStringValue(localIdentifier, "type"); |
|
153 |
final ScholExplorerConfiguration currentConf = conf.get(pidType); |
|
154 |
if (currentConf.getGeneratedUrl() != null) { |
|
155 |
final Instance.Builder instance = Instance.newBuilder(); |
|
156 |
final String pidValue = getStringValue(localIdentifier, "id"); |
|
157 |
instance.addUrl(String.format(currentConf.getGeneratedUrl(), pidValue)); |
|
158 |
instance.setAccessright(Qualifier.newBuilder() |
|
159 |
.setClassid("UNKNOWN") |
|
160 |
.setClassname("not available") |
|
161 |
.setSchemeid("dnet:access_modes") |
|
162 |
.setSchemename("dnet:access_modes") |
|
163 |
.build()); |
|
161 | 164 |
|
162 |
instance.setCollectedfrom(collectedFrom); |
|
163 |
result.addInstance(instance); |
|
164 |
} |
|
165 |
instance.setInstancetype(Qualifier.newBuilder() |
|
166 |
.setClassid("0000") |
|
167 |
.setClassname("Unknown") |
|
168 |
.setSchemeid("dnet:publication_resource") |
|
169 |
.setSchemename("dnet:publication_resource") |
|
170 |
.build()); |
|
171 |
instance.setHostedby(KeyValue.newBuilder() |
|
172 |
.setKey("10|openaire____::55045bd2a65019fd8e6741a755395c8c") |
|
173 |
.setValue("Unknown Repository") |
|
174 |
.build()); |
|
175 |
|
|
176 |
instance.setCollectedfrom(collectedFrom); |
|
177 |
result.addInstance(instance); |
|
178 |
} |
|
179 |
}); |
|
180 |
|
|
165 | 181 |
generateExternalReference(extractRelations(rootElement, "externalRels")) |
166 | 182 |
.forEach(result::addExternalReference); |
167 | 183 |
oafEntityBuilder.setResult(result.build()); |
168 | 184 |
oafBuilder.setEntity(oafEntityBuilder.build()); |
169 | 185 |
|
170 |
// System.out.println(JsonFormat.printToString(oafBuilder.build()));
|
|
186 |
System.out.println(JsonFormat.printToString(oafBuilder.build())); |
|
171 | 187 |
|
172 | 188 |
actions.add(factory.createAtomicAction(setName, agent, oafEntityBuilder.getId(), "result", "body", oafBuilder.build().toByteArray())); |
173 | 189 |
|
... | ... | |
199 | 215 |
relation.addCollectedfrom(collectedFrom); |
200 | 216 |
oaf.setRel(relation.build()); |
201 | 217 |
|
202 |
// System.out.println(JsonFormat.printToString(oaf.build()));
|
|
218 |
//System.out.println(JsonFormat.printToString(oaf.build()));
|
|
203 | 219 |
return factory.createAtomicAction(setName, agent, source, cfRelation, target, oaf.build().toByteArray()); |
204 | 220 |
} |
205 | 221 |
|
... | ... | |
313 | 329 |
.build(); |
314 | 330 |
} |
315 | 331 |
|
316 |
private static StructuredProperty getPid(final JsonObject localIdentifier, final Map<String, ScholExplorerConfiguration> configurationMap) {
|
|
332 |
private static StructuredProperty getPid(final JsonObject localIdentifier, final Map<String, ScholExplorerConfiguration> conf) { |
|
317 | 333 |
final String pidType = getStringValue(localIdentifier, "type"); |
318 |
final ScholExplorerConfiguration configuration = configurationMap.get(pidType);
|
|
319 |
if (configuration.getCleandPidType() == null) |
|
334 |
final ScholExplorerConfiguration configuration = conf.get(pidType); |
|
335 |
if (configuration.getCleandPidType() == null) {
|
|
320 | 336 |
return null; |
337 |
} |
|
321 | 338 |
final String pid = getStringValue(localIdentifier, "id"); |
322 | 339 |
return StructuredProperty.newBuilder() |
323 | 340 |
.setValue(pid) |
Also available in: Unified diff
fixed mapping from scholix to openaire model