Skip to content

Commit

Permalink
Rework methods to retrieve child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkellnhofer committed Feb 15, 2018
1 parent b6eaf19 commit ddab396
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 65 deletions.
20 changes: 12 additions & 8 deletions example/src/main/java/com/dracoon/sdk/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static void main(String[] args) throws Exception {
//checkUserKeyPair(client);
//deleteUserKeyPair(client);

//listRootNodes(client);
//listRootNodesPaged(client);
//listNodes(client);
listNodesPaged(client);
//getNode(client);
//getNodeNotFound(client);

Expand All @@ -70,7 +70,7 @@ public static void main(String[] args) throws Exception {
//downloadFile(client);

//searchNodes(client);
searchNodesPaged(client);
//searchNodesPaged(client);
}

private static void getServerData(DracoonClient client) throws DracoonException {
Expand Down Expand Up @@ -115,20 +115,24 @@ private static void deleteUserKeyPair(DracoonClient client) throws DracoonExcept
client.account().deleteUserKeyPair();
}

private static void listRootNodes(DracoonClient client) throws DracoonException {
NodeList nodeList = client.nodes().getRootNodes();
private static void listNodes(DracoonClient client) throws DracoonException {
long parentNodeId = 0L;

NodeList nodeList = client.nodes().getNodes(parentNodeId);
for (Node node : nodeList.getItems()) {
System.out.println(node.getId() + ": " + node.getParentPath() + node.getName());
}
}

private static void listRootNodesPaged(DracoonClient client) throws DracoonException {
NodeList nodeList1 = client.nodes().getRootNodes(0, 4);
private static void listNodesPaged(DracoonClient client) throws DracoonException {
long parentNodeId = 0L;

NodeList nodeList1 = client.nodes().getNodes(parentNodeId, 0, 4);
System.out.println("Nodes page 1:");
for (Node node : nodeList1.getItems()) {
System.out.println(node.getId() + ": " + node.getParentPath() + node.getName());
}
NodeList nodeList2 = client.nodes().getRootNodes(4, 4);
NodeList nodeList2 = client.nodes().getNodes(parentNodeId, 4, 4);
System.out.println("Nodes page 2:");
for (Node node : nodeList2.getItems()) {
System.out.println(node.getId() + ": " + node.getParentPath() + node.getName());
Expand Down
45 changes: 13 additions & 32 deletions src/main/java/com/dracoon/sdk/DracoonClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,54 +147,35 @@ public interface Groups {
public interface Nodes {

/**
* Retrieves all root nodes.
*
* @return root nodes
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
NodeList getRootNodes() throws DracoonNetIOException, DracoonApiException;

/**
* Retrieves root nodes for a specific range.
*
* @param offset The range offset.
* @param limit The range limit.
*
* @return root nodes
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
NodeList getRootNodes(int offset, int limit) throws DracoonNetIOException,
DracoonApiException;

/**
* Retrieves all child nodes of a node.
* Retrieves child nodes of a node.<br>
* <br>
* Use parent node ID <code>0</code> to retrieve root nodes.
*
* @param parentNodeId The ID of the parent node.
* @param parentNodeId The ID of the parent node. (ID must be 0 or positive.)
*
* @return list of nodes
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
NodeList getChildNodes(long parentNodeId) throws DracoonNetIOException, DracoonApiException;
NodeList getNodes(long parentNodeId) throws DracoonNetIOException, DracoonApiException;

/**
* Retrieves child nodes of a node for a specific range.
* Retrieves child nodes of a node. The arguments {@code offset} and {@code limit} restrict
* the result to a specific range.<br>
* <br>
* Use parent node ID <code>0</code> to retrieve root nodes.
*
* @param parentNodeId The ID of the parent node.
* @param offset The range offset.
* @param limit The range limit.
* @param parentNodeId The ID of the parent node. (ID must be 0 or positive.)
* @param offset The range offset. (Zero-based index; must be 0 or positive.)
* @param limit The range limit. (Number of records; must be positive.)
*
* @return list of nodes
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
NodeList getChildNodes(long parentNodeId, int offset, int limit)
NodeList getNodes(long parentNodeId, int offset, int limit)
throws DracoonNetIOException, DracoonApiException;

/**
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/com/dracoon/sdk/internal/DracoonNodesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,25 @@ class DracoonNodesImpl extends DracoonRequestHandler implements DracoonClient.No
// --- Query methods ---

@Override
public NodeList getRootNodes() throws DracoonNetIOException, DracoonApiException {
return getChildNodes(0L);
}

@Override
public NodeList getRootNodes(int offset, int limit) throws DracoonNetIOException,
DracoonApiException {
return getChildNodes(0L, offset, limit);
}

@Override
public NodeList getChildNodes(long parentNodeId) throws DracoonNetIOException,
public NodeList getNodes(long parentNodeId) throws DracoonNetIOException,
DracoonApiException {
return getChildNodesInternally(parentNodeId, null, null);
return getNodesInternally(parentNodeId, null, null);
}

@Override
public NodeList getChildNodes(long parentNodeId, int offset, int limit)
public NodeList getNodes(long parentNodeId, int offset, int limit)
throws DracoonNetIOException, DracoonApiException {
return getChildNodesInternally(parentNodeId, offset, limit);
return getNodesInternally(parentNodeId, offset, limit);
}

private NodeList getChildNodesInternally(long parentNodeId, Integer offset, Integer limit)
private NodeList getNodesInternally(long parentNodeId, Integer offset, Integer limit)
throws DracoonNetIOException, DracoonApiException {
assertServerApiVersion();

NodeValidator.validateGetChildRequest(parentNodeId);

String accessToken = mClient.getAccessToken();
Call<ApiNodeList> call = mService.getChildNodes(accessToken, parentNodeId, 0, null, null,
Call<ApiNodeList> call = mService.getNodes(accessToken, parentNodeId, 0, null, null,
offset, limit);
Response<ApiNodeList> response = mHttpHelper.executeRequest(call);

Expand Down Expand Up @@ -153,7 +142,7 @@ public Node getNode(String nodePath) throws DracoonNetIOException, DracoonApiExc
break;
}

NodeList nodes = getChildNodes(parentNodeId);
NodeList nodes = getNodes(parentNodeId);

Node node = null;
for (int j = 0; j < nodes.getItems().size(); j++) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/dracoon/sdk/internal/DracoonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Call<Void> setUserKeyPair(@Header(AUTHORIZATION_HEADER) String token,
Call<Void> deleteUserKeyPair(@Header(AUTHORIZATION_HEADER) String token);

@GET(API_PATH + "/nodes")
Call<ApiNodeList> getChildNodes(@Header(AUTHORIZATION_HEADER) String token,
@Query("parent_id") Long id,
@Query("depth_level") Integer depthLevel,
@Query(value = "filter", encoded = true) String filter,
@Query(value = "sort", encoded = true) String sort,
@Query("offset") Integer offset,
@Query("limit") Integer limit);
Call<ApiNodeList> getNodes(@Header(AUTHORIZATION_HEADER) String token,
@Query("parent_id") Long id,
@Query("depth_level") Integer depthLevel,
@Query(value = "filter", encoded = true) String filter,
@Query(value = "sort", encoded = true) String sort,
@Query("offset") Integer offset,
@Query("limit") Integer limit);

@GET(API_PATH + "/nodes/{node_id}")
Call<ApiNode> getNode(@Header(AUTHORIZATION_HEADER) String token,
Expand Down

0 comments on commit ddab396

Please sign in to comment.