com.arangodb.entity.EdgeDefinition Java Examples

The following examples show how to use com.arangodb.entity.EdgeDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArangoDBUtil.java    From arangodb-tinkerpop-provider with Apache License 2.0 6 votes vote down vote up
/**
   * Create the EdgeDefinition for the graph properties.
   *
* @param graph The graph
   * @param vertexCollections the vertex collections
   * @param edgeCollections the edge collections
   * @return the edge definition
   */
	
  public static EdgeDefinition createPropertyEdgeDefinitions(
final ArangoDBGraph graph,
final List<String> vertexCollections,
final List<String> edgeCollections) {
      final List<String> from = new ArrayList<>(vertexCollections);
      from.addAll(edgeCollections);
      from.add(graph.getPrefixedCollectioName(ArangoDBGraph.ELEMENT_PROPERTIES_COLLECTION));
      String[] f = from.toArray(new String[from.size()]);
      EdgeDefinition ed = new EdgeDefinition()
              .collection(graph.getPrefixedCollectioName(ArangoDBGraph.ELEMENT_PROPERTIES_EDGE_COLLECTION))
              .from(f)
              .to(graph.getPrefixedCollectioName(ArangoDBGraph.ELEMENT_PROPERTIES_COLLECTION));
      return ed;
  }
 
Example #2
Source File: BaseGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws InterruptedException, ExecutionException {
    if (arangoDB == null) {
        arangoDB = new ArangoDBAsync.Builder().build();
    }
    if (arangoDB.db(TEST_DB).exists().get()) {
        arangoDB.db(TEST_DB).drop().get();
    }
    arangoDB.createDatabase(TEST_DB).get();
    BaseGraphTest.db = arangoDB.db(TEST_DB);

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final EdgeDefinition edgeDefinition = new EdgeDefinition().collection(EDGE_COLLECTION_NAME)
            .from(VERTEXT_COLLECTION_NAME).to(VERTEXT_COLLECTION_NAME);
    edgeDefinitions.add(edgeDefinition);
    db.createGraph(GRAPH_NAME, edgeDefinitions, null).get();
    addExampleElements();
}
 
Example #3
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() {
    assumeTrue(isEnterprise());
    assumeTrue(isCluster());

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection("smartGraph-edge-" + rnd()).from("smartGraph-vertex-" + rnd()).to("smartGraph-vertex-" + rnd()));

    String graphId = GRAPH_NAME + rnd();
    final GraphEntity g = db.createGraph(graphId, edgeDefinitions, new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").numberOfShards(2));

    assertThat(g, is(notNullValue()));
    assertThat(g.getIsSmart(), is(true));
    assertThat(g.getSmartGraphAttribute(), is("test"));
    assertThat(g.getNumberOfShards(), is(2));
}
 
Example #4
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void getInfo() {
    final GraphEntity info = graph.getInfo();
    assertThat(info, is(notNullValue()));
    assertThat(info.getName(), is(GRAPH_NAME));
    assertThat(info.getEdgeDefinitions().size(), is(2));
    final Iterator<EdgeDefinition> iterator = info.getEdgeDefinitions().iterator();
    final EdgeDefinition e1 = iterator.next();
    assertThat(e1.getCollection(), is(EDGE_COL_1));
    assertThat(e1.getFrom(), hasItem(VERTEX_COL_1));
    assertThat(e1.getTo(), hasItem(VERTEX_COL_2));
    final EdgeDefinition e2 = iterator.next();
    assertThat(e2.getCollection(), is(EDGE_COL_2));
    assertThat(e2.getFrom(), hasItem(VERTEX_COL_2));
    assertThat(e2.getTo(), hasItems(VERTEX_COL_1, VERTEX_COL_3));
    assertThat(info.getOrphanCollections(), is(empty()));

    if (isCluster()) {
        for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2}) {
            final CollectionPropertiesEntity properties = db.collection(collection).getProperties();
            assertThat(properties.getReplicationFactor(), is(REPLICATION_FACTOR));
            assertThat(properties.getNumberOfShards(), is(NUMBER_OF_SHARDS));
        }
    }
}
 
