1
|
package eu.dnetlib.data.transform.xml;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.common.collect.Lists;
|
7
|
import com.google.common.collect.Maps;
|
8
|
import eu.dnetlib.data.graph.model.DNGFRowKeyDecoder;
|
9
|
import eu.dnetlib.data.proto.DNGFProtos;
|
10
|
import eu.dnetlib.data.proto.DNGFProtos.DNGF;
|
11
|
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity;
|
12
|
import eu.dnetlib.data.proto.DatasetProtos;
|
13
|
import eu.dnetlib.data.proto.DatasetProtos.Dataset;
|
14
|
import eu.dnetlib.data.proto.FieldTypeProtos.Instance;
|
15
|
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty;
|
16
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
17
|
import org.w3c.dom.NamedNodeMap;
|
18
|
import org.w3c.dom.Node;
|
19
|
import org.w3c.dom.NodeList;
|
20
|
|
21
|
public class OdfToHbaseXsltFunctions extends CommonDNetXsltFunctions {
|
22
|
|
23
|
private static Map<String, String> mappingAccess = Maps.newHashMap();
|
24
|
|
25
|
static {
|
26
|
|
27
|
mappingAccess.put("info:eu-repo/semantics/openAccess", "OPEN");
|
28
|
mappingAccess.put("info:eu-repo/semantics/closedAccess", "CLOSED");
|
29
|
mappingAccess.put("info:eu-repo/semantics/restrictedAccess", "RESTRICTED");
|
30
|
mappingAccess.put("info:eu-repo/semantics/embargoedAccess", "EMBARGO");
|
31
|
|
32
|
// Transformator now maps the access rights into proper values, not sure if it does for all datasets.
|
33
|
mappingAccess.put("OPEN", "OPEN");
|
34
|
mappingAccess.put("CLOSED", "CLOSED");
|
35
|
mappingAccess.put("RESTRICTED", "RESTRICTED");
|
36
|
mappingAccess.put("EMBARGO", "EMBARGO");
|
37
|
|
38
|
}
|
39
|
|
40
|
protected static DNGFEntity.Builder odfDatasetProto(
|
41
|
final String resultId,
|
42
|
final NodeList about,
|
43
|
final NodeList titles,
|
44
|
final NodeList subjects,
|
45
|
final NodeList publisher,
|
46
|
final NodeList descriptions,
|
47
|
final NodeList dates,
|
48
|
final NodeList dateaccepted,
|
49
|
final NodeList resourceTypes,
|
50
|
final NodeList formats,
|
51
|
final NodeList sizes,
|
52
|
final NodeList languages,
|
53
|
final NodeList cobjcategory,
|
54
|
final NodeList contributors,
|
55
|
final NodeList rights,
|
56
|
final NodeList version,
|
57
|
final NodeList pidList,
|
58
|
final String hostedbyId,
|
59
|
final String hostedbyName,
|
60
|
final String collectedfromId,
|
61
|
final String collectedfromName,
|
62
|
final NodeList originalIds,
|
63
|
final String instanceUri,
|
64
|
final String dateOfCollection,
|
65
|
final String dateOfTransformation) {
|
66
|
|
67
|
final String entityId = DNGFRowKeyDecoder.decode(resultId).getKey();
|
68
|
|
69
|
final Dataset.Builder dataset = Dataset.newBuilder();
|
70
|
Dataset.Metadata.Builder metadataProto = Dataset.Metadata.newBuilder();
|
71
|
|
72
|
// subject
|
73
|
for (int i = 0; i < subjects.getLength(); i++) {
|
74
|
Node currentNode = subjects.item(i);
|
75
|
NodeList childNodes = currentNode.getChildNodes();
|
76
|
if (childNodes.getLength() > 0) {
|
77
|
String subjectValue = childNodes.item(0).getNodeValue();
|
78
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("subject"),
|
79
|
getStructuredProperty(subjectValue, "keyword", "keyword", "dnet:result_subject", "dnet:result_subject"));
|
80
|
}
|
81
|
}
|
82
|
|
83
|
// title
|
84
|
manageTitle(titles, metadataProto);
|
85
|
|
86
|
// description
|
87
|
for (int i = 0; i < descriptions.getLength(); i++) {
|
88
|
Node currentNode = descriptions.item(i);
|
89
|
if (currentNode != null && currentNode.hasChildNodes()) {
|
90
|
String descriptionValue = currentNode.getChildNodes().item(0).getNodeValue();
|
91
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("description"), descriptionValue);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
// contributors
|
96
|
for (int i = 0; i < contributors.getLength(); i++) {
|
97
|
Node currentNode = contributors.item(i);
|
98
|
if (currentNode != null && currentNode.hasChildNodes()) {
|
99
|
String contributorValue = currentNode.getChildNodes().item(0).getNodeValue();
|
100
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("contributor"), contributorValue);
|
101
|
}
|
102
|
}
|
103
|
|
104
|
// publisher
|
105
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("publisher"), getFirstItem(publisher));
|
106
|
|
107
|
// dates
|
108
|
manageDate(dates, metadataProto);
|
109
|
|
110
|
|
111
|
// dateofacceptance
|
112
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("dateofacceptance"), getFirstItem(dateaccepted));
|
113
|
|
114
|
// size
|
115
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("size"), getFirstItem(sizes));
|
116
|
|
117
|
// format
|
118
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("format"), getFirstItem(formats));
|
119
|
|
120
|
// version
|
121
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("version"), getFirstItem(version));
|
122
|
|
123
|
// language
|
124
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("language"),
|
125
|
setQualifier(getDefaultQualifier("dnet:languages"), Lists.newArrayList(getFirstItem(languages))));
|
126
|
|
127
|
//resource type
|
128
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("resourcetype"),
|
129
|
setQualifier(getDefaultQualifier("dnet:dataCite_resource"), Lists.newArrayList(getFirstItem(resourceTypes))));
|
130
|
|
131
|
// resultType
|
132
|
addField(metadataProto, Dataset.Metadata.getDescriptor().findFieldByName("resulttype"), getSimpleQualifier("dataset", "dnet:result_typologies"));
|
133
|
|
134
|
String tmpID;
|
135
|
String TmpName;
|
136
|
|
137
|
if (hostedbyId == null && hostedbyName == null) {
|
138
|
tmpID = collectedfromId;
|
139
|
TmpName = collectedfromName;
|
140
|
} else {
|
141
|
tmpID = hostedbyId;
|
142
|
TmpName = hostedbyName;
|
143
|
}
|
144
|
|
145
|
final Instance.Builder instance = Instance.newBuilder().setHostedby(getKV(tmpID, TmpName));
|
146
|
|
147
|
String tmpRigths = "UNKNOWN";
|
148
|
final String firstRight = getFirstItem(rights);
|
149
|
if (mappingAccess.containsKey(firstRight)) {
|
150
|
tmpRigths = mappingAccess.get(firstRight);
|
151
|
}
|
152
|
|
153
|
addField(instance, Instance.getDescriptor().findFieldByName("licence"),
|
154
|
setQualifier(getDefaultQualifier("dnet:access_modes"), Lists.newArrayList(tmpRigths)));
|
155
|
|
156
|
addField(instance, Instance.getDescriptor().findFieldByName("instancetype"),
|
157
|
setQualifier(getDefaultQualifier("dnet:dataCite_resource"), Lists.newArrayList(getFirstItem(cobjcategory))));
|
158
|
|
159
|
addField(instance, Instance.getDescriptor().findFieldByName("url"), instanceUri);
|
160
|
|
161
|
dataset.addInstance(instance);
|
162
|
|
163
|
List<StructuredProperty> pids = parsePids(pidList);
|
164
|
|
165
|
// original ids
|
166
|
final List<String> originalIdList = Lists.newArrayList();
|
167
|
for (int i = 0; i < originalIds.getLength(); i++) {
|
168
|
Node currentNode = originalIds.item(i);
|
169
|
if (currentNode != null && currentNode.hasChildNodes()) {
|
170
|
originalIdList.add(currentNode.getChildNodes().item(0).getNodeValue());
|
171
|
}
|
172
|
}
|
173
|
|
174
|
DNGFEntity.Builder entity =
|
175
|
getEntity(Type.dataset, entityId, getKV(collectedfromId, collectedfromName), originalIdList, dateOfCollection, dateOfTransformation, pids).setDataset(
|
176
|
dataset.setMetadata(metadataProto));
|
177
|
|
178
|
entity.setOaiprovenance(getOAIProvenance(about));
|
179
|
|
180
|
return entity;
|
181
|
}
|
182
|
|
183
|
|
184
|
public static String odfDataset(
|
185
|
final String resultId,
|
186
|
final NodeList about,
|
187
|
final NodeList metadata,
|
188
|
final NodeList titles,
|
189
|
final NodeList subjects,
|
190
|
final NodeList publisher,
|
191
|
final NodeList descriptions,
|
192
|
final NodeList dates,
|
193
|
final NodeList dateaccepted,
|
194
|
final NodeList resourceTypes,
|
195
|
final NodeList formats,
|
196
|
final NodeList sizes,
|
197
|
final NodeList languages,
|
198
|
final NodeList cobjcategory,
|
199
|
final NodeList contributors,
|
200
|
final NodeList rights,
|
201
|
final NodeList version,
|
202
|
final NodeList pidList,
|
203
|
final String provenance,
|
204
|
final String trust,
|
205
|
final String hostedbyId,
|
206
|
final String hostedbyName,
|
207
|
final String collectedfromId,
|
208
|
final String collectedfromName,
|
209
|
final NodeList originalIds,
|
210
|
final String instanceUri,
|
211
|
final String dateOfCollection,
|
212
|
final String dateOfTransformation) {
|
213
|
|
214
|
try {
|
215
|
final DNGFEntity.Builder entity = odfDatasetProto(
|
216
|
resultId, about, titles, subjects, publisher, descriptions, dates, dateaccepted,
|
217
|
resourceTypes, formats, sizes, languages, cobjcategory, contributors, rights, version,
|
218
|
pidList, hostedbyId, hostedbyName, collectedfromId, collectedfromName,
|
219
|
originalIds, instanceUri, dateOfCollection, dateOfTransformation);
|
220
|
|
221
|
final DNGF dngf = getOaf(entity, getDataInfo(about, provenance, trust, false, false));
|
222
|
return base64(dngf.toByteArray());
|
223
|
} catch (Throwable e) {
|
224
|
e.printStackTrace(System.err);
|
225
|
throw new RuntimeException(e);
|
226
|
}
|
227
|
|
228
|
}
|
229
|
|
230
|
public static String getFirstItem(final NodeList list) {
|
231
|
String out = "";
|
232
|
if (list != null) {
|
233
|
|
234
|
if (list.getLength() > 0 && list.item(0).getChildNodes() != null && list.item(0).getChildNodes().getLength() > 0) {
|
235
|
out = list.item(0).getChildNodes().item(0).getNodeValue();
|
236
|
}
|
237
|
}
|
238
|
return out;
|
239
|
}
|
240
|
|
241
|
|
242
|
//personDataset_Authorship($personId, $datasetId, $position, 'isAuthorOf', $provenance, $trust, $about)
|
243
|
|
244
|
|
245
|
public static String personDataset_Authorship(
|
246
|
final String personIdentifier,
|
247
|
final String datasetIdentifier,
|
248
|
final int position,
|
249
|
final String relation,
|
250
|
final String provenance,
|
251
|
final String trust,
|
252
|
final NodeList about) {
|
253
|
|
254
|
return authorship(personIdentifier, "person",
|
255
|
datasetIdentifier, "dataset", position,
|
256
|
relation, provenance, trust, about);
|
257
|
|
258
|
|
259
|
}
|
260
|
|
261
|
|
262
|
|
263
|
|
264
|
}
|