8000 graph: added getGraphList · anderick/arangodb-java-driver@0e759f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e759f0

Browse files
committed
graph: added getGraphList
1 parent a7ce6c6 commit 0e759f0

File tree

6 files changed

+157
-37
lines changed

6 files changed

+157
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Support version: ArangoDB-2.2.x
66
# Required
77

88
* [ArangoDB](https://github.com/triAGENS/ArangoDB) Version 2.2.x
9-
* Java 5 later
9+
* Java 1.6 later
1010

1111

1212
# Basics

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,29 +1711,36 @@ public ReplicationApplierStateEntity getReplicationApplierState() throws ArangoE
17111711
return replicationDriver.getReplicationApplierState(getDefaultDatabase());
17121712
}
17131713

1714-
// ---------------------------------------- end of replication
1715-
// ----------------------------------------
1716-
// ---------------------------------------- start of graph
1717-
// ----------------------------------------
1714+
// *** end of replication ***
1715+
1716+
// ***************************************
1717+
// *** start of graph ********************
1718+
// ***************************************
17181719

17191720
/**
1720-
* @param documentKey
1721-
* @param vertices
1722-
* @param edges
1723-
* @param waitForSync
1724-
* @return
1721+
* Returns a GraphsEntity containing all graph as GraphEntity object of the
1722+
* default database.
1723+
*
1724+
* @return GraphsEntity
17251725
* @throws ArangoException
1726-
* @since 1.4.0
1727-
* @deprecated
17281726
*/
1729-
@Deprecated
1730-
public GraphEntity createGraph(String documentKey, String vertices, String edges, Boolean waitForSync)
1731-
throws ArangoException {
1732-
return graphDriver.createGraph(getDefaultDatabase(), documentKey, vertices, edges, waitForSync);
1727+
public GraphsEntity getGraphs() throws ArangoException {
1728+
return graphDriver.getGraphs(getDefaultDatabase());
17331729
}
17341730

17351731
/**
1736-
* creates a graph
1732+
* Creates a list of the names of all available graphs of the default
1733+
* database.
1734+
*
1735+
* @return List<String>
1736+
* @throws ArangoException
1737+
*/
1738+
public List<String> getGraphList() throws ArangoException {
1739+
return graphDriver.getGraphList(getDefaultDatabase());
1740+
}
1741+
1742+
/**
1743+
* Creates a graph.
17371744
*
17381745
* @param graphName
17391746
* @param edgeDefinitions
@@ -1751,7 +1758,7 @@ public GraphEntity createGraph(
17511758
}
17521759

17531760
/**
1754-
* creates an empty graph
1761+
* Creates an empty graph.
17551762
*
17561763
* @param graphName
17571764
* @param waitForSync
@@ -1763,17 +1770,8 @@ public GraphEntity createGraph(String graphName, Boolean waitForSync) throws Ara
17631770
}
17641771

17651772
/**
1766-
* Creates a list of all available graphs of the default database.
1767-
*
1768-
* @return GraphsEntity
1769-
* @throws ArangoException
1770-
*/
1771-
public GraphsEntity getGraphs() throws ArangoException {
1772-
return graphDriver.getGraphs(getDefaultDatabase());
1773-
}
1774-
1775-
/**
1776-
* Get graph object by name
1773+
* Get graph object by name, including its edge definitions and vertex
1774+
* collections.
17771775
*
17781776
* @param graphName
17791777
* @return GraphEntity
@@ -1785,7 +1783,7 @@ public GraphEntity getGraph(String graphName) throws ArangoException {
17851783

17861784
/**
17871785
* Delete a graph by its name. The collections of the graph will not be
1788-
* deleted.
1786+
* dropped.
17891787
*
17901788
* @param graphName
17911789
* @throws ArangoException
@@ -1796,7 +1794,7 @@ public void deleteGraph(String graphName) throws ArangoException {
17961794

17971795
/**
17981796
* Delete a graph by its name. If dropCollections is true, all collections of
1799-
* the graph will be deleted, if they are not used in another graph.
1797+
* the graph will be dropped, if they are not used in another graph.
18001798
*
18011799
* @param graphName
18021800
* @param dropCollections

src/main/java/com/arangodb/InternalGraphDriver.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
public interface InternalGraphDriver extends BaseDriverInterface {
2121
GraphEntity createGraph(String databaseName, String graphName, Boolean waitForSync) throws ArangoException;
2222

23+
/**
24+
* Creates a graph.
25+
*
26+
* @param databaseName
27+
* @param graphName
28+
* @param edgeDefinitions
29+
* @param orphanCollections
30+
* @param waitForSync
31+
* @return GraphEntity
32+
* @throws ArangoException
33+
*/
2334
GraphEntity createGraph(
2435
String databaseName,
2536
String graphName,
@@ -31,17 +42,44 @@ GraphEntity createGraph(String databaseName, String documentKey, String vertices
3142
throws ArangoException;
3243

3344
/**
34-
* Creates a list of all available graphs of the default database
35-
* databaseName.
45+
* Returns a GraphsEntity containing all graph as GraphEntity object.
3646
*
3747
* @param databaseName
3848
* @return GraphsEntity
3949
* @throws ArangoException
4050
*/
4151
GraphsEntity getGraphs(String databaseName) throws ArangoException;
4252

53+
/**
54+
* Creates a list of the names of all available graphs.
55+
*
56+
* @param databaseName
57+
* @return List<String>
58+
* @throws ArangoException
59+
*/
60+
List<String> getGraphList(String databaseName) throws ArangoException;
61+
62+
/**
63+
* Get graph object by name, including its edge definitions and vertex
64+
* collections.
65+
*
66+
* @param databaseName
67+
* @param graphName
68+
* @return GraphEntity
69+
* @throws ArangoException
70+
*/
4371
GraphEntity getGraph(String databaseName, String graphName) throws ArangoException;
4472

73+
/**
74+
* Delete a graph by its name. If dropCollections is true, all collections of
75+
* the graph will be dropped, if they are not used in another graph.
76+
*
77+
* @param databaseName
78+
* @param graphName
79+
* @param dropCollections
80+
* @return DeletedEntity
81+
* @throws ArangoException
82+
*/
4583
DeletedEntity deleteGraph(String databaseName, String graphName, Boolean dropCollections) throws ArangoException;
4684

4785
List<String> getVertexCollections(String databaseName, String graphName) throws ArangoException;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* Copyright holder is triAGENS GmbH, Cologne, Germany
16+
*
17+
* @author gschwab
18+
* @author Copyright 2014, triAGENS GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
import java.util.List;
24+
25+
public class StringsEntity extends BaseEntity {
26+
27+
List<String> list;
28+
29+
public List<String> getList() {
30+
return list;
31+
}
32+
33+
public void setGraphs(List<String> list) {
34+
this.list = list;
35+
}
36+
37+
}

src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717
package com.arangodb.impl;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collection;
2021
import java.util.List;
2122
import java.util.Locale;
2223
import java.util.Map;
2324

25+
import org.apache.commons.collections4.CollectionUtils;
26+
2427
import com.arangodb.ArangoConfigure;
2528
import com.arangodb.ArangoException;
2629
import com.arangodb.CursorResultSet;
@@ -114,19 +117,40 @@ public GraphEntity createGraph(
114117< F438 /code>
}
115118

116119
/**
117-
* get all existing graphs of <database>
120+
* Returns a GraphsEntity containing all graph as GraphEntity object.
118121
*
119122
* @param databaseName
120-
* @return
123+
* @return GraphsEntity
121124
* @throws ArangoException
122125
*/
123126
@Override
124127
public GraphsEntity getGraphs(String databaseName) throws ArangoException {
125128

126-
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(baseUrl, databaseName, "/_api/gharial"));
129+
GraphsEntity graphsEntity = new GraphsEntity();
130+
List<GraphEntity> graphEntities = new ArrayList<GraphEntity>();
131+
List<String> graphList = this.getGraphList(databaseName);
132+
if (CollectionUtils.isNotEmpty(graphList)) {
133+
for (String graphName : graphList) {
134+
graphEntities.add(this.getGraph(databaseName, graphName));
135+
}
136+
}
137+
graphsEntity.setGraphs(graphEntities);
138+
return graphsEntity;
127139

128-
return createEntity(res, GraphsEntity.class);
140+
}
129141

142+
@Override
143+
public List<String> getGraphList(String databaseName) throws ArangoException {
144+
HttpResponseEntity res = httpManager.doGet(createEndpointUrl(baseUrl, databaseName, "/_api/gharial"));
145+
GraphsEntity graphsEntity = createEntity(res, GraphsEntity.class);
146+
List<String> graphList = new ArrayList<String>();
147+
List<GraphEntity> graphs = graphsEntity.getGraphs();
148+
if (CollectionUtils.isNotEmpty(graphs)) {
149+
for (GraphEntity graph : graphs) {
150+
graphList.add(graph.getDocumentKey());
151+
}
152+
}
153+
return graphList;
130154
}
131155

132156
/**

src/test/java/com/arangodb/ArangoDriverGraphTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.hamcrest.CoreMatchers.is;
2020
import static org.hamcrest.CoreMatchers.not;
2121
import static org.hamcrest.Matchers.greaterThan;
22+
import static org.hamcrest.Matchers.startsWith;
2223
import static org.junit.Assert.assertThat;
2324
import static org.junit.Assert.fail;
2425

@@ -34,6 +35,7 @@
3435

3536
/**
3637
* @author tamtam180 - kirscheless at gmail.com
38+
* @author gschwab
3739
*
3840
*/
3941
public class ArangoDriverGraphTest extends BaseGraphTest {
@@ -54,6 +56,27 @@ public void test_get_graphs() throws ArangoException {
5456
driver.createGraph("UnitTestGraph3", true);
5557
graphs = driver.getGraphs();
5658
assertThat(graphs.getGraphs().size(), is(3));
59+
assertThat(graphs.getGraphs().get(0).getName(), startsWith("UnitTestGraph"));
60+
assertThat(graphs.getGraphs().get(1).getName(), startsWith("UnitTestGraph"));
61+
assertThat(graphs.getGraphs().get(2).getName(), startsWith("UnitTestGraph"));
62+
}
63+
64+
@Test
65+
public void test_getGraphList() throws ArangoException {
66+
List<String> graphs = driver.getGraphList();
67+
assertThat(graphs.size(), is(0));
68+
String graphName1 = "UnitTestGraph1";
69+
String graphName2 = "UnitTestGraph2";
70+
String graphName3 = "UnitTestGraph3";
71+
driver.createGraph(graphName1, true);
72+
driver.createGraph(graphName2, true);
73+
driver.createGraph(graphName3, true);
74+
graphs = driver.getGraphList();
75+
assertThat(graphs.size(), is(3));
76+
assertThat(graphs.contains(graphName1), is(true));
77+
assertThat(graphs.contains(graphName2), is(true));
78+
assertThat(graphs.contains(graphName3), is(true));
79+
assertThat(graphs.contains("foo"), is(false));
5780
}
5881

5982
@Test

0 commit comments

Comments
 (0)
0