Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.dataexport;
2

    
3
import com.google.common.collect.Lists;
4
import com.googlecode.protobuf.format.JsonFormat;
5
import eu.dnetlib.data.mapreduce.util.LicenseComparator;
6
import eu.dnetlib.data.proto.*;
7
import eu.dnetlib.dhp.schema.oaf.*;
8
import org.apache.commons.lang3.StringUtils;
9

    
10
import java.io.Serializable;
11
import java.util.List;
12
import java.util.stream.Collectors;
13

    
14
public class ProtoConverter implements Serializable {
15

    
16
    public static final String UNKNOWN = "UNKNOWN";
17
    public static final String NOT_AVAILABLE = "not available";
18
    public static final String DNET_ACCESS_MODES = "dnet:access_modes";
19

    
20
    public static Oaf convert(OafProtos.Oaf oaf) {
21
        try {
22
            switch (oaf.getKind()) {
23
                case entity:
24
                    return convertEntity(oaf);
25
                case relation:
26
                    return convertRelation(oaf);
27
                default:
28
                    throw new IllegalArgumentException("invalid kind " + oaf.getKind());
29
            }
30
        } catch (Throwable e) {
31
            throw new RuntimeException("error on getting " + JsonFormat.printToString(oaf), e);
32
        }
33
    }
34

    
35
    private static Relation convertRelation(OafProtos.Oaf oaf) {
36
        final OafProtos.OafRel r = oaf.getRel();
37
        final Relation rel = new Relation();
38
        rel.setDataInfo(mapDataInfo(oaf.getDataInfo()));
39
        rel.setLastupdatetimestamp(oaf.getLastupdatetimestamp());
40
        rel.setSource(r.getSource());
41
        rel.setTarget(r.getTarget());
42
        rel.setRelType(r.getRelType().toString());
43
        rel.setSubRelType(r.getSubRelType().toString());
44
        rel.setRelClass(r.getRelClass());
45
        rel.setCollectedfrom(r.getCollectedfromCount() > 0 ?
46
                r.getCollectedfromList().stream()
47
                        .map(kv -> mapKV(kv))
48
                        .collect(Collectors.toList()) : null);
49
        return rel;
50
    }
51

    
52
    private static OafEntity convertEntity(OafProtos.Oaf oaf) {
53

    
54
        switch (oaf.getEntity().getType()) {
55
            case result:
56
                final Result r = convertResult(oaf);
57
                r.setInstance(convertInstances(oaf));
58
                return r;
59
            case project:
60
                return convertProject(oaf);
61
            case datasource:
62
                return convertDataSource(oaf);
63
            case organization:
64
                return convertOrganization(oaf);
65
            default:
66
                throw new RuntimeException("received unknown type");
67
        }
68
    }
69

    
70
    private static List<Instance> convertInstances(OafProtos.Oaf oaf) {
71

    
72
        final ResultProtos.Result r = oaf.getEntity().getResult();
73
        if (r.getInstanceCount() > 0) {
74
            return r.getInstanceList()
75
                    .stream()
76
                    .map(i -> convertInstance(i))
77
                    .collect(Collectors.toList());
78
        }
79
        return Lists.newArrayList();
80
    }
81

    
82
    private static Instance convertInstance(ResultProtos.Result.Instance ri) {
83
        final Instance i = new Instance();
84
        i.setAccessright(mapQualifier(ri.getAccessright()));
85
        i.setCollectedfrom(mapKV(ri.getCollectedfrom()));
86
        i.setDateofacceptance(mapStringField(ri.getDateofacceptance()));
87
        i.setDistributionlocation(ri.getDistributionlocation());
88
        i.setHostedby(mapKV(ri.getHostedby()));
89
        i.setInstancetype(mapQualifier(ri.getInstancetype()));
90
        i.setLicense(mapStringField(ri.getLicense()));
91
        i.setUrl(ri.getUrlList());
92
        i.setRefereed(mapStringField(ri.getRefereed()));
93
        i.setProcessingchargeamount(mapStringField(ri.getProcessingchargeamount()));
94
        i.setProcessingchargecurrency(mapStringField(ri.getProcessingchargecurrency()));
95
        return i;
96
    }
97

    
98
    private static Organization convertOrganization(OafProtos.Oaf oaf) {
99
        final OrganizationProtos.Organization.Metadata m = oaf.getEntity().getOrganization().getMetadata();
100
        final Organization org = setOaf(new Organization(), oaf);
101
        setEntity(org, oaf);
102
        org.setLegalshortname(mapStringField(m.getLegalshortname()));
103
        org.setLegalname(mapStringField(m.getLegalname()));
104
        org.setAlternativeNames(m.getAlternativeNamesList().
105
                stream()
106
                .map(ProtoConverter::mapStringField)
107
                .collect(Collectors.toList()));
108
        org.setWebsiteurl(mapStringField(m.getWebsiteurl()));
109
        org.setLogourl(mapStringField(m.getLogourl()));
110
        org.setEclegalbody(mapStringField(m.getEclegalbody()));
111
        org.setEclegalperson(mapStringField(m.getEclegalperson()));
112
        org.setEcnonprofit(mapStringField(m.getEcnonprofit()));
113
        org.setEcresearchorganization(mapStringField(m.getEcresearchorganization()));
114
        org.setEchighereducation(mapStringField(m.getEchighereducation()));
115
        org.setEcinternationalorganizationeurinterests(mapStringField(m.getEcinternationalorganizationeurinterests()));
116
        org.setEcinternationalorganization(mapStringField(m.getEcinternationalorganization()));
117
        org.setEcenterprise(mapStringField(m.getEcenterprise()));
118
        org.setEcsmevalidated(mapStringField(m.getEcsmevalidated()));
119
        org.setEcnutscode(mapStringField(m.getEcnutscode()));
120
        org.setCountry(mapQualifier(m.getCountry()));
121

    
122
        return org;
123
    }
124

    
125
    private static Datasource convertDataSource(OafProtos.Oaf oaf) {
126
        final DatasourceProtos.Datasource.Metadata m = oaf.getEntity().getDatasource().getMetadata();
127
        final Datasource datasource = setOaf(new Datasource(), oaf);
128
        setEntity(datasource, oaf);
129
        datasource.setAccessinfopackage(m.getAccessinfopackageList()
130
                .stream()
131
                .map(ProtoConverter::mapStringField)
132
                .collect(Collectors.toList()));
133
        datasource.setCertificates(mapStringField(m.getCertificates()));
134
        datasource.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()));
