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

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

    
13
public class ProtoConverter implements Serializable {
14

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

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

    
47
    private static OafEntity convertEntity(OafProtos.Oaf oaf) {
48

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

    
65
    private static List<Instance> convertInstances(OafProtos.Oaf oaf) {
66

    
67
        final ResultProtos.Result r = oaf.getEntity().getResult();
68
        if (r.getInstanceCount() > 0) {
69
            return r.getInstanceList()
70
                    .stream()
71
                    .map(i -> convertInstance(i))
72
                    .collect(Collectors.toList());
73
        }
74
        return Lists.newArrayList();
75
    }
76

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

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

    
117
        return org;
118
    }
119

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

    
176

    
177
        return datasource;
178
    }
179

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

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

    
232
    private static Software createSoftware(OafProtos.Oaf oaf) {
233
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
234
        Software software = setOaf(new Software(), oaf);
235
        setEntity(software, oaf);
236
        setResult(software, oaf);
237

    
238
        software.setDocumentationUrl(m.getDocumentationUrlList()
239
                .stream()
240
                .map(ProtoConverter::mapStringField)
241
                .collect(Collectors.toList()));
242
        software.setLicense(m.getLicenseList()
243
                .stream()
244
                .map(ProtoConverter::mapStructuredProperty)
245
                .collect(Collectors.toList()));
246
        software.setCodeRepositoryUrl(mapStringField(m.getCodeRepositoryUrl()));
247
        software.setProgrammingLanguage(mapQualifier(m.getProgrammingLanguage()));
248
        return software;
249
    }
250

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

    
269
        return otherResearchProducts;
270
    }
271

    
272
    private static Publication createPublication(OafProtos.Oaf oaf) {
273

    
274
        ResultProtos.Result.Metadata m = oaf.getEntity().getResult().getMetadata();
275
        Publication publication = setOaf(new Publication(), oaf);
276
        setEntity(publication, oaf);
277
        setResult(publication, oaf);
278
        publication.setJournal(mapJournal(m.getJournal()));
279
        return publication;
280
    }
281

    
282
    private static Dataset createDataset(OafProtos.Oaf oaf) {
283

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

    
300
    }
301

    
302
    public static <T extends Oaf> T setOaf(T oaf, OafProtos.Oaf o) {
303
        oaf.setDataInfo(mapDataInfo(o.getDataInfo()));
304
        oaf.setLastupdatetimestamp(o.getLastupdatetimestamp());
305
        return oaf;
306
    }
307

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

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

    
387
        entity.setBestaccessright(getBestAccessRights(oaf.getEntity().getResult().getInstanceList()));
388

    
389
        return entity;
390
    }
391

    
392
    private static Qualifier getBestAccessRights(List<ResultProtos.Result.Instance> instanceList) {
393
        if (instanceList != null) {
394
            return mapQualifier(instanceList.stream()
395
                    .map(i -> i.getAccessright())
396
                    .sorted(new LicenseComparator())
397
                    .findFirst()
398
                    .get());
399
        }
400
        return null;
401
    }
402

    
403
    private static Context mapContext(ResultProtos.Result.Context context) {
404

    
405
        final Context entity = new Context();
406
        entity.setId(context.getId());
407
        entity.setDataInfo(context.getDataInfoList()
408
                .stream()
409
                .map(ProtoConverter::mapDataInfo)
410
                .collect(Collectors.toList()));
411
        return entity;
412
    }
413

    
414

    
415
    public static KeyValue mapKV(FieldTypeProtos.KeyValue kv) {
416
        final KeyValue keyValue = new KeyValue();
417
        keyValue.setKey(kv.getKey());
418
        keyValue.setValue(kv.getValue());
419
        keyValue.setDataInfo(mapDataInfo(kv.getDataInfo()));
420
        return keyValue;
421
    }
422

    
423
    public static DataInfo mapDataInfo(FieldTypeProtos.DataInfo d) {
424
        final DataInfo dataInfo = new DataInfo();
425
        dataInfo.setDeletedbyinference(d.getDeletedbyinference());
426
        dataInfo.setInferenceprovenance(d.getInferenceprovenance());
427
        dataInfo.setInferred(d.getInferred());
428
        dataInfo.setInvisible(d.getInvisible());
429
        dataInfo.setProvenanceaction(mapQualifier(d.getProvenanceaction()));
430
        dataInfo.setTrust(d.getTrust());
431
        return dataInfo;
432
    }
433

    
434
    public static Qualifier mapQualifier(FieldTypeProtos.Qualifier q) {
435
        final Qualifier qualifier = new Qualifier();
436
        qualifier.setClassid(q.getClassid());
437
        qualifier.setClassname(q.getClassname());
438
        qualifier.setSchemeid(q.getSchemeid());
439
        qualifier.setSchemename(q.getSchemename());
440
        return qualifier;
441
    }
442

    
443
    public static Country mapQualifierAsCountry(FieldTypeProtos.Qualifier q) {
444
        final Country c = new Country();
445
        c.setClassid(q.getClassid());
446
        c.setClassname(q.getClassname());
447
        c.setSchemeid(q.getSchemeid());
448
        c.setSchemename(q.getSchemename());
449
        c.setDataInfo(mapDataInfo(q.getDataInfo()));
450
        return c;
451
    }
