docs: protected void mergeRelationship(final Map<SpecNode, CSNodeWrapper> nodeMapping, final SpecNodeWithRelationships specNode,
              final CSNodeWrapper entity, final CSNodeProvider nodeProvider) {
          final UpdateableCollectionWrapper<CSRelatedNodeWrapper> relatedToNodes = entity.getRelatedToNodes() == null ? nodeProvider
                  .newCSRelatedNodeCollection() : entity.getRelatedToNodes();
          final List<CSRelatedNodeWrapper> existingRelationships = new ArrayList<CSRelatedNodeWrapper>(relatedToNodes.getItems());
  
          LOG.debug("Processing relationships for entity: {}", entity.getEntityId());
  
          // Check to make sure that the spec topic has any relationships
          if (!specNode.getRelationships().isEmpty()) {
              int relationshipSortCount = 1;
  
              for (final Relationship relationship : specNode.getRelationships()) {
                  // All process relationships should not be stored
                  if (relationship instanceof ProcessRelationship) continue;
  
                  LOG.debug("Processing Relationship: {}", relationship.getSecondaryRelationshipId());
  
                  // Determine the relationship mode
                  final Integer relationshipMode;
                  if (relationship instanceof TargetRelationship) {
                      relationshipMode = CommonConstants.CS_RELATIONSHIP_MODE_TARGET;
                  } else {
                      relationshipMode = CommonConstants.CS_RELATIONSHIP_MODE_ID;
                  }
  
  
                  // See if the related node already exists
                  CSRelatedNodeWrapper foundRelatedNode = findExistingRelatedNode(relationship, existingRelationships);
  
                  if (foundRelatedNode != null) {
                      LOG.debug("Found existing related node {}", foundRelatedNode.getRelationshipId());
                      // Remove the related node from the list of existing nodes
                      existingRelationships.remove(foundRelatedNode);
  
                      // Found a node so update anything that might have changed
                      boolean updated = false;
                      if (foundRelatedNode.getRelationshipSort() != relationshipSortCount) {
                          foundRelatedNode.setRelationshipSort(relationshipSortCount);
                          updated = true;
                      }
  
                      // Make sure the modes still match
                      if (!relationshipMode.equals(foundRelatedNode.getRelationshipMode())) {
                          foundRelatedNode.setRelationshipMode(relationshipMode);
                          updated = true;
                      }
  
                      // If the node was updated, set it's state in the collection to updated, otherwise just put it back in normally.
                      if (updated) {
                          relatedToNodes.remove(foundRelatedNode);
                          relatedToNodes.addUpdateItem(foundRelatedNode);
                      }
                  } else {
                      LOG.debug("Creating new relationship");
                      // No related node was found for the relationship so make a new one.
                      final CSNodeWrapper relatedNode;
                      if (relationship instanceof TargetRelationship) {
                          relatedNode = nodeMapping.get(((TargetRelationship) relationship).getSecondaryRelationship());
                      } else {
                          relatedNode = nodeMapping.get(((TopicRelationship) relationship).getSecondaryRelationship());
                      }
  
                      foundRelatedNode = nodeProvider.newCSRelatedNode(relatedNode);
                      foundRelatedNode.setRelationshipType(RelationshipType.getRelationshipTypeId(relationship.getType()));
                      foundRelatedNode.setRelationshipSort(relationshipSortCount);
                      foundRelatedNode.setRelationshipMode(relationshipMode);
  
                      relatedToNodes.addNewItem(foundRelatedNode);
                  }
  
                  // increment the sort counter
                  relationshipSortCount++;
              }
          }
  
          // Remove any existing relationships that are no longer valid
          if (!existingRelationships.isEmpty()) {
              for (final CSRelatedNodeWrapper relatedNode : existingRelationships) {
                  LOG.debug("Removing relationship {}", relatedNode.getRelationshipId());
                  relatedToNodes.remove(relatedNode);
                  relatedToNodes.addRemoveItem(relatedNode);
              }
          }
  
          // Check if anything was changed, if so then set the changes
          if (!relatedToNodes.getAddItems().isEmpty() || !relatedToNodes.getUpdateItems().isEmpty() || !relatedToNodes.getRemoveItems()
                  .isEmpty()) {
              entity.setRelatedToNodes(relatedToNodes);
  
              // Make sure the node is in the updated state
              if (entity.getParent() == null) {
                  entity.getContentSpec().getChildren().remove(entity);
                  if (entity.getId() == null) {
                      entity.getContentSpec().getChildren().addNewItem(entity);
                  } else {
                      entity.getContentSpec().getChildren().addUpdateItem(entity);
                  }
              } else {
                  final CSNodeWrapper parent = entity.getParent();
                  parent.getChildren().remove(entity);
                  if (entity.getId() == null) {
                      parent.getChildren().addNewItem(entity);
                  } else {
                      parent.getChildren().addUpdateItem(entity);
                  }
              }
          }
      }