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
                r.setExternalReference(convertExternalRefs(oaf));
59
                return r;
60
            case project:
61
                return convertProject(oaf);
62
            case datasource:
63
                return convertDataSource(oaf);
64
            case organization:
65
                return convertOrganization(oaf);
66
            default:
67
                throw new RuntimeException("received unknown type");
68
        }
69
    }
70

    
71
    private static List<ExternalReference> convertExternalRefs(OafProtos.Oaf oaf) {
72
        ResultProtos.Result r = oaf.getEntity().getResult();
73
        if (r.getExternalReferenceCount() > 0) {
74
            return r.getExternalReferenceList()
75
                    .stream()
76
                    .map(e -> convertExtRef(e))
77
                    .collect(Collectors.toList());
78
        }
79
        return Lists.newArrayList();
80
    }
81

    
82
    private static ExternalReference convertExtRef(ResultProtos.Result.ExternalReference e) {
83
        ExternalReference ex = new ExternalReference();
84
        ex.setUrl(e.getUrl());
85
        ex.setSitename(e.getSitename());
86
        ex.setRefidentifier(e.getRefidentifier());
87
        ex.setQuery(e.getQuery());
88
        ex.setQualifier(mapQualifier(e.getQualifier()));
89
        ex.setLabel(e.getLabel());
90
        ex.setDescription(e.getDescription());
91
        ex.setDataInfo(ex.getDataInfo());
92
        return ex;
93
    }
94

    
95
    private static List<Instance> convertInstances(OafProtos.Oaf oaf) {
96

    
97
        final ResultProtos.Result r = oaf.getEntity().getResult();
98
        if (r.getInstanceCount() > 0) {
99
            return r.getInstanceList()
100
                    .stream()
101
                    .map(i -> convertInstance(i))
102
                    .collect(Collectors.toList());
103
        }
104
        return Lists.newArrayList();
105
    }
106

    
107
    private static Instance convertInstance(ResultProtos.Result.Instance ri) {
108
        final Instance i = new Instance();
109
        i.setAccessright(mapQualifier(ri.getAccessright()));
110
        i.setCollectedfrom(mapKV(ri.getCollectedfrom()));
111
        i.setDateofacceptance(mapStringField(ri.getDateofacceptance()));
112
        i.setDistributionlocation(ri.getDistributionlocation());
113
        i.setHostedby(mapKV(ri.getHostedby()));
114
        i.setInstancetype(mapQualifier(ri.getInstancetype()));
115
        i.setLicense(mapStringField(ri.getLicense()));
116
        i.setUrl(ri.getUrlList());
117
        i.setRefereed(mapStringField(ri.getRefereed()));
118
        i.setProcessingchargeamount(mapStringField(ri.getProcessingchargeamount()));
119
        i.setProcessingchargecurrency(mapStringField(ri.getProcessingchargecurrency()));
120
        return i;
121
    }
122

    
123
    private static Organization convertOrganization(OafProtos.Oaf oaf) {
124
        final OrganizationProtos.Organization.Metadata m = oaf.getEntity().getOrganization().getMetadata();
125
        final Organization org = setOaf(new Organization(), oaf);
126
        setEntity(org, oaf);
127
        org.setLegalshortname(mapStringField(m.getLegalshortname()));
128
        org.setLegalname(mapStringField(m.getLegalname()));
129
        org.setAlternativeNames(m.getAlternativeNamesList().
130
                stream()
131
                .map(ProtoConverter::mapStringField)
132
                .collect(Collectors.toList()));
133
        org.setWebsiteurl(mapStringField(m.getWebsiteurl()));
134
        org.setLogourl(mapStringField(m.getLogourl()));
135
        org.setEclegalbody(mapStringField(m.getEclegalbody()));
136
        org.setEclegalperson(mapStringField(m.getEclegalperson()));
137
        org.setEcnonprofit(mapStringField(m.getEcnonprofit()));
138
        org.setEcresearchorganization(mapStringField(m.getEcresearchorganization()));
139
        org.setEchighereducation(mapStringField(m.getEchighereducation()));
140
        org.setEcinternationalorganizationeurinterests(mapStringField(m.getEcinternationalorganizationeurinterests()));
141
        org.setEcinternationalorganization(mapStringField(m.getEcinternationalorganization()));
142
        org.setEcenterprise(mapStringField(m.getEcenterprise()));
143
        org.setEcsmevalidated(mapStringField(m.getEcsmevalidated()));
144
        org.setEcnutscode(mapStringField(m.getEcnutscode()));
145
        org.setCountry(mapQualifier(m.getCountry()));
146

    
147
        return org;
148
    }