135
        datasource.setContactemail(mapStringField(m.getContactemail()));
136
        datasource.setDatabaseaccessrestriction(mapStringField(m.getDatabaseaccessrestriction()));
137
        datasource.setDatabaseaccesstype(mapStringField(m.getDatabaseaccesstype()));
138
        datasource.setDataprovider(mapBoolField(m.getDataprovider()));
139
        datasource.setDatasourcetype(mapQualifier(m.getDatasourcetype()));
140
        datasource.setDatauploadrestriction(mapStringField(m.getDatauploadrestriction()));
141
        datasource.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()));
142
        datasource.setDatauploadtype(mapStringField(m.getDatauploadtype()));
143
        datasource.setDateofvalidation(mapStringField(m.getDateofvalidation()));
144
        datasource.setDescription(mapStringField(m.getDescription()));
145
        datasource.setEnglishname(mapStringField(m.getEnglishname()));
146
        datasource.setLatitude(mapStringField(m.getLatitude()));
147
        datasource.setLongitude(mapStringField(m.getLongitude()));
148
        datasource.setLogourl(mapStringField(m.getLogourl()));
149
        datasource.setMissionstatementurl(mapStringField(m.getMissionstatementurl()));
150
        datasource.setNamespaceprefix(mapStringField(m.getNamespaceprefix()));
151
        datasource.setOdcontenttypes(m.getOdcontenttypesList()
152
                .stream()
153
                .map(ProtoConverter::mapStringField)
154
                .collect(Collectors.toList()));
