Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
script:
- docker-compose -f .ci/doc/docker-compose.yml run doc-tests index


- stage: Deployment Doc Dev
name: Deploy next-docs.kuzzle.io
if: type = push AND branch =~ /^[0-9]+-dev$/
Expand Down
25 changes: 25 additions & 0 deletions doc/3/controllers/index/create/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
code: true
type: page
title: create
description: Creates an index.
---

# create

Creates a new index in Kuzzle

## Arguments

```java
CompletableFuture<Void> create(final String index)
throws NotConnectedException, InternalException
```

| Argument | Type | Description |
|----------|-------------------|-------------|
| `index` | <pre>String</pre> | Index name |

## Usage

<<< ./snippets/create.java
1 change: 1 addition & 0 deletions doc/3/controllers/index/create/snippets/create.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kuzzle.getIndexController().create("nyc-open-data").get();
8 changes: 8 additions & 0 deletions doc/3/controllers/index/create/snippets/create.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Index#CreateAsync
description: Creates a new index.
hooks:
before: curl -X DELETE kuzzle:7512/nyc-open-data
after:
template: default
expected: Success
25 changes: 25 additions & 0 deletions doc/3/controllers/index/delete/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
code: true
type: page
title: delete
description: Deletes an index.
---

# delete

Deletes an entire index from Kuzzle.

## Arguments

```java
CompletableFuture<Void> delete(final String index)
throws NotConnectedException, InternalException
```

| Argument | Type | Description |
|----------|-------------------|-------------|
| `index` | <pre>String</pre> | Index name |

## Usage

<<< ./snippets/delete.java
1 change: 1 addition & 0 deletions doc/3/controllers/index/delete/snippets/delete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kuzzle.getIndexController().delete("nyc-open-data").get();
8 changes: 8 additions & 0 deletions doc/3/controllers/index/delete/snippets/delete.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Index#Delete
description: Delete an index.
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create
after:
template: default
expected: Success
29 changes: 29 additions & 0 deletions doc/3/controllers/index/exists/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
code: true
type: page
title: exists
description: Check for index existence.
---

# exists

Checks if the given index exists in Kuzzle.

## Arguments

```java
CompletableFuture<Boolean> exists(final String index)
throws NotConnectedException, InternalException
```

| Argument | Type | Description |
|----------|-------------------|-------------|
| `index` | <pre>String</pre> | Index name |

## Return

Returns a `boolean` that indicates whether the index exists or not.

## Usage

<<< ./snippets/exists.java
1 change: 1 addition & 0 deletions doc/3/controllers/index/exists/snippets/exists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Boolean result = kuzzle.getIndexController().exists("nyc-open-data").get();
8 changes: 8 additions & 0 deletions doc/3/controllers/index/exists/snippets/exists.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Index#ExistsAsync
description: Test if an index exists.
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create
after:
template: print-result
expected: true
8 changes: 8 additions & 0 deletions doc/3/controllers/index/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
code: true
type: branch
title: Index
description: Index Controller
---

# Index Controller
25 changes: 25 additions & 0 deletions doc/3/controllers/index/list/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
code: true
type: page
title: list
description: Lists the indexes.
---

# list

Gets the complete list of indexes handled by Kuzzle.

## Arguments

```java
CompletableFuture<ArrayList<String>> list()
throws NotConnectedException, InternalException
```

## Return

Returns an `ArrayList<String>` containing the list of index names handled by Kuzzle.

## Usage

<<< ./snippets/list.java
1 change: 1 addition & 0 deletions doc/3/controllers/index/list/snippets/list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ArrayList<String> result = kuzzle.getIndexController().list().get();
10 changes: 10 additions & 0 deletions doc/3/controllers/index/list/snippets/list.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Index#ListAsync
description: List indexes handled by Kuzzle.
hooks:
before: |
curl -X POST kuzzle:7512/admin/_resetDatabase
curl -X POST kuzzle:7512/nyc-open-data/_create
after:
template: print-result
expected: ["nyc-open-data"]
29 changes: 29 additions & 0 deletions doc/3/controllers/index/m-delete/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
code: true
type: page
title: mDelete
description: Deletes multiple indexes.
---

# mDelete

Deletes multiple indexes.

## Arguments

```java
CompletableFuture<ArrayList<String>> mDelete(final ArrayList<String> indexes)
throws NotConnectedException, InternalException
```

| Argument | Type | Description |
|-----------|-------------------|-----------------------|
| `indexes` | <pre>ArrayList<String></pre> | List of indexes names |

## Return

Returns an `ArrayList<String>` containing the list of indexes names deleted.

## Usage

<<< ./snippets/mDelete.java
3 changes: 3 additions & 0 deletions doc/3/controllers/index/m-delete/snippets/mDelete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ArrayList<String> indexes = new ArrayList<>();
indexes.add("nyc-open-data");
ArrayList<String> result = kuzzle.getIndexController().mDelete(indexes).get();
8 changes: 8 additions & 0 deletions doc/3/controllers/index/m-delete/snippets/mDelete.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Index#MDeleteAsync
description: Delete multiple indexes.
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create ; curl -X POST kuzzle:7512/mtp-open-data/_create
after:
template: print-result
expected: ["nyc-open-data"]
98 changes: 98 additions & 0 deletions src/main/java/io/kuzzle/sdk/API/Controllers/IndexController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package io.kuzzle.sdk.API.Controllers;

import io.kuzzle.sdk.CoreClasses.Maps.KuzzleMap;
import io.kuzzle.sdk.Exceptions.InternalException;
import io.kuzzle.sdk.Exceptions.NotConnectedException;
import io.kuzzle.sdk.Kuzzle;

import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;

public class IndexController extends BaseController {
public IndexController(final Kuzzle kuzzle) {
super(kuzzle);
}

/**
* Creates a new index in Kuzzle via the persistence engine.
*
* @param index
* @return A CompletableFuture
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<Void> create(final String index) throws NotConnectedException, InternalException {
return kuzzle
.query(new KuzzleMap()
.put("controller", "index")
.put("action", "create")
.put("index", index))
.thenApplyAsync((response) -> null);
}

/**
* Deletes an index in Kuzzle via the persistence engine.
*
* @param index
* @return A CompletableFuture
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<Void> delete(final String index) throws NotConnectedException, InternalException {
return kuzzle
.query(new KuzzleMap()
.put("controller", "index")
.put("action", "delete")
.put("index", index))
.thenApplyAsync((response) -> null);
}

/**
* Checks if an index exists in the Kuzzle persistence engine.
*
* @param index
* @return A CompletableFuture<Boolean>
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<Boolean> exists(final String index) throws NotConnectedException, InternalException {
return kuzzle
.query(new KuzzleMap()
.put("controller", "index")
.put("action", "exists")
.put("index", index))
.thenApplyAsync((response) -> (Boolean) response.result);
}

/**
* Lists indexes from the Kuzzle persistence engine.
*
* @return A CompletableFuture<ArrayList<String>>
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<ArrayList<String>> list() throws NotConnectedException, InternalException {
return kuzzle
.query(new KuzzleMap()
.put("controller", "index")
.put("action", "list"))
.thenApplyAsync((response) -> (((KuzzleMap) response.result).getArrayList("indexes")));
}

/**
* Deletes multiple indexes from the Kuzzle persistence engine.
*
* @param indexes
* @return A CompletableFuture<ArrayList<String>>
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<ArrayList<String>> mDelete(final ArrayList<String> indexes) throws NotConnectedException, InternalException {
return kuzzle
.query(new KuzzleMap()
.put("controller", "index")
.put("action", "mDelete")
.put("body", new KuzzleMap().put("indexes", indexes)))
.thenApplyAsync((response) -> (((KuzzleMap) response.result).getArrayList("deleted")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public enum KuzzleExceptionCode {
MISSING_REQUESTID(0, "Missing field requestId"),
MSSING_QUERY(400, "You must provide a query"),
MISSING_QUERY(400, "You must provide a query"),
NOT_CONNECTED(500, "Not connected."),
CONNECTION_LOST(500, "Connection lost"),
WRONG_VOLATILE_TYPE(
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/io/kuzzle/sdk/Kuzzle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kuzzle.sdk;

import io.kuzzle.sdk.API.Controllers.IndexController;
import io.kuzzle.sdk.API.Controllers.RealtimeController;
import io.kuzzle.sdk.CoreClasses.Json.JsonSerializer;
import io.kuzzle.sdk.CoreClasses.Maps.KuzzleMap;
Expand Down Expand Up @@ -69,10 +70,20 @@ public Kuzzle(final AbstractProtocol networkProtocol)
this(networkProtocol, new KuzzleOptions());
}

/**
* @return The AuthController
*/
public AuthController getAuthController() {
return new AuthController(this);
}

/**
* @return The IndexController
*/
public IndexController getIndexController() {
return new IndexController(this);
}

/**
* @return RealtimeController
*/
Expand Down Expand Up @@ -200,7 +211,7 @@ public CompletableFuture<Response> query(
final ConcurrentHashMap<String, Object> query)
throws InternalException, NotConnectedException {
if (query == null) {
throw new InternalException(KuzzleExceptionCode.MSSING_QUERY);
throw new InternalException(KuzzleExceptionCode.MISSING_QUERY);
}

if (networkProtocol.getState() == ProtocolState.CLOSE) {
Expand Down
Loading