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
33 changes: 33 additions & 0 deletions doc/3/controllers/collection/get-mapping/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
code: true
type: page
title: getMapping
description: Return collection mapping
---

# getMapping

Returns the collection mapping.

<br/>

```java
public CompletableFuture<ConcurrentHashMap<String, Object>> getMapping(
final String index,
final String collection) throws NotConnectedException, InternalException
```

<br/>

| Arguments | Type | Description |
| ------------ | ----------------- | --------------- |
| `index` | <pre>String</pre> | Index name |
| `collection` | <pre>String</pre> | Collection name |

## Returns

Returns a `ConcurrentHashMap<String, Object>` representing the collection mapping.

## Usage

<<< ./snippets/get-mapping.js
25 changes: 25 additions & 0 deletions doc/3/controllers/collection/get-mapping/snippets/get-mapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ConcurrentHashMap<String, Object> result = kuzzle
.getCollectionController()
.getMapping("nyc-open-data", "yellow-taxi")
.get();

/*
{
_meta={
schema={},
allowForm=false
},
dynamic=true,
properties={
key={
type=text,
fields={
keyword={
ignore_above=256,
type=keyword
}
}
}
}
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: collection#getMapping
description: Return collection mapping
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create && curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi
after:
template: print-result
expected: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.kuzzle.sdk.Kuzzle;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class CollectionController extends BaseController {

Expand Down Expand Up @@ -38,4 +39,30 @@ public CompletableFuture<Boolean> exists(
.thenApplyAsync(
(response) -> (Boolean) response.result);
}

/**
* Get collection mapping
*
* @param index
* @param collection
* @return a CompletableFuture
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<ConcurrentHashMap<String, Object>> getMapping(
final String index,
final String collection) throws NotConnectedException, InternalException {

final KuzzleMap query = new KuzzleMap();
query
.put("index", index)
.put("collection", collection)
.put("controller", "collection")
.put("action", "getMapping");

return kuzzle
.query(query)
.thenApplyAsync(
(response) -> (ConcurrentHashMap<String, Object>) response.result);
}
}
31 changes: 31 additions & 0 deletions src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,35 @@ public void existsCollectionShouldThrowWhenNotConnected() throws NotConnectedExc

kuzzleMock.getCollectionController().exists(index, collection);
}

@Test
public void getMappingCollectionTest() throws NotConnectedException, InternalException {

Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol));
String index = "nyc-open-data";
String collection = "yellow-taxi";


ArgumentCaptor<KuzzleMap> arg = ArgumentCaptor.forClass(KuzzleMap.class);

kuzzleMock.getCollectionController().getMapping(index, collection);
Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture());

assertEquals((arg.getValue()).getString("controller"), "collection");
assertEquals((arg.getValue()).getString("action"), "getMapping");
assertEquals((arg.getValue()).getString("index"), "nyc-open-data");
assertEquals((arg.getValue()).getString("collection"), "yellow-taxi");
}

@Test(expected = NotConnectedException.class)
public void getMappingShouldThrowWhenNotConnected() throws NotConnectedException, InternalException {
AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class);
Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer<ProtocolState>) invocation -> ProtocolState.CLOSE);

Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol));
String index = "nyc-open-data";
String collection = "yellow-taxi";

kuzzleMock.getCollectionController().getMapping(index, collection);
}
}