Project

General

Profile

« Previous | Next » 

Revision 49882

Implemented mapping from DMF to proto for WDS

View differences:

WdsToHbaseXsltFunctions.java
1 1
package eu.dnetlib.data.transform.xml;
2 2

  
3
import java.util.ArrayList;
3 4
import java.util.List;
4 5

  
5 6
import com.google.common.collect.Lists;
7
import eu.dnetlib.data.proto.DNGFProtos;
6 8
import eu.dnetlib.data.proto.DNGFProtos.DNGF;
7 9
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity;
8 10
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity.Builder;
11
import eu.dnetlib.data.proto.FieldTypeProtos;
9 12
import eu.dnetlib.data.proto.WdsDatasetProtos.WdsDataset;
10 13
import eu.dnetlib.data.proto.WdsDatasetProtos.WdsDataset.GeoLocation;
11 14
import org.apache.commons.lang3.StringUtils;
15
import org.w3c.dom.NamedNodeMap;
12 16
import org.w3c.dom.Node;
13 17
import org.w3c.dom.NodeList;
14 18

  
......
45 49
			final NodeList originalIds,
46 50
			final String instanceUri,
47 51
			final String dateOfCollection,
48
			final String dateOfTransformation) {
52
			final String dateOfTransformation,
53
			final NodeList relatedIdentifiers
54
			) {
49 55

  
50 56
		try {
51 57
			final DNGFEntity.Builder entity = odfDatasetProto(
......
54 60
					pidList, hostedbyId, hostedbyName, collectedfromId, collectedfromName,
55 61
					originalIds, instanceUri, dateOfCollection, dateOfTransformation);
56 62

  
63

  
64
			List<RelatedIdentifier> parsedRelatedIdentifiers = parseRelatedIdentifiers(relatedIdentifiers);
65
			parsedRelatedIdentifiers.stream().filter(it -> !it.getTargetIdType().equals("dnet")).forEach(
66
					r -> entity.getDatasetBuilder().getMetadataBuilder().addExtension(WdsDataset.otherRels, r.toOtherRelation()));
67

  
57 68
			if(geoLocations != null) {
58 69
				parseGeoLocations(entity, geoLocations);
59 70
			}
60 71

  
61 72
			final DNGF dngf = getOaf(entity, getDataInfo(about, provenance, trust, false, false));
73

  
74

  
75

  
76

  
62 77
			return base64(dngf.toByteArray());
63 78
		} catch (Throwable e) {
64 79
			e.printStackTrace(System.err);
......
108 123
		geos.forEach(g -> entity.getDatasetBuilder().getMetadataBuilder().addExtension(WdsDataset.geolocation, g));
109 124
	}
110 125

  
126
	public static String createRel(
127
			final String source,
128
			final String target,
129
			final String relationSemantic,
130
			final String relType,
131
			final String provenanceAction,
132
			final String trust,
133
			final NodeList about) {
134

  
135
		try {
136
			DNGFProtos.DNGFRel.Builder rel = relProto(source.trim(), target.trim(), relationSemantic, relType);
137
			final DNGFProtos.DNGF pmf = getOaf(rel, getDataInfo(about, provenanceAction, trust, false, false));
138
			return base64(pmf.toByteArray());
139
		} catch (Throwable e) {
140
			e.printStackTrace(System.err);
141
			throw new RuntimeException(e);
142
		}
143

  
144
	}
145

  
146

  
147
	private static List<RelatedIdentifier>  parseRelatedIdentifiers(final NodeList relatedIdentifier) {
148
		List<RelatedIdentifier> result = new ArrayList<>();
149
		for(int i =0; i < relatedIdentifier.getLength(); i++ ) {
150
			final Node currentNode = relatedIdentifier.item(i);
151
			final String targetId =currentNode.getTextContent();
152
			final NamedNodeMap attributes = currentNode.getAttributes();
153
			final String entityType  = getAttributeValue(attributes, "entityType");
154
			final String relatedIdentifierType  = getAttributeValue(attributes, "relatedIdentifierType");
155
			final String relationType  = getAttributeValue(attributes, "relationType");
156
			result.add(new RelatedIdentifier(entityType, targetId, relationType, relatedIdentifierType));
157
		}
158
		return result;
159

  
160
	}
161

  
162

  
163

  
164

  
165

  
166

  
111 167
}

Also available in: Unified diff