Beispiel #1
0
  private void editConference(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String confNameBeforeEdit = request.getParameter(ProjConst.CONF_NAME_BEFORE_EDIT);
    Conference origConf = ConferenceDao.getInstance().getConferenceByName(confNameBeforeEdit);

    String confName = request.getParameter(ProjConst.CONF_NAME);
    String desc = request.getParameter(ProjConst.CONF_DESC);
    String location = request.getParameter(ProjConst.CONF_LOCATION);

    DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");

    Date startDate = (Date) formatter.parse(request.getParameter(ProjConst.CONF_START_DATE));
    Date endDate = (Date) formatter.parse(request.getParameter(ProjConst.CONF_END_DATE));

    Location locationInstance = LocationDao.getInstance().getLocationByName(location);

    origConf
        .setName(confName)
        .setDescription(desc)
        .setLocation(locationInstance)
        .setStartDate(startDate)
        .setEndDate(endDate);

    JsonObject jsonObject = new JsonObject();

    String resultSuccess;
    String message;
    try {

      ConferenceDao.getInstance().updateConference(origConf);
      message = "Conference successfully edited";
      resultSuccess = "true";

    } catch (Exception e) {
      message = "Found problem while editing conference";
      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 edit conference");
        json = gson.toJson(jsonObject);
      }
      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }
Beispiel #2
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();
    }
  }
Beispiel #3
0
  private void deleteConference(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    JsonObject jsonObject = new JsonObject();

    String confName = request.getParameter(ProjConst.CONF_NAME);

    String resultSuccess;
    String message;
    try {
      ConferenceDao.getInstance().deleteConference(confName);
      message = "Conference successfully deleted";
      resultSuccess = "true";

    } catch (Exception e) {
      message = "Found problem while deleting conference, message: " + e.getMessage();
      resultSuccess = "false";
    }

    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();
    }
  }
Beispiel #4
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();
    }
  }
Beispiel #5
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();
    }
  }
Beispiel #6
0
  private void print(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String confName = request.getParameter(ProjConst.CONF_NAME);
    String userId = request.getParameter(ProjConst.USER_ID);

    User user = UserDao.getInstance().getUserById(Long.parseLong(userId));
    Conference conference = ConferenceDao.getInstance().getConferenceByName(confName);

    JsonObject jsonObject = new JsonObject();

    String resultSuccess;
    String message;

    try {
      String[] header = new String[] {"         " + conference.getName()};
      String[] stringToPrint = new String[3];
      Date today = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
      stringToPrint[0] = "Date: " + sdf.format(today);
      stringToPrint[1] = "My Name: " + user.getName();
      stringToPrint[2] = "My Company: " + user.getCompany().getName();

      TextPrinter tp = new TextPrinter();
      tp.doPrint(header, stringToPrint, true);

      resultSuccess = "true";
      message = "Participant tag is printing";

    } 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;
      jsonObject.addProperty("resultSuccess", resultSuccess);
      jsonObject.addProperty("message", message);
      json = gson.toJson(jsonObject);
      out.write(json);
      out.flush();
    } finally {
      out.close();
    }
  }
Beispiel #7
0
  private void conferenceNameValidation(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      Gson gson = new Gson();

      String confName = request.getParameter("data");
      if (confName != null) {
        String json;
        if (ConferenceDao.getInstance().isConferenceNameExists(confName))
          json = gson.toJson("true");
        else json = gson.toJson("false");
        out.write(json);
      }
      out.flush();
    } finally {
      out.close();
    }
  }
Beispiel #8
0
  private void removeUser(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ParseException {
    String confName = request.getParameter(ProjConst.CONF_NAME);
    String userId = request.getParameter(ProjConst.USER_ID);

    User user = UserDao.getInstance().getUserById(Long.parseLong(userId));
    Conference conference = ConferenceDao.getInstance().getConferenceByName(confName);

    JsonObject jsonObject = new JsonObject();

    String resultSuccess;
    String message;
    try {
      // ConferencesUsersDao.getInstance().removeUserFromConference(conference, user);
      ConferencesParticipantsDao.getInstance().removeUserArrivalFromConference(conference, user);
      resultSuccess = "true";
      message =
          "User "
              + user.getName()
              + " removed from arrival list to conference "
              + conference.getName();

    } catch (Exception e) {
      resultSuccess = "false";
      message = "Failed to update user arrival";
    }

    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();
    }
  }