Search in sources :

Example 1 with NotificationBean

use of models.NotificationBean in project bil372-proje by mertserezli.

the class ProjectServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    PrintWriter pw = response.getWriter();
    UserBean currentUser = (UserBean) request.getSession().getAttribute("currentSessionUser");
    String date = request.getParameter("date");
    ProjectBean currentProject = (ProjectBean) request.getSession().getAttribute("currentProject");
    if (date == null) {
        pw.println("Date cannot be empty!");
        return;
    }
    ArrayList<UserBean> workers = Work_Emp_ProDAO.getWorkers(currentProject);
    boolean found = false;
    for (UserBean worker : workers) {
        if (!worker.getUsername().equals(currentUser.getUsername())) {
            found = true;
            break;
        }
    }
    if (!found) {
        pw.println("You cannot set up a meeting!");
        return;
    }
    ProjectDAO.setNewMeeting(currentProject, date);
    for (UserBean worker : workers) {
        NotificationBean n = new NotificationBean();
        n.setDate(Date);
        n.setNotification("(Project)" + currentProject.getTitle() + " adli projenizde " + date + " tarihine bir meeting set edildi");
        n.setUsername(worker.getUsername());
        NotificationDAO.sendNotification(n);
    }
}
Also used : NotificationBean(models.NotificationBean) UserBean(models.UserBean) ProjectBean(models.ProjectBean) PrintWriter(java.io.PrintWriter)

Example 2 with NotificationBean

use of models.NotificationBean in project bil372-proje by mertserezli.

the class ProjectServlet method doPost.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    String click = request.getParameter("click");
    PrintWriter pw = response.getWriter();
    if (click.equals("Add Employee")) {
        String username = request.getParameter("username");
        ProjectBean currentProject = (ProjectBean) request.getSession().getAttribute("currentProject");
        UserBean user = new UserBean();
        user.setUserName(username);
        ProfileDAO.loadUser(user);
        boolean success = Work_Emp_ProDAO.addEmployee(user, currentProject);
        if (success) {
            ArrayList<UserBean> workers = Work_Emp_ProDAO.getWorkers(currentProject);
            for (UserBean u : workers) {
                NotificationBean n = new NotificationBean();
                n.setDate(Date);
                n.setNotification("(Project)-" + username + " adlı calisan" + currentProject.getTitle() + " adli projenize eklendi");
                n.setUsername(u.getUsername());
                NotificationDAO.sendNotification(n);
            }
            pw.println("New Employee has been added");
        } else {
            pw.println("New Employee could not be added");
        }
    } else if (click.equals("Add Comment")) {
        UserBean user = (UserBean) request.getSession().getAttribute("currentuser");
        ProjectBean currentProject = (ProjectBean) request.getSession().getAttribute("currentProject");
        String content = request.getParameter("content");
        CommentBean comment = new CommentBean();
        comment.setContent(content);
        comment.setPid(currentProject.getPid());
        comment.setUsername(user.getUsername());
        boolean success = CommentsDAO.addComment(currentProject, user, comment);
        if (success) {
            ArrayList<UserBean> workers = Work_Emp_ProDAO.getWorkers(currentProject);
            for (UserBean u : workers) {
                NotificationBean n = new NotificationBean();
                n.setDate(Date);
                n.setNotification("(Project)-" + user.getUsername() + " adli kullanici " + currentProject.getTitle() + " adli projenize yorum yapti");
                n.setUsername(u.getUsername());
                NotificationDAO.sendNotification(n);
            }
            pw.println("New Comment has been added");
        } else {
            pw.println("New Comment could not be added");
        }
    } else if (click.equals("upvote")) {
        ProjectBean currentProject = (ProjectBean) request.getSession().getAttribute("currentProject");
        boolean success = ProjectDAO.upvote(currentProject);
        if (success) {
            pw.println("Upvoted Project");
        } else {
            pw.println("Could not upvote Project");
        }
    } else if (click.equals("downvote")) {
        ProjectBean currentProject = (ProjectBean) request.getSession().getAttribute("currentProject");
        boolean success = ProjectDAO.downvote(currentProject);
        if (success) {
            pw.println("Downvoted Project");
        } else {
            pw.println("Could not Downvote Project");
        }
    }
}
Also used : NotificationBean(models.NotificationBean) UserBean(models.UserBean) ProjectBean(models.ProjectBean) ArrayList(java.util.ArrayList) CommentBean(models.CommentBean) PrintWriter(java.io.PrintWriter)