149

    
150
    private static Datasource convertDataSource(OafProtos.Oaf oaf) {
151
        final DatasourceProtos.Datasource.Metadata m = oaf.getEntity().getDatasource().getMetadata();
152
        final Datasource datasource = setOaf(new Datasource(), oaf);
153
        setEntity(datasource, oaf);
154
        datasource.setAccessinfopackage(m.getAccessinfopackageList()
155
                .stream()
156
                .map(ProtoConverter::mapStringField)
157
                .collect(Collectors.toList()));
158
        datasource.setCertificates(mapStringField(m.getCertificates()));
159
        datasource.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()));
160
        datasource.setContactemail(mapStringField(m.getContactemail()));
161
        datasource.setDatabaseaccessrestriction(mapStringField(m.getDatabaseaccessrestriction()));
162
        datasource.setDatabaseaccesstype(mapStringField(m.getDatabaseaccesstype()));
163
        datasource.setDataprovider(mapBoolField(m.getDataprovider()));
164
        datasource.setDatasourcetype(mapQualifier(m.getDatasourcetype()));
165
        datasource.setDatauploadrestriction(mapStringField(m.getDatauploadrestriction()));
166
        datasource.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()));
167
        datasource.setDatauploadtype(mapStringField(m.getDatauploadtype()));
168
        datasource.setDateofvalidation(mapStringField(m.getDateofvalidation()));
169
        datasource.setDescription(mapStringField(m.getDescription()));
170
        datasource.setEnglishname(mapStringField(m.getEnglishname()));
171
        datasource.setLatitude(mapStringField(m.getLatitude()));
172
        datasource.setLongitude(mapStringField(m.getLongitude()));
173
        datasource.setLogourl(mapStringField(m.getLogourl()));
174
        datasource.setMissionstatementurl(mapStringField(m.getMissionstatementurl()));
175
        datasource.setNamespaceprefix(mapStringField(m.getNamespaceprefix()));
176
        datasource.setOdcontenttypes(m.getOdcontenttypesList()
177
                .stream()
178
                .map(ProtoConverter::mapStringField)
179
                .collect(Collectors.toList()));
180
        datasource.setOdlanguages(m.getOdlanguagesList()
181
                .stream()
182
                .map(ProtoConverter::mapStringField)
183
                .collect(Collectors.toList()));
184
        datasource.setOdnumberofitems(mapStringField(m.getOdnumberofitems()));
185
        datasource.setOdnumberofitemsdate(mapStringField(m.getOdnumberofitemsdate()));
186
        datasource.setOdpolicies(mapStringField(m.getOdpolicies()));
187
        datasource.setOfficialname(mapStringField(m.getOfficialname()));
188
        datasource.setOpenairecompatibility(mapQualifier(m.getOpenairecompatibility()));
189
        datasource.setPidsystems(mapStringField(m.getPidsystems()));
190
        datasource.setPolicies(m.getPoliciesList()
191
                .stream()
192
                .map(ProtoConverter::mapKV)
193
                .collect(Collectors.toList()));
194
        datasource.setQualitymanagementkind(mapStringField(m.getQualitymanagementkind()));