155
        datasource.setOdlanguages(m.getOdlanguagesList()
156
                .stream()
157
                .map(ProtoConverter::mapStringField)
158
                .collect(Collectors.toList()));
159
        datasource.setOdnumberofitems(mapStringField(m.getOdnumberofitems()));
160
        datasource.setOdnumberofitemsdate(mapStringField(m.getOdnumberofitemsdate()));
161
        datasource.setOdpolicies(mapStringField(m.getOdpolicies()));
162
        datasource.setOfficialname(mapStringField(m.getOfficialname()));
163
        datasource.setOpenairecompatibility(mapQualifier(m.getOpenairecompatibility()));
164
        datasource.setPidsystems(mapStringField(m.getPidsystems()));
165
        datasource.setPolicies(m.getPoliciesList()
166
                .stream()
167
                .map(ProtoConverter::mapKV)
168
                .collect(Collectors.toList()));
169
        datasource.setQualitymanagementkind(mapStringField(m.getQualitymanagementkind()));
170
        datasource.setReleaseenddate(mapStringField(m.getReleaseenddate()));
171
        datasource.setServiceprovider(mapBoolField(m.getServiceprovider()));
172
        datasource.setReleasestartdate(mapStringField(m.getReleasestartdate()));
173
        datasource.setSubjects(m.getSubjectsList()
174
                .stream()
175
                .map(ProtoConverter::mapStructuredProperty)
176
                .collect(Collectors.toList()));
177
        datasource.setVersioning(mapBoolField(m.getVersioning()));
178
        datasource.setWebsiteurl(mapStringField(m.getWebsiteurl()));
179
        datasource.setJournal(mapJournal(m.getJournal()));
180

    
181

    
182
        return datasource;
183
    }
184

    
185
    private static Project convertProject(OafProtos.Oaf oaf) {
186
        final ProjectProtos.Project.Metadata m = oaf.getEntity().getProject().getMetadata();
187
        final Project project = setOaf(new Project(), oaf);
188
        setEntity(project, oaf);
189
        project.setAcronym(mapStringField(m.getAcronym()));
190
        project.setCallidentifier(mapStringField(m.getCallidentifier()));
191
        project.setCode(mapStringField(m.getCode()));
192
        project.setContactemail(mapStringField(m.getContactemail()));
193
        project.setContactfax(mapStringField(m.getContactfax()));
194
        project.setContactfullname(mapStringField(m.getContactfullname()));
195
        project.setContactphone(mapStringField(m.getContactphone()));
196
        project.setContracttype(mapQualifier(m.getContracttype()));
197
        project.setCurrency(mapStringField(m.getCurrency()));
198
        project.setDuration(mapStringField(m.getDuration()));
199
        project.setEcarticle29_3(mapStringField(m.getEcarticle293()));
200
        project.setEcsc39(mapStringField(m.getEcsc39()));
201
        project.setOamandatepublications(mapStringField(m.getOamandatepublications()));
202
        project.setStartdate(mapStringField(m.getStartdate()));
203
        project.setEnddate(mapStringField(m.getEnddate()));
204
        project.setFundedamount(m.getFundedamount());
205
        project.setTotalcost(m.getTotalcost());
206
        project.setKeywords(mapStringField(m.getKeywords()));
207
        project.setSubjects(m.getSubjectsList().stream()
208
                .map(sp -> mapStructuredProperty(sp))
209
                .collect(Collectors.toList()));
210
        project.setTitle(mapStringField(m.getTitle()));
211
        project.setWebsiteurl(mapStringField(m.getWebsiteurl()));
212
        project.setFundingtree(m.getFundingtreeList().stream()
213
                .map(f -> mapStringField(f))
214
                .collect(Collectors.toList()));
215
        project.setJsonextrainfo(mapStringField(m.getJsonextrainfo()));
216
        project.setSummary(mapStringField(m.getSummary()));
217
        project.setOptional1(mapStringField(m.getOptional1()));
218
        project.setOptional2(mapStringField(m.getOptional2()));
219
        return project;
220
    }
