Package org.eurekaj.api.datatypes.basic

Examples of org.eurekaj.api.datatypes.basic.BasicUser


                session = getAccountService().getSession(cookieUuidToken);
              }
             
              if (session != null) {
                BasicSession updatedSession = new BasicSession(session);
                BasicUser httpUser = ParseJsonObjects.parseUser(jsonObject);
               
                logger.info("HTTP user: " + new Gson().toJson(httpUser));
               
                updatedSession.setAccountName(httpUser.getAccountName());
                getAccountService().persistSession(updatedSession);
               
                logger.info("persisted new session: " + new Gson().toJson(updatedSession));
               
                BasicUser newUser = new BasicUser(httpUser);
                newUser.setUserRole("admin");
                newUser.setUserName(session.getEmail());
                getAccountService().persistUser(newUser);
               
                logger.info("persisted user: " + new Gson().toJson(newUser));
               
                BasicAccount newAccount = new BasicAccount();
                newAccount.setId(httpUser.getAccountName());
                newAccount.setAccountType("new");
               
                getAccountService().persistAccount(newAccount);
               
                jsonResponse = "{ \"registered\": " + "true, \"uuidToken\": \"" + updatedSession.getUuid() + "\"}";
              } else {
                jsonResponse = "{ \"registered\": " + "false}";
              }
             
              logger.info(jsonObject);
            } else if (isGet(e) && cookieUuidToken != null) {
              logger.info("isGet: " + cookieUuidToken);
              Session cookieSession = getAccountService().getSession(cookieUuidToken);
              logger.info("cookieSession: " + new Gson().toJson(cookieSession));
              if (cookieSession != null && cookieSession.getEmail() != null) {
                User sessionUser = getAccountService().getUser(cookieSession.getEmail(), cookieSession.getAccountName());
                logger.info("sessionUser: " + new Gson().toJson(sessionUser));
                if (getRootUser() != null && sessionUser != null && sessionUser.getUserName().equals(getRootUser())) {
                  BasicUser rootUser = new BasicUser(sessionUser);
                  rootUser.setUserRole("root");
                  jsonResponse = "{\"user\": " + new Gson().toJson(rootUser) + "}";
                    logger.info("Returning user: " + jsonResponse);
                } else if (sessionUser != null ) {
                  jsonResponse = "{\"user\": " + new Gson().toJson(sessionUser) + "}";
                    logger.info("Returning user: " + jsonResponse);
View Full Code Here


        logger.info("jsonResponse: " + jsonResponse);
        writeContentsToBuffer(ctx, jsonResponse, "text/json");
    }
 
  private BasicUser getUnregisteredUserWith(String username) {
    BasicUser user = null;
   
    List<User> userList = getAccountService().getUsers(username);
   
    for (User storedUser : userList) {
      if (storedUser.getUserRole() == "unregistered") {
        user = new BasicUser(storedUser);
      }
    }
   
    return user;
  }
View Full Code Here

  }

  @Override
  public User getUser(String username, String accountName) {
    String json = asString(db.get(bytes(userBucketKey + username.replace("@", "__") + ";" + accountName)));
    BasicUser user = gson.fromJson(json, BasicUser.class);
    return user;
  }
View Full Code Here

    List<User> userList = new ArrayList<>();
   
    DBIterator iterator = db.iterator();
    iterator.seek(bytes(userBucketKey + ";" + username.replace("@", "__")));
    while (iterator.hasNext() && asString(iterator.peekNext().getKey()).startsWith(userBucketKey)) {
      BasicUser user = gson.fromJson(asString(iterator.next().getValue()), BasicUser.class);
      logger.info("Got User: " + user.getUserName() + " with role: " + user.getUserRole());
      if (user.getUserName().equals(username)) {
        userList.add(user);
      }
    }
   
    logger.info("found: " + userList.size() + " users");
View Full Code Here

    return userList;
  }

  @Override
  public void persistUser(User user) {
    db.put(bytes(userBucketKey + user.getUserName().replace("@", "__") + ";" + user.getAccountName()), bytes(gson.toJson(new BasicUser(user))));   
  }
View Full Code Here

        }
  }

  @Override
  public User getUser(String username, String accountName) {
    BasicUser user = null;
   
    Bucket myBucket = null;
        try {
            myBucket = riakClient.fetchBucket("User;" + this.encodeUri(username)).execute();
            user = myBucket.fetch(this.encodeUri(accountName), BasicUser.class).execute();
View Full Code Here

  @Override
  public void persistUser(User user) {
    Bucket myBucket = null;
        try {
            myBucket = riakClient.fetchBucket("User;" + this.encodeUri(user.getUserName())).execute();
            myBucket.store(this.encodeUri(user.getAccountName()), new BasicUser(user)).execute();
        } catch (RiakRetryFailedException rrfe) {
            rrfe.printStackTrace();
        }   
  }
View Full Code Here

        return account;
    }

    public static BasicUser parseUser(JSONObject userJsonObject) throws JSONException {
        BasicUser user = new BasicUser();

        if (userJsonObject.has("accountName")) {
            user.setAccountName(userJsonObject.getString("accountName"));
        }

        if (userJsonObject.has("userRole")) {
            user.setUserRole(userJsonObject.getString("userRole"));
        }
       
        if (userJsonObject.has("firstName")) {
            user.setFirstname(userJsonObject.getString("firstName"));
        }
       
        if (userJsonObject.has("lastName")) {
            user.setLastname(userJsonObject.getString("lastName"));
        }
       
        if (userJsonObject.has("country")) {
            user.setCountry(userJsonObject.getString("country"));
        }
       
        if (userJsonObject.has("company")) {
            user.setCompany(userJsonObject.getString("company"));
        }
       
        if (userJsonObject.has("usage")) {
            user.setUsage(userJsonObject.getString("usage"));
        }
       
        if (userJsonObject.has("uuidToken")) {
            user.setId(userJsonObject.getString("uuidToken"));
        }
       
        if (userJsonObject.has("authLevel")) {
          String authLevel = userJsonObject.getString("authLevel");
          if (authLevel != null && authLevel.equals("new")) {
            user.setUserRole("new");
          }
        }

        return user;
    }
View Full Code Here

TOP

Related Classes of org.eurekaj.api.datatypes.basic.BasicUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.