Package org.eurekaj.api.datatypes

Examples of org.eurekaj.api.datatypes.User


  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    String jsonResponse = "";
        String uri = getUri(e);
        String cookieUuidToken = getCookieValue(e, "uuidToken");
        User loggedInUser = getLoggedInUser(cookieUuidToken);
       
        logger.info("cookieUuidToken: " + cookieUuidToken);
       
        String id = getUrlId(e, "accessTokens");
       
      logger.info("Http Message Content: " + getHttpMessageContent(e));
        JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));
       
        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<>();
          }
View Full Code Here


  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    String jsonResponse = "";
    String cookieUuidToken = getCookieValue(e, "uuidToken");
    logger.info("cookieUuidToken: " + cookieUuidToken);
    User loggedInUser = getLoggedInUser(cookieUuidToken);
    String messageContent = getHttpMessageContent(e);

    logger.info(messageContent);

    if (isGet(e) && isAdmin(loggedInUser)) { // Get account for current user
View Full Code Here

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    log.info("MainMenuChannelHandler");
    String jsonResponse = "";
    String cookieUuidToken = getCookieValue(e, "uuidToken");
    User loggedInUser = null;
    if (cookieUuidToken != null) {
      loggedInUser = getLoggedInUser(cookieUuidToken);
    }
        JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));
        String accountName = getAccountForAccessToken(jsonObject);
       
        try {         
            HttpRequest request = (HttpRequest)e.getMessage();
            String uri = request.getUri();

            String objectArrayName = "mainMenus";
            if (uri.contains("adminMenus")) {
                objectArrayName = "adminMenus";
            }

            String id = UriUtil.getIdFromUri(uri, objectArrayName);

            if (id != null) {
                id = id.replaceAll("\\%20", " ");
            }
            log.debug("Accepted JSON: \n" + jsonObject);

            if (isAdmin(loggedInUser) && isDelete(e) && id != null) {
              getBerkeleyTreeMenuService().deleteTreeMenuNode(id, loggedInUser.getAccountName());
             
              log.info("Deleting Main Menu Item with id: " + id);
             
            } else if (isUser(loggedInUser) || accountName != null) {
              String loggedInAccountName = accountName;
              if (accountName == null) {
                loggedInAccountName = loggedInUser.getAccountName();
              }
             
              String decoded = "{}";
              if (uri.contains("?") && uri.contains("{") && uri.contains("}")) {
                decoded = URLDecoder.decode(uri.substring(uri.lastIndexOf('?')+1, uri.length()), "UTF-8");
View Full Code Here

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        String jsonResponse = "";
        String cookieUuidToken = getCookieValue(e, "uuidToken");
        User loggedInUser = getLoggedInUser(cookieUuidToken);

        try {
            JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));
            if (isUser(loggedInUser) && jsonObject.has("getInstrumentationTableData")) {
                JSONObject keyObject = jsonObject.getJSONObject("getInstrumentationTableData");
                String pathFromClient = keyObject.getString("path");
                Double averageSum = 0.0d;
                String startsWith = null;
                String endsWith = null;

                String[] pathParts = pathFromClient.split(";");
                if (pathParts.length == 2) {
                    startsWith = pathParts[0];
                    endsWith = pathParts[1];

                    int chartTimespan = getChartTimeSpan(keyObject);

                    Long fromPeriod = getFromPeriod(chartTimespan, keyObject);
                    Long toPeriod = getToPeriod(keyObject);

                    int numNodesFound = 0;

                    for (Statistics statistics : getBerkeleyTreeMenuService().getTreeMenu(loggedInUser.getAccountName())) {
                        if (statistics.getGuiPath().startsWith(startsWith)
                                && statistics.getGuiPath().endsWith(endsWith)) {

                            numNodesFound++;
                            Double averageNodeValue = 0.0d;
                            List<LiveStatistics> liveList = getBerkeleyTreeMenuService().getLiveStatistics(statistics.getGuiPath(), loggedInUser.getAccountName(), fromPeriod, toPeriod);

                            if (liveList.size() > 0) {
                                Double sumValue = 0.0d;
                                for (LiveStatistics liveStatistics : liveList) {
                                    sumValue += liveStatistics.getValue();
View Full Code Here

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    String jsonResponse = "";
    String cookieUuidToken = getCookieValue(e, "uuidToken");
    logger.info("cookieUuidToken: " + cookieUuidToken);
    User loggedInUser = getLoggedInUser(cookieUuidToken);
    String messageContent = getHttpMessageContent(e);

    String id = getUrlId(e, "alertRecipients");
   
    logger.info(messageContent);

    if (isGet(e) && isAdmin(loggedInUser)) { // Get account for current user
      List<AlertRecipient> alertRecipientList = getAdministrationService().getAlertRecipients(loggedInUser.getAccountName());
      JsonArray alertArray = new JsonArray();
      for (AlertRecipient ar : alertRecipientList) {
        BasicAlertRecipient basicAr = new BasicAlertRecipient(ar);
        alertArray.add(new Gson().toJsonTree(basicAr, BasicAlertRecipient.class));
      }
     
      JsonObject alertPlugins = new JsonObject();
      alertPlugins.add("alertRecipients", alertArray);

      jsonResponse = alertPlugins.toString();
    } else if ((isPost(e) || isPut(e)) && isAdmin(loggedInUser)) {
      AlertRecipientModel alertRecipientModel = new Gson().fromJson(messageContent, AlertRecipientModel.class);
      BasicAlertRecipient alertRecipient = alertRecipientModel.getAlertRecipient();
     
      if (id != null) {
        alertRecipient.setId(id);
      }
      alertRecipient.setAccountName(loggedInUser.getAccountName());
     
     
      logger.info("Persisting Alert Recipient: " + new Gson().toJson(alertRecipient));
     
      getAdministrationService().persistAlertRecipient(alertRecipient);
     
      alertRecipientModel.setAlertRecipient(alertRecipient);
      jsonResponse = new Gson().toJson(alertRecipientModel);
    } else if (isDelete(e) && isAdmin(loggedInUser)) {
      getAdministrationService().deleteAlertRecipient(loggedInUser.getAccountName(), id);
     
      logger.info("Deleting Alert Recipient with id: " + id + " for account: " + loggedInUser.getAccountName());
      jsonResponse = "{\"deleted\": true}";
    }
   
    logger.info("jsonResponse: " + jsonResponse);
    writeContentsToBuffer(ctx, jsonResponse, "text/json");
View Full Code Here

 
  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    String jsonResponse = "";
    String cookieUuidToken = getCookieValue(e, "uuidToken");
        User loggedInUser = getLoggedInUser(cookieUuidToken);

        try {
            JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));
            HttpRequest request = (HttpRequest)e.getMessage();
            String uri = request.getUri();
            String id = UriUtil.getIdFromUri(uri, "chartGroups");

            if (id != null) {
                id = id.replaceAll("\\%20", " ");
            }

            log.info("got chartGroup JSON" + jsonObject.toString());
           
            if (isAdmin(loggedInUser) && (isPut(e) || isPost(e))) {
              GroupedStatistics groupedStatistics = ParseJsonObjects.parseInstrumentationGroup(jsonObject, id, loggedInUser.getAccountName());
                if (groupedStatistics != null && groupedStatistics.getName() != null && groupedStatistics.getName().length() > 0) {
                    getBerkeleyTreeMenuService().persistGroupInstrumentation(groupedStatistics);
                }
                JSONObject topObject = new JSONObject();
                topObject.put("chartGroup", BuildJsonObjectsUtil.generateChartGroupJson(groupedStatistics));
                jsonResponse = topObject.toString();
            } else if (isAdmin(loggedInUser) && isGet(e)) {
                JSONObject topObject = new JSONObject();
                topObject.put("chartGroups", BuildJsonObjectsUtil.generateInstrumentationGroupsJson(getBerkeleyTreeMenuService().getGroupedStatistics(loggedInUser.getAccountName())));

              jsonResponse = topObject.toString();
                log.debug("Got InstrumentationGroups:\n" + jsonResponse);
            } else if (isAdmin(loggedInUser) && isDelete(e) && id != null) {
                getBerkeleyTreeMenuService().deleteChartGroup(id, loggedInUser.getAccountName());
            }

        } catch (JSONException jsonException) {
            throw new IOException("Unable to process JSON Request", jsonException);
        }
View Full Code Here

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
   
        String jsonResponse = "";
        String cookieUuidToken = getCookieValue(e, "uuidToken");
        User loggedInUser = getLoggedInUser(cookieUuidToken);
        try {
            HttpRequest request = (HttpRequest)e.getMessage();
            JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));

            String id = getUrlId(e, "alerts");

            log.info("Got: " + jsonObject.toString());
            if (isAdmin(loggedInUser) && jsonObject.has("getAlertPlugins")) {
                jsonResponse = BuildJsonObjectsUtil.generateAlertPluginsJson(ManagerAlertPluginService.getInstance().getLoadedAlertPlugins());
                log.debug("Got Alert Plugins:\n" + jsonResponse);
            } else if (isAdmin(loggedInUser) && (isPut(e) || isPost(e))) {
                Alert parsedAlert = ParseJsonObjects.parseAlertJson(jsonObject, id, loggedInUser.getAccountName());
                if (parsedAlert != null && parsedAlert.getAlertName() != null && parsedAlert.getAlertName().length() > 0) {
                    getBerkeleyTreeMenuService().persistAlert(parsedAlert);
                }
                JSONObject alertTopObject = new JSONObject();
                alertTopObject.put("alert", BuildJsonObjectsUtil.generateAlertJSON(parsedAlert));

                jsonResponse = alertTopObject.toString();
            } else if (isUser(loggedInUser) && jsonObject.has("getTriggeredAlerts")) {
                Long toTimePeriod = Calendar.getInstance().getTimeInMillis() / 15000;
                Long fromTimePeriod = toTimePeriod - (4 * 60);
                List<TriggeredAlert> triggeredAlertList = getBerkeleyTreeMenuService().getTriggeredAlerts(loggedInUser.getAccountName(), fromTimePeriod, toTimePeriod);
                jsonResponse = BuildJsonObjectsUtil.generateTriggeredAlertsJson(triggeredAlertList);
                log.debug("Got Triggered Alerts:\n" + jsonResponse);
            } else if (isAdmin(loggedInUser) && isDelete(e) && id != null) {
                getBerkeleyTreeMenuService().deleteAlert(id, loggedInUser.getAccountName());
                log.debug("Successfully deleted Alert with name:\n" + id);
            } else if(isUser(loggedInUser)){
              jsonResponse = BuildJsonObjectsUtil.generateAlertsJson(getBerkeleyTreeMenuService().getAlerts(loggedInUser.getAccountName()));
                log.debug("Got Alerts:\n" + jsonResponse);
            }
           
            if (jsonResponse.length() == 0 && isGet(e)) {
              jsonResponse = "{}";
View Full Code Here

     
      return cookieValue;
    }
   
    protected User getLoggedInUser(String cookieUuidToken) {
    User loggedInUser = null;
        Session session = getAccountService().getSession(cookieUuidToken);
        if (session != null) {
          loggedInUser = getAccountService().getUser(session.getEmail(), session.getAccountName());
        }
       
View Full Code Here

        String cookieUuidToken = getCookieValue(e, "uuidToken");
       
        JSONObject jsonObject = BuildJsonObjectsUtil.extractJsonContents(getHttpMessageContent(e));
        String accountName = getAccountForAccessToken(jsonObject);
       
        User loggedInUser = getLoggedInUser(cookieUuidToken);

        JSONObject keyObject = new JSONObject();

        if (id != null) {
            if (id.indexOf("?") > 0) {
                keyObject = getKeyObjectFromQueryString(id.substring(id.indexOf("?")));
                id = id.substring(0, id.indexOf("?"));
            }
        }

        log.info("id: " + id);
        log.info("keyObject: " + keyObject.toString());
        try {

            if ((isUser(loggedInUser) || accountName != null) && id != null) {
              String loggedInAccountName = accountName;
              if (accountName == null) {
                loggedInAccountName = loggedInUser.getAccountName();
              }
             
                String chartId = id;
                String chartPath = null;
View Full Code Here

                getAccountService().persistSession(newSession);
               
                jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "false}";
              } else if (userList.size() == 1) {
                //One user with one account, return correct uuid
                User user = userList.get(0);
                //userHash.put(user.getId(), new BasicUser(user));
                logger.info("One User: " + new Gson().toJson(user));
             
                BasicSession newSession = new BasicSession();
                newSession.setUuid(UUID.randomUUID().toString());
                newSession.setEmail(email);
                newSession.setExpiry(expiry);
                newSession.setAccountName(user.getAccountName());
                getAccountService().persistSession(newSession);
               
                logger.info("Updating Session: " + new Gson().toJson(newSession));
               
              jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "true}";
               
              } else if (userList.size() > 1) {
                //One user with multiple accounts, return list of accounts
                jsonResponse = "{\"error\": \"not_yet_implemented\"}";
              }
             
            } else if (isPost(e) && uri.endsWith("/auth/register") && cookieUuidToken != null) {
              logger.info("isPost /auth/register. Cookie: " + cookieUuidToken);
              Session session = null;
              if (cookieUuidToken != null) {
                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 ) {
View Full Code Here

TOP

Related Classes of org.eurekaj.api.datatypes.User

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.