1 |
40198
|
claudio.at
|
package eu.dnetlib.data.transform.xml;
|
2 |
|
|
|
3 |
52169
|
claudio.at
|
import java.util.List;
|
4 |
40198
|
claudio.at
|
import java.util.Map;
|
5 |
|
|
|
6 |
52542
|
alessia.ba
|
import com.google.common.collect.Lists;
|
7 |
40198
|
claudio.at
|
import com.google.protobuf.Message.Builder;
|
8 |
|
|
import eu.dnetlib.data.mapreduce.util.OafRowKeyDecoder;
|
9 |
52169
|
claudio.at
|
import eu.dnetlib.data.proto.FieldTypeProtos.KeyValue;
|
10 |
40198
|
claudio.at
|
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 |
52169
|
claudio.at
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
16 |
40198
|
claudio.at
|
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 |
52169
|
claudio.at
|
return rel(source, target, relType, subRelType, relClass, null, provenanceAction, trust, null, null);
|
34 |
40198
|
claudio.at
|
}
|
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 |
52169
|
claudio.at
|
final NodeList metadata,
|
43 |
40198
|
claudio.at
|
final String provenanceAction,
|
44 |
43367
|
claudio.at
|
final String trust) {
|
45 |
52169
|
claudio.at
|
return rel(source, target, relType, subRelType, relClass, metadata, provenanceAction, trust, null, null);
|
46 |
43367
|
claudio.at
|
}
|
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 |
52169
|
claudio.at
|
final NodeList metadata,
|
55 |
43367
|
claudio.at
|
final String provenanceAction,
|
56 |
40198
|
claudio.at
|
final String trust,
|
57 |
|
|
final NodeList about) {
|
58 |
52169
|
claudio.at
|
return rel(source, target, relType, subRelType, relClass, metadata, provenanceAction, trust, about, null);
|
59 |
40198
|
claudio.at
|
}
|
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 |
52169
|
claudio.at
|
final NodeList metadata,
|
68 |
40198
|
claudio.at
|
final String provenanceAction,
|
69 |
|
|
final String trust,
|
70 |
|
|
final NodeList about,
|
71 |
|
|
final Map<String, String> params) {
|
72 |
52169
|
claudio.at
|
|
73 |
|
|
ValueMap values = null;
|
74 |
52542
|
alessia.ba
|
List<KeyValue> collectedFrom = Lists.newArrayList();
|
75 |
40198
|
claudio.at
|
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 |
52169
|
claudio.at
|
final RelMetadata.Builder metadataBuilder = RelMetadata.newBuilder().setSemantics(getSimpleQualifier(relClass, getVocabularyName(rType)));
|
83 |
40198
|
claudio.at
|
|
84 |
52169
|
claudio.at
|
final Builder subRel = getSubRelBuilder(metadataBuilder, srType, params);
|
85 |
40198
|
claudio.at
|
|
86 |
52542
|
alessia.ba
|
if(metadata != null) {
|
87 |
|
|
values = ValueMap.parseNodeList(metadata);
|
88 |
|
|
collectedFrom = getKeyValues(values, "collectedFrom", Type.datasource);
|
89 |
|
|
}
|
90 |
40198
|
claudio.at
|
|
91 |
52169
|
claudio.at
|
final OafRel.Builder rel = getRelBuilder(rType, srType, getRel(eSource, eTarget, rType, srType, relClass, collectedFrom, false), subRel);
|
92 |
|
|
|
93 |
40198
|
claudio.at
|
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 |
|
|
}
|