452

    
453
    public static StructuredProperty mapStructuredProperty(FieldTypeProtos.StructuredProperty sp) {
454
        final StructuredProperty structuredProperty = new StructuredProperty();
455
        structuredProperty.setValue(sp.getValue());
456
        structuredProperty.setQualifier(mapQualifier(sp.getQualifier()));
457
        structuredProperty.setDataInfo(mapDataInfo(sp.getDataInfo()));
458
        return structuredProperty;
459
    }
460

    
461
    public static ExtraInfo mapExtraInfo(FieldTypeProtos.ExtraInfo extraInfo) {
462
        final ExtraInfo entity = new ExtraInfo();
463
        entity.setName(extraInfo.getName());
464
        entity.setTypology(extraInfo.getTypology());
465
        entity.setProvenance(extraInfo.getProvenance());
466
        entity.setTrust(extraInfo.getTrust());
467
        entity.setValue(extraInfo.getValue());
468
        return entity;
469
    }
470

    
471
    public static OAIProvenance mapOAIProvenance(FieldTypeProtos.OAIProvenance oaiProvenance) {
472
        final OAIProvenance entity = new OAIProvenance();
473
        entity.setOriginDescription(mapOriginalDescription(oaiProvenance.getOriginDescription()));
474
        return entity;
475
    }
476

    
477
    public static OriginDescription mapOriginalDescription(FieldTypeProtos.OAIProvenance.OriginDescription originDescription) {
478
        final OriginDescription originDescriptionResult = new OriginDescription();
479
        originDescriptionResult.setHarvestDate(originDescription.getHarvestDate());
480
        originDescriptionResult.setAltered(originDescription.getAltered());
481
        originDescriptionResult.setBaseURL(originDescription.getBaseURL());
482
        originDescriptionResult.setIdentifier(originDescription.getIdentifier());
483
        originDescriptionResult.setDatestamp(originDescription.getDatestamp());
484
        originDescriptionResult.setMetadataNamespace(originDescription.getMetadataNamespace());
485
        return originDescriptionResult;
486
    }
487

    
488
    public static Field<String> mapStringField(FieldTypeProtos.StringField s) {
489
        final Field<String> stringField = new Field<>();
490
        stringField.setValue(s.getValue());
491
        stringField.setDataInfo(mapDataInfo(s.getDataInfo()));
492
        return stringField;
493
    }
494

    
495
    public static Field<Boolean> mapBoolField(FieldTypeProtos.BoolField b) {
496
        final Field<Boolean> booleanField = new Field<>();
497
        booleanField.setValue(b.getValue());
498
        booleanField.setDataInfo(mapDataInfo(b.getDataInfo()));
499
        return booleanField;
500
    }
501

    
502
    public static Field<Integer> mapIntField(FieldTypeProtos.IntField b) {
503
        final Field<Integer> entity = new Field<>();
504
        entity.setValue(b.getValue());
505
        entity.setDataInfo(mapDataInfo(b.getDataInfo()));
506
        return entity;
507
    }
508

    
509
    public static Journal mapJournal(FieldTypeProtos.Journal j) {
510
        final Journal journal = new Journal();
511
        journal.setConferencedate(j.getConferencedate());
512
        journal.setConferenceplace(j.getConferenceplace());
513
        journal.setEdition(j.getEdition());
514
        journal.setEp(j.getEp());
515
        journal.setIss(j.getIss());
516
        journal.setIssnLinking(j.getIssnLinking());
517
        journal.setIssnOnline(j.getIssnOnline());
518
        journal.setIssnPrinted(j.getIssnPrinted());
519
        journal.setName(j.getName());
520
        journal.setSp(j.getSp());
521
        journal.setVol(j.getVol());
522
        journal.setDataInfo(mapDataInfo(j.getDataInfo()));
523
        return journal;
524
    }
525

    
526
    public static Author mapAuthor(FieldTypeProtos.Author author) {
527
        final Author entity = new Author();
528
        entity.setFullname(author.getFullname());
529
        entity.setName(author.getName());
530
        entity.setSurname(author.getSurname());
531
        entity.setRank(author.getRank());
532
        entity.setPid(author.getPidList()
533
                .stream()
534
                .map(kv -> {
535
                    final StructuredProperty sp = new StructuredProperty();
536
                    sp.setValue(kv.getValue());
537
                    final Qualifier q = new Qualifier();
538
                    q.setClassid(kv.getKey());
539
                    q.setClassname(kv.getKey());
540
                    sp.setQualifier(q);
541
                    return sp;
542
                })
543
                .collect(Collectors.toList()));
544
        entity.setAffiliation(author.getAffiliationList()
545
                .stream()
546
                .map(ProtoConverter::mapStringField)
547
                .collect(Collectors.toList()));
548
        return entity;
549

    
550
    }
551

    
552
    public static GeoLocation mapGeolocation(ResultProtos.Result.GeoLocation geoLocation) {
553
        final GeoLocation entity = new GeoLocation();
554
        entity.setPoint(geoLocation.getPoint());
555
        entity.setBox(geoLocation.getBox());
556
        entity.setPlace(geoLocation.getPlace());
557
        return entity;
558
    }
559
}
(9-9/10)