Project

General

Profile

1 44953 claudio.at
package eu.dnetlib.data.graph.model;
2 42814 claudio.at
3
import java.util.List;
4
5
import com.google.common.base.Function;
6
import com.google.common.collect.Iterables;
7
import com.google.common.collect.Lists;
8
import com.google.protobuf.Descriptors.FieldDescriptor;
9
import com.google.protobuf.GeneratedMessage;
10 43514 claudio.at
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity;
11 42814 claudio.at
import eu.dnetlib.data.proto.TypeProtos.Type;
12
import eu.dnetlib.data.transform.AbstractProtoMapper;
13
14 43514 claudio.at
public class DNGFEntityDecoder extends AbstractProtoMapper {
15 42814 claudio.at
16 43514 claudio.at
	private final DNGFEntity dngfEntity;
17 42814 claudio.at
18 43514 claudio.at
	private DNGFEntityDecoder(final DNGFEntity oafEntity) {
19
		this.dngfEntity = oafEntity;
20 42814 claudio.at
	}
21
22 43514 claudio.at
	public static DNGFEntityDecoder decode(final DNGFEntity oafEntity) {
23
		return new DNGFEntityDecoder(oafEntity);
24 42814 claudio.at
	}
25
26
	public Type getType() {
27 43514 claudio.at
		return dngfEntity.getType();
28 42814 claudio.at
	}
29
30
	public String getId() {
31 43514 claudio.at
		return dngfEntity.getId();
32 42814 claudio.at
	}
33
34 43514 claudio.at
	public GeneratedMessage getDNGFEntity() {
35
		return dngfEntity;
36 42814 claudio.at
	}
37
38
	public GeneratedMessage getEntity() {
39 43514 claudio.at
		final FieldDescriptor fd = dngfEntity.getDescriptorForType().findFieldByName(typeName());
40
		return (GeneratedMessage) dngfEntity.getField(fd);
41 42814 claudio.at
	}
42
43
	public String typeName() {
44 43514 claudio.at
		return dngfEntity.getType().toString();
45 42814 claudio.at
	}
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 List<String> getFieldValues(final String path) {
55 43514 claudio.at
		return Lists.newLinkedList(Iterables.transform(processPath(getDNGFEntity(), path, eu.dnetlib.pace.config.Type.String), new Function<Object, String>() {
56 42814 claudio.at
57
			@Override
58
			public String apply(final Object o) {
59
				return o.toString();
60
			}
61
		}));
62
	}
63
64
	public String getDateOfCollection() {
65 43514 claudio.at
		return dngfEntity.getDateofcollection();
66 42814 claudio.at
	}
67
68
	public String getDateOfTransformation() {
69 43514 claudio.at
		return dngfEntity.getDateoftransformation();
70 42814 claudio.at
	}
71
}