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
22 changes: 19 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,27 @@ jobs:
- "$HOME/.gradle/wrapper/"
install:
- cd $TRAVIS_BUILD_DIR/
- gradle assemble
- ./gradlew assemble
script:
- ./gradlew build

- stage: Unit Tests
name: Run unit tests
language: java
jdk: openjdk8
sudo: false
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
install:
- cd $TRAVIS_BUILD_DIR/
- gradle assemble
- ./gradlew assemble
script:
- gradle build
- ./gradlew test

stages:
- name: Unit Tests
Expand Down
29 changes: 13 additions & 16 deletions src/main/java/io/kuzzle/sdk/API/Controllers/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public AuthController(final Kuzzle kuzzle) {

/**
* Checks the validity of an authentication token.
*
* @param token
* An authentication token
*
* @param token An authentication token
* @return a CompletableFuture
* @throws NotConnectedException
* @throws InternalException
Expand All @@ -43,12 +42,10 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> checkToken(

/**
* Creates new credentials for the current user.
*
* @param strategy
* A String representing the strategy
* @param credentials
* A ConcurrentHashMap<String, Object> representing
* credentials information
*
* @param strategy A String representing the strategy
* @param credentials A ConcurrentHashMap<String, Object> representing
* credentials information
* @return A CompletableFuture
* @throws NotConnectedException
* @throws InternalException
Expand All @@ -75,9 +72,8 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> createMyCredentials(
/**
* Checks that the current authenticated user has credentials for the
* specified authentication strategy.
*
* @param strategy
* A String representing the strategy
*
* @param strategy A String representing the strategy
* @return A CompletableFuture
* @throws NotConnectedException
* @throws InternalException
Expand Down Expand Up @@ -152,7 +148,8 @@ public CompletableFuture<ArrayList<String>> getStrategies()
throws NotConnectedException, InternalException {
final KuzzleMap query = new KuzzleMap();

query.put("controller", "auth").put("action", "getStrategies");
query.put("controller", "auth")
.put("action", "getStrategies");

return kuzzle
.query(query)
Expand All @@ -170,13 +167,13 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> login(
.put("action", "login")
.put("strategy", strategy)
.put("body", credentials)
.put("expiresIn", (expiresIn == null ? "1h" : expiresIn));
.put("expiresIn", expiresIn);

return kuzzle.query(query).thenApplyAsync((response) -> {
final KuzzleMap map = KuzzleMap
.from((ConcurrentHashMap<String, Object>) response.result);
kuzzle.setAuthenticationToken(map.getString("jwt"));
if (!map.isNull("_id")) {
if (map.getString("_id") != null) {
kuzzle.trigger(Event.loginAttempt, true);
} else {
kuzzle.trigger(Event.loginAttempt, false);
Expand Down Expand Up @@ -259,7 +256,7 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> updateSelf(
}

public CompletableFuture<Boolean> validateMyCredentials(final String strategy,
final ConcurrentHashMap<String, Object> credentials)
final ConcurrentHashMap<String, Object> credentials)
throws NotConnectedException, InternalException {
final KuzzleMap query = new KuzzleMap();

Expand Down
41 changes: 6 additions & 35 deletions src/main/java/io/kuzzle/sdk/CoreClasses/Task.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
package io.kuzzle.sdk.CoreClasses;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

/**
* @param <T> The object type that the task return.
*/
public class Task<T> {
/**
* A countDownLatch used to lock the future.
*/
protected CountDownLatch countDownLatch;
/**
* A completable future.
*/
protected CompletableFuture<T> future;

/**
* The object instance to return.
*/
protected AtomicReference<T> atomicReference;

/**
* Initializes a new instance of the Task.
*/
public Task() {
atomicReference = new AtomicReference<T>();
countDownLatch = new CountDownLatch(1);
future = CompletableFuture.<T>supplyAsync(() -> {
try {
countDownLatch.await();

return atomicReference.get();
} catch (InterruptedException e) {
return null;
}
});
}
protected CompletableFuture<T> future = new CompletableFuture<>();

/**
* @return The associated CompletableFuture.
Expand All @@ -48,7 +20,7 @@ public CompletableFuture<T> getFuture() {

/**
* Set the exception of the CompletableFuture.
*
*
* @param exception
*/
public void setException(Exception exception) {
Expand Down Expand Up @@ -78,7 +50,7 @@ public boolean isCompletedExceptionally() {

/**
* Set if the future is cancelled.
*
*
* @param state
*/
public void setCancelled(boolean state) {
Expand All @@ -89,16 +61,15 @@ public void setCancelled(boolean state) {
* Unlock the future.
*/
public void trigger() {
countDownLatch.countDown();
future.complete(null);
}

/**
* Unlock the future and set the object.
*
*
* @param object
*/
public void trigger(T object) {
atomicReference.set(object);
countDownLatch.countDown();
future.complete(object);
}
}
32 changes: 13 additions & 19 deletions src/main/java/io/kuzzle/sdk/Kuzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public class Kuzzle extends EventManager {

/**
* Initialize a new instance of Kuzzle
*
* @param networkProtocol
* The network protocol
*
* @param networkProtocol The network protocol
* @throws IllegalArgumentException
*/
public Kuzzle(final AbstractProtocol networkProtocol)
Expand All @@ -73,15 +72,13 @@ public AuthController getAuthController() {

/**
* Initialize a new instance of Kuzzle
*
* @param networkProtocol
* The network protocol
* @param options
* Kuzzle options
*
* @param networkProtocol The network protocol
* @param options Kuzzle options
* @throws IllegalArgumentException
*/
public Kuzzle(final AbstractProtocol networkProtocol,
final KuzzleOptions options) throws IllegalArgumentException {
final KuzzleOptions options) throws IllegalArgumentException {
if (networkProtocol == null) {
throw new IllegalArgumentException("networkProtocol can't be null");
}
Expand All @@ -108,7 +105,7 @@ public Kuzzle(final AbstractProtocol networkProtocol,

/**
* Establish a network connection
*
*
* @throws Exception
*/
public void connect() throws Exception {
Expand All @@ -124,9 +121,8 @@ public void disconnect() {

/**
* Handles the ResponseReceivedEvent from the network protocol
*
* @param payload
* Raw API Response
*
* @param payload Raw API Response
*/
protected void onResponseReceived(final Object... payload) {

Expand Down Expand Up @@ -178,9 +174,8 @@ protected void onStateChanged(final Object... args) {

/**
* Sends an API request to Kuzzle and returns the corresponding API
*
* @param query
* Kuzzle API query
*
* @param query Kuzzle API query
* @return A CompletableFuture
* @throws InternalException
* @throws NotConnectedException
Expand Down Expand Up @@ -242,9 +237,8 @@ public String getAuthenticationToken() {

/**
* Set the authentication token
*
* @param token
* Authentication token
*
* @param token Authentication token
*/
public void setAuthenticationToken(final String token) {
if (authenticationToken == null) {
Expand Down
Loading