From 59df6a88b87c54878864be66481edc3aafb3924d Mon Sep 17 00:00:00 2001 From: Jose Cano Date: Thu, 10 Sep 2015 23:19:09 +0200 Subject: [PATCH] It's over. Pending only review and clean after delivery. --- WebContent/js/getNoteIdsList.js | 75 ++++++++ WebContent/jsp/businessNotesList.jsp | 17 +- .../jsp/modal/NewBusNoteFormProductModal.jsp | 2 +- .../jsp/modal/NewBusNoteFormSupplierModal.jsp | 2 +- WebContent/jsp/modal/NewThreadModalForm.jsp | 57 ++++++ WebContent/jsp/newBusinessNoteForm.jsp | 8 +- WebContent/jsp/threadsList.jsp | 66 +++++++ src/controller/BusinessLookUp.java | 12 ++ src/controller/LoginServlet.java | 3 - src/dao/BusinessNoteDAO.java | 5 + src/dao/BusinessNoteDAOImpl.java | 81 +++++++- src/dao/ThreadDAO.java | 11 ++ src/dao/ThreadDAOImpl.java | 177 ++++++++++++++++++ src/dao/ThreadNoteDAO.java | 13 ++ src/dao/ThreadNoteDAOImpl.java | 54 ++++++ src/model/NoteVO.java | 7 +- src/model/ThreadNoteVO.java | 28 +-- src/model/ThreadVO.java | 33 +++- src/persistence/DDBBThread.java | 29 ++- src/persistence/DDBBThreadNote.java | 3 + src/service/AddBusinessNoteService.java | 4 +- src/service/AddThreadService.java | 93 +++++++++ src/service/GetThreadsListService.java | 30 +++ 23 files changed, 774 insertions(+), 36 deletions(-) create mode 100644 WebContent/js/getNoteIdsList.js create mode 100644 WebContent/jsp/modal/NewThreadModalForm.jsp create mode 100644 WebContent/jsp/threadsList.jsp create mode 100644 src/dao/ThreadDAO.java create mode 100644 src/dao/ThreadDAOImpl.java create mode 100644 src/dao/ThreadNoteDAO.java create mode 100644 src/dao/ThreadNoteDAOImpl.java create mode 100644 src/service/AddThreadService.java create mode 100644 src/service/GetThreadsListService.java diff --git a/WebContent/js/getNoteIdsList.js b/WebContent/js/getNoteIdsList.js new file mode 100644 index 0000000..8c40080 --- /dev/null +++ b/WebContent/js/getNoteIdsList.js @@ -0,0 +1,75 @@ +/** + * + */ + +var addThread; +var addThreadValue; +var note; +var noteId; +var companyTelephone; +var companyEmail; + +$('#newThreadButton').click(function() { + origin = "Supplier"; + addIdsList(); + +}); + +function addIdsList() { + + var table = document.getElementById("list"); + for(var i=0; i 0) { + for (loop = 0; loop < company.length; loop++) { + getData(companies[loop]); + createAndFillInOption(origin); + } + } + } +} \ No newline at end of file diff --git a/WebContent/jsp/businessNotesList.jsp b/WebContent/jsp/businessNotesList.jsp index 48ce29f..37dfa17 100644 --- a/WebContent/jsp/businessNotesList.jsp +++ b/WebContent/jsp/businessNotesList.jsp @@ -26,9 +26,11 @@

BusinessNotes List

Table showing all notes chronologically ordered.

- +
+ + @@ -45,6 +47,7 @@ Iterator iterator = notesList.iterator(); while (iterator.hasNext()) { BusinessNoteVO note = (BusinessNoteVO) iterator.next(); + int noteId = note.getNoteId(); Date creationDate = note.getCreationDate(); String noteTitle = note.getNoteTitle(); String noteText = note.getNoteText(); @@ -68,6 +71,8 @@ } %> + + @@ -82,7 +87,17 @@ %>
Add ThreadnoteId Creation Date Title Text
<%=noteId%> <%=creationDate%> <%=noteTitle%> <%=noteText%>
+
+ + +
+ + + + + \ No newline at end of file diff --git a/WebContent/jsp/modal/NewBusNoteFormProductModal.jsp b/WebContent/jsp/modal/NewBusNoteFormProductModal.jsp index f82c58f..deb186a 100644 --- a/WebContent/jsp/modal/NewBusNoteFormProductModal.jsp +++ b/WebContent/jsp/modal/NewBusNoteFormProductModal.jsp @@ -22,7 +22,7 @@ +
@@ -133,9 +135,9 @@
- - - + + + diff --git a/WebContent/jsp/threadsList.jsp b/WebContent/jsp/threadsList.jsp new file mode 100644 index 0000000..bf19046 --- /dev/null +++ b/WebContent/jsp/threadsList.jsp @@ -0,0 +1,66 @@ +<%@page import="model.ThreadVO"%> +<%@page import="java.util.Date"%> +<%@page import="java.util.List"%> +<%@page import="java.util.Iterator"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> + + + + + + + + +Threads List + + +
+
+
+ +
+
+ +
+