221

    
222
    private static Result convertResult(OafProtos.Oaf oaf) {
223
        switch (oaf.getEntity().getResult().getMetadata().getResulttype().getClassid()) {
224
            case "dataset":
225
                return createDataset(oaf);
226
            case "publication":
227
                return createPublication(oaf);
228
            case "software":
229
                return createSoftware(oaf);
230
            case "other":
231
                return createORP(oaf);
232
            default:
233
                throw new RuntimeException("received unknown type: " + oaf.getEntity().getResult().getMetadata().getResulttype().getClassid());
234
        }
235
    }
236

    
237
    private static Software createSoftware(OafProtos.Oaf oaf) {
238
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
239
        Software software = setOaf(new Software(), oaf);
240
        setEntity(software, oaf);
241
        setResult(software, oaf);
242

    
243
        software.setDocumentationUrl(m.getDocumentationUrlList()
244
                .stream()
245
                .map(ProtoConverter::mapStringField)
246
                .collect(Collectors.toList()));
247
        software.setLicense(m.getLicenseList()
248
                .stream()
249
                .map(ProtoConverter::mapStructuredProperty)
250
                .collect(Collectors.toList()));
251
        software.setCodeRepositoryUrl(mapStringField(m.getCodeRepositoryUrl()));
252
        software.setProgrammingLanguage(mapQualifier(m.getProgrammingLanguage()));
253
        return software;
254
    }
255

    
256
    private static OtherResearchProduct createORP(OafProtos.Oaf oaf) {
257
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
258
        OtherResearchProduct otherResearchProducts = setOaf(new OtherResearchProduct(), oaf);
259
        setEntity(otherResearchProducts, oaf);
260
        setResult(otherResearchProducts, oaf);
261
        otherResearchProducts.setContactperson(m.getContactpersonList()
262
                .stream()
263
                .map(ProtoConverter::mapStringField)
264
                .collect(Collectors.toList()));
265
        otherResearchProducts.setContactgroup(m.getContactgroupList()
266
                .stream()
267
                .map(ProtoConverter::mapStringField)
268
                .collect(Collectors.toList()));
269
        otherResearchProducts.setTool(m.getToolList()
270
                .stream()
271
                .map(ProtoConverter::mapStringField)
272
                .collect(Collectors.toList()));
273

    
274
        return otherResearchProducts;
275
    }
276

    
277
    private static Publication createPublication(OafProtos.Oaf oaf) {
278

    
279
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
280
        Publication publication = setOaf(new Publication(), oaf);
281
        setEntity(publication, oaf);
282
        setResult(publication, oaf);
283
        publication.setJournal(mapJournal(m.getJournal()));
284
        return publication;
285
    }
286

    
287
    private static Dataset createDataset(OafProtos.Oaf oaf) {
288

    
289
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
290
        Dataset dataset = setOaf(new Dataset(), oaf);
291
        setEntity(dataset, oaf);
292
        setResult(dataset, oaf);
293
        dataset.setStoragedate(mapStringField(m.getStoragedate()));
294
        dataset.setDevice(mapStringField(m.getDevice()));
295
        dataset.setSize(mapStringField(m.getSize()));
296
        dataset.setVersion(mapStringField(m.getVersion()));
297
        dataset.setLastmetadataupdate(mapStringField(m.getLastmetadataupdate()));
298
        dataset.setMetadataversionnumber(mapStringField(m.getMetadataversionnumber()));
299
        dataset.setGeolocation(m.getGeolocationList()
300
                .stream()
301
                .map(ProtoConverter::mapGeolocation)
302
                .collect(Collectors.toList()));
303
        return dataset;
304

    
305
    }
306

    
307
    public static <T extends Oaf> T setOaf(T oaf, OafProtos.Oaf o) {
308
        oaf.setDataInfo(mapDataInfo(o.getDataInfo()));
309
        oaf.setLastupdatetimestamp(o.getLastupdatetimestamp());
310
        return oaf;
311
    }
