diff --git a/core/src/main/java/apoc/refactor/GraphRefactoring.java b/core/src/main/java/apoc/refactor/GraphRefactoring.java index 2b9140921..731481a93 100644 --- a/core/src/main/java/apoc/refactor/GraphRefactoring.java +++ b/core/src/main/java/apoc/refactor/GraphRefactoring.java @@ -913,21 +913,22 @@ private void mergeNodes(Node source, Node target, RefactorConfig conf, List<Stri private void copyRelationships(Node source, Node target, boolean delete, boolean createNewSelfRel) { for (Relationship rel : source.getRelationships()) { - final var type = rel.getType(); var startNode = rel.getStartNode(); - if (startNode.getElementId().equals(source.getElementId())) startNode = target; var endNode = rel.getEndNode(); + + if (!createNewSelfRel && startNode.getElementId().equals(endNode.getElementId())) continue; + + if (startNode.getElementId().equals(source.getElementId())) startNode = target; if (endNode.getElementId().equals(source.getElementId())) endNode = target; + final var type = rel.getType(); final var properties = rel.getAllProperties(); // Delete first to avoid breaking constraints. if (delete) rel.delete(); - if (createNewSelfRel || !startNode.getElementId().equals(endNode.getElementId())) { - final var newRel = startNode.createRelationshipTo(endNode, type); - properties.forEach(newRel::setProperty); - } + final var newRel = startNode.createRelationshipTo(endNode, type); + properties.forEach(newRel::setProperty); } } } diff --git a/core/src/test/java/apoc/ArgumentDescriptionsTest.java b/core/src/test/java/apoc/ArgumentDescriptionsTest.java index 82ef43969..5f5d1fc62 100644 --- a/core/src/test/java/apoc/ArgumentDescriptionsTest.java +++ b/core/src/test/java/apoc/ArgumentDescriptionsTest.java @@ -20,6 +20,7 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; import apoc.agg.CollAggregation; import apoc.agg.Graph; @@ -329,7 +330,10 @@ private void generate(CypherVersion version, Function<CypherVersion, JsonNode> s System.out.println("common:"); System.out.println(writer.writeValueAsString(commonJson)); System.out.println(); + System.out.println("=".repeat(80)); + System.out.println(); System.out.println("cypher %s specific:".formatted(version.versionName)); System.out.println(writer.writeValueAsString(specificJson)); + fail("Remove call to generate"); } } diff --git a/core/src/test/resources/procedures/common/procedures.json b/core/src/test/resources/procedures/common/procedures.json index 3c8c8da2f..9c565ad4a 100644 --- a/core/src/test/resources/procedures/common/procedures.json +++ b/core/src/test/resources/procedures/common/procedures.json @@ -6138,7 +6138,7 @@ } ] }, { "isDeprecated" : false, - "signature" : "apoc.refactor.from(rel :: RELATIONSHIP, newNode :: NODE) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", + "signature" : "apoc.refactor.from(rel :: RELATIONSHIP, newNode :: NODE, config = {} :: MAP) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", "name" : "apoc.refactor.from", "description" : "Redirects the given `RELATIONSHIP` to the given start `NODE`.", "returnDescription" : [ { @@ -6168,10 +6168,16 @@ "description" : "The node to redirect the given relationship to.", "isDeprecated" : false, "type" : "NODE" + }, { + "name" : "config", + "description" : "{\n failOnErrors = false :: BOOLEAN\n}\n", + "isDeprecated" : false, + "default" : "DefaultParameterValue{value={}, type=MAP}", + "type" : "MAP" } ] }, { "isDeprecated" : false, - "signature" : "apoc.refactor.invert(rel :: RELATIONSHIP) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", + "signature" : "apoc.refactor.invert(rel :: RELATIONSHIP, config = {} :: MAP) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", "name" : "apoc.refactor.invert", "description" : "Inverts the direction of the given `RELATIONSHIP`.", "returnDescription" : [ { @@ -6196,6 +6202,12 @@ "description" : "The relationship to reverse.", "isDeprecated" : false, "type" : "RELATIONSHIP" + }, { + "name" : "config", + "description" : "{\n failOnErrors = false :: BOOLEAN\n}\n", + "isDeprecated" : false, + "default" : "DefaultParameterValue{value={}, type=MAP}", + "type" : "MAP" } ] }, { "isDeprecated" : false, @@ -6662,7 +6674,7 @@ } ] }, { "isDeprecated" : false, - "signature" : "apoc.refactor.to(rel :: RELATIONSHIP, endNode :: NODE) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", + "signature" : "apoc.refactor.to(rel :: RELATIONSHIP, endNode :: NODE, config = {} :: MAP) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)", "name" : "apoc.refactor.to", "description" : "Redirects the given `RELATIONSHIP` to the given end `NODE`.", "returnDescription" : [ { @@ -6692,6 +6704,12 @@ "description" : "The new end node the relationship should point to.", "isDeprecated" : false, "type" : "NODE" + }, { + "name" : "config", + "description" : "{\n failOnErrors = false :: BOOLEAN\n}\n", + "isDeprecated" : false, + "default" : "DefaultParameterValue{value={}, type=MAP}", + "type" : "MAP" } ] }, { "isDeprecated" : false,