Example #5
Source File: BaseGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() {
    if (arangoDB == null) {
        arangoDB = new ArangoDB.Builder().build();
    }
    if (arangoDB.db(TEST_DB).exists())
        arangoDB.db(TEST_DB).drop();
    arangoDB.createDatabase(TEST_DB);
    BaseGraphTest.db = arangoDB.db(TEST_DB);

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final EdgeDefinition edgeDefinition = new EdgeDefinition().collection(EDGE_COLLECTION_NAME)
            .from(VERTEXT_COLLECTION_NAME).to(VERTEXT_COLLECTION_NAME);
    edgeDefinitions.add(edgeDefinition);
    if (!db.graph(GRAPH_NAME).exists())
        db.createGraph(GRAPH_NAME, edgeDefinitions, null);
    addExampleElements();
}
 
Example #6
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() throws InterruptedException, ExecutionException {
    assumeTrue(isCluster());
    assumeTrue(isEnterprise());
    for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2,
            VERTEX_COL_3, VERTEX_COL_4}) {
        if (db.collection(collection).exists().get()) {
            db.collection(collection).drop().get();
        }
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_smart", edgeDefinitions,
            new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").replicationFactor(REPLICATION_FACTOR)
                    .numberOfShards(NUMBER_OF_SHARDS))
            .get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getIsSmart(), is(true));
    assertThat(graph.getSmartGraphAttribute(), is("test"));
    assertThat(graph.getNumberOfShards(), is(2));
    if (db.graph(GRAPH_NAME + "_smart").exists().get()) {
        db.graph(GRAPH_NAME + "_smart").drop().get();
    }
}
 
Example #7
Source File: ArangoDBUtil.java    From arangodb-tinkerpop-provider with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the default edge definitions. When no relations are provided, the graph schema is
 * assumed to be fully connected, i.e. there is an EdgeDefintion for each possible combination
 * of Vertex-Edge-Vertex triplets.
 *
 * @param verticesCollectionNames    the vertex collection names
 * @param edgesCollectionNames        the edge collection names
 * @return the list of edge definitions
 */

public static List<EdgeDefinition> createDefaultEdgeDefinitions(
	List<String> verticesCollectionNames,
	List<String> edgesCollectionNames) {
	List<EdgeDefinition> result = new ArrayList<>();
	for (String e : edgesCollectionNames) {
		for (String from : verticesCollectionNames) {
			for (String to : verticesCollectionNames) {
				EdgeDefinition ed = new EdgeDefinition()
					.collection(e)
					.from(from)
					.to(to);
				result.add(ed);
			}
		}
	}
	return result;
}
 
Example #8
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void smartGraph() throws InterruptedException, ExecutionException {
    assumeTrue(isCluster());
    assumeTrue(isEnterprise());
    for (final String collection : new String[]{EDGE_COL_1, EDGE_COL_2, VERTEX_COL_1, VERTEX_COL_2,
            VERTEX_COL_3, VERTEX_COL_4}) {
        if (db.collection(collection).exists().get()) {
            db.collection(collection).drop().get();
        }
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_smart", edgeDefinitions,
            new GraphCreateOptions().isSmart(true).smartGraphAttribute("test").replicationFactor(REPLICATION_FACTOR)
                    .numberOfShards(NUMBER_OF_SHARDS))
            .get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getIsSmart(), is(true));
    assertThat(graph.getSmartGraphAttribute(), is("test"));
    assertThat(graph.getNumberOfShards(), is(2));
    if (db.graph(GRAPH_NAME + "_smart").exists().get()) {
        db.graph(GRAPH_NAME + "_smart").drop().get();
    }
}
 