312

    
313
    public static <T extends OafEntity> T setEntity(T entity, OafProtos.Oaf oaf) {
314
        //setting Entity fields
315
        final OafProtos.OafEntity e = oaf.getEntity();
316
        entity.setId(e.getId());
317
        entity.setOriginalId(e.getOriginalIdList());
318
        entity.setCollectedfrom(e.getCollectedfromList()
319
                .stream()
320
                .map(ProtoConverter::mapKV)
321
                .collect(Collectors.toList()));
322
        entity.setPid(e.getPidList().stream()
323
                .map(ProtoConverter::mapStructuredProperty)
324
                .collect(Collectors.toList()));
325
        entity.setDateofcollection(e.getDateofcollection());
326
        entity.setDateoftransformation(e.getDateoftransformation());
327
        entity.setExtraInfo(e.getExtraInfoList()
328
                .stream()
329
                .map(ProtoConverter::mapExtraInfo)
330
                .collect(Collectors.toList()));
331
        return entity;
332
    }
333

    
334
    public static <T extends Result> T setResult(T entity, OafProtos.Oaf oaf) {
335
        //setting Entity fields
336
        final ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
337
        entity.setAuthor(m.getAuthorList()
338
                .stream()
339
                .map(ProtoConverter::mapAuthor)
340
                .collect(Collectors.toList()));
341
        entity.setResulttype(mapQualifier(m.getResulttype()));
342
        entity.setLanguage(mapQualifier(m.getLanguage()));
343
        entity.setCountry(m.getCountryList()
344
                .stream()
345
                .map(ProtoConverter::mapQualifierAsCountry)
346
                .collect(Collectors.toList()));
347
        entity.setSubject(m.getSubjectList()
348
                .stream()
349
                .map(ProtoConverter::mapStructuredProperty)
350
                .collect(Collectors.toList()));
351
        entity.setTitle(m.getTitleList()
352
                .stream()
353
                .map(ProtoConverter::mapStructuredProperty)
354
                .collect(Collectors.toList()));
355
        entity.setRelevantdate(m.getRelevantdateList()
356
                .stream()
357
                .map(ProtoConverter::mapStructuredProperty)
358
                .collect(Collectors.toList()));
359
        entity.setDescription(m.getDescriptionList()
360
                .stream()
361
                .map(ProtoConverter::mapStringField)
362
                .collect(Collectors.toList()));
363
        entity.setDateofacceptance(mapStringField(m.getDateofacceptance()));
364
        entity.setPublisher(mapStringField(m.getPublisher()));
365
        entity.setEmbargoenddate(mapStringField(m.getEmbargoenddate()));
366
        entity.setSource(m.getSourceList()
367
                .stream()
368
                .map(ProtoConverter::mapStringField)
369
                .collect(Collectors.toList()));
370
        entity.setFulltext(m.getFulltextList()
371
                .stream()
372
                .map(ProtoConverter::mapStringField)
373
                .collect(Collectors.toList()));
374
        entity.setFormat(m.getFormatList()
375
                .stream()
376
                .map(ProtoConverter::mapStringField)
377
                .collect(Collectors.toList()));
378
        entity.setContributor(m.getContributorList()
379
                .stream()
380
                .map(ProtoConverter::mapStringField)
381
                .collect(Collectors.toList()));
382
        entity.setResourcetype(mapQualifier(m.getResourcetype()));
383
        entity.setCoverage(m.getCoverageList()
384
                .stream()
385
                .map(ProtoConverter::mapStringField)
386
                .collect(Collectors.toList()));
387
        entity.setContext(m.getContextList()
388
                .stream()
389
                .map(ProtoConverter::mapContext)
390
                .collect(Collectors.toList()));
391

    
392
        entity.setBestaccessright(getBestAccessRights(oaf.getEntity().getResult().getInstanceList()));
393

    
394
        return entity;
395
    }