Threads List

+

Table showing all threads chronologically ordered.

+
+ + + + + + + + + + + + + <% + List threadsList = (List)request.getAttribute("threadsList"); + Iterator iterator = threadsList.iterator(); + while (iterator.hasNext()) { + ThreadVO thread = (ThreadVO) iterator.next(); + int threadId = thread.getThreadId(); + Date creationDate = thread.getCreationDate(); + String threadTitle = thread.getThreadTitle(); + Integer notesNumber = thread.getNotesList().size(); + %> + + + + + + + + + <% + } + %> + +
threadIdCreation DateTitleNumber of Notes
<%=threadId%><%=creationDate%><%=threadTitle%><%=notesNumber%>ViewDelete
+
+ + + \ No newline at end of file diff --git a/src/controller/BusinessLookUp.java b/src/controller/BusinessLookUp.java index edd3037..bba5acb 100644 --- a/src/controller/BusinessLookUp.java +++ b/src/controller/BusinessLookUp.java @@ -6,6 +6,7 @@ import service.AddPersonalNoteService; import service.AddProductService; import service.AddSupplierService; +import service.AddThreadService; import service.ExportTableService; import service.GetBusinessNotesListService; import service.GetCompaniesListService; @@ -14,6 +15,7 @@ import service.GetPersonalNotesListService; import service.GetProductsListService; import service.GetSuppliersListService; +import service.GetThreadsListService; import service.ImportTableService; import service.NewCompanyFormService; import service.NewCustomerFormService; @@ -38,6 +40,7 @@ public class BusinessLookUp { private final String NOTES_LIST = "notesList"; private final String BUSINESS_NOTES_LIST = "businessNotesList"; private final String PERSONAL_NOTES_LIST = "personalNotesList"; + private final String THREADS_LIST = "threadsList"; private final String CUSTOMERS_LIST = "customersList"; private final String SUPPLIERS_LIST = "suppliersList"; @@ -51,6 +54,7 @@ public class BusinessLookUp { private final String ADD_COMPANY = "addCompany"; private final String ADD_BUSINESS_NOTE = "addBusinessNote"; private final String ADD_PERSONAL_NOTE = "addPersonalNote"; + private final String ADD_THREAD = "addThread"; private final String EXPORT_TABLE = "exportTable"; private final String IMPORT_TABLE = "importTable"; @@ -90,6 +94,10 @@ public Service getBusinessService(String serviceType) { case PERSONAL_NOTES_LIST: serviceClass = new GetPersonalNotesListService(); break; + case THREADS_LIST: + serviceClass = new GetThreadsListService(); + break; + case CUSTOMERS_LIST: serviceClass = new GetCustomerListService(); break; @@ -102,6 +110,7 @@ public Service getBusinessService(String serviceType) { case PRODUCTS_LIST: serviceClass = new GetProductsListService(); break; + case ADD_CUSTOMER: serviceClass = new AddCustomerService(); break; @@ -120,6 +129,9 @@ public Service getBusinessService(String serviceType) { case ADD_PERSONAL_NOTE: serviceClass = new AddPersonalNoteService(); break; + case ADD_THREAD: + serviceClass = new AddThreadService(); + break; case EXPORT_TABLE: serviceClass = new ExportTableService(); break; diff --git a/src/controller/LoginServlet.java b/src/controller/LoginServlet.java index 5cc5ff5..7876455 100644 --- a/src/controller/LoginServlet.java +++ b/src/controller/LoginServlet.java @@ -16,9 +16,6 @@ public class LoginServlet extends HttpServlet { - /** - * - */ private static final long serialVersionUID = 1L; private static final UserDAO userDao = new UserDAOImpl(DBUtil.getConnection(), null); diff --git a/src/dao/BusinessNoteDAO.java b/src/dao/BusinessNoteDAO.java index 69b4079..0bc9c22 100644 --- a/src/dao/BusinessNoteDAO.java +++ b/src/dao/BusinessNoteDAO.java @@ -1,5 +1,7 @@ package dao; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.List; import model.BusinessNoteVO; @@ -10,5 +12,8 @@ public interface BusinessNoteDAO extends DAO { List getLastBusinessNotes(); List getPersistenceBusinessNotesList(); void insertList(List notesList); + List getBusinessNotesListFromRs(ResultSet rs) throws SQLException; + BusinessNoteVO getBusinessNoteFromRs(ResultSet rs) throws SQLException; + BusinessNoteVO getBusinessNoteById(int noteId); } diff --git a/src/dao/BusinessNoteDAOImpl.java b/src/dao/BusinessNoteDAOImpl.java index 29dfcf5..a13df99 100644 --- a/src/dao/BusinessNoteDAOImpl.java +++ b/src/dao/BusinessNoteDAOImpl.java @@ -5,7 +5,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Date; import java.util.List; import javax.servlet.http.HttpSession; @@ -198,4 +197,84 @@ public void insertList(List notesList) { } } + @Override + public BusinessNoteVO getBusinessNoteById(int noteId) { + + String sql = "select * from business_note bus " + + "join note n " + + "on n.note_id = bus.note_id " + + "where bus.note_id = ?"; + + BusinessNoteVO busNote = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + statement = connection.prepareStatement(sql); + int p = 1; + statement.setInt(p, noteId); + p++; + resultSet = statement.executeQuery(); + if(resultSet.next()) { + busNote = getBusinessNoteFromRs(resultSet); + } + } catch (SQLException ex) { + ex.printStackTrace(); + } finally { + closeStmtAndRs(statement, resultSet); + } + return busNote; + } + + @Override + public List getBusinessNotesListFromRs(ResultSet rs) + throws SQLException { + + List list = new ArrayList(); + + BusinessNoteVO businessNote; + while (rs.next()) { + businessNote = getBusinessNoteFromRs(rs); + list.add(businessNote); + } + return list; + } + + @Override + public BusinessNoteVO getBusinessNoteFromRs(ResultSet rs) + throws SQLException { + + BusinessNoteVO businessNote; + + DDBBBusinessNote ddbbBusinessNote = new DDBBBusinessNote();; + DDBBNote ddbbNote = new DDBBNote(); + ddbbNote.loadResult(rs); + ddbbBusinessNote.loadResult(rs); + + businessNote = new BusinessNoteVO(ddbbNote, ddbbBusinessNote); + + CustomerVO customer = null; + SupplierVO supplier = null; + ProductVO product = null; + if(!ddbbBusinessNote.isCustomerIdNull()) { + customer = customerDao.getCustomerById( + ddbbBusinessNote.getCustomerId()); + } + if(!ddbbBusinessNote.isSupplierIdNull()) { + supplier = supplierDao.getSupplierById( + ddbbBusinessNote.getSupplierId()); + } + if(!ddbbBusinessNote.isProductIdNull()) { + product = productDao.getProductById( + ddbbBusinessNote.getProductId()); + } + + businessNote.setCustomer(customer); + businessNote.setSupplier(supplier); + businessNote.setProduct(product); + + return businessNote; + } + + } diff --git a/src/dao/ThreadDAO.java b/src/dao/ThreadDAO.java new file mode 100644 index 0000000..804278a --- /dev/null +++ b/src/dao/ThreadDAO.java @@ -0,0 +1,11 @@ +package dao; + +import java.util.List; + +import model.ThreadVO; + +public interface ThreadDAO extends DAO { + + List getThreadsList(); + +} diff --git a/src/dao/ThreadDAOImpl.java b/src/dao/ThreadDAOImpl.java new file mode 100644 index 0000000..ca6637e --- /dev/null +++ b/src/dao/ThreadDAOImpl.java @@ -0,0 +1,177 @@ +package dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpSession; + +import model.BusinessNoteVO; +import model.CustomerVO; +import model.NoteVO; +import model.ProductVO; +import model.Profile; +import model.SupplierVO; +import model.ThreadVO; +import persistence.DDBBBusinessNote; +import persistence.DDBBNote; +import persistence.DDBBThread; +import utils.DateUtils; + +public class ThreadDAOImpl extends DAOImpl implements ThreadDAO { + + private static final String MANAGER_LIST = + "SELECT * FROM THREAD T " + + "JOIN THREAD_NOTE TN ON TN.THREAD_ID = T.THREAD_ID " + + "JOIN NOTE N ON N.NOTE_ID = TN.NOTE_ID " + + "JOIN BUSINESS_NOTE BN ON BN.NOTE_ID = N.NOTE_ID " + + "WHERE T.THREAD_ID = ?"; + + private static final String SALES_TEAM_LIST = + "SELECT * FROM THREAD T " + + "JOIN THREAD_NOTE TN ON TN.THREAD_ID = T.THREAD_ID " + + "JOIN NOTE N ON N.NOTE_ID = TN.NOTE_ID " + + "JOIN BUSINESS_NOTE BN ON BN.NOTE_ID = N.NOTE_ID " + + "WHERE N.USER_ID = ? " + + "AND T.THREAD_ID = ?"; + + private static final String THREAD_ID_LIST = + "SELECT * FROM THREAD"; + + private static final String THREAD_ID_LIST_ST = + "SELECT DISCTINT T.THREAD_ID, T.THREAD_TITLE, T.CREATION_DATE " + + "FROM THREAD T " + + "JOIN THREAD_NOTE TN ON TN.THREAD_ID = T.THREAD_ID " + + "JOIN NOTE N ON N.NOTE_ID = TN.NOTE_ID " + + "WHERE N.USER_ID = ?"; + + private Profile profile; + Integer userId; + private BusinessNoteDAO businessDao; + + + public ThreadDAOImpl(Connection connection, HttpSession session) { + super(connection, session); + businessDao = new BusinessNoteDAOImpl(connection, session); + userId = (Integer) getSession().getAttribute("userId"); + profile = (Profile) getSession().getAttribute("profile"); + } + + @Override + public int insert(Object o){ + + int threadId = -1; + + ThreadVO thread = (ThreadVO) o; + DDBBThread ddbbThread = thread.getPersistenceObject(); + try { + threadId = ddbbThread.insert(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + + return threadId; + } + + @Override + public Object search(Object o) { + return null; + } + + @Override + public void update(Object o) { + + } + + @Override + public void delete(Object o) { + + } + + @Override + public List getThreadsList() { + + String SQL = null; + + if(Profile.MANAGER.equals(profile)) { + SQL = MANAGER_LIST; + } else if (Profile.SALES_TEAM.equals(profile)) { + SQL = SALES_TEAM_LIST; + } + + List threadsList = getThreadsIdList(); + List notesList; + + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + statement = connection.prepareStatement(SQL); + for(ThreadVO eachThread : threadsList) { + int p = 1; + if(Profile.SALES_TEAM.equals(profile)) { + statement.setInt(p, userId); + p++; + } + statement.setInt(p, eachThread.getThreadId()); + p++; + resultSet = statement.executeQuery(); + notesList = businessDao.getBusinessNotesListFromRs(resultSet); + eachThread.setNotesList(notesList); + } + } catch (SQLException ex) { + ex.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e.getCause().toString()); + System.out.println(e.getClass().toString()); + System.out.println(e.getMessage()); + } finally { + closeStmtAndRs(statement, resultSet); + } + return threadsList; + } + + private List getThreadsIdList() { + + String SQL = null; + + if(Profile.MANAGER.equals(profile)) { + SQL = THREAD_ID_LIST; + } else if (Profile.SALES_TEAM.equals(profile)) { + SQL = THREAD_ID_LIST_ST; + } + + List list = new ArrayList(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + statement = connection.prepareStatement(SQL); + int p = 1; + if(Profile.SALES_TEAM.equals(profile)) { + statement.setInt(p, userId); + p++; + } + resultSet = statement.executeQuery(); + + ThreadVO thread; + while (resultSet.next()) { + thread = new ThreadVO(); + thread.setThreadId(resultSet.getInt("THREAD_ID")); + thread.setThreadTitle(resultSet.getString("THREAD_TITLE")); + thread.setCreationDate(resultSet.getDate("CREATION_DATE")); + list.add(thread); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return list; + } + + +} diff --git a/src/dao/ThreadNoteDAO.java b/src/dao/ThreadNoteDAO.java new file mode 100644 index 0000000..a01a888 --- /dev/null +++ b/src/dao/ThreadNoteDAO.java @@ -0,0 +1,13 @@ +package dao; + +import java.util.List; + +import model.BusinessNoteVO; +import model.ThreadNoteVO; +import persistence.DDBBBusinessNote; + +public interface ThreadNoteDAO extends DAO { + + void insertList(List threadNotesList); + +} diff --git a/src/dao/ThreadNoteDAOImpl.java b/src/dao/ThreadNoteDAOImpl.java new file mode 100644 index 0000000..480ff3a --- /dev/null +++ b/src/dao/ThreadNoteDAOImpl.java @@ -0,0 +1,54 @@ +package dao; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import javax.servlet.http.HttpSession; + +import model.ThreadNoteVO; +import persistence.DDBBThreadNote; + +public class ThreadNoteDAOImpl extends DAOImpl implements ThreadNoteDAO { + + public ThreadNoteDAOImpl(Connection connection, HttpSession session) { + super(connection, session); + } + + @Override + public int insert(Object o){ + + int threadNoteId = -1; + + ThreadNoteVO threadNote = (ThreadNoteVO) o; + DDBBThreadNote ddbbThreadNote = threadNote.getPersistenceObject(); + try { + threadNoteId = ddbbThreadNote.insert(connection); + } catch (SQLException e) { + e.printStackTrace(); + } + + return threadNoteId; + } + + @Override + public Object search(Object o) { + return null; + } + + @Override + public void update(Object o) { + + } + + @Override + public void delete(Object o) { + + } + + @Override + public void insertList(List threadNotesList) { + + } + +} diff --git a/src/model/NoteVO.java b/src/model/NoteVO.java index 45185ed..2e4988f 100644 --- a/src/model/NoteVO.java +++ b/src/model/NoteVO.java @@ -87,17 +87,18 @@ public DDBBNote getPersistenceObject() { public void setFromPersistenceObject(DDBBNote ddbbNote) { - UserVO user = new UserVO(); + UserVO user = null; if(!ddbbNote.isUserIdNull()) { + user = new UserVO(); user.setUserId(ddbbNote.getUserId()); } setUser(user); if(!ddbbNote.isNoteIdNull()) { - setNoteId(ddbbNote.getUserId()); + setNoteId(ddbbNote.getNoteId()); } else { - setNoteId(noteId); + setNoteId(null); } if(!ddbbNote.isCreationDateNull()) { setCreationDate(new Date( diff --git a/src/model/ThreadNoteVO.java b/src/model/ThreadNoteVO.java index e541563..3ff7c9b 100644 --- a/src/model/ThreadNoteVO.java +++ b/src/model/ThreadNoteVO.java @@ -4,31 +4,31 @@ public class ThreadNoteVO { - private Integer threadId; - private Integer noteId; + private ThreadVO thread; + private BusinessNoteVO note; - public Integer getThreadId() { - return threadId; + public ThreadVO getThread() { + return thread; } - public void setThreadId(Integer threadId) { - this.threadId = threadId; + public void setThread(ThreadVO thread) { + this.thread = thread; } - public Integer getNoteId() { - return noteId; + public BusinessNoteVO getNote() { + return note; } - public void setNoteId(Integer noteId) { - this.noteId = noteId; + public void setNote(BusinessNoteVO note) { + this.note = note; } public DDBBThreadNote getPersistenceObject() { DDBBThreadNote ddbbThreadNote = new DDBBThreadNote(); - if(getThreadId() != null) { - ddbbThreadNote.setThreadId(getThreadId()); + if(getThread() != null) { + ddbbThreadNote.setThreadId(getThread().getThreadId()); } else { ddbbThreadNote.setThreadIdNull(); } - if(getNoteId() != null) { - ddbbThreadNote.setNoteId(getNoteId()); + if(getNote() != null) { + ddbbThreadNote.setNoteId(getNote().getNoteId()); } else { ddbbThreadNote.setNoteIdNull(); } diff --git a/src/model/ThreadVO.java b/src/model/ThreadVO.java index 7c1e3df..f0aef5c 100644 --- a/src/model/ThreadVO.java +++ b/src/model/ThreadVO.java @@ -1,11 +1,16 @@ package model; +import java.util.Date; +import java.util.List; + import persistence.DDBBThread; public class ThreadVO { private Integer threadId; private String threadTitle; + private Date creationDate; + private List notesList; public Integer getThreadId() { return threadId; @@ -19,7 +24,18 @@ public String getThreadTitle() { public void setThreadTitle(String threadTitle) { this.threadTitle = threadTitle; } - + public Date getCreationDate() { + return creationDate; + } + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + public List getNotesList() { + return notesList; + } + public void setNotesList(List notesList) { + this.notesList = notesList; + } public DDBBThread getPersistenceObject() { DDBBThread ddbbThread = new DDBBThread(); if(getThreadId() != null) { @@ -32,6 +48,12 @@ public DDBBThread getPersistenceObject() { } else { ddbbThread.setThreadTitleNull(); } + if(getCreationDate() != null) { + ddbbThread.setCreationDate( + new java.sql.Date(getCreationDate().getTime())); + } else { + ddbbThread.setCreationDateNull(); + } return ddbbThread; } @@ -47,9 +69,10 @@ public void setFromPersistenceObject(DDBBThread ddbbThread) { } else { setThreadTitle(null); } + if(!ddbbThread.isCreationDateNull()) { + setCreationDate(ddbbThread.getCreationDate()); + } else { + setCreationDate(null); + } } - - - - } diff --git a/src/persistence/DDBBThread.java b/src/persistence/DDBBThread.java index 5762d8a..c7168f9 100644 --- a/src/persistence/DDBBThread.java +++ b/src/persistence/DDBBThread.java @@ -9,13 +9,14 @@ public class DDBBThread { - private static final String INSERT_ALL = "insert into thread (THREAD_TITLE) values (?)"; + private static final String INSERT_ALL = "insert into thread (THREAD_TITLE, CREATION_DATE) values (?,?)"; private static final String LAST_ID = "SELECT LAST_INSERT_ID()"; private static final String SQL_READ="SELECT * FROM thread WHERE THREAD_ID=?"; private static final String SQL_DELETE="DELETE FROM thread WHERE THREAD_ID=?"; private int threadId; private String threadTitle; + private Date creationDate; private int threadIdNull; @@ -31,6 +32,12 @@ public String getThreadTitle() { public void setThreadTitle(String threadTitle) { this.threadTitle = threadTitle; } + public Date getCreationDate() { + return creationDate; + } + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } public int getThreadIdNull() { return threadIdNull; @@ -47,6 +54,12 @@ public boolean isThreadTitleNull() { public void setThreadTitleNull() { this.threadTitle = null; } + public boolean isCreationDateNull() { + return getCreationDate() == null; + } + public void setCreationDateNull() { + setCreationDate(null); + } public void loadResult(ResultSet rs) throws SQLException { @@ -71,7 +84,7 @@ public Integer insert(Connection connection) throws SQLException { try { - // SQL: NOTE_ID (INT): + // SQL: THREAD_TITLE (STRING): if (isThreadTitleNull()) { ps.setNull(p, java.sql.Types.VARCHAR); @@ -80,6 +93,18 @@ public Integer insert(Connection connection) throws SQLException { { ps.setString(p, getThreadTitle()); } + p++; + // SQL: CREATION_DATE (DATE): + if (isCreationDateNull()) + { + ps.setDate(p, new Date(getCreationDate().getTime())); + } + else + { + ps.setDate(p, getCreationDate()); + } + p++; + ps.executeUpdate(); rs = stmt.executeQuery(LAST_ID); diff --git a/src/persistence/DDBBThreadNote.java b/src/persistence/DDBBThreadNote.java index 9258aca..ad57683 100644 --- a/src/persistence/DDBBThreadNote.java +++ b/src/persistence/DDBBThreadNote.java @@ -80,6 +80,7 @@ public Integer insert(Connection connection) throws SQLException { { ps.setInt(p, getThreadId()); } + p++; // SQL: NOTE_ID (INT): if (isNoteIdNull()) { @@ -89,6 +90,8 @@ public Integer insert(Connection connection) throws SQLException { { ps.setInt(p, getNoteId()); } + p++; + ps.executeUpdate(); lastKey = getThreadId(); diff --git a/src/service/AddBusinessNoteService.java b/src/service/AddBusinessNoteService.java index ed6428b..4bf8000 100644 --- a/src/service/AddBusinessNoteService.java +++ b/src/service/AddBusinessNoteService.java @@ -121,8 +121,8 @@ public void getDomainData(HttpServletRequest request) { } userId = (Integer) getSession().getAttribute("userId"); - noteText = request.getParameter("noteTitle"); - noteTitle = request.getParameter("noteText"); + noteTitle = request.getParameter("noteTitle"); + noteText = request.getParameter("noteText"); creationDate = new Date(); } diff --git a/src/service/AddThreadService.java b/src/service/AddThreadService.java new file mode 100644 index 0000000..5afb281 --- /dev/null +++ b/src/service/AddThreadService.java @@ -0,0 +1,93 @@ +package service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import model.BusinessNoteVO; +import model.ThreadNoteVO; +import model.ThreadVO; +import dao.BusinessNoteDAO; +import dao.BusinessNoteDAOImpl; +import dao.ThreadDAO; +import dao.ThreadDAOImpl; +import dao.ThreadNoteDAO; +import dao.ThreadNoteDAOImpl; + +public class AddThreadService extends ServiceImpl implements Service { + + private String threadTitle; + private Date creationDate; + private List notesIdList; + private Integer threadId; + + private ThreadVO thread; + private BusinessNoteVO note; + private ThreadNoteVO threadNote; + + private ThreadDAO threadDao; + private BusinessNoteDAO noteDao; + private ThreadNoteDAO threadNoteDao; + + @Override + protected void execute() { + + instantiation(); + createThread(); + createNoteThreads(); + request.setAttribute("nextStep", "threadsList"); + } + + private void instantiation() { + + noteDao = new BusinessNoteDAOImpl(getConnection(), getSession()); + threadDao = new ThreadDAOImpl(getConnection(), getSession()); + threadNoteDao = new ThreadNoteDAOImpl(getConnection(), getSession()); + thread = new ThreadVO(); + threadNote = new ThreadNoteVO(); + } + + private void createThread() { + setThreadAttributes(); + threadId = threadDao.insert(thread); + thread.setThreadId(threadId); + + } + + private void setThreadAttributes() { + thread.setThreadTitle(threadTitle); + thread.setCreationDate(creationDate); + } + + private void createNoteThreads() { + + for(Integer eachNoteId : notesIdList) { + getNoteThreadObjects(eachNoteId); + threadNote.setThread(thread); + threadNote.setNote(note); + threadNoteDao.insert(threadNote); + } + } + + private void getNoteThreadObjects(Integer noteId) { + note = noteDao.getBusinessNoteById(noteId); + } + + @Override + public void getDomainData(HttpServletRequest request) { + + notesIdList = new ArrayList(); + String[] idsList = request.getParameterValues("IdsList"); + for(int i = 0; i < idsList.length; i++) { + int noteId = Integer.parseInt(idsList[i]); + notesIdList.add(noteId); + } + + threadTitle = request.getParameter("threadTitle"); + creationDate = new Date(); + + } + +} diff --git a/src/service/GetThreadsListService.java b/src/service/GetThreadsListService.java new file mode 100644 index 0000000..6b6464a --- /dev/null +++ b/src/service/GetThreadsListService.java @@ -0,0 +1,30 @@ +package service; + +import java.util.List; + +import model.ThreadVO; +import dao.ThreadDAO; +import dao.ThreadDAOImpl; + +public class GetThreadsListService extends ServiceImpl implements Service { + + @Override + protected void execute() { + + getThreadsList(); + request.setAttribute("url", "threadsList.jsp?"); + } + + private void getThreadsList() { + + try { + ThreadDAO threadDao = new ThreadDAOImpl(getConnection(), getSession()); + List threadsList = threadDao.getThreadsList(); + request.setAttribute("threadsList", threadsList); + } catch (Exception e) { + System.out.println(e); + } + + } + +}