package com.example.whatsmymood;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

/**
 * Created by Malcolm on 2017-03-11.
 */

public class CreateUserController {

    public CreateUserController(){
    }

    public boolean create(String username, String password) {

        // Check that user name is unique in elastic search index

        ElasticSearchUserController.GetUserTask getUserTask = new ElasticSearchUserController.GetUserTask();
        getUserTask.execute(username);

        try {
            ArrayList<UserAccount> userList = getUserTask.get();
            if (!userList.isEmpty()) {
                return false;
            } else {
                UserAccount user = new UserAccount(username, password);
                ElasticSearchUserController.AddUserTask addUserTask = new ElasticSearchUserController.AddUserTask();
                addUserTask.execute(user);
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    }


}

@@ -1120,17 +1120,32 @@
     
-%7D%0A
+    return false;
 %0A    %7D%0A%0A
 %0A%7D%0A
@@ -1145,7 +1145,9 @@
  %7D%0A%0A
-%0A
 %7D%0A
+%0A%0A%0A

Create Account works with elastic search