396

    
397
    private static Qualifier getBestAccessRights(List<ResultProtos.Result.Instance> instanceList) {
398
        if (instanceList != null) {
399
            final Qualifier rights = mapQualifier(instanceList.stream()
400
                    .map(i -> i.getAccessright())
401
                    .sorted(new LicenseComparator())
402
                    .findFirst()
403
                    .get());
404

    
405
            if (StringUtils.isBlank(rights.getClassid())) {
406
                rights.setClassid(UNKNOWN);
407
            }
408
            if (StringUtils.isBlank(rights.getClassname()) || UNKNOWN.equalsIgnoreCase(rights.getClassname())) {
409
                rights.setClassname(NOT_AVAILABLE);
410
            }
411
            if (StringUtils.isBlank(rights.getSchemeid())) {
412
                rights.setSchemeid(DNET_ACCESS_MODES);
413
            }
414
            if (StringUtils.isBlank(rights.getSchemename())) {
415
                rights.setSchemename(DNET_ACCESS_MODES);
416
            }
417

    
418
            return rights;
419
        }
420
        return null;
421
    }
422

    
423
    private static Context mapContext(ResultProtos.Result.Context context) {
424

    
425
        final Context entity = new Context();
426
        entity.setId(context.getId());
427
        entity.setDataInfo(context.getDataInfoList()
428
                .stream()
429
                .map(ProtoConverter::mapDataInfo)
430
                .collect(Collectors.toList()));
431
        return entity;
432
    }
433

    
434

    
435
    public static KeyValue mapKV(FieldTypeProtos.KeyValue kv) {
436
        final KeyValue keyValue = new KeyValue();
437
        keyValue.setKey(kv.getKey());
438
        keyValue.setValue(kv.getValue());
439
        keyValue.setDataInfo(mapDataInfo(kv.getDataInfo()));
440
        return keyValue;
441
    }
442

    
443
    public static DataInfo mapDataInfo(FieldTypeProtos.DataInfo d) {
444
        final DataInfo dataInfo = new DataInfo();
445
        dataInfo.setDeletedbyinference(d.getDeletedbyinference());
446
        dataInfo.setInferenceprovenance(d.getInferenceprovenance());
447
        dataInfo.setInferred(d.getInferred());
448
        dataInfo.setInvisible(d.getInvisible());
449
        dataInfo.setProvenanceaction(mapQualifier(d.getProvenanceaction()));
450
        dataInfo.setTrust(d.getTrust());
451
        return dataInfo;
452
    }
453

    
454
    public static Qualifier mapQualifier(FieldTypeProtos.Qualifier q) {
455
        final Qualifier qualifier = new Qualifier();
456
        qualifier.setClassid(q.getClassid());
457
        qualifier.setClassname(q.getClassname());
458
        qualifier.setSchemeid(q.getSchemeid());
459
        qualifier.setSchemename(q.getSchemename());
460
        return qualifier;
461
    }
462

    
463
    public static Country mapQualifierAsCountry(FieldTypeProtos.Qualifier q) {
464
        final Country c = new Country();
465
        c.setClassid(q.getClassid());
466
        c.setClassname(q.getClassname());
467
        c.setSchemeid(q.getSchemeid());
468
        c.setSchemename(q.getSchemename());
469
        c.setDataInfo(mapDataInfo(q.getDataInfo()));
470
        return c;
471
    }
472

    
473
    public static StructuredProperty mapStructuredProperty(FieldTypeProtos.StructuredProperty sp) {
474
        final StructuredProperty structuredProperty = new StructuredProperty();
475
        structuredProperty.setValue(sp.getValue());
476
        structuredProperty.setQualifier(mapQualifier(sp.getQualifier()));
477
        structuredProperty.setDataInfo(mapDataInfo(sp.getDataInfo()));
478
        return structuredProperty;
479
    }
480

    
481
    public static ExtraInfo mapExtraInfo(FieldTypeProtos.ExtraInfo extraInfo) {
482
        final ExtraInfo entity = new ExtraInfo();
483
        entity.setName(extraInfo.getName());
484
        entity.setTypology(extraInfo.getTypology());
485
        entity.setProvenance(extraInfo.getProvenance());
486
        entity.setTrust(extraInfo.getTrust());
487
        entity.setValue(extraInfo.getValue());
488
        return entity;
489
    }
490

    
491
    public static OAIProvenance mapOAIProvenance(FieldTypeProtos.OAIProvenance oaiProvenance) {
492
        final OAIProvenance entity = new OAIProvenance();
493
        entity.setOriginDescription(mapOriginalDescription(oaiProvenance.getOriginDescription()));
494
        return entity;
495
    }
