Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions core/src/main/java/org/fao/geonet/kernel/EditLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.Vector;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.jxpath.ri.parser.Token;
Expand Down Expand Up @@ -271,7 +263,7 @@ private void addChildToParent(MetadataSchema mdSchema, Element targetElement, El
// remove everything and then, depending on removeExisting
// readd all children to the element and assure a correct position for the new one: at the end of the others
// or just add the new one
List existingAllType = new ArrayList(targetElement.getChildren());
List<Element> existingAllType = new ArrayList(targetElement.getChildren());
targetElement.removeContent();
for (String singleType: type.getAlElements()) {
List<Element> existingForThisType = filterOnQname(existingAllType, singleType);
Expand All @@ -282,9 +274,22 @@ private void addChildToParent(MetadataSchema mdSchema, Element targetElement, El
LOGGER_ADD_ELEMENT.debug("#### - add child {}", existingChild.toString());
}
}
if (qname.equals(singleType))
if (qname.equals(singleType)) {
targetElement.addContent(childToAdd);
}

filterOnQname(existingAllType, "geonet:child")
.stream()
.filter(gnChild -> (gnChild.getAttributeValue("prefix") + ":" + gnChild.getAttributeValue("name")).equals(singleType))
.findFirst()
.ifPresent(targetElement::addContent);
}

Stream.concat(
filterOnQname(existingAllType, "geonet:element").stream(),
filterOnQname(existingAllType, "geonet:attribute").stream()
).forEach(targetElement::addContent);

}

public void addXMLFragments(String schema, Element md, Map<String, String> xmlInputs) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ public synchronized Element addElementEmbedded(UserSession session, String id, S

//--- locate the geonet:element and geonet:info elements and clone for
//--- later re-use
Element refEl = (Element) (el.getChild(Edit.RootChild.ELEMENT, Edit.NAMESPACE)).clone();
Element info = null;

if (md.getChild(Edit.RootChild.INFO, Edit.NAMESPACE) != null) {
Expand All @@ -376,14 +375,15 @@ public synchronized Element addElementEmbedded(UserSession session, String id, S
if (defaultChild != null) {
defaultValue = defaultChild.getAttributeValue(Edit.Attribute.Attr.VALUE);
}
attributeDef.removeAttribute(Edit.Attribute.Attr.ADD);
attributeDef.setAttribute(new Attribute(Edit.Attribute.Attr.DEL, "true"));
}
}

Pair<Namespace, String> attInfo = parseAttributeName(name, ":", id, md, editLib);
//--- Add new attribute with default value
el.setAttribute(new Attribute(attInfo.two(), defaultValue, attInfo.one()));

// TODO : add attribute should be false and del true after adding an attribute
child = el;
} else {
//--- normal element
Expand All @@ -409,19 +409,13 @@ public synchronized Element addElementEmbedded(UserSession session, String id, S
}
//--- now enumerate the new child (if not a simple attribute)
if (childName == null || !childName.equals("geonet:attribute")) {
//--- now add the geonet:element back again to keep ref number
el.addContent(refEl);

int iRef = editLib.findMaximumRef(md);
editLib.expandElements(schema, child);
editLib.enumerateTreeStartingAt(child, iRef + 1, Integer.parseInt(ref));

//--- add editing info to everything from the parent down
editLib.expandTree(mds, el);

editLib.expandTree(mds, child);
}
if (info != null) {
//--- attach the info element to the child
//--- remove and re-attach the info element to the child
child.removeChild(Edit.RootChild.INFO, Edit.NAMESPACE);
child.addContent(info);
}

Expand Down