1
|
package eu.dnetlib.data.transform.xml;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.common.collect.Lists;
|
7
|
import com.google.protobuf.Message.Builder;
|
8
|
import eu.dnetlib.data.mapreduce.util.OafRowKeyDecoder;
|
9
|
import eu.dnetlib.data.proto.FieldTypeProtos.KeyValue;
|
10
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
11
|
import eu.dnetlib.data.proto.OafProtos.OafRel;
|
12
|
import eu.dnetlib.data.proto.RelMetadataProtos.RelMetadata;
|
13
|
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
|
14
|
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType;
|
15
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
16
|
import org.w3c.dom.NodeList;
|
17
|
|
18
|
/**
|
19
|
* Created by claudio on 01/12/15.
|
20
|
*/
|
21
|
public class CommonDNetXsltFunctions extends AbstractDNetXsltFunctions {
|
22
|
|
23
|
private static final int MAX_COAUTHORS = 50;
|
24
|
|
25
|
public static String rel(
|
26
|
final String source,
|
27
|
final String target,
|
28
|
final String relType,
|
29
|
final String subRelType,
|
30
|
final String relClass,
|
31
|
final String provenanceAction,
|
32
|
final String trust) {
|
33
|
return rel(source, target, relType, subRelType, relClass, null, provenanceAction, trust, null, null);
|
34
|
}
|
35
|
|
36
|
public static String rel(
|
37
|
final String source,
|
38
|
final String target,
|
39
|
final String relType,
|
40
|
final String subRelType,
|
41
|
final String relClass,
|
42
|
final NodeList metadata,
|
43
|
final String provenanceAction,
|
44
|
final String trust) {
|
45
|
return rel(source, target, relType, subRelType, relClass, metadata, provenanceAction, trust, null, null);
|
46
|
}
|
47
|
|
48
|
public static String rel(
|
49
|
final String source,
|
50
|
final String target,
|
51
|
final String relType,
|
52
|
final String subRelType,
|
53
|
final String relClass,
|
54
|
final NodeList metadata,
|
55
|
final String provenanceAction,
|
56
|
final String trust,
|
57
|
final NodeList about) {
|
58
|
return rel(source, target, relType, subRelType, relClass, metadata, provenanceAction, trust, about, null);
|
59
|
}
|
60
|
|
61
|
public static String rel(
|
62
|
final String source,
|
63
|
final String target,
|
64
|
final String relType,
|
65
|
final String subRelType,
|
66
|
final String relClass,
|
67
|
final NodeList metadata,
|
68
|
final String provenanceAction,
|
69
|
final String trust,
|
70
|
final NodeList about,
|
71
|
final Map<String, String> params) {
|
72
|
|
73
|
ValueMap values = null;
|
74
|
List<KeyValue> collectedFrom = Lists.newArrayList();
|
75
|
try {
|
76
|
final String eSource = OafRowKeyDecoder.decode(source).getKey();
|
77
|
final String eTarget = OafRowKeyDecoder.decode(target).getKey();
|
78
|
|
79
|
final RelType rType = RelType.valueOf(relType);
|
80
|
final SubRelType srType = SubRelType.valueOf(subRelType);
|
81
|
|
82
|
final RelMetadata.Builder metadataBuilder = RelMetadata.newBuilder().setSemantics(getSimpleQualifier(relClass, getVocabularyName(rType)));
|
83
|
|
84
|
final Builder subRel = getSubRelBuilder(metadataBuilder, srType, params);
|
85
|
|
86
|
if(metadata != null) {
|
87
|
values = ValueMap.parseNodeList(metadata);
|
88
|
collectedFrom = getKeyValues(values, "collectedFrom", Type.datasource);
|
89
|
}
|
90
|
|
91
|
final OafRel.Builder rel = getRelBuilder(rType, srType, getRel(eSource, eTarget, rType, srType, relClass, collectedFrom, false), subRel);
|
92
|
|
93
|
final Oaf oaf = getOaf(rel, getDataInfo(about, provenanceAction, trust, false, false));
|
94
|
return base64(oaf.toByteArray());
|
95
|
} catch (Exception e) {
|
96
|
e.printStackTrace(System.err);
|
97
|
throw new RuntimeException(e);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
}
|