Skip to content

Commit

Permalink
Remove geonet: elements from metadata before commit
Browse files Browse the repository at this point in the history
Some harvesters eg. csw were adding metadata elements to the database
with geonet: elements in them - this causes problems when the record
is viewed/edited
  • Loading branch information
sppigot committed Sep 4, 2014
1 parent 443ed37 commit 28c690c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions web/src/main/java/org/fao/geonet/kernel/XmlSerializer.java
Expand Up @@ -42,6 +42,7 @@

import org.apache.log4j.Priority;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Edit;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.kernel.schema.MetadataSchema;
import org.fao.geonet.kernel.setting.SettingManager;
Expand Down Expand Up @@ -259,6 +260,8 @@ protected String insertDb(Dbms dbms, String schema, Element xml, int serial,

if (resolveXLinks()) Processor.removeXLink(xml);

xml = removeGeonetElements(xml);

String date = new ISODate().toString();

if (createDate == null)
Expand Down Expand Up @@ -319,6 +322,7 @@ protected String insertDb(Dbms dbms, String schema, Element xml, int serial,
*/
protected void updateDb(Dbms dbms, String id, Element xml, String changeDate, String root, boolean updateDateStamp, String uuid) throws SQLException {
if (resolveXLinks()) Processor.removeXLink(xml);
xml = removeGeonetElements(xml);
if (logEmptyWithheld(id, xml, "XmlSerializer.updateDb")) {
StackTraceElement[] stacktrace = new Exception("").getStackTrace();
StringBuffer info = new StringBuffer();
Expand Down Expand Up @@ -407,6 +411,33 @@ private void fixCR(Element xml) {
}
}

private Element removeGeonetElements(Element md) {
//--- purge geonet: attributes

List listAtts = md.getAttributes();
for (int i=0; i<listAtts.size(); i++) {
Attribute attr = (Attribute) listAtts.get(i);
if (Edit.NAMESPACE.getPrefix().equals(attr.getNamespacePrefix())) {
attr.detach();
i--;
}
}

//--- purge geonet: children
List list = md.getChildren();
for (int i=0; i<list.size(); i++) {
Element child = (Element) list.get(i);
if (!Edit.NAMESPACE.getPrefix().equals(child.getNamespacePrefix()))
removeGeonetElements(child);
else {
child.detach();
i--;
}
}

return md;
}

/* API to be overridden by extensions */

public abstract void delete(Dbms dbms, String table, String id, ServiceContext context)
Expand Down

0 comments on commit 28c690c

Please sign in to comment.