Revision 44900
Added by Claudio Atzori over 7 years ago
DbmfToHbaseXsltFunctions.java | ||
---|---|---|
12 | 12 |
import eu.dnetlib.data.proto.FieldTypeProtos.DataInfo; |
13 | 13 |
import eu.dnetlib.data.proto.FieldTypeProtos.Instance; |
14 | 14 |
import eu.dnetlib.data.proto.FieldTypeProtos.KeyValue; |
15 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
15 | 16 |
import eu.dnetlib.data.proto.OrganizationProtos.Organization; |
16 | 17 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
17 | 18 |
import eu.dnetlib.data.proto.ProjectProtos.Project; |
... | ... | |
64 | 65 |
|
65 | 66 |
public static String oafRel(final String relationType, |
66 | 67 |
final String source, |
68 |
final String sourceType, |
|
67 | 69 |
final String target, |
70 |
final String targetType, |
|
68 | 71 |
final NodeList nodeList, |
69 | 72 |
final String relClass, |
70 | 73 |
final String relScheme) { |
71 | 74 |
|
72 | 75 |
final String eSource = DNGFRowKeyDecoder.decode(source).getKey(); |
73 | 76 |
final String eTarget = DNGFRowKeyDecoder.decode(target).getKey(); |
74 |
final RelType relType = RelType.valueOf(relationType);
|
|
77 |
final Qualifier relType = getSimpleQualifier(relClass, relScheme).build();
|
|
75 | 78 |
|
76 |
switch (relType) { |
|
77 |
case datasourceOrganization: |
|
78 |
Provision.Builder provision = Provision.newBuilder().setRelMetadata( |
|
79 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Provision.RelName.valueOf(relClass).toString(), relScheme))); |
|
80 |
DatasourceOrganization.Builder dorg = DatasourceOrganization.newBuilder().setProvision(provision); |
|
81 |
|
|
82 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.provision, relClass, false, dorg, provision); |
|
83 |
case personPublication: |
|
84 |
Authorship.Builder authP = Authorship.newBuilder().setRelMetadata( |
|
85 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Authorship.RelName.valueOf(relClass).toString(), relScheme))); |
|
86 |
PersonPublication.Builder personPublication = PersonPublication.newBuilder().setAuthorship(authP); |
|
87 |
|
|
88 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.authorship, relClass, false, personPublication, authP); |
|
89 |
case personDataset: |
|
90 |
Authorship.Builder authD = Authorship.newBuilder().setRelMetadata( |
|
91 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Authorship.RelName.valueOf(relClass).toString(), relScheme))); |
|
92 |
PersonDataset.Builder personDataset = PersonDataset.newBuilder().setAuthorship(authD); |
|
93 |
|
|
94 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.authorship, relClass, false, personDataset, authD); |
|
95 |
case projectPerson: |
|
96 |
ContactPerson.Builder contact = ContactPerson.newBuilder().setRelMetadata( |
|
97 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(ContactPerson.RelName.valueOf(relClass).toString(), relScheme))); |
|
98 |
ProjectPerson.Builder projectPerson = ProjectPerson.newBuilder().setContactPerson(contact); |
|
99 |
|
|
100 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.contactPerson, relClass, false, projectPerson, contact); |
|
101 |
case projectOrganization: |
|
102 |
Participation.Builder participant = Participation.newBuilder().setRelMetadata( |
|
103 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Participation.RelName.valueOf(relClass).toString(), relScheme))); |
|
104 |
ProjectOrganization.Builder projectOrganization = ProjectOrganization.newBuilder().setParticipation(participant); |
|
105 |
|
|
106 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.participation, relClass, false, projectOrganization, participant); |
|
107 |
case publicationProject: |
|
108 |
Outcome.Builder outcomeP = Outcome.newBuilder().setRelMetadata( |
|
109 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Outcome.RelName.valueOf(relClass).toString(), relScheme))); |
|
110 |
PublicationProject.Builder publicationProject = PublicationProject.newBuilder().setOutcome(outcomeP); |
|
111 |
|
|
112 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.outcome, relClass, false, publicationProject, outcomeP); |
|
113 |
case datasetProject: |
|
114 |
Outcome.Builder outcome = Outcome.newBuilder().setRelMetadata( |
|
115 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Outcome.RelName.valueOf(relClass).toString(), relScheme))); |
|
116 |
DatasetProject.Builder datasetProject = DatasetProject.newBuilder().setOutcome(outcome); |
|
117 |
|
|
118 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.outcome, relClass, false, datasetProject, outcome); |
|
119 |
default: |
|
120 |
throw new IllegalArgumentException("unhandled relType: " + relationType); |
|
121 |
} |
|
79 |
return serializeOafRel(nodeList, eSource, Type.valueOf(sourceType), eTarget, Type.valueOf(targetType), relType, false, DNGFRel.newBuilder()); |
|
122 | 80 |
} |
123 | 81 |
|
124 | 82 |
// //////////////////////////////////////////////////////// |
... | ... | |
167 | 125 |
} |
168 | 126 |
} |
169 | 127 |
|
170 |
protected static String serializeOafRel(final NodeList nodeList, |
|
128 |
protected static String serializeOafRel( |
|
129 |
final NodeList nodeList, |
|
171 | 130 |
final String sourceId, |
131 |
final Type sourceType, |
|
172 | 132 |
final String targetId, |
173 |
final RelType relType, |
|
174 |
final SubRelType subRelType, |
|
175 |
final String relClass, |
|
133 |
final Type targetType, |
|
134 |
final Qualifier relType, |
|
176 | 135 |
final boolean isChild, |
177 |
final Builder rel, |
|
178 |
final Builder subRel) { |
|
136 |
final Builder rel) { |
|
179 | 137 |
try { |
180 | 138 |
|
181 | 139 |
final DataInfo.Builder dataInfo = DataInfo.newBuilder(); |
182 | 140 |
|
183 |
parseNodelist(nodeList, rel, subRel, dataInfo);
|
|
141 |
parseNodelist(nodeList, rel, dataInfo); |
|
184 | 142 |
|
185 |
DNGFRel.Builder builder = getRel(sourceId, targetId, relType, subRelType, relClass, isChild);
|
|
143 |
DNGFRel.Builder builder = getRel(sourceId, sourceType, targetId, targetType, relType, isChild);
|
|
186 | 144 |
|
187 |
FieldDescriptor subRelDescriptor = rel.getDescriptorForType().findFieldByName(subRelType.toString()); |
|
188 |
rel.setField(subRelDescriptor, subRel.build()); |
|
189 |
|
|
190 | 145 |
FieldDescriptor relDescriptor = DNGFRel.getDescriptor().findFieldByName(relType.toString()); |
191 | 146 |
builder.setField(relDescriptor, rel.build()); |
192 | 147 |
|
Also available in: Unified diff
1st attempt to simplify the proto model