Java Code Examples for com.arangodb.entity.GraphEntity#getEdgeDefinitions()

The following examples show how to use com.arangodb.entity.GraphEntity#getEdgeDefinitions() . 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: 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 2
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 3
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 4
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)));
       	}
       }
}