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