Project

General

Profile

« Previous | Next » 

Revision 35773

reverted to r35450

View differences:

modules/dnet-openaireplus-mapping-utils/trunk/src/main/java/eu/dnetlib/data/transform/xml/DmfToHbaseXsltFunctions.java
122 122

  
123 123
			// metadata.setNationality(getSimpleQualifier("UNKNOWN", "dnet:countries"));
124 124
			final List<StructuredProperty> pids = Lists.newArrayList(getStructuredProperty(originalId, "oai", "oai", "dnet:pid_types", "dnet:pid_types"));
125
			final OafEntity.Builder entity =
126
					getEntity(Type.person, entityId, getKV(collectedFromId, collectedFromName), originalId, dateOfCollection, pids)
127
							.setPerson(person.setMetadata(metadata));
125
			final OafEntity.Builder entity = getEntity(Type.person, entityId, getKV(collectedFromId, collectedFromName), originalId, dateOfCollection, pids)
126
					.setPerson(person.setMetadata(metadata));
128 127

  
129 128
			return base64(getOaf(entity, getDataInfo(dataInfo, provenanceAction, trust, false, false)).toByteArray());
130 129
		} catch (final Throwable e) {
......
322 321
			pids.addAll(parsePids(nodelist));
323 322
			pids.add(getStructuredProperty(originalId, "oai", getClassName("oai"), "dnet:pid_types", "dnet:pid_types"));
324 323

  
325
			final OafEntity.Builder entity =
326
					getEntity(Type.result, entityId, getKV(collectedFromId, collectedFromName), originalId, dateOfCollection, pids)
324
			final OafEntity.Builder entity = getEntity(Type.result, entityId, getKV(collectedFromId, collectedFromName), originalId, dateOfCollection, pids)
327 325
					.setResult(result.setMetadata(metadata));
328 326

  
329 327
			final Oaf oaf = getOaf(entity, getDataInfo(dataInfo, provenanceAction, trust, false, false));
modules/dnet-openaireplus-mapping-utils/trunk/src/main/java/eu/dnetlib/data/transform/xml/AbstractDNetOafXsltFunctions.java
7 7

  
8 8
import org.apache.commons.codec.binary.Base64;
9 9
import org.apache.commons.codec.binary.Hex;
10
import org.apache.commons.lang.StringEscapeUtils;
11 10
import org.apache.commons.lang.StringUtils;
12 11
import org.apache.commons.lang.math.NumberUtils;
13 12
import org.w3c.dom.NamedNodeMap;
......
968 967
	}
969 968

  
970 969
	protected static KeyValue getKV(final String id, final String name) {
971
		return KeyValue.newBuilder().setKey(id).setValue(escapeXml(name)).build();
970
		return KeyValue.newBuilder().setKey(id).setValue(name).build();
972 971
	}
