From 1dbbe42ae098b2b24fb2c1f48860f19cdce8aef8 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Thu, 27 Mar 2014 16:23:27 +0000 Subject: [PATCH] Re-configure so that single mode is the default --- .../eu/ehri/project/commands/RelationAdd.java | 16 ++++++++-------- .../ehri/project/commands/RelationAddTest.java | 16 +++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/ehri-cmdline/src/main/java/eu/ehri/project/commands/RelationAdd.java b/ehri-cmdline/src/main/java/eu/ehri/project/commands/RelationAdd.java index 073a1e42f..5ea6c258a 100644 --- a/ehri-cmdline/src/main/java/eu/ehri/project/commands/RelationAdd.java +++ b/ehri-cmdline/src/main/java/eu/ehri/project/commands/RelationAdd.java @@ -27,15 +27,15 @@ public RelationAdd() { @Override protected void setCustomOptions() { - options.addOption(new Option("u", "unique", false, - "Ensure the out entity only has one relationship of this type")); options.addOption(new Option("s", "single", false, - "Don't create this relationship if it already exists")); + "Ensure the out entity only has one relationship of this type by removing any others")); + options.addOption(new Option("d", "allow-duplicates", false, + "Allow creating multiple edges with the same label between the same two nodes")); } @Override public String getHelp() { - return "Usage: add-rel [OPTIONS] [-Pkey=value] "; + return "Usage: add-rel [OPTIONS] "; } @Override @@ -65,16 +65,16 @@ public int execWithOptions(final FramedGraph graph Vertex target = manager.getVertex(dst); try { - if (cmdLine.hasOption("unique")) { + if (cmdLine.hasOption("allow-duplicates")) { + source.addEdge(label, target); + } else if (cmdLine.hasOption("unique")) { if (!JavaHandlerUtils.addUniqueRelationship(source, target, label)) { System.err.println("Relationship already exists"); } - } else if (cmdLine.hasOption("single")) { + } else { if (!JavaHandlerUtils.addSingleRelationship(source, target, label)) { System.err.println("Relationship already exists"); } - } else { - source.addEdge(label, target); } graph.getBaseGraph().commit(); } catch (Exception e) { diff --git a/ehri-cmdline/src/test/java/eu/ehri/project/commands/RelationAddTest.java b/ehri-cmdline/src/test/java/eu/ehri/project/commands/RelationAddTest.java index a3757aebb..7476cafd1 100644 --- a/ehri-cmdline/src/test/java/eu/ehri/project/commands/RelationAddTest.java +++ b/ehri-cmdline/src/test/java/eu/ehri/project/commands/RelationAddTest.java @@ -1,22 +1,16 @@ package eu.ehri.project.commands; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Vertex; import eu.ehri.project.models.EntityClass; -import eu.ehri.project.test.AbstractFixtureTest; import eu.ehri.project.test.GraphTestBase; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.PosixParser; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; /** * @author Mike Bryant (http://github.com/mikesname) @@ -38,9 +32,9 @@ public void setUp() throws Exception { } @Test - public void testAddRelation() throws Exception { + public void testAddRelationWithDuplicates() throws Exception { assertEquals(0L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); - CommandLine commandLine = relationAdd.getCmdLine(new String[]{"mike", "knows", "linda"}); + CommandLine commandLine = relationAdd.getCmdLine(new String[]{"mike", "knows", "linda", "--allow-duplicates"}); int retVal = relationAdd.execWithOptions(graph, commandLine); assertEquals(0, retVal); assertEquals(1L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); @@ -52,9 +46,9 @@ public void testAddRelation() throws Exception { } @Test - public void testAddUniqueRelation() throws Exception { + public void testAddRelation() throws Exception { assertEquals(0L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); - CommandLine commandLine = relationAdd.getCmdLine(new String[]{"-u", "mike", "knows", "linda"}); + CommandLine commandLine = relationAdd.getCmdLine(new String[]{"mike", "knows", "linda"}); int retVal = relationAdd.execWithOptions(graph, commandLine); assertEquals(0, retVal); assertEquals(1L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); @@ -74,7 +68,7 @@ public void testAddSingleRelation() throws Exception { assertEquals(1L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); assertEquals(1L, Iterables.size(linda.getVertices(Direction.IN, "knows"))); - CommandLine commandLine2 = relationAdd.getCmdLine(new String[]{"-s", "mike", "knows", "reto"}); + CommandLine commandLine2 = relationAdd.getCmdLine(new String[]{"--single", "mike", "knows", "reto"}); relationAdd.execWithOptions(graph, commandLine2); assertEquals(1L, Iterables.size(mike.getVertices(Direction.OUT, "knows"))); assertEquals(0L, Iterables.size(linda.getVertices(Direction.IN, "knows")));