Search in sources :

Example 6 with NotificationBean

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

the class MessageServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    try {
        PrintWriter pw = response.getWriter();
        UserBean currentUser = (UserBean) request.getSession().getAttribute("currentSessionUser");
        java.sql.Date date = new java.sql.Date(Calendar.getInstance().getTime().getTime());
        MessageBean message = new MessageBean();
        message.setSender(currentUser.getUsername());
        message.setReceiver(request.getParameter("receivers").split(","));
        message.setDate(date);
        message.setTitle(request.getParameter("title"));
        message.setContent(request.getParameter("content"));
        boolean success = MessageDAO.sendMessage(message);
        if (success) {
            for (String receiver : message.getReceiver()) {
                NotificationBean notification = new NotificationBean();
                notification.setUsername(receiver);
                notification.setDate(date);
                notification.setNotification("(Mesaj)" + message.getSender() + " adli kullanici size mesaj gonderdi");
                NotificationDAO.sendNotification(notification);
            }
            pw.println("Message is sent succesfully");
            return;
        }
        pw.println("Message couldn't sent");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageBean(models.MessageBean) NotificationBean(models.NotificationBean) UserBean(models.UserBean) Date(java.sql.Date) ServletException(javax.servlet.ServletException) PrintWriter(java.io.PrintWriter) Date(java.sql.Date)

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