Search in sources :

Example 1 with CommentBean

use of models.CommentBean 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 2 with CommentBean

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

the class ProjectDAO method getComments.

public static ArrayList<CommentBean> getComments(ProjectBean project) {
    int pid = project.getPid();
    ArrayList<CommentBean> comments = new ArrayList<>();
    String query = "select * from project_comments where pid=?";
    try {
        connection = new ConnectionManager();
        currentConnection = connection.getConnection();
        ps = currentConnection.prepareStatement(query);
        ps.setInt(1, pid);
        rs = ps.executeQuery();
        while (rs.next()) {
            CommentBean comment = new CommentBean();
            comment.setCid(rs.getInt("cid"));
            comment.setContent(rs.getString("content"));
            comment.setPid(rs.getInt("pid"));
            comment.setUsername(rs.getString("username"));
            comments.add(comment);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new ArrayList<>();
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    connection = null;
    currentConnection = null;
    return comments;
}
Also used : ArrayList(java.util.ArrayList) CommentBean(models.CommentBean)

Example 3 with CommentBean

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

the class ProjectLoader method getComments.

public static String getComments(ProjectBean project) {
    ArrayList<CommentBean> comments = ProjectDAO.getComments(project);
    String html = "";
    for (CommentBean comment : comments) {
        html += "<tr>" + "<td>" + comment.getCid() + "</td>" + "<td>" + comment.getUsername() + "</td>" + "<td>" + comment.getContent() + "</td>" + "</tr>";
    }
    return html;
}
Also used : CommentBean(models.CommentBean)

Aggregations

CommentBean (models.CommentBean)3 ArrayList (java.util.ArrayList)2 PrintWriter (java.io.PrintWriter)1 NotificationBean (models.NotificationBean)1 ProjectBean (models.ProjectBean)1 UserBean (models.UserBean)1