Example #9
Source File: BaseGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws InterruptedException, ExecutionException {
    if (arangoDB == null) {
        arangoDB = new ArangoDBAsync.Builder().build();
    }
    if (arangoDB.db(TEST_DB).exists().get()) {
        arangoDB.db(TEST_DB).drop().get();
    }
    arangoDB.createDatabase(TEST_DB).get();
    BaseGraphTest.db = arangoDB.db(TEST_DB);

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final EdgeDefinition edgeDefinition = new EdgeDefinition().collection(EDGE_COLLECTION_NAME)
            .from(VERTEXT_COLLECTION_NAME).to(VERTEXT_COLLECTION_NAME);
    edgeDefinitions.add(edgeDefinition);
    db.createGraph(GRAPH_NAME, edgeDefinitions, null).get();
    addExampleElements();
}
 
Example #10
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void dropPlusDropCollections() throws InterruptedException, ExecutionException {
    final String edgeCollection = "edge_dropC";
    final String vertexCollection = "vertex_dropC";
    final String graph = GRAPH_NAME + "_dropC";
    final GraphEntity result = db.graph(graph).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
            .get();
    assertThat(result, is(notNullValue()));
    db.graph(graph).drop(true).get();
    assertThat(db.collection(edgeCollection).exists().get(), is(false));
    assertThat(db.collection(vertexCollection).exists().get(), is(false));
}
 
Example #11
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws InterruptedException, ExecutionException {
    if (db.graph(GRAPH_NAME).exists().get()) {
        db.graph(GRAPH_NAME).drop().get();
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphCreateOptions options = new GraphCreateOptions();
    if (arangoDB.getRole().get() != ServerRole.SINGLE) {
        options.replicationFactor(REPLICATION_FACTOR).numberOfShards(NUMBER_OF_SHARDS);
    }
    db.createGraph(GRAPH_NAME, edgeDefinitions, options).get();
}
 
Example #12
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() throws ExecutionException, InterruptedException {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)).get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #13
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void removeEdgeDefinition() throws InterruptedException, ExecutionException {
    final GraphEntity graph = db.graph(GRAPH_NAME).removeEdgeDefinition(EDGE_COL_1).get();
    final Collection<EdgeDefinition> edgeDefinitions = graph.getEdgeDefinitions();
    assertThat(edgeDefinitions.size(), is(1));
    assertThat(edgeDefinitions.iterator().next().getCollection(), is(EDGE_COL_2));
    setup();
}
 
Example #14
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    final Collection<EdgeDefinition> edgeDefinitions = Arrays.asList(ed1, ed2);

    final GraphCreateOptions options = new GraphCreateOptions()
            .replicationFactor(REPLICATION_FACTOR)
            .numberOfShards(NUMBER_OF_SHARDS);

    BaseTest.initGraph(GRAPH_NAME, edgeDefinitions, options);
}
 
Example #15
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void drop() throws InterruptedException, ExecutionException {
    final String edgeCollection = "edge_drop";
    final String vertexCollection = "vertex_drop";
    final String graph = GRAPH_NAME + "_drop";
    final GraphEntity result = db.graph(graph).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
            .get();
    assertThat(result, is(notNullValue()));
    db.graph(graph).drop().get();
    assertThat(db.collection(edgeCollection).exists().get(), is(true));
    assertThat(db.collection(vertexCollection).exists().get(), is(true));
}
 
Example #16
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2));
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #17
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void removeEdgeDefinition() {
    final GraphEntity g = graph.removeEdgeDefinition(EDGE_COL_1);
    final Collection<EdgeDefinition> edgeDefinitions = g.getEdgeDefinitions();
    assertThat(edgeDefinitions.size(), is(1));
    assertThat(edgeDefinitions.iterator().next().getCollection(), is(EDGE_COL_2));

    //revert
    graph.addEdgeDefinition(ed1);
}
 
Example #18
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void drop() {
    final String edgeCollection = "edge_" + rnd();
    final String vertexCollection = "vertex_" + rnd();
    final String graphId = GRAPH_NAME + rnd();
    final GraphEntity result = db.graph(graphId).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
    assertThat(result, is(notNullValue()));
    db.graph(graphId).drop();
    assertThat(db.collection(edgeCollection).exists(), is(true));
    assertThat(db.collection(vertexCollection).exists(), is(true));
}
 
