Пример #1
0
  private void assignUsers(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String confName = request.getParameter(ProjConst.CONF_NAME);
    Conference conference = ConferenceDao.getInstance().getConferenceByName(confName);

    String userNamesNotFormatted = request.getParameter("userNames");
    String[] userNames = userNamesNotFormatted.split(",");

    List<User> users = new LinkedList<User>();

    for (String user : userNames) {
      if (user != null) users.add(UserDao.getInstance().getUserByUserName(user));
    }

    String userRole = request.getParameter("userRole");

    JsonObject jsonObject = new JsonObject();

    String resultSuccess;
    String message;
    try {
      ConferencesUsersDao.getInstance()
          .assignUsersToConference(conference, users, Integer.parseInt(userRole));
      resultSuccess = "true";
      message =
          "User/s "
              + userNamesNotFormatted
              + " assigned to conference "
              + confName
              + " with role "
              + UserRole.resolveUserRoleToFriendlyName(Integer.parseInt(userRole)).toString();

    } catch (Exception e) {
      resultSuccess = "false";
      message = e.getMessage();
    }

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      Gson gson = new Gson();
      String json;
      if (ConferenceDao.getInstance().isConferenceNameExists(confName)) {
        jsonObject.addProperty("resultSuccess", resultSuccess);
        jsonObject.addProperty("message", message);
        json = gson.toJson(jsonObject);
      } else {
        jsonObject.addProperty("resultSuccess", "false");
        jsonObject.addProperty("message", "Failed to assign user");
        json = gson.toJson(jsonObject);
      }
      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }
Пример #2
0
  private void sendInvitationToUsers(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String conf = request.getParameter(ProjConst.CONF_NAME);
    Conference conference = ConferenceDao.getInstance().getConferenceByName(conf);

    String userName = request.getParameter("userNames");
    String[] userNames = userName.split(",");

    List<User> users = new LinkedList<User>();

    for (String user : userNames) {
      if (user != null) users.add(UserDao.getInstance().getUserByUserName(user));
    }

    JsonObject jsonObject = new JsonObject();

    String resultSuccess = null;
    String message = null;

    for (User user : users) {
      try {
        ConferencesUsersDao.getInstance()
            .sendConferenceAssignmentNotificationEmailToUsers(conference, user);
      } catch (Exception e) {
        message = "Some invitation were not sent";
        resultSuccess = "false";
      }
    }

    if (resultSuccess == null) {
      message = "Initation/s sent successfully";
      resultSuccess = "true";
    }

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      Gson gson = new Gson();
      String json;

      jsonObject.addProperty("resultSuccess", resultSuccess);
      jsonObject.addProperty("message", message);
      json = gson.toJson(jsonObject);

      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }
Пример #3
0
  private void updateAttendance(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    JsonObject jsonObject = new JsonObject();

    String confName = request.getParameter(ProjConst.CONF_NAME);
    Conference conference = ConferenceDao.getInstance().getConferenceByName(confName);

    String userName = request.getParameter(ProjConst.USER_NAME);
    User user = UserDao.getInstance().getUserByUserName(userName);

    String value = request.getParameter("value");

    String resultSuccess;
    String message;
    try {
      ConferencesUsersDao.getInstance()
          .updateUserAttendanceApproval(conference, user, UserAttendanceStatus.valueOf(value));
      message = "Attendance successfully updated for user " + user.getName();
      resultSuccess = "true";

    } catch (Exception e) {
      message = "Found problem while update user attendance";
      resultSuccess = "false";
    }

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      Gson gson = new Gson();
      String json;
      if (ConferenceDao.getInstance().isConferenceNameExists(confName)) {
        jsonObject.addProperty("resultSuccess", resultSuccess);
        jsonObject.addProperty("message", message);
        json = gson.toJson(jsonObject);
      } else {
        jsonObject.addProperty("resultSuccess", "false");
        jsonObject.addProperty("message", "Failed to delete conference");
        json = gson.toJson(jsonObject);
      }
      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }
Пример #4
0
  private void getConferences(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String userId = request.getParameter(ProjConst.USER_ID);
    String filter = request.getParameter("filter");

    User user = UserDao.getInstance().getUserById(Long.parseLong(userId));

    // JsonObject jsonObject = new JsonObject();

    // String resultSuccess;
    // String message;

    List<String> confList = new LinkedList<String>();

    try {
      List<Conference> conferences =
          ConferencesUsersDao.getInstance().getScopedConferenceByDate(user, filter);
      for (Conference conf : conferences) {
        confList.add(conf.getName());
      }
      // message = "Conference successfully added";
      // resultSuccess = "true";

    } catch (Exception e) {
      // message = "Found problem while adding conference";
      // resultSuccess = "false";
    }

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      Gson gson = new Gson();
      String json;
      json = gson.toJson(confList);

      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }