} else {
// Get the identification properties for each contribution ...
Location contributionLocation = contribution.getLocationInSource();
for (Property idProperty : contributionLocation) {
// Record the property ...
Property existing = properties.put(idProperty.getName(), idProperty);
if (existing != null) {
// There's already an existing property, so we need to merge them ...
Property merged = merge(existing, idProperty, context.getPropertyFactory(), removeDuplicateProperties);
properties.put(merged.getName(), merged);
}
}
// Accumulate the children ...
Iterator<Location> childIterator = contribution.getChildren();
while (childIterator.hasNext()) {
Location child = childIterator.next();
Name childName = child.getPath().getLastSegment().getName();
int index = Path.NO_INDEX;
Integer previous = childNames.put(childName, 1);
if (previous != null) {
int previousValue = previous.intValue();
// Correct the index in the child name map ...
childNames.put(childName, ++previousValue);
index = previousValue;
}
Path pathToChild = pathFactory.create(location.getPath(), childName, index);
federatedNode.addChild(new Location(pathToChild));
}
// Add in the properties ...
Iterator<Property> propertyIter = contribution.getProperties();
while (propertyIter.hasNext()) {
Property property = propertyIter.next();
// Skip the "uuid" property on all root nodes ...
if (isRoot && property.getName().getLocalName().equals("uuid")) continue;
// Record the property ...
Property existing = properties.put(property.getName(), property);
if (existing != null) {
// There's already an existing property, so we need to merge them ...
Property merged = merge(existing, property, context.getPropertyFactory(), removeDuplicateProperties);
properties.put(property.getName(), merged);
}
}
}
}
if (idProperties.size() != 0) {
// Update the location based upon the merged ID properties ...
Location newLocation = new Location(location.getPath(), idProperties.values());
federatedNode.setActualLocationOfNode(newLocation);
// Look for the UUID property on the location, and update the federated node ...
Property uuidProperty = idProperties.get(DnaLexicon.UUID);
if (uuidProperty != null && !uuidProperty.isEmpty()) {
UUID uuid = context.getValueFactories().getUuidFactory().create(uuidProperty.getValues().next());
federatedNode.setUuid(uuid);
// Set the UUID as a property ...
properties.put(uuidProperty.getName(), uuidProperty);
}
} else {
// Generate a new UUID property and add to the node ...
UUID uuid = federatedNode.getUuid();
if (uuid == null) {
uuid = context.getValueFactories().getUuidFactory().create();
federatedNode.setUuid(uuid);
}
// Set the UUID as a property ...
Property uuidProperty = context.getPropertyFactory().create(DnaLexicon.UUID, uuid);
properties.put(uuidProperty.getName(), uuidProperty);
}
// Assign the merge plan ...
MergePlan mergePlan = MergePlan.create(contributions);
federatedNode.setMergePlan(mergePlan);