1
|
package eu.dnetlib.data.mapreduce.util;
|
2
|
|
3
|
import java.util.LinkedList;
|
4
|
import java.util.List;
|
5
|
import java.util.stream.Collectors;
|
6
|
|
7
|
import com.google.protobuf.Descriptors.FieldDescriptor;
|
8
|
import com.google.protobuf.GeneratedMessage;
|
9
|
import eu.dnetlib.data.proto.OafProtos.OafEntity;
|
10
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
11
|
import eu.dnetlib.data.transform.AbstractProtoMapper;
|
12
|
import eu.dnetlib.pace.model.FieldDef;
|
13
|
|
14
|
public class OafEntityDecoder extends AbstractProtoMapper {
|
15
|
|
16
|
private final OafEntity oafEntity;
|
17
|
|
18
|
private OafEntityDecoder(final OafEntity oafEntity) {
|
19
|
this.oafEntity = oafEntity;
|
20
|
}
|
21
|
|
22
|
public static OafEntityDecoder decode(final OafEntity oafEntity) {
|
23
|
return new OafEntityDecoder(oafEntity);
|
24
|
}
|
25
|
|
26
|
public Type getType() {
|
27
|
return oafEntity.getType();
|
28
|
}
|
29
|
|
30
|
public String getId() {
|
31
|
return oafEntity.getId();
|
32
|
}
|
33
|
|
34
|
public GeneratedMessage getOafEntity() {
|
35
|
return oafEntity;
|
36
|
}
|
37
|
|
38
|
public GeneratedMessage getEntity() {
|
39
|
final FieldDescriptor fd = oafEntity.getDescriptorForType().findFieldByName(typeName());
|
40
|
return (GeneratedMessage) oafEntity.getField(fd);
|
41
|
}
|
42
|
|
43
|
public String typeName() {
|
44
|
return oafEntity.getType().toString();
|
45
|
}
|
46
|
|
47
|
public GeneratedMessage getMetadata() {
|
48
|
final GeneratedMessage entity = getEntity();
|
49
|
final FieldDescriptor fd = entity.getDescriptorForType().findFieldByName("metadata");
|
50
|
final GeneratedMessage field = (GeneratedMessage) entity.getField(fd);
|
51
|
return field;
|
52
|
}
|
53
|
|
54
|
public String getDateOfCollection() {
|
55
|
return oafEntity.getDateofcollection();
|
56
|
}
|
57
|
|
58
|
public String getDateOfTransformation() {
|
59
|
return oafEntity.getDateoftransformation();
|
60
|
}
|
61
|
}
|