Example #19
Source File: ArangoEdgeCollectionTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws InterruptedException, ExecutionException {
    if (!db.collection(VERTEX_COLLECTION_NAME).exists().get()) {
        db.createCollection(VERTEX_COLLECTION_NAME, null).get();
    }
    if (!db.collection(EDGE_COLLECTION_NAME).exists().get()) {
        db.createCollection(EDGE_COLLECTION_NAME, new CollectionCreateOptions().type(CollectionType.EDGES)).get();
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COLLECTION_NAME).from(VERTEX_COLLECTION_NAME)
            .to(VERTEX_COLLECTION_NAME));
    db.createGraph(GRAPH_NAME, edgeDefinitions, null).get();
}
 
Example #20
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void dropPlusDropCollections() throws InterruptedException, ExecutionException {
    final String edgeCollection = "edge_dropC";
    final String vertexCollection = "vertex_dropC";
    final String graph = GRAPH_NAME + "_dropC";
    final GraphEntity result = db.graph(graph).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
            .get();
    assertThat(result, is(notNullValue()));
    db.graph(graph).drop(true).get();
    assertThat(db.collection(edgeCollection).exists().get(), is(false));
    assertThat(db.collection(vertexCollection).exists().get(), is(false));
}
 
Example #21
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void drop() throws InterruptedException, ExecutionException {
    final String edgeCollection = "edge_drop";
    final String vertexCollection = "vertex_drop";
    final String graph = GRAPH_NAME + "_drop";
    final GraphEntity result = db.graph(graph).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
            .get();
    assertThat(result, is(notNullValue()));
    db.graph(graph).drop().get();
    assertThat(db.collection(edgeCollection).exists().get(), is(true));
    assertThat(db.collection(vertexCollection).exists().get(), is(true));
}
 
Example #22
Source File: ArangoGraphTest.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
public void dropPlusDropCollections() {
    final String edgeCollection = "edge_dropC" + rnd();
    final String vertexCollection = "vertex_dropC" + rnd();
    final String graphId = GRAPH_NAME + "_dropC" + rnd();
    final GraphEntity result = db.graph(graphId).create(Collections
            .singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)));
    assertThat(result, is(notNullValue()));
    db.graph(graphId).drop(true);
    assertThat(db.collection(edgeCollection).exists(), is(false));
    assertThat(db.collection(vertexCollection).exists(), is(false));
}
 
Example #23
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void removeEdgeDefinition() throws InterruptedException, ExecutionException {
    final GraphEntity graph = db.graph(GRAPH_NAME).removeEdgeDefinition(EDGE_COL_1).get();
    final Collection<EdgeDefinition> edgeDefinitions = graph.getEdgeDefinitions();
    assertThat(edgeDefinitions.size(), is(1));
    assertThat(edgeDefinitions.iterator().next().getCollection(), is(EDGE_COL_2));
    setup();
}
 
Example #24
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@Test
public void createWithReplicationAndMinReplicationFactor() throws ExecutionException, InterruptedException {
    assumeTrue(isAtLeastVersion(3, 5));
    assumeTrue(isCluster());
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)).get();
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getName(), is(GRAPH_NAME + "_1"));
    assertThat(graph.getMinReplicationFactor(), is(2));
    assertThat(graph.getReplicationFactor(), is(2));
    db.graph(GRAPH_NAME + "_1").drop();
}
 
Example #25
Source File: ArangoGraphTest.java    From arangodb-java-driver-async with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws InterruptedException, ExecutionException {
    if (db.graph(GRAPH_NAME).exists().get()) {
        db.graph(GRAPH_NAME).drop().get();
    }
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphCreateOptions options = new GraphCreateOptions();
    if (arangoDB.getRole().get() != ServerRole.SINGLE) {
        options.replicationFactor(REPLICATION_FACTOR).numberOfShards(NUMBER_OF_SHARDS);
    }
    db.createGraph(GRAPH_NAME, edgeDefinitions, options).get();
}
 
