Skip to content

Commit

Permalink
Re-configure so that single mode is the default
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesname committed Mar 27, 2014
1 parent d84d392 commit 1dbbe42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] <source> <rel-name> <target>";
return "Usage: add-rel [OPTIONS] <source> <rel-name> <target>";
}

@Override
Expand Down Expand Up @@ -65,16 +65,16 @@ public int execWithOptions(final FramedGraph<? extends TransactionalGraph> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")));
Expand All @@ -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")));
Expand All @@ -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")));
Expand Down

0 comments on commit 1dbbe42

Please sign in to comment.