496

    
497
    public static OriginDescription mapOriginalDescription(FieldTypeProtos.OAIProvenance.OriginDescription originDescription) {
498
        final OriginDescription originDescriptionResult = new OriginDescription();
499
        originDescriptionResult.setHarvestDate(originDescription.getHarvestDate());
500
        originDescriptionResult.setAltered(originDescription.getAltered());
501
        originDescriptionResult.setBaseURL(originDescription.getBaseURL());
502
        originDescriptionResult.setIdentifier(originDescription.getIdentifier());
503
        originDescriptionResult.setDatestamp(originDescription.getDatestamp());
504
        originDescriptionResult.setMetadataNamespace(originDescription.getMetadataNamespace());
505
        return originDescriptionResult;
506
    }
507

    
508
    public static Field<String> mapStringField(FieldTypeProtos.StringField s) {
509
        final Field<String> stringField = new Field<>();
510
        stringField.setValue(s.getValue());
511
        stringField.setDataInfo(mapDataInfo(s.getDataInfo()));
512
        return stringField;
513
    }
514

    
515
    public static Field<Boolean> mapBoolField(FieldTypeProtos.BoolField b) {
516
        final Field<Boolean> booleanField = new Field<>();
517
        booleanField.setValue(b.getValue());
518
        booleanField.setDataInfo(mapDataInfo(b.getDataInfo()));
519
        return booleanField;
520
    }
521

    
522
    public static Field<Integer> mapIntField(FieldTypeProtos.IntField b) {
523
        final Field<Integer> entity = new Field<>();
524
        entity.setValue(b.getValue());
525
        entity.setDataInfo(mapDataInfo(b.getDataInfo()));
526
        return entity;
527
    }
528

    
529
    public static Journal mapJournal(FieldTypeProtos.Journal j) {
530
        final Journal journal = new Journal();
531
        journal.setConferencedate(j.getConferencedate());
532
        journal.setConferenceplace(j.getConferenceplace());
533
        journal.setEdition(j.getEdition());
534
        journal.setEp(j.getEp());
535
        journal.setIss(j.getIss());
536
        journal.setIssnLinking(j.getIssnLinking());
537
        journal.setIssnOnline(j.getIssnOnline());
538
        journal.setIssnPrinted(j.getIssnPrinted());
539
        journal.setName(j.getName());
540
        journal.setSp(j.getSp());
541
        journal.setVol(j.getVol());
542
        journal.setDataInfo(mapDataInfo(j.getDataInfo()));
543
        return journal;
544
    }
545

    
546
    public static Author mapAuthor(FieldTypeProtos.Author author) {
547
        final Author entity = new Author();
548
        entity.setFullname(author.getFullname());
549
        entity.setName(author.getName());
550
        entity.setSurname(author.getSurname());
551
        entity.setRank(author.getRank());
552
        entity.setPid(author.getPidList()
553
                .stream()
554
                .map(kv -> {
555
                    final StructuredProperty sp = new StructuredProperty();
556
                    sp.setValue(kv.getValue());
557
                    final Qualifier q = new Qualifier();
558
                    q.setClassid(kv.getKey());
559
                    q.setClassname(kv.getKey());
560
                    sp.setQualifier(q);
561
                    return sp;
562
                })
563
                .collect(Collectors.toList()));
564
        entity.setAffiliation(author.getAffiliationList()
565
                .stream()
566
                .map(ProtoConverter::mapStringField)
567
                .collect(Collectors.toList()));
568
        return entity;
569

    
570
    }
571

    
572
    public static GeoLocation mapGeolocation(ResultProtos.Result.GeoLocation geoLocation) {
573
        final GeoLocation entity = new GeoLocation();
574
        entity.setPoint(geoLocation.getPoint());
575
        entity.setBox(geoLocation.getBox());
576
        entity.setPlace(geoLocation.getPlace());
577
        return entity;
578
    }
579
}
(9-9/10)