Example #26
Source File: ArangoDBUtil.java    From arangodb-tinkerpop-provider with Apache License 2.0 4 votes vote down vote up
/**
 * Validate if an existing graph is correctly configured to handle the desired vertex, edges 
 * and relations.
 *
 * @param verticesCollectionNames    The names of collections for nodes
 * @param edgesCollectionNames        The names of collections for edges
 * @param requiredDefinitions                The description of edge definitions
 * @param graph                    the graph
 * @param options                    The options used to create the graph
 * @throws ArangoDBGraphException 	If the graph settings do not match the configuration information
 */

public static void checkGraphForErrors(
	List<String> verticesCollectionNames,
	List<String> edgesCollectionNames,
	List<EdgeDefinition> requiredDefinitions,
	ArangoGraph graph,
	GraphCreateOptions options) throws ArangoDBGraphException {

	checkGraphVertexCollections(verticesCollectionNames, graph, options);

	GraphEntity ge = graph.getInfo();
       Collection<EdgeDefinition> graphEdgeDefinitions = ge.getEdgeDefinitions();
       if (CollectionUtils.isEmpty(requiredDefinitions)) {
       	// If no relations are defined, vertices and edges can only have one value
       	if ((verticesCollectionNames.size() != 1) || (edgesCollectionNames.size() != 1)) {
       		throw new ArangoDBGraphException("No relations where specified but more than one vertex/edge where defined.");
       	}
       	if (graphEdgeDefinitions.size() != 2) {		// There is always a edgeDefinition for ELEMENT_HAS_PROPERTIES
       		throw new ArangoDBGraphException("No relations where specified but the graph has more than one EdgeDefinition.");
   		}
       }
	Map<String, EdgeDefinition> eds = requiredDefinitions.stream().collect(Collectors.toMap(EdgeDefinition::getCollection, ed -> ed));

       Iterator<EdgeDefinition> it = graphEdgeDefinitions.iterator();
       while (it.hasNext()) {
       	EdgeDefinition existing = it.next();
       	if (eds.containsKey(existing.getCollection())) {
       		EdgeDefinition requiredEdgeDefinition = eds.remove(existing.getCollection());
       		HashSet<String> existingSet = new HashSet<String>(existing.getFrom());
       		HashSet<String> requiredSet = new HashSet<String>(requiredEdgeDefinition.getFrom());
       		if (!existingSet.equals(requiredSet)) {
       			throw new ArangoDBGraphException(String.format("The from collections dont match for edge definition %s", existing.getCollection()));
       		}
       		existingSet.clear();
       		existingSet.addAll(existing.getTo());
       		requiredSet.clear();
       		requiredSet.addAll(requiredEdgeDefinition.getTo());
       		if (!existingSet.equals(requiredSet)) {
       			throw new ArangoDBGraphException(String.format("The to collections dont match for edge definition %s", existing.getCollection()));
       		}
       	} else {
       		throw new ArangoDBGraphException(String.format("The graph has a surplus edge definition %s", edgeDefinitionString(existing)));
       	}
       }
}
 
Example #27
Source File: ArangoGraphImpl.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Override
public GraphEntity addEdgeDefinition(final EdgeDefinition definition) throws ArangoDBException {
    return executor.execute(addEdgeDefinitionRequest(definition), addEdgeDefinitionResponseDeserializer());
}
 
Example #28
Source File: ArangoGraphAsyncImpl.java    From arangodb-java-driver-async with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<GraphEntity> create(final Collection<EdgeDefinition> edgeDefinitions) {
	return db().createGraph(name(), edgeDefinitions);
}
 
Example #29
Source File: ArangoGraphAsyncImpl.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<GraphEntity> replaceEdgeDefinition(final EdgeDefinition definition) {
    return executor.execute(replaceEdgeDefinitionRequest(definition), replaceEdgeDefinitionResponseDeserializer());
}
 
Example #30
Source File: ArangoGraphAsyncImpl.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<GraphEntity> addEdgeDefinition(final EdgeDefinition definition) {
    return executor.execute(addEdgeDefinitionRequest(definition), addEdgeDefinitionResponseDeserializer());
}