if ((isPost(e) || isPut(e)) && isAdmin(loggedInUser)) {
AccessTokenModel accessTokenModel = new Gson().fromJson(getHttpMessageContent(e), AccessTokenModel.class);
BasicAccessToken newAccessToken = accessTokenModel.getAccessToken();
Account account = getAccountService().getAccount(loggedInUser.getAccountName());
if (account != null && newAccessToken != null && newAccessToken.getId() != null && newAccessToken.getId().length() >= 16) {
newAccessToken.setAccountName(account.getId());
logger.info("Persisting AccessToken: " + new Gson().toJson(newAccessToken));
getAccountService().persistAccessToken(newAccessToken);
if (account.getAccessTokens() == null) {
BasicAccount newAccount = new BasicAccount(account);
newAccount.setAccessTokens(new ArrayList<String>());
account = newAccount;
}
account.getAccessTokens().add(newAccessToken.getId());
getAccountService().persistAccount(account);
}
jsonResponse = new Gson().toJson(accessTokenModel);
} else if (isGet(e) && isAdmin(loggedInUser)) {
logger.info("Account Name: " + loggedInUser.getAccountName());
Account account = getAccountService().getAccount(loggedInUser.getAccountName());
logger.info("Account: " + account);
List<String> accessTokens = account.getAccessTokens();
if (accessTokens == null) {
accessTokens = new ArrayList<>();
}
JsonArray accessTokenArray = new JsonArray();
for (String accessToken : accessTokens) {
AccessToken accessTokenObject = getAccountService().getAccessToken(accessToken);
if (accessTokenObject != null && accessTokenObject.getAccountName().equals(account.getId())) {
accessTokenArray.add(new Gson().toJsonTree(accessTokenObject));
}
}
JsonObject accessTokensJson = new JsonObject();