Revision 49096
Added by Claudio Atzori over 6 years ago
ProtoMapping.java | ||
---|---|---|
3 | 3 |
import java.io.StringReader; |
4 | 4 |
import java.util.List; |
5 | 5 |
import java.util.Map; |
6 |
import java.util.Set;
|
|
6 |
import java.util.stream.Collectors;
|
|
7 | 7 |
|
8 |
import com.google.common.base.Function; |
|
9 | 8 |
import com.google.common.collect.Iterables; |
10 |
import com.google.common.collect.Lists; |
|
11 | 9 |
import com.google.common.collect.Maps; |
12 |
import com.google.common.collect.Sets; |
|
13 | 10 |
import eu.dnetlib.broker.objects.*; |
14 | 11 |
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty; |
15 | 12 |
import eu.dnetlib.data.proto.OafProtos.Oaf; |
... | ... | |
31 | 28 |
public abstract class ProtoMapping { |
32 | 29 |
|
33 | 30 |
protected static List<Instance> mapInstances(final List<Result.Instance> in) { |
34 |
final Set<Instance> instances = Sets.newHashSet(Iterables.transform(in, new Function<Result.Instance, Instance>() { |
|
35 |
|
|
36 |
@Override |
|
37 |
public Instance apply(final Result.Instance i) { |
|
38 |
return new Instance() |
|
31 |
return in.stream() |
|
32 |
.map(i -> new Instance() |
|
39 | 33 |
.setHostedby(getValue(i.getHostedby())) |
40 | 34 |
.setInstancetype(getValue(i.getInstancetype())) |
41 |
.setLicense(getKey(i.getLicence())) |
|
42 |
.setUrl(Iterables.getFirst(i.getUrlList(), "")); |
|
43 |
} |
|
44 |
})); |
|
45 |
return Lists.newArrayList(instances); |
|
35 |
.setLicense(getKey(i.getAccessright())) |
|
36 |
.setUrl(Iterables.getFirst(i.getUrlList(), ""))) |
|
37 |
.collect(Collectors.toList()); |
|
46 | 38 |
} |
47 | 39 |
|
48 | 40 |
protected static List<Pid> mapPids(final List<StructuredProperty> sp) { |
49 |
return Lists.newArrayList(Iterables.transform(sp, new Function<StructuredProperty, Pid>() { |
|
50 |
|
|
51 |
@Override |
|
52 |
public Pid apply(final StructuredProperty sp) { |
|
53 |
return new Pid().setType(sp.getQualifier().getClassid()).setValue(sp.getValue()); |
|
54 |
} |
|
55 |
})); |
|
41 |
return sp.stream() |
|
42 |
.map(s -> new Pid().setType(s.getQualifier().getClassid()).setValue(s.getValue())) |
|
43 |
.collect(Collectors.toList()); |
|
56 | 44 |
} |
57 | 45 |
|
58 | 46 |
protected static Journal mapJournal(final ResultProtos.Result.Journal j) { |
... | ... | |
64 | 52 |
} |
65 | 53 |
|
66 | 54 |
protected static List<ExternalReference> mapExternalRefs(final List<Result.ExternalReference> ext) { |
67 |
return Lists.newArrayList(Iterables.transform(ext, new Function<Result.ExternalReference, ExternalReference>() { |
|
68 |
|
|
69 |
@Override |
|
70 |
public ExternalReference apply(final Result.ExternalReference e) { |
|
71 |
return new ExternalReference() |
|
55 |
return ext.stream() |
|
56 |
.map(e -> new ExternalReference() |
|
72 | 57 |
.setUrl(e.getUrl()) |
73 | 58 |
.setType(getKey(e.getQualifier())) |
74 | 59 |
.setRefidentifier(e.getRefidentifier()) |
75 |
.setSitename(e.getSitename()); |
|
76 |
} |
|
77 |
})); |
|
60 |
.setSitename(e.getSitename())) |
|
61 |
.collect(Collectors.toList()); |
|
78 | 62 |
} |
79 | 63 |
|
80 | 64 |
protected static final List<Project> mapRelatedProjects(final OafEntity entity) { |
... | ... | |
85 | 69 |
projectMap.put(p.getId(), Oaf.newBuilder(rel).build()); |
86 | 70 |
} |
87 | 71 |
|
88 |
return Lists.transform(Lists.newArrayList(projectMap.values()), getProjectMappingFunction()); |
|
72 |
return projectMap.values().stream() |
|
73 |
.map(o -> mapRelatedProject(o.getRel().getCachedOafTarget().getEntity().getProject())) |
|
74 |
.collect(Collectors.toList()); |
|
89 | 75 |
} |
90 | 76 |
|
91 | 77 |
protected static final Project mapRelatedProject(final ProjectProtos.Project project) { |
... | ... | |
111 | 97 |
return p; |
112 | 98 |
} |
113 | 99 |
|
114 |
private static Function<Oaf, Project> getProjectMappingFunction() { |
|
115 |
return new Function<Oaf, Project>() { |
|
116 |
|
|
117 |
@Override |
|
118 |
public Project apply(final Oaf oafRel) { |
|
119 |
return mapRelatedProject(oafRel.getRel().getCachedOafTarget().getEntity().getProject()); |
|
120 |
} |
|
121 |
}; |
|
122 |
} |
|
123 |
|
|
124 | 100 |
} |
Also available in: Unified diff
fixing mapping for license vs accessright #3128, cleanup