195
        datasource.setReleaseenddate(mapStringField(m.getReleaseenddate()));
196
        datasource.setServiceprovider(mapBoolField(m.getServiceprovider()));
197
        datasource.setReleasestartdate(mapStringField(m.getReleasestartdate()));
198
        datasource.setSubjects(m.getSubjectsList()
199
                .stream()
200
                .map(ProtoConverter::mapStructuredProperty)
201
                .collect(Collectors.toList()));
202
        datasource.setVersioning(mapBoolField(m.getVersioning()));
203
        datasource.setWebsiteurl(mapStringField(m.getWebsiteurl()));
204
        datasource.setJournal(mapJournal(m.getJournal()));
205

    
206

    
207
        return datasource;
208
    }
209

    
210
    private static Project convertProject(OafProtos.Oaf oaf) {
211
        final ProjectProtos.Project.Metadata m = oaf.getEntity().getProject().getMetadata();
212
        final Project project = setOaf(new Project(), oaf);
213
        setEntity(project, oaf);
214
        project.setAcronym(mapStringField(m.getAcronym()));
215
        project.setCallidentifier(mapStringField(m.getCallidentifier()));
216
        project.setCode(mapStringField(m.getCode()));
217
        project.setContactemail(mapStringField(m.getContactemail()));
218
        project.setContactfax(mapStringField(m.getContactfax()));
219
        project.setContactfullname(mapStringField(m.getContactfullname()));
220
        project.setContactphone(mapStringField(m.getContactphone()));
221
        project.setContracttype(mapQualifier(m.getContracttype()));
222
        project.setCurrency(mapStringField(m.getCurrency()));
223
        project.setDuration(mapStringField(m.getDuration()));
224
        project.setEcarticle29_3(mapStringField(m.getEcarticle293()));
225
        project.setEcsc39(mapStringField(m.getEcsc39()));
226
        project.setOamandatepublications(mapStringField(m.getOamandatepublications()));
227
        project.setStartdate(mapStringField(m.getStartdate()));
228
        project.setEnddate(mapStringField(m.getEnddate()));
229
        project.setFundedamount(m.getFundedamount());
230
        project.setTotalcost(m.getTotalcost());
231
        project.setKeywords(mapStringField(m.getKeywords()));
232
        project.setSubjects(m.getSubjectsList().stream()
233
                .map(sp -> mapStructuredProperty(sp))
234
                .collect(Collectors.toList()));
235
        project.setTitle(mapStringField(m.getTitle()));
236
        project.setWebsiteurl(mapStringField(m.getWebsiteurl()));
237
        project.setFundingtree(m.getFundingtreeList().stream()
238
                .map(f -> mapStringField(f))
239
                .collect(Collectors.toList()));
240
        project.setJsonextrainfo(mapStringField(m.getJsonextrainfo()));
241
        project.setSummary(mapStringField(m.getSummary()));
242
        project.setOptional1(mapStringField(m.getOptional1()));
243
        project.setOptional2(mapStringField(m.getOptional2()));
244
        return project;
245
    }
246

    
247
    private static Result convertResult(OafProtos.Oaf oaf) {
248
        switch (oaf.getEntity().getResult().getMetadata().getResulttype().getClassid()) {
249
            case "dataset":
250
                return createDataset(oaf);
251
            case "publication":
252
                return createPublication(oaf);
253
            case "software":
254
                return createSoftware(oaf);
255
            case "other":
256
                return createORP(oaf);
257
            default:
258
                throw new RuntimeException("received unknown type: " + oaf.getEntity().getResult().getMetadata().getResulttype().getClassid());
259
        }
260
    }
261

    
262
    private static Software createSoftware(OafProtos.Oaf oaf) {
263
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
264
        Software software = setOaf(new Software(), oaf);
265
        setEntity(software, oaf);
266
        setResult(software, oaf);
267

    
268
        software.setDocumentationUrl(m.getDocumentationUrlList()
269
                .stream()
270
                .map(ProtoConverter::mapStringField)
271
                .collect(Collectors.toList()));
272
        software.setLicense(m.getLicenseList()
273
                .stream()
274
                .map(ProtoConverter::mapStructuredProperty)
275
                .collect(Collectors.toList()));
276
        software.setCodeRepositoryUrl(mapStringField(m.getCodeRepositoryUrl()));
277
        software.setProgrammingLanguage(mapQualifier(m.getProgrammingLanguage()));
278
        return software;
279
    }
280

    
281
    private static OtherResearchProduct createORP(OafProtos.Oaf oaf) {
282
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
283
        OtherResearchProduct otherResearchProducts = setOaf(new OtherResearchProduct(), oaf);
284
        setEntity(otherResearchProducts, oaf);
285
        setResult(otherResearchProducts, oaf);
286
        otherResearchProducts.setContactperson(m.getContactpersonList()
287
                .stream()
288
                .map(ProtoConverter::mapStringField)
289
                .collect(Collectors.toList()));
290
        otherResearchProducts.setContactgroup(m.getContactgroupList()
291
                .stream()
292
                .map(ProtoConverter::mapStringField)
293
                .collect(Collectors.toList()));
294
        otherResearchProducts.setTool(m.getToolList()
295
                .stream()
296
                .map(ProtoConverter::mapStringField)
297
                .collect(Collectors.toList()));
298

    
299
        return otherResearchProducts;
300
    }
301

    
302
    private static Publication createPublication(OafProtos.Oaf oaf) {
303

    
304
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
305
        Publication publication = setOaf(new Publication(), oaf);
306
        setEntity(publication, oaf);
307
        setResult(publication, oaf);
308
        publication.setJournal(mapJournal(m.getJournal()));
309
        return publication;
310
    }
311

    
312
    private static Dataset createDataset(OafProtos.Oaf oaf) {
313

    
314
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
315
        Dataset dataset = setOaf(new Dataset(), oaf);
316
        setEntity(dataset, oaf);
317
        setResult(dataset, oaf);
318
        dataset.setStoragedate(mapStringField(m.getStoragedate()));
319
        dataset.setDevice(mapStringField(m.getDevice()));
320
        dataset.setSize(mapStringField(m.getSize()));
321
        dataset.setVersion(mapStringField(m.getVersion()));
322
        dataset.setLastmetadataupdate(mapStringField(m.getLastmetadataupdate()));
323
        dataset.setMetadataversionnumber(mapStringField(m.getMetadataversionnumber()));
324
        dataset.setGeolocation(m.getGeolocationList()
325
                .stream()
326
                .map(ProtoConverter::mapGeolocation)
327
                .collect(Collectors.toList()));
328
        return dataset;
329

    
330
    }
331

    
332
    public static <T extends Oaf> T setOaf(T oaf, OafProtos.Oaf o) {
333
        oaf.setDataInfo(mapDataInfo(o.getDataInfo()));
334
        oaf.setLastupdatetimestamp(o.getLastupdatetimestamp());
335
        return oaf;
336
    }
337

    
338
    public static <T extends OafEntity> T setEntity(T entity, OafProtos.Oaf oaf) {
339
        //setting Entity fields
340
        final OafProtos.OafEntity e = oaf.getEntity();
341
        entity.setId(e.getId());
342
        entity.setOriginalId(e.getOriginalIdList());
343
        entity.setCollectedfrom(e.getCollectedfromList()
344
                .stream()
345
                .map(ProtoConverter::mapKV)
346
                .collect(Collectors.toList()));
347
        entity.setPid(e.getPidList().stream()
348
                .map(ProtoConverter::mapStructuredProperty)
349
                .collect(Collectors.toList()));
350
        entity.setDateofcollection(e.getDateofcollection());
351
        entity.setDateoftransformation(e.getDateoftransformation());
352
        entity.setExtraInfo(e.getExtraInfoList()
353
                .stream()
354
                .map(ProtoConverter::mapExtraInfo)
355
                .collect(Collectors.toList()));
356
        return entity;
357
    }
