Search in sources :

Example 1 with UserBean

use of models.UserBean 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 UserBean

use of models.UserBean 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 UserBean

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

the class SearchServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    String searchType = request.getParameter("searchType");
    String toSearch = request.getParameter("searchBar");
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    if (searchType.equals("users")) {
        List<UserBean> users = null;
        String category = request.getParameter("userCategory");
        if (category.equals("username")) {
            try {
                users = SearchDAO.searchForUser(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        } else if (category.equals("jobtitle")) {
            try {
                users = SearchDAO.searchForUserJobTitle(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        } else if (category.equals("qualifications")) {
            try {
                users = SearchDAO.searchForUserWithQualifications(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        }
        for (UserBean u : users) {
            pw.println("<a href=\"profile.jsp?username=" + u.getUsername() + "\"style=\"display:block\">" + u.getUsername() + "</a>");
        }
    } else if (searchType.equals("projects")) {
        List<ProjectBean> projects = null;
        String category = request.getParameter("projectCategory");
        if (category.equals("title")) {
            try {
                projects = SearchDAO.searchForProject(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        } else if (category.equals("description")) {
            try {
                projects = SearchDAO.searchForProjectDescription(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        } else if (category.equals("tags")) {
            try {
                projects = SearchDAO.searchForProjectWithTags(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        }
        for (ProjectBean p : projects) {
            pw.println("<a href=\"project.jsp?pid=" + p.getPid() + "\"style=\"display:block\">" + p.getTitle() + "</a>");
        }
    } else if (searchType.equals("companies")) {
        List<CompanyBean> companies = null;
        String category = request.getParameter("companyCategory");
        if (category.equals("name")) {
            try {
                companies = SearchDAO.searchForCompany(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting  companies from DB", e);
            }
        } else if (category.equals("description")) {
            try {
                companies = SearchDAO.searchForCompanyDescription(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting  companies from DB", e);
            }
        }
        for (CompanyBean c : companies) {
            pw.println("<a href=\"company.jsp?name=" + c.getName() + "\"style=\"display:block\">" + c.getName() + "</a>");
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) UserBean(models.UserBean) SQLException(java.sql.SQLException) ProjectBean(models.ProjectBean) List(java.util.List) CompanyBean(models.CompanyBean) PrintWriter(java.io.PrintWriter)

Example 4 with UserBean

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

the class SignUpServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    PrintWriter pw = response.getWriter();
    try {
        UserBean user = new UserBean();
        user.setFirstName(request.getParameter("firstname"));
        user.setUserName(request.getParameter("username"));
        user.setLastName(request.getParameter("lastname"));
        user.setEmail(request.getParameter("email"));
        user.setPassword(request.getParameter("password"));
        user.setJobTitle(request.getParameter("jobtitle"));
        SignUpDAO.signUpCheck(user);
        if (!user.isValid()) {
            pw.println("<h1>This username or Email already exists!</h1> <br/>");
        } else if (SignUpDAO.signUp(user)) {
            pw.println("<h1>New user Successfully created!</h1> <br/>");
        } else
            pw.println("<h1>New user could not be created!</h1> <br/>");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserBean(models.UserBean) ServletException(javax.servlet.ServletException) PrintWriter(java.io.PrintWriter)

Example 5 with UserBean

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

the class TaskTreeServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    ProjectBean project = new ProjectBean();
    RequestDispatcher dispatcher;
    ServletContext context = getServletContext();
    int pid = Integer.parseInt(request.getParameter("pid"));
    project.setPid(pid);
    try {
        project = ProjectDAO.getProject(project);
        if (!project.getTitle().equals("Project Not Found")) {
            String tree = getTreeHTML(project);
            ArrayList<UserBean> employeeList = ProjectDAO.getEmployees(project);
            request.setAttribute("employeeList", employeeList);
            request.setAttribute("tree", tree);
            request.setAttribute("project", project);
            dispatcher = context.getNamedDispatcher("taskTree");
            dispatcher.forward(request, response);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserBean(models.UserBean) ProjectBean(models.ProjectBean) ServletContext(javax.servlet.ServletContext) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

UserBean (models.UserBean)21 ArrayList (java.util.ArrayList)8 PrintWriter (java.io.PrintWriter)6 ProjectBean (models.ProjectBean)5 ServletException (javax.servlet.ServletException)4 NotificationBean (models.NotificationBean)4 PreparedStatement (java.sql.PreparedStatement)3 Date (java.sql.Date)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1 Part (javax.servlet.http.Part)1 CommentBean (models.CommentBean)1 CompanyBean (models.CompanyBean)1 MessageBean (models.MessageBean)1 TaskBean (models.TaskBean)1