Example 3 with NotificationBean

use of models.NotificationBean in project bil372-proje by mertserezli.

the class NotificationDAO method getUpcomingMeetings.

public static List<NotificationBean> getUpcomingMeetings(String usernameRequest) {
    List<NotificationBean> result = new ArrayList<NotificationBean>();
    java.sql.Date dateNow = new java.sql.Date(Calendar.getInstance().getTime().getTime());
    UserBean user = new UserBean();
    user.setUserName(usernameRequest);
    ArrayList<ProjectBean> projects = UploadDAO.loadProjects(user);
    for (ProjectBean p : projects) {
        ProjectDAO.getProject(p);
        if (p.getMeeting_dates() != null) {
            for (Date d : p.getMeeting_dates()) {
                if (dateNow.getMonth() == d.getMonth() && dateNow.getYear() == d.getYear() && d.getDay() - dateNow.getDay() <= 7) {
                    int day = d.getDay() - dateNow.getDay();
                    NotificationBean n = new NotificationBean();
                    n.setDate(dateNow);
                    n.setNotification("(Project) " + p.getTitle() + " adli projenizin " + d + " tarihli meetingine " + day + " gün kalmistir");
                    n.setUsername(usernameRequest);
                    result.add(n);
                }
            }
        }
    }
    return result;
}
Also used : NotificationBean(models.NotificationBean) UserBean(models.UserBean) ProjectBean(models.ProjectBean) ArrayList(java.util.ArrayList) Date(java.sql.Date) Date(java.sql.Date)

Example 4 with NotificationBean

use of models.NotificationBean in project bil372-proje by mertserezli.

the class NotificationDAO method getUpcomingDeadlines.

public static List<NotificationBean> getUpcomingDeadlines(String usernameRequest) throws SQLException {
    List<NotificationBean> result = new ArrayList<NotificationBean>();
    java.sql.Date dateNow = new java.sql.Date(Calendar.getInstance().getTime().getTime());
    List<TaskBean> tasks = TaskDAO.searchTasksForUser(usernameRequest);
    for (TaskBean t : tasks) {
        Date d = t.getDeadline();
        if (d.getYear() == dateNow.getYear() && d.getMonth() == dateNow.getMonth() && d.getDay() - dateNow.getDay() <= 7) {
            int day = d.getDay() - dateNow.getDay();
            NotificationBean n = new NotificationBean();
            n.setDate(dateNow);
            n.setUsername(usernameRequest);
            n.setNotification("(Task) " + t.getTitle() + " adli taskinizin " + d + " tarihli deadline tarihine " + day + " gün kalmistir");
            result.add(n);
        }
    }
    return result;
}
Also used : NotificationBean(models.NotificationBean) ArrayList(java.util.ArrayList) TaskBean(models.TaskBean) Date(java.sql.Date) Date(java.sql.Date)

Example 5 with NotificationBean

use of models.NotificationBean in project bil372-proje by mertserezli.

the class NotificationDAO method getNotifications.

public static List<NotificationBean> getNotifications(String usernameRequest) throws SQLException {
    List<NotificationBean> result = new ArrayList<NotificationBean>();
    String searchQuery = "Select * From emp_notification where username=?";
    try {
        ConnectionManager connect = new ConnectionManager();
        currentConnection = connect.getConnection();
        ps = currentConnection.prepareStatement(searchQuery);
        ps.setString(1, usernameRequest);
        rs = ps.executeQuery();
        while (rs.next()) {
            NotificationBean n = new NotificationBean();
            n.setNid(rs.getInt("nid"));
            n.setNotification(rs.getString("notification"));
            n.setUsername(rs.getString("username"));
            n.setDate(rs.getDate("date"));
            result.add(n);
        }
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    return result;
}
Also used : NotificationBean(models.NotificationBean) ArrayList(java.util.ArrayList)

Aggregations

NotificationBean (models.NotificationBean)6 ArrayList (java.util.ArrayList)4 UserBean (models.UserBean)4 PrintWriter (java.io.PrintWriter)3 Date (java.sql.Date)3 ProjectBean (models.ProjectBean)3 ServletException (javax.servlet.ServletException)1 CommentBean (models.CommentBean)1 MessageBean (models.MessageBean)1 TaskBean (models.TaskBean)1