358

    
359
    public static <T extends Result> T setResult(T entity, OafProtos.Oaf oaf) {
360
        //setting Entity fields
361
        final ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
362
        entity.setAuthor(m.getAuthorList()
363
                .stream()
364
                .map(ProtoConverter::mapAuthor)
365
                .collect(Collectors.toList()));
366
        entity.setResulttype(mapQualifier(m.getResulttype()));
367
        entity.setLanguage(mapQualifier(m.getLanguage()));
368
        entity.setCountry(m.getCountryList()
369
                .stream()
370
                .map(ProtoConverter::mapQualifierAsCountry)
371
                .collect(Collectors.toList()));
372
        entity.setSubject(m.getSubjectList()
373
                .stream()
374
                .map(ProtoConverter::mapStructuredProperty)
375
                .collect(Collectors.toList()));
376
        entity.setTitle(m.getTitleList()
377
                .stream()
378
                .map(ProtoConverter::mapStructuredProperty)
379
                .collect(Collectors.toList()));
380
        entity.setRelevantdate(m.getRelevantdateList()
381
                .stream()
382
                .map(ProtoConverter::mapStructuredProperty)
383
                .collect(Collectors.toList()));
384
        entity.setDescription(m.getDescriptionList()
385
                .stream()
386
                .map(ProtoConverter::mapStringField)
387
                .collect(Collectors.toList()));
388
        entity.setDateofacceptance(mapStringField(m.getDateofacceptance()));
389
        entity.setPublisher(mapStringField(m.getPublisher()));
390
        entity.setEmbargoenddate(mapStringField(m.getEmbargoenddate()));
391
        entity.setSource(m.getSourceList()
392
                .stream()
393
                .map(ProtoConverter::mapStringField)
394
                .collect(Collectors.toList()));
395
        entity.setFulltext(m.getFulltextList()
396
                .stream()
397
                .map(ProtoConverter::mapStringField)
398
                .collect(Collectors.toList()));
399
        entity.setFormat(m.getFormatList()
400
                .stream()
401
                .map(ProtoConverter::mapStringField)
402
                .collect(Collectors.toList()));
403
        entity.setContributor(m.getContributorList()
404
                .stream()
405
                .map(ProtoConverter::mapStringField)
406
                .collect(Collectors.toList()));
407
        entity.setResourcetype(mapQualifier(m.getResourcetype()));
408
        entity.setCoverage(m.getCoverageList()
409
                .stream()
410
                .map(ProtoConverter::mapStringField)
411
                .collect(Collectors.toList()));
412
        entity.setContext(m.getContextList()
413
                .stream()
414
                .map(ProtoConverter::mapContext)
415
                .collect(Collectors.toList()));
416

    
417
        entity.setBestaccessright(getBestAccessRights(oaf.getEntity().getResult().getInstanceList()));
418

    
419
        return entity;
420
    }
421

    
422
    private static Qualifier getBestAccessRights(List<ResultProtos.Result.Instance> instanceList) {
423
        if (instanceList != null) {
424
            final Qualifier rights = mapQualifier(instanceList.stream()
425
                    .map(i -> i.getAccessright())
426
                    .sorted(new LicenseComparator())
427
                    .findFirst()
428
                    .get());
429

    
430
            if (StringUtils.isBlank(rights.getClassid())) {
431
                rights.setClassid(UNKNOWN);
432
            }
433
            if (StringUtils.isBlank(rights.getClassname()) || UNKNOWN.equalsIgnoreCase(rights.getClassname())) {
434
                rights.setClassname(NOT_AVAILABLE);
435
            }
436
            if (StringUtils.isBlank(rights.getSchemeid())) {
437
                rights.setSchemeid(DNET_ACCESS_MODES);
438
            }
439
            if (StringUtils.isBlank(rights.getSchemename())) {
440
                rights.setSchemename(DNET_ACCESS_MODES);
441
            }
442

    
443
            return rights;
444
        }
445
        return null;
446
    }
447

    
448
    private static Context mapContext(ResultProtos.Result.Context context) {
449

    
450
        final Context entity = new Context();
451
        entity.setId(context.getId());
452
        entity.setDataInfo(context.getDataInfoList()
453
                .stream()
454
                .map(ProtoConverter::mapDataInfo)
455
                .collect(Collectors.toList()));
456
        return entity;
457
    }
458

    
459

    
460
    public static KeyValue mapKV(FieldTypeProtos.KeyValue kv) {
461
        final KeyValue keyValue = new KeyValue();
462
        keyValue.setKey(kv.getKey());
463
        keyValue.setValue(kv.getValue());
464
        keyValue.setDataInfo(mapDataInfo(kv.getDataInfo()));
465
        return keyValue;
466
    }
467

    
468
    public static DataInfo mapDataInfo(FieldTypeProtos.DataInfo d) {
469
        final DataInfo dataInfo = new DataInfo();
470
        dataInfo.setDeletedbyinference(d.getDeletedbyinference());
471
        dataInfo.setInferenceprovenance(d.getInferenceprovenance());
472
        dataInfo.setInferred(d.getInferred());
473
        dataInfo.setInvisible(d.getInvisible());
474
        dataInfo.setProvenanceaction(mapQualifier(d.getProvenanceaction()));
475
        dataInfo.setTrust(d.getTrust());
476
        return dataInfo;
477
    }
478

    
479
    public static Qualifier mapQualifier(FieldTypeProtos.Qualifier q) {
480
        final Qualifier qualifier = new Qualifier();
481
        qualifier.setClassid(q.getClassid());
482
        qualifier.setClassname(q.getClassname());
483
        qualifier.setSchemeid(q.getSchemeid());
484
        qualifier.setSchemename(q.getSchemename());
485
        return qualifier;
486
    }
487

    
488
    public static Country mapQualifierAsCountry(FieldTypeProtos.Qualifier q) {
489
        final Country c = new Country();
490
        c.setClassid(q.getClassid());
491
        c.setClassname(q.getClassname());
492
        c.setSchemeid(q.getSchemeid());
493
        c.setSchemename(q.getSchemename());
494
        c.setDataInfo(mapDataInfo(q.getDataInfo()));
495
        return c;
496
    }
497

    
498
    public static StructuredProperty mapStructuredProperty(FieldTypeProtos.StructuredProperty sp) {
499
        final StructuredProperty structuredProperty = new StructuredProperty();
500
        structuredProperty.setValue(sp.getValue());
501
        structuredProperty.setQualifier(mapQualifier(sp.getQualifier()));
502
        structuredProperty.setDataInfo(mapDataInfo(sp.getDataInfo()));
503
        return structuredProperty;
504
    }
505

    
506
    public static ExtraInfo mapExtraInfo(FieldTypeProtos.ExtraInfo extraInfo) {
507
        final ExtraInfo entity = new ExtraInfo();
508
        entity.setName(extraInfo.getName());
509
        entity.setTypology(extraInfo.getTypology());
510
        entity.setProvenance(extraInfo.getProvenance());
511
        entity.setTrust(extraInfo.getTrust());
512
        entity.setValue(extraInfo.getValue());
513
        return entity;
514
    }
515

    
516
    public static OAIProvenance mapOAIProvenance(FieldTypeProtos.OAIProvenance oaiProvenance) {
517
        final OAIProvenance entity = new OAIProvenance();
518
        entity.setOriginDescription(mapOriginalDescription(oaiProvenance.getOriginDescription()));
519
        return entity;
520
    }
