1
|
package eu.dnetlib.data.transform;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.function.Function;
|
5
|
|
6
|
import com.google.common.collect.Lists;
|
7
|
import eu.dnetlib.data.mapreduce.util.OafDecoder;
|
8
|
import eu.dnetlib.data.mapreduce.util.OafEntityDecoder;
|
9
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
10
|
|
11
|
public class OafToRowMapper implements Function<Oaf, List<Row>> {
|
12
|
|
13
|
public static final String BODY = "body";
|
14
|
|
15
|
@Override
|
16
|
public List<Row> apply(final Oaf oaf) {
|
17
|
final List<Row> rows = Lists.newArrayList();
|
18
|
|
19
|
final OafDecoder d = OafDecoder.decode(oaf);
|
20
|
final OafEntityDecoder entity = d.decodeEntity();
|
21
|
|
22
|
final Row r = new Row(d.getCFQ(), entity.getId());
|
23
|
switch (entity.getType()) {
|
24
|
|
25
|
case project:
|
26
|
r.addColumn(new Column<>(BODY, oaf.toByteArray()));
|
27
|
break;
|
28
|
case result:
|
29
|
oaf.getEntity().getCachedOafRelList().stream()
|
30
|
.map(cachedRel -> {
|
31
|
final Oaf.Builder oafRel = Oaf.newBuilder(cachedRel);
|
32
|
oafRel.getRelBuilder().clearCachedOafTarget();
|
33
|
return oafRel.build();
|
34
|
}).forEach(oafRel -> r.addColumn(new Column<>(OafDecoder.decode(oafRel).getCFQ(), oafRel.toByteArray())));
|
35
|
break;
|
36
|
case datasource:
|
37
|
|
38
|
break;
|
39
|
case organization:
|
40
|
|
41
|
break;
|
42
|
}
|
43
|
|
44
|
return rows;
|
45
|
}
|
46
|
|
47
|
}
|