973 972

  
974 973
	protected static OafRel.Builder getRel(final String sourceId,
......
987 986
			final String originalId,
988 987
			final String dateOfCollection,
989 988
			final List<StructuredProperty> pids) {
990
		final OafEntity.Builder builder = OafEntity.newBuilder().setType(type).setId(id).addCollectedfrom(collectedFrom).addOriginalId(originalId)
989
		OafEntity.Builder builder = OafEntity.newBuilder().setType(type).setId(id).addCollectedfrom(collectedFrom).addOriginalId(originalId)
991 990
				.setDateofcollection(dateOfCollection);
992 991

  
993 992
		if ((pids != null) && !pids.isEmpty()) {
......
1003 1002
			final boolean deletedbyinference,
1004 1003
			final boolean inferred) {
1005 1004

  
1006
		final DataInfo.Builder dataInfoBuilder = DataInfo.newBuilder();
1005
		DataInfo.Builder dataInfoBuilder = DataInfo.newBuilder();
1007 1006
		dataInfoBuilder.setInferred(Boolean.valueOf(inferred));
1008 1007
		dataInfoBuilder.setDeletedbyinference(Boolean.valueOf(deletedbyinference));
1009 1008
		dataInfoBuilder.setTrust(trust);
......
1012 1011
		// checking instanceof because when receiving an empty <oaf:datainfo> we don't want to parse it.
1013 1012
		if (((dataInfo != null) && (dataInfo.getLength() > 0)) /* && (dataInfo instanceof org.w3c.dom.Element) */) {
1014 1013

  
1015
			final org.w3c.dom.Element e = (org.w3c.dom.Element) dataInfo.item(0);
1014
			org.w3c.dom.Element e = (org.w3c.dom.Element) dataInfo.item(0);
1016 1015

  
1017 1016
			org.w3c.dom.Element elem = getDirectChild(e, "inferred");
1018 1017
			dataInfoBuilder.setInferred(Boolean.valueOf(elem != null ? elem.getTextContent() : String.valueOf(inferred)));
......
1027 1026
			dataInfoBuilder.setInferenceprovenance(elem != null ? elem.getTextContent() : "");
1028 1027

  
1029 1028
			elem = getDirectChild(e, "provenanceaction");
1030
			final Qualifier.Builder pBuilder = Qualifier.newBuilder();
1029
			Qualifier.Builder pBuilder = Qualifier.newBuilder();
1031 1030
			if (elem.hasAttributes()) {
1032
				final NamedNodeMap attributes = elem.getAttributes();
1031
				NamedNodeMap attributes = elem.getAttributes();
1033 1032
				pBuilder.setClassid(attributes.getNamedItem("classid").getNodeValue());
1034 1033
				pBuilder.setClassname(attributes.getNamedItem("classname").getNodeValue());
1035 1034
				pBuilder.setSchemeid(attributes.getNamedItem("schemeid").getNodeValue());
......
1078 1077
			final String classid,
1079 1078
			final String schemeid) {
1080 1079
		if (values != null) {
1081
			for (final String s : values) {
1080
			for (String s : values) {
1082 1081
				addField(builder, fd, getStructuredProperty(s, classid, classid, schemeid, schemeid));
1083 1082
			}
1084 1083
		}
......
1095 1094
				final Node pidType = node.getAttributes().getNamedItem("identifierType");
1096 1095

  
1097 1096
				for (int j = 0; j < node.getChildNodes().getLength(); j++) {
1098
					final Node child = node.getChildNodes().item(j);
1097
					Node child = node.getChildNodes().item(j);
1099 1098

  
1100 1099
					if ((child.getNodeType() == Node.TEXT_NODE) && (pidType != null) && (pidType.getNodeValue() != null) && !pidType.getNodeValue().isEmpty()
1101 1100
							&& !pidType.getNodeValue().equalsIgnoreCase("url")) {
1102 1101

  
1103
						final String type = pidType.getNodeValue().toLowerCase();
1102
						String type = pidType.getNodeValue().toLowerCase();
1104 1103

  
1105
						final String value = child.getTextContent();
1104
						String value = child.getTextContent();
1106 1105

  
1107 1106
						pids.add(getStructuredProperty(value, type, getClassName(type), "dnet:pid_types", "dnet:pid_types"));
1108 1107
						break;
......
1119 1118
		if (value == null) return;
1120 1119

  
1121 1120
		if (value instanceof List<?>) {
1122
			for (final Object o : (List<Object>) value) {
1121
			for (Object o : (List<Object>) value) {
1123 1122
				addField(builder, descriptor, o);
1124 1123
			}
1125 1124
		} else {
......
1144 1143
				fieldValue = Integer.valueOf(value.toString());
1145 1144
				break;
1146 1145
			case MESSAGE:
1147
				final Builder q = builder.newBuilderForField(descriptor);
1146
				Builder q = builder.newBuilderForField(descriptor);
1148 1147

  
1149 1148
				if (value instanceof Builder) {
1150 1149
					value = ((Builder) value).build();
1151
					final byte[] b = ((Message) value).toByteArray();
1150
					byte[] b = ((Message) value).toByteArray();
1152 1151
					try {
1153 1152
						q.mergeFrom(b);
1154
					} catch (final InvalidProtocolBufferException e) {
1153
					} catch (InvalidProtocolBufferException e) {
1155 1154
						throw new IllegalArgumentException("Unable to merge value: " + value + " with builder: " + q.getDescriptorForType().getName());
1156 1155
					}
1157 1156
				} else if (Qualifier.getDescriptor().getName().equals(q.getDescriptorForType().getName())) {
1158 1157
					if (value instanceof Qualifier) {
1159 1158
						q.mergeFrom((Qualifier) value);
1160 1159
					} else {
1161
						parseMessage(q, Qualifier.getDescriptor(), escapeXml(value.toString()), "@@@");
1160
						parseMessage(q, Qualifier.getDescriptor(), value.toString(), "@@@");
1162 1161
					}
1163 1162
				} else if (StructuredProperty.getDescriptor().getName().equals(q.getDescriptorForType().getName())) {
1164 1163
					if (value instanceof StructuredProperty) {
......
1218 1217
	}
1219 1218

  
1220 1219
	protected static void parseMessage(final Builder builder, final Descriptor descriptor, final String value, final String split) {
1221
		final IterablePair<FieldDescriptor, String> iterablePair =
1222
				new IterablePair<FieldDescriptor, String>(descriptor.getFields(), Lists.newArrayList(Splitter
1223
						.on(split).trimResults().split(value)));
1220
		IterablePair<FieldDescriptor, String> iterablePair = new IterablePair<FieldDescriptor, String>(descriptor.getFields(), Lists.newArrayList(Splitter
1221
				.on(split).trimResults().split(value)));
1224 1222

  
1225
		for (final Pair<FieldDescriptor, String> p : iterablePair) {
1223
		for (Pair<FieldDescriptor, String> p : iterablePair) {
1226 1224
			addField(builder, p.getKey(), p.getValue());
1227 1225
		}
1228 1226
	}
......
1248 1246
	}
1249 1247

  
1250 1248
	protected static Qualifier.Builder getDefaultQualifier(final String scheme) {
1251
		final Qualifier.Builder qualifier = Qualifier.newBuilder().setSchemeid(scheme).setSchemename(scheme);
1249
		Qualifier.Builder qualifier = Qualifier.newBuilder().setSchemeid(scheme).setSchemename(scheme);
1252 1250
		return qualifier;
1253 1251
	}
1254 1252

  
......
1258 1256
			final String schemeid,
1259 1257
			final String schemename) {
1260 1258
		if ((value == null) || value.isEmpty()) return null;
1261
		return StructuredProperty.newBuilder().setValue(escapeXml(value)).setQualifier(getQualifier(classid, classname, schemeid, schemename)).build();
1259
		return StructuredProperty.newBuilder().setValue(value).setQualifier(getQualifier(classid, classname, schemeid, schemename)).build();
1262 1260
	}
1263 1261

  
1264 1262
	protected static StringField.Builder sf(final String s) {
1265
		return StringField.newBuilder().setValue(escapeXml(s));
1263
		return StringField.newBuilder().setValue(s);
1266 1264
	}
1267 1265

  
1268 1266
	public static String generateNsPrefix(final String prefix, final String externalId) {
......
1271 1269

  
1272 1270
	public static String md5(final String s) {
1273 1271
		try {
1274
			final MessageDigest md = MessageDigest.getInstance("MD5");
1272
			MessageDigest md = MessageDigest.getInstance("MD5");
1275 1273
			md.update(s.getBytes("UTF-8"));
1276 1274
			return new String(Hex.encodeHex(md.digest()));
1277
		} catch (final Exception e) {
1275
		} catch (Exception e) {
1278 1276
			System.err.println("Error creating id");
1279 1277
			return null;
1280 1278
		}
......
1293 1291
		return oafId(entityType, StringUtils.substringBefore(fullId, "::"), StringUtils.substringAfter(fullId, "::"));
1294 1292
	}
1295 1293

  
1296
	public static String escapeXml(final String s) {
1297
		return StringEscapeUtils.escapeXml(s);
1298
	}
1299

  
1300 1294
	/**
1301 1295
	 * Gets the classname of the given class code
1302
	 *
1296
	 * 
1303 1297
	 * @param code
1304 1298
	 *            class code.
1305 1299
	 * @return the class name, if the code is a key of the map. The code itself otherwise.
1306 1300
	 */
1307 1301
	public static String getClassName(final String code) {
1308
		final String classname = code2name.get(code);
1302
		String classname = code2name.get(code);
1309 1303
		if (StringUtils.isBlank(classname)) return code;
1310 1304
		return classname;
1311 1305
	}
modules/dnet-openaireplus-mapping-utils/trunk/pom.xml
10 10
	<groupId>eu.dnetlib</groupId>
11 11
	<artifactId>dnet-openaireplus-mapping-utils</artifactId>
12 12
	<packaging>jar</packaging>
13
	<version>3.0.2-SNAPSHOT</version>
13
	<version>3.0.1-SNAPSHOT</version>
14 14
	<scm>
15 15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-openaireplus-mapping-utils/trunk</developerConnection>
16 16
	</scm>

Also available in: Unified diff