521

    
522
    public static OriginDescription mapOriginalDescription(FieldTypeProtos.OAIProvenance.OriginDescription originDescription) {
523
        final OriginDescription originDescriptionResult = new OriginDescription();
524
        originDescriptionResult.setHarvestDate(originDescription.getHarvestDate());
525
        originDescriptionResult.setAltered(originDescription.getAltered());
526
        originDescriptionResult.setBaseURL(originDescription.getBaseURL());
527
        originDescriptionResult.setIdentifier(originDescription.getIdentifier());
528
        originDescriptionResult.setDatestamp(originDescription.getDatestamp());
529
        originDescriptionResult.setMetadataNamespace(originDescription.getMetadataNamespace());
530
        return originDescriptionResult;
531
    }
532

    
533
    public static Field<String> mapStringField(FieldTypeProtos.StringField s) {
534
        final Field<String> stringField = new Field<>();
535
        stringField.setValue(s.getValue());
536
        stringField.setDataInfo(mapDataInfo(s.getDataInfo()));
537
        return stringField;
538
    }
539

    
540
    public static Field<Boolean> mapBoolField(FieldTypeProtos.BoolField b) {
541
        final Field<Boolean> booleanField = new Field<>();
542
        booleanField.setValue(b.getValue());
543
        booleanField.setDataInfo(mapDataInfo(b.getDataInfo()));
544
        return booleanField;
545
    }
546

    
547
    public static Field<Integer> mapIntField(FieldTypeProtos.IntField b) {
548
        final Field<Integer> entity = new Field<>();
549
        entity.setValue(b.getValue());
550
        entity.setDataInfo(mapDataInfo(b.getDataInfo()));
551
        return entity;
552
    }
553

    
554
    public static Journal mapJournal(FieldTypeProtos.Journal j) {
555
        final Journal journal = new Journal();
556
        journal.setConferencedate(j.getConferencedate());
557
        journal.setConferenceplace(j.getConferenceplace());
558
        journal.setEdition(j.getEdition());
559
        journal.setEp(j.getEp());
560
        journal.setIss(j.getIss());
561
        journal.setIssnLinking(j.getIssnLinking());
562
        journal.setIssnOnline(j.getIssnOnline());
563
        journal.setIssnPrinted(j.getIssnPrinted());
564
        journal.setName(j.getName());
565
        journal.setSp(j.getSp());
566
        journal.setVol(j.getVol());
567
        journal.setDataInfo(mapDataInfo(j.getDataInfo()));
568
        return journal;
569
    }
570

    
571
    public static Author mapAuthor(FieldTypeProtos.Author author) {
572
        final Author entity = new Author();
573
        entity.setFullname(author.getFullname());
574
        entity.setName(author.getName());
575
        entity.setSurname(author.getSurname());
576
        entity.setRank(author.getRank());
577
        entity.setPid(author.getPidList()
578
                .stream()
579
                .map(kv -> {
580
                    final StructuredProperty sp = new StructuredProperty();
581
                    sp.setValue(kv.getValue());
582
                    final Qualifier q = new Qualifier();
583
                    q.setClassid(kv.getKey());
584
                    q.setClassname(kv.getKey());
585
                    sp.setQualifier(q);
586
                    return sp;
587
                })
588
                .collect(Collectors.toList()));
589
        entity.setAffiliation(author.getAffiliationList()
590
                .stream()
591
                .map(ProtoConverter::mapStringField)
592
                .collect(Collectors.toList()));
593
        return entity;
594

    
595
    }
596

    
597
    public static GeoLocation mapGeolocation(ResultProtos.Result.GeoLocation geoLocation) {
598
        final GeoLocation entity = new GeoLocation();
599
        entity.setPoint(geoLocation.getPoint());
600
        entity.setBox(geoLocation.getBox());
601
        entity.setPlace(geoLocation.getPlace());
602
        return entity;
603
    }
604
}
(9-9/10)