From c79885f5ee765204a5de39e47aff83176c9210b0 Mon Sep 17 00:00:00 2001 From: anjey Date: Sun, 15 Dec 2013 12:36:33 +0600 Subject: [PATCH 01/30] actions added, doAction() added --- WebContent/WEB-INF/jsp/home.jsp | 12 +++++ WebContent/WEB-INF/jsp/login.jsp | 19 +++++++ WebContent/WEB-INF/jsp/main.jsp | 15 ++++++ WebContent/WEB-INF/web.xml | 12 +++++ src/com/epam/devteam/action/Action.java | 24 +++++++++ .../epam/devteam/action/ActionException.java | 53 +++++++++++++++++++ .../epam/devteam/action/ActionFactory.java | 30 +++++++++++ src/com/epam/devteam/action/HomeAction.java | 24 +++++++++ src/com/epam/devteam/action/LoginAction.java | 28 ++++++++++ src/com/epam/devteam/action/MainAction.java | 24 +++++++++ src/com/epam/devteam/servlet/Controller.java | 51 ++++++++++++------ 11 files changed, 276 insertions(+), 16 deletions(-) create mode 100644 WebContent/WEB-INF/jsp/home.jsp create mode 100644 WebContent/WEB-INF/jsp/login.jsp create mode 100644 WebContent/WEB-INF/jsp/main.jsp create mode 100644 src/com/epam/devteam/action/Action.java create mode 100644 src/com/epam/devteam/action/ActionException.java create mode 100644 src/com/epam/devteam/action/ActionFactory.java create mode 100644 src/com/epam/devteam/action/HomeAction.java create mode 100644 src/com/epam/devteam/action/LoginAction.java create mode 100644 src/com/epam/devteam/action/MainAction.java diff --git a/WebContent/WEB-INF/jsp/home.jsp b/WebContent/WEB-INF/jsp/home.jsp new file mode 100644 index 0000000..4328c5f --- /dev/null +++ b/WebContent/WEB-INF/jsp/home.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Home + + + Hello from home page! + + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/login.jsp b/WebContent/WEB-INF/jsp/login.jsp new file mode 100644 index 0000000..5483c43 --- /dev/null +++ b/WebContent/WEB-INF/jsp/login.jsp @@ -0,0 +1,19 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Login + + + Hello from login page! +
+ + Input your username and password:
+
+
+ +
+ + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp new file mode 100644 index 0000000..b0319a4 --- /dev/null +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Main + + + Hello from main page!
+
+ +
+ + \ No newline at end of file diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index e1e4ab0..0145e8a 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -9,4 +9,16 @@ default.htm default.jsp + + + + Controller + Controller + com.epam.devteam.servlet.Controller + + + + Controller + /do/* + \ No newline at end of file diff --git a/src/com/epam/devteam/action/Action.java b/src/com/epam/devteam/action/Action.java new file mode 100644 index 0000000..a490530 --- /dev/null +++ b/src/com/epam/devteam/action/Action.java @@ -0,0 +1,24 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public interface Action { + + /** + * Is used to make required action and get view where to redirect user. + * @param request Request to process. + * @param response Response to send. + * @return View where to redirect user + * @throws ActionException + */ + public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException; +} diff --git a/src/com/epam/devteam/action/ActionException.java b/src/com/epam/devteam/action/ActionException.java new file mode 100644 index 0000000..3000fb3 --- /dev/null +++ b/src/com/epam/devteam/action/ActionException.java @@ -0,0 +1,53 @@ +/** + * + */ +package com.epam.devteam.action; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public class ActionException extends Exception { + + /** + * Serial version ID. + */ + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with null as its detail message. + */ + public ActionException() { + super(); + } + + /** + * Constructs a new exception with the specified detail message and + * cause. + * @param message the detail message. + * @param cause the cause. + */ + public ActionException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new exception with the specified detail message. + * @param message the detail message. + */ + public ActionException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified cause and a detail + * message of (cause==null ? null : cause.toString()). + * @param cause the cause. + */ + public ActionException(Throwable cause) { + super(cause); + } + + +} diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java new file mode 100644 index 0000000..d25381f --- /dev/null +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -0,0 +1,30 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public class ActionFactory { + public static Action getAction(HttpServletRequest request){ + Action action = null; + String req = null; + if (request != null) { + req = request.getMethod() + request.getPathInfo(); + System.out.println(req); + } + if ("GET/login".equals(req) || "POST/login".equals(req)) { + action = new LoginAction(); + } else if ("GET/home".equals(req)) { + action = new HomeAction(); + } else { + action = new MainAction(); + } + return action; + } +} diff --git a/src/com/epam/devteam/action/HomeAction.java b/src/com/epam/devteam/action/HomeAction.java new file mode 100644 index 0000000..080119c --- /dev/null +++ b/src/com/epam/devteam/action/HomeAction.java @@ -0,0 +1,24 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public class HomeAction implements Action{ + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + return "home"; + } + + + +} diff --git a/src/com/epam/devteam/action/LoginAction.java b/src/com/epam/devteam/action/LoginAction.java new file mode 100644 index 0000000..77e53b5 --- /dev/null +++ b/src/com/epam/devteam/action/LoginAction.java @@ -0,0 +1,28 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public class LoginAction implements Action { + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + if ("login".equals(request.getParameter("command"))) { + System.out.println(request.getParameter("username")); + System.out.println(request.getParameter("password")); + System.out.println("Welcome user!"); + return "home"; + } + return "login"; + } + +} diff --git a/src/com/epam/devteam/action/MainAction.java b/src/com/epam/devteam/action/MainAction.java new file mode 100644 index 0000000..370cff0 --- /dev/null +++ b/src/com/epam/devteam/action/MainAction.java @@ -0,0 +1,24 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Dec 14, 2013 + * @author anjey + * + */ +public class MainAction implements Action{ + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + return "main"; + } + + + +} diff --git a/src/com/epam/devteam/servlet/Controller.java b/src/com/epam/devteam/servlet/Controller.java index e42e392..8119c83 100644 --- a/src/com/epam/devteam/servlet/Controller.java +++ b/src/com/epam/devteam/servlet/Controller.java @@ -1,39 +1,58 @@ package com.epam.devteam.servlet; import java.io.IOException; + import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.epam.devteam.action.Action; +import com.epam.devteam.action.ActionFactory; + /** * Servlet implementation class Controller */ -@WebServlet("/Controller") public class Controller extends HttpServlet { private static final long serialVersionUID = 1L; - - /** - * @see HttpServlet#HttpServlet() - */ - public Controller() { - super(); - // TODO Auto-generated constructor stub - } /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + * @see HttpServlet#HttpServlet() */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub + public Controller() { + super(); } /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + //request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response); + doAction(request, response); } + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + doAction(request, response); + } + + protected void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try{ + Action action = ActionFactory.getAction(request); + String view = action.execute(request, response); + if (view.equals(request.getPathInfo().substring(1))) { + request.getRequestDispatcher("/WEB-INF/jsp/" + view + ".jsp").forward(request, response); + } else { + response.sendRedirect(view); + } + } catch (Exception e) { + throw new ServletException("Executing action failed.", e); + } + } } From 7804a20dbf9bd3fd30f7307a002336d60878724d Mon Sep 17 00:00:00 2001 From: anjey Date: Wed, 18 Dec 2013 15:06:51 +0600 Subject: [PATCH 02/30] controlle and db were merged --- .classpath | 1 + src/com/epam/devteam/action/LoginAction.java | 42 ++++++++++++++----- .../dao/impl/PostgresqlDaoFactory.java | 2 +- .../devteam/dao/impl/PostgresqlUserDao.java | 12 ++++-- src/com/epam/devteam/db/ConnectionPool.java | 11 +++-- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.classpath b/.classpath index 3aa4c20..b82e428 100644 --- a/.classpath +++ b/.classpath @@ -15,5 +15,6 @@ + diff --git a/src/com/epam/devteam/action/LoginAction.java b/src/com/epam/devteam/action/LoginAction.java index 77e53b5..7af8ed9 100644 --- a/src/com/epam/devteam/action/LoginAction.java +++ b/src/com/epam/devteam/action/LoginAction.java @@ -3,9 +3,17 @@ */ package com.epam.devteam.action; +import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.epam.devteam.dao.DaoFactory; +import com.epam.devteam.dao.DaoFactoryTypes; +import com.epam.devteam.dao.UserDao; +import com.epam.devteam.db.ConnectionPool; +import com.epam.devteam.entity.User; + /** * @date Dec 14, 2013 * @author anjey @@ -13,16 +21,30 @@ */ public class LoginAction implements Action { - @Override - public String execute(HttpServletRequest request, - HttpServletResponse response) throws ActionException { - if ("login".equals(request.getParameter("command"))) { - System.out.println(request.getParameter("username")); - System.out.println(request.getParameter("password")); - System.out.println("Welcome user!"); - return "home"; - } - return "login"; + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + if ("login".equals(request.getParameter("command"))) { + System.out.println(request.getParameter("username")); + System.out.println(request.getParameter("password")); + System.out.println("Welcome user!"); + return "home"; + } + try { + DaoFactory df = DaoFactory + .takeDaoFactory(DaoFactoryTypes.POSTGRESQL); + ConnectionPool.INSTANCE.init(); + df.setConnectionPool(ConnectionPool.INSTANCE); + UserDao ud = df.takeUserDao(); + List users = ud.listUsers(); + for (User user : users) { + System.out.println(user); + } + } catch (Exception e) { + System.out.println("You fucking failed!"); + e.printStackTrace(); } + return "login"; + } } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java index f404f33..e30437e 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java @@ -45,7 +45,7 @@ public void setConnectionPool(ConnectionPool connectionPool) { public UserDao takeUserDao() throws DaoException { Connection connection = connectionPool.takeConnection(); if (connection == null) { - throw new DaoException("Cannot take connection!"); + throw new DaoException("Can not take connection."); } return new PostgresqlUserDao(connection); } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java index 13b6a5f..b7e5d2e 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java @@ -81,12 +81,18 @@ public List listUsers() throws DaoException { ResultSet resultSet = null; try { statement = connection.createStatement(); - LOGGER.debug("A statement was created"); - resultSet = statement.executeQuery("SELECT * FROM users"); + LOGGER.debug("A statement was created."); + } catch (SQLException e) { + LOGGER.warn("Can not create a statement."); + } + + try { + resultSet = statement.executeQuery("SELECT * FROM users;"); users = new ArrayList(); while (resultSet.next()) { user = new User(); user.setId(resultSet.getLong("id")); + user.setEmail(resultSet.getString("email")); user.setPassword(resultSet.getString("password")); user.setFirstname(resultSet.getString("firstname")); user.setLastname(resultSet.getString("lastname")); @@ -95,7 +101,7 @@ public List listUsers() throws DaoException { users.add(user); } } catch (SQLException e) { - LOGGER.warn("Can't create a statement."); + LOGGER.warn("Can not execute query."); } return users; } diff --git a/src/com/epam/devteam/db/ConnectionPool.java b/src/com/epam/devteam/db/ConnectionPool.java index a332c06..9592e74 100644 --- a/src/com/epam/devteam/db/ConnectionPool.java +++ b/src/com/epam/devteam/db/ConnectionPool.java @@ -6,6 +6,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -23,7 +24,7 @@ public enum ConnectionPool { private static final Logger LOGGER = Logger.getLogger(ConnectionPool.class); private static final String DRIVER_NAME = "org.postgresql.Driver"; - private static final String URL = "jdbc:postgresql://localhost:5432/postgres"; + private static final String URL = "jdbc:postgresql://localhost:5432/devteam"; private static final String USER = "postgres"; private static final String PASSWORD = "postgres"; private static final int CONNECTIONS_QUANTITY = 10; @@ -35,7 +36,7 @@ public enum ConnectionPool { * It is not possible to initialize this object outside of this class. */ private ConnectionPool() { - // init(); ???? + //init(); } /** @@ -47,11 +48,13 @@ public void init() throws ConnectionPoolException { try { Class.forName(DRIVER_NAME); + LOGGER.debug("Database driver was initialized."); } catch (ClassNotFoundException e) { - LOGGER.error("Data base driver not found"); + LOGGER.error("Data base driver not found."); throw new ConnectionPoolException(); } semaphore = new Semaphore(CONNECTIONS_QUANTITY); + freeConnections = new ArrayBlockingQueue(CONNECTIONS_QUANTITY); for (int i = 0; i < CONNECTIONS_QUANTITY; i++) { Connection connection; try { @@ -79,6 +82,7 @@ public Connection takeConnection() { if (semaphore.tryAcquire(MAX_WAIT_TIME, TimeUnit.MILLISECONDS)) { connection = freeConnections.poll(MAX_WAIT_TIME, TimeUnit.MILLISECONDS); + LOGGER.debug("Connection has been taken."); } } catch (InterruptedException e) { LOGGER.warn("Can't take connection"); @@ -96,6 +100,7 @@ public void returnConnection(Connection connection) { freeConnections.offer(connection, MAX_WAIT_TIME, TimeUnit.MILLISECONDS); semaphore.release(); + LOGGER.debug("Connection has been returned."); } catch (InterruptedException e) { LOGGER.warn("Can't return connection!"); } From 4919264cb5544e23c25effb7e9d528f48a8c4780 Mon Sep 17 00:00:00 2001 From: anjey Date: Thu, 19 Dec 2013 20:04:47 +0600 Subject: [PATCH 03/30] Connection pool, Dao factory and Property manager were modified. Singeltone pattern was remade with dublechecked approach and lazy initialization. Context listener was added. --- WebContent/WEB-INF/web.xml | 53 ++-- resources/log4j.properties | 8 + resources/properties.properties | 7 + src/com/epam/devteam/action/LoginAction.java | 7 +- src/com/epam/devteam/dao/DaoFactory.java | 55 ++++- src/com/epam/devteam/dao/DaoFactoryTypes.java | 15 -- .../dao/impl/PostgresqlDaoFactory.java | 9 +- .../devteam/dao/impl/PostgresqlUserDao.java | 42 +++- src/com/epam/devteam/db/ConnectionPool.java | 150 ++++++++---- .../devteam/db/ConnectionPoolException.java | 2 +- src/com/epam/devteam/db/DatabaseType.java | 19 ++ .../devteam/listener/ContextListener.java | 50 ++++ src/com/epam/devteam/servlet/Controller.java | 74 +++--- .../util/property/PropertyManager.java | 229 ++++++++++++++++++ .../property/PropertyManagerException.java | 53 ++++ 15 files changed, 621 insertions(+), 152 deletions(-) create mode 100644 resources/log4j.properties create mode 100644 resources/properties.properties delete mode 100644 src/com/epam/devteam/dao/DaoFactoryTypes.java create mode 100644 src/com/epam/devteam/db/DatabaseType.java create mode 100644 src/com/epam/devteam/listener/ContextListener.java create mode 100644 src/com/epam/devteam/util/property/PropertyManager.java create mode 100644 src/com/epam/devteam/util/property/PropertyManagerException.java diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 0145e8a..dde9b9c 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -1,24 +1,33 @@ - - devteam - - index.html - index.htm - index.jsp - default.html - default.htm - default.jsp - - - - - Controller - Controller - com.epam.devteam.servlet.Controller - - - - Controller - /do/* - + + devteam + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + + + + Controller + Controller + com.epam.devteam.servlet.Controller + + + + Controller + /do/* + + + + + ContextListener + com.epam.devteam.listener.ContextListener + \ No newline at end of file diff --git a/resources/log4j.properties b/resources/log4j.properties new file mode 100644 index 0000000..107db0b --- /dev/null +++ b/resources/log4j.properties @@ -0,0 +1,8 @@ +# Root logger option +log4j.rootLogger=DEBUG, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/resources/properties.properties b/resources/properties.properties new file mode 100644 index 0000000..b9eabb1 --- /dev/null +++ b/resources/properties.properties @@ -0,0 +1,7 @@ +db.currentdb = postgresql +db.postgresql.driver = org.postgresql.Driver +db.postgresql.url = jdbc:postgresql://localhost:5432/devteam +db.postgresql.user = postgres +db.postgresql.password = postgres +db.postgresql.connections = 10 +db.postgresql.waitTime = 5000 \ No newline at end of file diff --git a/src/com/epam/devteam/action/LoginAction.java b/src/com/epam/devteam/action/LoginAction.java index 7af8ed9..52b6b2a 100644 --- a/src/com/epam/devteam/action/LoginAction.java +++ b/src/com/epam/devteam/action/LoginAction.java @@ -9,9 +9,7 @@ import javax.servlet.http.HttpServletResponse; import com.epam.devteam.dao.DaoFactory; -import com.epam.devteam.dao.DaoFactoryTypes; import com.epam.devteam.dao.UserDao; -import com.epam.devteam.db.ConnectionPool; import com.epam.devteam.entity.User; /** @@ -31,10 +29,7 @@ public String execute(HttpServletRequest request, return "home"; } try { - DaoFactory df = DaoFactory - .takeDaoFactory(DaoFactoryTypes.POSTGRESQL); - ConnectionPool.INSTANCE.init(); - df.setConnectionPool(ConnectionPool.INSTANCE); + DaoFactory df = DaoFactory.takeDaoFactory(); UserDao ud = df.takeUserDao(); List users = ud.listUsers(); for (User user : users) { diff --git a/src/com/epam/devteam/dao/DaoFactory.java b/src/com/epam/devteam/dao/DaoFactory.java index d3919e2..d11e98f 100644 --- a/src/com/epam/devteam/dao/DaoFactory.java +++ b/src/com/epam/devteam/dao/DaoFactory.java @@ -7,6 +7,10 @@ import com.epam.devteam.dao.impl.PostgresqlDaoFactory; import com.epam.devteam.db.ConnectionPool; +import com.epam.devteam.db.ConnectionPoolException; +import com.epam.devteam.db.DatabaseType; +import com.epam.devteam.util.property.PropertyManager; +import com.epam.devteam.util.property.PropertyManagerException; /** * @date Dec 15, 2013 @@ -15,39 +19,72 @@ */ public abstract class DaoFactory { private static final Logger LOGGER = Logger.getLogger(DaoFactory.class); - + private static DatabaseType databaseType = null; + /** * Is used to set connection pool to the dao factory. * * @param connectionPool The connection pool to set. */ public abstract void setConnectionPool(ConnectionPool connectionPool); - + /** * Is used to take user dao. + * * @return The user dao implementation. * @throws DaoException If something fails. */ public abstract UserDao takeUserDao() throws DaoException; - + /** - * Is used to take dao factory implementation to work with required database. + * Is used to take dao factory implementation to work with required + * database. Database type is defined in property file. + * * @param daoFactoryTypes The implementation type. * @return The dao factory instance. - * @throws DaoException If required databse type is not required. + * @throws DaoException If something wrong with database type or something + * fails with connection pool. + * @see DatabaseType */ - public static DaoFactory takeDaoFactory(DaoFactoryTypes daoFactoryTypes) - throws DaoException { + public static DaoFactory takeDaoFactory() throws DaoException { DaoFactory daoFactory = null; - switch (daoFactoryTypes) { + if (databaseType == null) { + initDatabaseType(); + } + switch (databaseType) { case POSTGRESQL: daoFactory = new PostgresqlDaoFactory(); break; default: - LOGGER.error("Not available dao factory type!"); + LOGGER.warn("Database type is defined but not available!"); + throw new DaoException(); + } + try { + daoFactory.setConnectionPool(ConnectionPool.getInstance()); + } catch (ConnectionPoolException e) { + LOGGER.error("Connection pool can not be initialized"); throw new DaoException(); } return daoFactory; } + /** + * Is used to initialize current used database type during the first dao + * factory access. + * + * @throws DaoException If something fails with property manager or current + * database property is wrong. + * @see DatabaseType + */ + public static void initDatabaseType() throws DaoException { + try { + PropertyManager propertyManager = PropertyManager.getInstance(); + databaseType = DatabaseType.valueOf(propertyManager.getString( + "db.currentdb").toUpperCase()); + LOGGER.debug("Database type was initialized as " + databaseType); + } catch (PropertyManagerException e) { + LOGGER.error("Database type can not be initialized."); + throw new DaoException(); + } + } } diff --git a/src/com/epam/devteam/dao/DaoFactoryTypes.java b/src/com/epam/devteam/dao/DaoFactoryTypes.java deleted file mode 100644 index e4dfbd8..0000000 --- a/src/com/epam/devteam/dao/DaoFactoryTypes.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - */ -package com.epam.devteam.dao; - -/** - * @date Dec 15, 2013 - * @author anjey - * - */ -public enum DaoFactoryTypes { - - POSTGRESQL; - -} diff --git a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java index e30437e..724580d 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java @@ -3,8 +3,6 @@ */ package com.epam.devteam.dao.impl; -import java.sql.Connection; - import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.DaoFactory; import com.epam.devteam.dao.UserDao; @@ -39,14 +37,9 @@ public void setConnectionPool(ConnectionPool connectionPool) { /** * Is used to take user dao. * @return The user dao implementation. - * @throws DaoException If something fails. */ @Override public UserDao takeUserDao() throws DaoException { - Connection connection = connectionPool.takeConnection(); - if (connection == null) { - throw new DaoException("Can not take connection."); - } - return new PostgresqlUserDao(connection); + return new PostgresqlUserDao(connectionPool); } } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java index b7e5d2e..b46bcb1 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java @@ -14,17 +14,19 @@ import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.UserDao; +import com.epam.devteam.db.ConnectionPool; +import com.epam.devteam.db.ConnectionPoolException; import com.epam.devteam.entity.User; /** * @date Dec 15, 2013 - * @author anjey + * @author Andrey Kovalskiy * */ public class PostgresqlUserDao implements UserDao { private static final Logger LOGGER = Logger .getLogger(PostgresqlUserDao.class); - private Connection connection; + private ConnectionPool connectionPool; /** * Initializes a newly created {@code PostgresqlUserDao} object. @@ -39,8 +41,8 @@ public PostgresqlUserDao() { * * @param connection The connection to use to connect to the database. */ - public PostgresqlUserDao(Connection connection) { - this.connection = connection; + public PostgresqlUserDao(ConnectionPool connectionPool) { + this.connectionPool = connectionPool; } @Override @@ -77,15 +79,24 @@ public void deleteUser(User user) throws DaoException { public List listUsers() throws DaoException { List users = null; User user = null; + Connection connection = null; Statement statement = null; ResultSet resultSet = null; + + try { + connection = connectionPool.takeConnection(); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection can not be taken."); + throw new DaoException(); + } try { statement = connection.createStatement(); - LOGGER.debug("A statement was created."); + LOGGER.debug("Statement has been created."); } catch (SQLException e) { - LOGGER.warn("Can not create a statement."); + LOGGER.warn("Statement can not be created."); + finish(connection, statement); + throw new DaoException(); } - try { resultSet = statement.executeQuery("SELECT * FROM users;"); users = new ArrayList(); @@ -101,8 +112,23 @@ public List listUsers() throws DaoException { users.add(user); } } catch (SQLException e) { - LOGGER.warn("Can not execute query."); + LOGGER.warn("Query can not be executed."); + finish(connection, statement); + throw new DaoException(); } + finish(connection, statement); return users; } + + private void finish(Connection connection, Statement statement) { + if (statement != null) { + try { + statement.close(); + LOGGER.debug("Statement has been closed."); + } catch (SQLException e) { + LOGGER.warn("Statement can not be closed."); + } + }; + connectionPool.returnConnection(connection); + } } diff --git a/src/com/epam/devteam/db/ConnectionPool.java b/src/com/epam/devteam/db/ConnectionPool.java index 9592e74..763e82c 100644 --- a/src/com/epam/devteam/db/ConnectionPool.java +++ b/src/com/epam/devteam/db/ConnectionPool.java @@ -8,65 +8,82 @@ import java.sql.SQLException; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; +import com.epam.devteam.util.property.PropertyManager; +import com.epam.devteam.util.property.PropertyManagerException; + /** * @date Dec 15, 2013 * @author Andrey Kovalskiy * */ -public enum ConnectionPool { - - INSTANCE; +public class ConnectionPool { private static final Logger LOGGER = Logger.getLogger(ConnectionPool.class); - private static final String DRIVER_NAME = "org.postgresql.Driver"; - private static final String URL = "jdbc:postgresql://localhost:5432/devteam"; - private static final String USER = "postgres"; - private static final String PASSWORD = "postgres"; - private static final int CONNECTIONS_QUANTITY = 10; - private static final long MAX_WAIT_TIME = 5000; - private Semaphore semaphore; + private static volatile ConnectionPool instance; + private String driverName; + private String url; + private String user; + private String password; + private int connections; + private long waitTime; private BlockingQueue freeConnections; - /** - * It is not possible to initialize this object outside of this class. - */ - private ConnectionPool() { - //init(); + public static ConnectionPool getInstance() throws ConnectionPoolException { + ConnectionPool localInstance = instance; + if (localInstance == null) { + synchronized (ConnectionPool.class) { + localInstance = instance; + if (localInstance == null) { + instance = localInstance = new ConnectionPool(); + instance.init(); + } + } + } + return localInstance; } /** - * Is is used to initialize connection pool instance. + * It is used to initialize connection pool instance. * * @throws ConnectionPoolException */ - public void init() throws ConnectionPoolException { - + private void init() throws ConnectionPoolException { + try { + PropertyManager propertyManager = PropertyManager.getInstance(); + String currentDatabase = propertyManager.getString("db.currentdb"); + driverName = propertyManager.getString("db." + currentDatabase + + ".driver"); + url = propertyManager.getString("db." + currentDatabase + ".url"); + user = propertyManager.getString("db." + currentDatabase + ".user"); + password = propertyManager.getString("db." + currentDatabase + + ".password"); + connections = propertyManager.getInt("db." + currentDatabase + + ".connections"); + waitTime = propertyManager.getLong("db." + currentDatabase + + ".waitTime"); + LOGGER.debug("Connection pool fields were initialized."); + } catch (PropertyManagerException e) { + LOGGER.error("Connection pool fields can not be initialized."); + throw new ConnectionPoolException(); + } try { - Class.forName(DRIVER_NAME); + Class.forName(driverName); LOGGER.debug("Database driver was initialized."); } catch (ClassNotFoundException e) { - LOGGER.error("Data base driver not found."); + LOGGER.error("Data base driver was not found."); throw new ConnectionPoolException(); } - semaphore = new Semaphore(CONNECTIONS_QUANTITY); - freeConnections = new ArrayBlockingQueue(CONNECTIONS_QUANTITY); - for (int i = 0; i < CONNECTIONS_QUANTITY; i++) { - Connection connection; - try { - connection = DriverManager.getConnection(URL, USER, PASSWORD); - } catch (SQLException e) { - LOGGER.error("Can't initialize pool connections!"); - throw new ConnectionPoolException(); - } + freeConnections = new ArrayBlockingQueue(connections); + for (int i = 0; i < connections; i++) { + Connection connection = createConnection(); freeConnections.add(connection); } - LOGGER.debug("Connection pool was initialized with " - + CONNECTIONS_QUANTITY + "connections."); + LOGGER.debug("Connection pool was initialized with " + connections + + " connections."); } /** @@ -74,19 +91,22 @@ public void init() throws ConnectionPoolException { * will wait for a while. If there is still no free connections method will * return null. * - * @return Free connection, otherwise null. + * @return Free connection from the connection pool. + * @throws ConnectionPoolException If connection can not be taken or is not + * valid and can not be created. */ - public Connection takeConnection() { + public Connection takeConnection() throws ConnectionPoolException { Connection connection = null; try { - if (semaphore.tryAcquire(MAX_WAIT_TIME, TimeUnit.MILLISECONDS)) { - connection = freeConnections.poll(MAX_WAIT_TIME, - TimeUnit.MILLISECONDS); - LOGGER.debug("Connection has been taken."); - } + connection = freeConnections.poll(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - LOGGER.warn("Can't take connection"); + LOGGER.warn("Interrupted while waiting"); } + if (!isConnectionValid(connection)) { + LOGGER.debug("Connection is not valid."); + connection = createConnection(); + } + LOGGER.debug("Connection has been taken"); return connection; } @@ -97,12 +117,10 @@ public Connection takeConnection() { */ public void returnConnection(Connection connection) { try { - freeConnections.offer(connection, MAX_WAIT_TIME, - TimeUnit.MILLISECONDS); - semaphore.release(); + freeConnections.offer(connection, waitTime, TimeUnit.MILLISECONDS); LOGGER.debug("Connection has been returned."); } catch (InterruptedException e) { - LOGGER.warn("Can't return connection!"); + LOGGER.debug("Connection can not be returned"); } } @@ -113,11 +131,49 @@ public void closeConnections() { for (Connection connection : freeConnections) { try { connection.close(); - semaphore.release(); + LOGGER.debug("Connection has been closed."); } catch (SQLException e) { - LOGGER.error("Can't close connection!"); + LOGGER.error("Connection can not be closed."); } } } + /** + * Is used to create new connection. + * + * @return The new connection. + * @throws ConnectionPoolException If connection can not be created. + */ + private Connection createConnection() throws ConnectionPoolException { + Connection connection; + try { + connection = DriverManager.getConnection(url, user, password); + LOGGER.debug("Connection has been created"); + } catch (SQLException e) { + LOGGER.warn("Connection cannot be created."); + throw new ConnectionPoolException(); + } + return connection; + } + + /** + * Is used to check if the connection has not been closed and still is + * valid. + * + * @return true if connection is valid, false otherwise. + * @throws ConnectionPoolException If something wrong with connection + * validation. + */ + private boolean isConnectionValid(Connection connection) + throws ConnectionPoolException { + boolean result = false; + try { + result = connection.isValid((int) waitTime); + } catch (SQLException e) { + LOGGER.warn("Connection validation failed."); + throw new ConnectionPoolException(); + } + return result; + } + } diff --git a/src/com/epam/devteam/db/ConnectionPoolException.java b/src/com/epam/devteam/db/ConnectionPoolException.java index 6713cc1..3479b49 100644 --- a/src/com/epam/devteam/db/ConnectionPoolException.java +++ b/src/com/epam/devteam/db/ConnectionPoolException.java @@ -5,7 +5,7 @@ /** * @date Dec 15, 2013 - * @author anjey + * @author Andrey Kovalskiy * */ public class ConnectionPoolException extends Exception { diff --git a/src/com/epam/devteam/db/DatabaseType.java b/src/com/epam/devteam/db/DatabaseType.java new file mode 100644 index 0000000..4871c48 --- /dev/null +++ b/src/com/epam/devteam/db/DatabaseType.java @@ -0,0 +1,19 @@ +/** + * + */ +package com.epam.devteam.db; + +/** + * @date Dec 15, 2013 + * @author anjey + * + */ +public enum DatabaseType { + + POSTGRESQL; + + @Override + public String toString() { + return name().toLowerCase(); + } +} diff --git a/src/com/epam/devteam/listener/ContextListener.java b/src/com/epam/devteam/listener/ContextListener.java new file mode 100644 index 0000000..571f4e4 --- /dev/null +++ b/src/com/epam/devteam/listener/ContextListener.java @@ -0,0 +1,50 @@ +/** + * + */ +package com.epam.devteam.listener; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.log4j.Logger; + +import com.epam.devteam.db.ConnectionPool; +import com.epam.devteam.db.ConnectionPoolException; + +/** + * @date Dec 19, 2013 + * @author Andrey Kovalskiy + * + */ +public final class ContextListener implements ServletContextListener { + private static final Logger LOGGER = Logger + .getLogger(ContextListener.class); + + /** + ** Notification that the web application initialization process is starting. + * All ServletContextListeners are notified of context initialization before + * any filter or servlet in the web application is initialized. + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + LOGGER.debug("Servlet initilization..."); + } + + /** + ** Notification that the servlet context is about to be shut down. All + * servlets and filters have been destroy()ed before any + * ServletContextListeners are notified of context destruction. + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + ConnectionPool connectionPool; + try { + connectionPool = ConnectionPool.getInstance(); + connectionPool.closeConnections(); + LOGGER.debug("Connections have been closed."); + } catch (ConnectionPoolException e) { + LOGGER.error("Somethng fails with connection pool."); + } + } + +} diff --git a/src/com/epam/devteam/servlet/Controller.java b/src/com/epam/devteam/servlet/Controller.java index 8119c83..8d987ea 100644 --- a/src/com/epam/devteam/servlet/Controller.java +++ b/src/com/epam/devteam/servlet/Controller.java @@ -14,45 +14,47 @@ * Servlet implementation class Controller */ public class Controller extends HttpServlet { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * @see HttpServlet#HttpServlet() - */ - public Controller() { - super(); - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - //request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response); - doAction(request, response); - } + /** + * @see HttpServlet#HttpServlet() + */ + public Controller() { + super(); + } - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doPost(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - doAction(request, response); - } + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + doAction(request, response); + } - protected void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - try{ - Action action = ActionFactory.getAction(request); - String view = action.execute(request, response); - if (view.equals(request.getPathInfo().substring(1))) { - request.getRequestDispatcher("/WEB-INF/jsp/" + view + ".jsp").forward(request, response); - } else { - response.sendRedirect(view); - } - } catch (Exception e) { - throw new ServletException("Executing action failed.", e); + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + doAction(request, response); } + + protected void doAction(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + try { + Action action = ActionFactory.getAction(request); + String view = action.execute(request, response); + if (view.equals(request.getPathInfo().substring(1))) { + request.getRequestDispatcher("/WEB-INF/jsp/" + view + ".jsp") + .forward(request, response); + } else { + response.sendRedirect(view); + } + } catch (Exception e) { + throw new ServletException("Executing action failed.", e); } + } + } diff --git a/src/com/epam/devteam/util/property/PropertyManager.java b/src/com/epam/devteam/util/property/PropertyManager.java new file mode 100644 index 0000000..a7224d9 --- /dev/null +++ b/src/com/epam/devteam/util/property/PropertyManager.java @@ -0,0 +1,229 @@ +/** + * + */ +package com.epam.devteam.util.property; + +import java.io.IOException; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import com.epam.devteam.util.property.PropertyManager; + +/** + * @date Dec 18, 2013 + * @author Andrey Kovalskiy + * + */ +public class PropertyManager { + + private static final Logger LOGGER = Logger + .getLogger(PropertyManager.class); + private static volatile PropertyManager instance = null; + private Properties properties = null; + private String message = null; + + /** + * Is used to get property manager implementation instance. Initialization + * is to be during the first access. + * + * @return The property manager instance. + * @throws PropertyManagerException If initialization fails. + */ + public static PropertyManager getInstance() throws PropertyManagerException { + PropertyManager localInstance = instance; + if (localInstance == null) { + synchronized (PropertyManager.class) { + localInstance = instance; + if (localInstance == null) { + instance = localInstance = new PropertyManager(); + instance.init(); + } + } + } + return instance; + } + + /** + * Is used to initialize property manager instance. + * + * @throws PropertyManagerException If the property file can not be loaded. + */ + private void init() throws PropertyManagerException { + properties = new Properties(); + try { + properties.load(PropertyManager.class.getClassLoader() + .getResourceAsStream("properties.properties")); + } catch (IOException e) { + message = "Can not load property file."; + LOGGER.error(message); + throw new PropertyManagerException(message); + } + } + + /** + * Is used to get the property with specified key. Returns property value as + * string. + * + * @param key The property key. + * @return The required property. + * @throws PropertyManagerException If property is not found. + */ + public String getString(String key) throws PropertyManagerException { + String value = null; + value = properties.getProperty(key); + if (value == null) { + message = "Value " + key + " is not defined."; + LOGGER.warn(message); + throw new PropertyManagerException(message); + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * a string. If property value is not found or has wrong format method will + * return default value. + * + * @param key The property key. + * @param defaultValue The value to be returned if something wrong with + * property value. + * @return The required property. + */ + public String getString(String key, String defaultValue) { + String value = null; + try { + value = getString(key); + } catch (PropertyManagerException e) { + value = defaultValue; + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * a long number. + * + * @param key The property key. + * @return The required property. + * @throws PropertyManagerException If property is not found or has wrong + * format. + */ + public long getLong(String key) throws PropertyManagerException { + long value = 0; + String temp = getString(key); + try { + value = Long.parseLong(temp); + } catch (NumberFormatException e) { + message = "Wrong " + key + " value format."; + LOGGER.warn(message); + throw new PropertyManagerException(message); + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * a long number. If property value is not found or has wrong format method + * will return default value. + * + * @param key The property key. + * @param defaultValue The value to be returned if something wrong with + * property value. + * @return The required property. + */ + public long getLong(String key, long defaultValue) { + long value = 0; + try { + value = getLong(key); + } catch (PropertyManagerException e) { + value = defaultValue; + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * an integer number. + * + * @param key The property key. + * @return The required property. + * @throws PropertyManagerException If property is not found or has wrong + * format. + */ + public int getInt(String key) throws PropertyManagerException { + int value = 0; + String temp = getString(key); + try { + value = Integer.parseInt(temp); + } catch (NumberFormatException e) { + message = "Wrong " + key + " value format."; + LOGGER.warn(message); + throw new PropertyManagerException(message); + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * an integer number. If property value is not found or has wrong format + * method will return default value. + * + * @param key The property key. + * @param defaultValue The value to be returned if something wrong with + * property value. + * @return The required property. + */ + public int getInt(String key, int defaultValue) { + int value = 0; + try { + value = getInt(key); + } catch (PropertyManagerException e) { + value = defaultValue; + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * double number. + * + * @param key The property key. + * @return The required property. + * @throws PropertyManagerException If property is not found or has wrong + * format. + */ + public double getDouble(String key) throws PropertyManagerException { + double value = 0; + String temp = getString(key); + try { + value = Double.parseDouble(temp); + } catch (NumberFormatException e) { + message = "Wrong " + key + " value format."; + LOGGER.warn(message); + throw new PropertyManagerException(message); + } + return value; + } + + /** + * Is used to get the property with specified key. Returns property value as + * a double number. If property value is not found or has wrong format + * method will return default value. + * + * @param key The property key. + * @param defaultValue The value to be returned if something wrong with + * property value. + * @return The required property. + */ + public double getDouble(String key, double defaultValue) { + double value = 0; + try { + value = getLong(key); + } catch (PropertyManagerException e) { + value = defaultValue; + } + return value; + } + +} diff --git a/src/com/epam/devteam/util/property/PropertyManagerException.java b/src/com/epam/devteam/util/property/PropertyManagerException.java new file mode 100644 index 0000000..6da6169 --- /dev/null +++ b/src/com/epam/devteam/util/property/PropertyManagerException.java @@ -0,0 +1,53 @@ +/** + * + */ +package com.epam.devteam.util.property; + +/** + * @date Dec 18, 2013 + * @author anjey + * + */ +public class PropertyManagerException extends Exception { + + /** + * Serial version ID. + */ + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with null as its detail message. + */ + public PropertyManagerException() { + super(); + } + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message. + */ + public PropertyManagerException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified cause and a detail message + * of (cause==null ? null : cause.toString()) + * + * @param cause the cause. + */ + public PropertyManagerException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message the detail message. + * @param cause the cause. + */ + public PropertyManagerException(String message, Throwable cause) { + super(message, cause); + } +} From 278d8b133646c5599f6c00b9d8d4f7a418460ab3 Mon Sep 17 00:00:00 2001 From: anjey Date: Thu, 2 Jan 2014 12:40:11 +0600 Subject: [PATCH 04/30] ConnectionPool connection leak has been fixed --- resources/properties.properties | 2 +- src/com/epam/devteam/dao/DaoFactory.java | 2 +- src/com/epam/devteam/db/ConnectionPool.java | 28 ++++++++++----------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/resources/properties.properties b/resources/properties.properties index b9eabb1..bac27ae 100644 --- a/resources/properties.properties +++ b/resources/properties.properties @@ -1,4 +1,4 @@ -db.currentdb = postgresql +db.name = postgresql db.postgresql.driver = org.postgresql.Driver db.postgresql.url = jdbc:postgresql://localhost:5432/devteam db.postgresql.user = postgres diff --git a/src/com/epam/devteam/dao/DaoFactory.java b/src/com/epam/devteam/dao/DaoFactory.java index d11e98f..e064583 100644 --- a/src/com/epam/devteam/dao/DaoFactory.java +++ b/src/com/epam/devteam/dao/DaoFactory.java @@ -80,7 +80,7 @@ public static void initDatabaseType() throws DaoException { try { PropertyManager propertyManager = PropertyManager.getInstance(); databaseType = DatabaseType.valueOf(propertyManager.getString( - "db.currentdb").toUpperCase()); + "db.name").toUpperCase()); LOGGER.debug("Database type was initialized as " + databaseType); } catch (PropertyManagerException e) { LOGGER.error("Database type can not be initialized."); diff --git a/src/com/epam/devteam/db/ConnectionPool.java b/src/com/epam/devteam/db/ConnectionPool.java index 763e82c..46b3cba 100644 --- a/src/com/epam/devteam/db/ConnectionPool.java +++ b/src/com/epam/devteam/db/ConnectionPool.java @@ -54,17 +54,13 @@ public static ConnectionPool getInstance() throws ConnectionPoolException { private void init() throws ConnectionPoolException { try { PropertyManager propertyManager = PropertyManager.getInstance(); - String currentDatabase = propertyManager.getString("db.currentdb"); - driverName = propertyManager.getString("db." + currentDatabase - + ".driver"); - url = propertyManager.getString("db." + currentDatabase + ".url"); - user = propertyManager.getString("db." + currentDatabase + ".user"); - password = propertyManager.getString("db." + currentDatabase - + ".password"); - connections = propertyManager.getInt("db." + currentDatabase - + ".connections"); - waitTime = propertyManager.getLong("db." + currentDatabase - + ".waitTime"); + String db = "db." + propertyManager.getString("db.name"); + driverName = propertyManager.getString(db + ".driver"); + url = propertyManager.getString(db + ".url"); + user = propertyManager.getString(db + ".user"); + password = propertyManager.getString(db + ".password"); + connections = propertyManager.getInt(db + ".connections"); + waitTime = propertyManager.getLong(db + ".waitTime"); LOGGER.debug("Connection pool fields were initialized."); } catch (PropertyManagerException e) { LOGGER.error("Connection pool fields can not be initialized."); @@ -100,13 +96,15 @@ public Connection takeConnection() throws ConnectionPoolException { try { connection = freeConnections.poll(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting"); + LOGGER.warn("Connection can not be taken: interrupted while waiting"); + throw new ConnectionPoolException(); } if (!isConnectionValid(connection)) { LOGGER.debug("Connection is not valid."); - connection = createConnection(); + Connection newConnection = createConnection(); + connection = newConnection; } - LOGGER.debug("Connection has been taken"); + LOGGER.debug("Connection has been taken."); return connection; } @@ -148,7 +146,7 @@ private Connection createConnection() throws ConnectionPoolException { Connection connection; try { connection = DriverManager.getConnection(url, user, password); - LOGGER.debug("Connection has been created"); + LOGGER.debug("Connection has been created."); } catch (SQLException e) { LOGGER.warn("Connection cannot be created."); throw new ConnectionPoolException(); From bfb5fe47e5d6eb130f8b15799205ea49829fa604 Mon Sep 17 00:00:00 2001 From: anjey Date: Fri, 3 Jan 2014 09:55:12 +0600 Subject: [PATCH 05/30] conection pool was refactored, request dao was developed (create feature) --- .../epam/devteam/action/ActionFactory.java | 36 ++-- .../devteam/action/RequestCreateAction.java | 23 +++ src/com/epam/devteam/dao/AbstractDao.java | 51 ++++++ src/com/epam/devteam/dao/Dao.java | 58 +++++++ src/com/epam/devteam/dao/RequestDao.java | 15 ++ .../dao/impl/PostgresqlRequestDao.java | 130 ++++++++++++++ .../devteam/dao/impl/PostgresqlUserDao.java | 39 ++++- src/com/epam/devteam/db/ConnectionPool.java | 22 +-- src/com/epam/devteam/entity/Customer.java | 5 + src/com/epam/devteam/entity/Employee.java | 91 ++++++++++ src/com/epam/devteam/entity/Request.java | 159 ++++++++++++++++++ src/com/epam/devteam/entity/User.java | 50 +++++- 12 files changed, 647 insertions(+), 32 deletions(-) create mode 100644 src/com/epam/devteam/action/RequestCreateAction.java create mode 100644 src/com/epam/devteam/dao/AbstractDao.java create mode 100644 src/com/epam/devteam/dao/Dao.java create mode 100644 src/com/epam/devteam/dao/RequestDao.java create mode 100644 src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java create mode 100644 src/com/epam/devteam/entity/Customer.java create mode 100644 src/com/epam/devteam/entity/Employee.java create mode 100644 src/com/epam/devteam/entity/Request.java diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java index d25381f..7b6abc4 100644 --- a/src/com/epam/devteam/action/ActionFactory.java +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -6,25 +6,27 @@ import javax.servlet.http.HttpServletRequest; /** - * @date Dec 14, 2013 + * @date Dec 14, 2013 * @author anjey - * + * */ public class ActionFactory { - public static Action getAction(HttpServletRequest request){ - Action action = null; - String req = null; - if (request != null) { - req = request.getMethod() + request.getPathInfo(); - System.out.println(req); - } - if ("GET/login".equals(req) || "POST/login".equals(req)) { - action = new LoginAction(); - } else if ("GET/home".equals(req)) { - action = new HomeAction(); - } else { - action = new MainAction(); - } - return action; + public static Action getAction(HttpServletRequest request) { + Action action = null; + String req = null; + if (request != null) { + req = request.getMethod() + request.getPathInfo(); + System.out.println(req); + } + if ("GET/login".equals(req) || "POST/login".equals(req)) { + action = new LoginAction(); + } else if ("GET/home".equals(req)) { + action = new HomeAction(); + } else if ("GET/request".equals(req)) { + action = new RequestCreateAction(); + } else { + action = new MainAction(); } + return action; + } } diff --git a/src/com/epam/devteam/action/RequestCreateAction.java b/src/com/epam/devteam/action/RequestCreateAction.java new file mode 100644 index 0000000..bb1ec70 --- /dev/null +++ b/src/com/epam/devteam/action/RequestCreateAction.java @@ -0,0 +1,23 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Jan 2, 2014 + * @author anjey + * + */ +public class RequestCreateAction implements Action{ + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + // TODO Auto-generated method stub + return "request"; + } + +} diff --git a/src/com/epam/devteam/dao/AbstractDao.java b/src/com/epam/devteam/dao/AbstractDao.java new file mode 100644 index 0000000..f870891 --- /dev/null +++ b/src/com/epam/devteam/dao/AbstractDao.java @@ -0,0 +1,51 @@ +/** + * + */ +package com.epam.devteam.dao; + +import com.epam.devteam.db.ConnectionPool; + +/** + * @date Jan 2, 2014 + * @author Andrey Kovalskiy + * + */ +public abstract class AbstractDao implements Dao { + private ConnectionPool connectionPool; + + /** + * Initializes a newly created {@code AbstractDao} object. + */ + public AbstractDao() { + super(); + } + + /** + * Initializes a newly created {@code AbstractDao} object and connection + * with the given connection value. + * + * @param connection The connection to use to connect to the database. + */ + public AbstractDao(ConnectionPool connectionPool) { + this.connectionPool = connectionPool; + } + + /** + * Returns the connectionPool field value. + * + * @return the connectionPool + */ + public ConnectionPool getConnectionPool() { + return connectionPool; + } + + /** + * Sets the connectionPool field value. + * + * @param connectionPool the connectionPool to set + */ + public void setConnectionPool(ConnectionPool connectionPool) { + this.connectionPool = connectionPool; + } + +} diff --git a/src/com/epam/devteam/dao/Dao.java b/src/com/epam/devteam/dao/Dao.java new file mode 100644 index 0000000..a60ed3b --- /dev/null +++ b/src/com/epam/devteam/dao/Dao.java @@ -0,0 +1,58 @@ +/** + * + */ +package com.epam.devteam.dao; + +import java.util.List; + +/** + * @date Jan 2, 2014 + * @author Andrey Kovalskiy + * + */ +public interface Dao { + + /** + * Is used to create the given object in the database. + * + * @param object The object to create. + * @throws DaoException If something fails at database level. + */ + void create(T object) throws DaoException; + + /** + * Is used to return an object in the database by the given id, otherwise + * {@code null}. + * + * @param id The id of the object to be returned. + * @return The object from the database with required id, otherwise + * {@code null}. + * @throws DaoException If something fails at database level. + */ + T find(Long id) throws DaoException; + + /** + * Is used to update the given object. + * + * @param object The object to update. + * @throws DaoException If something fails at database level. + */ + void update(T object) throws DaoException; + + /** + * Is used to delete the given object from the database. + * + * @param object The object to delete. + * @throws DaoException If something fails at database level. + */ + void delete(T object) throws DaoException; + + /** + * Is used to get all of the objects from the database. + * + * @return The list of all objects in the database. + * @throws DaoException If something fails at database level. + */ + List list() throws DaoException; + +} diff --git a/src/com/epam/devteam/dao/RequestDao.java b/src/com/epam/devteam/dao/RequestDao.java new file mode 100644 index 0000000..62ecb72 --- /dev/null +++ b/src/com/epam/devteam/dao/RequestDao.java @@ -0,0 +1,15 @@ +/** + * + */ +package com.epam.devteam.dao; + +import com.epam.devteam.entity.Request; + +/** + * @date Jan 2, 2014 + * @author anjey + * + */ +public abstract class RequestDao extends AbstractDao { + +} diff --git a/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java new file mode 100644 index 0000000..3e4379e --- /dev/null +++ b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java @@ -0,0 +1,130 @@ +package com.epam.devteam.dao.impl; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.epam.devteam.dao.DaoException; +import com.epam.devteam.dao.RequestDao; +import com.epam.devteam.db.ConnectionPoolException; +import com.epam.devteam.entity.Request; + +public class PostgresqlRequestDao extends RequestDao { + private static final Logger LOGGER = Logger + .getLogger(PostgresqlRequestDao.class); + + /** + * Is used to create given request in the database. + * + * @param object The request to create. + * @throws DaoException If something fails at database level. + */ + @Override + public void create(Request object) throws DaoException { + String sql = "INSERT INTO requests (date,status,customerId,managerId) VALUES (?,?,?,?)"; + Connection connection; + PreparedStatement statement; + try { + connection = getConnectionPool().takeConnection(); + LOGGER.debug("Connection has been taken"); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection cannot be taken."); + throw new DaoException(); + } + try { + statement = connection.prepareStatement(sql); + LOGGER.debug("Statement has been created."); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be created."); + throw new DaoException(); + } + try { + Request object1 = new Request(1L,new Date(new java.util.Date().getTime()),Request.Status.PENDING,null,123L,321L); + object = object1; + statement.setDate(1, object.getDate()); + statement.setString(2, object.getStatus().toString()); + statement.setLong(3, object.getCustomerId()); + statement.setLong(4, object.getManagerId()); + statement.execute(); + LOGGER.debug("Statement has been executed."); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be executed."); + throw new DaoException(); + } + freeConnection(connection, statement); + } + + /** + * Is used to return a request in the database by the given id, otherwise + * {@code null}. + * + * @param id The id of the object to be returned. + * @return The request from the database with required id, otherwise + * {@code null}. + * @throws DaoException If something fails at database level. + */ + @Override + public Request find(Long id) throws DaoException { + // TODO Auto-generated method stub + return null; + } + + /** + * Is used to update given request. + * + * @param object The object to update. + * @throws DaoException If something fails at database level. + */ + @Override + public void update(Request object) throws DaoException { + // TODO Auto-generated method stub + + } + + /** + * Is used to delete the given request from the database. + * + * @param object The object to delete. + * @throws DaoException If something fails at database level. + */ + @Override + public void delete(Request object) throws DaoException { + // TODO Auto-generated method stub + + } + + /** + * Is used to get all of the requests from the database. + * + * @return The list of all requests in the database. + * @throws DaoException If something fails at database level. + */ + @Override + public List list() throws DaoException { + // TODO Auto-generated method stub + return null; + } + + /** + * Is used to close statement and return connection to the connection pool. + * + * @param connection The connection to return. + * @param statement The statement to close. + */ + private void freeConnection(Connection connection, Statement statement) { + if (statement != null) { + try { + statement.close(); + LOGGER.debug("Statement has been closed."); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be closed."); + } + } + getConnectionPool().returnConnection(connection); + } +} diff --git a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java index b46bcb1..db55bf2 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java @@ -4,10 +4,12 @@ package com.epam.devteam.dao.impl; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.sql.Date; import java.util.List; import org.apache.log4j.Logger; @@ -47,8 +49,38 @@ public PostgresqlUserDao(ConnectionPool connectionPool) { @Override public void createUser(User user) throws DaoException { - // TODO Auto-generated method stub + Connection connection = null; + PreparedStatement statement = null; + + try { + connection = connectionPool.takeConnection(); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection can not be taken."); + throw new DaoException(); + } + try { + statement = connection + .prepareStatement("INSERT INTO users (id,email,password,firstname,lastname,patronymic,birthdate) VALUES (?,?,?,?,?,?,?)"); + LOGGER.debug("Statement has been created."); + } catch (SQLException e) { + LOGGER.warn("Statement can not be created."); + finish(connection, statement); + throw new DaoException(); + } + try { + statement.setInt(1, 2); + statement.setString(2, "k@mail.ru"); + statement.setString(3, "123456"); + statement.setString(4, "alex"); + statement.setString(5, "kim"); + statement.setString(6, "hen"); + statement.setDate(7, new Date(new java.util.Date().getTime())); + statement.execute(); + } catch (SQLException e) { + LOGGER.warn("User cannot be created."); + } + finish(connection, statement); } @Override @@ -82,7 +114,7 @@ public List listUsers() throws DaoException { Connection connection = null; Statement statement = null; ResultSet resultSet = null; - + createUser(null); try { connection = connectionPool.takeConnection(); } catch (ConnectionPoolException e) { @@ -128,7 +160,8 @@ private void finish(Connection connection, Statement statement) { } catch (SQLException e) { LOGGER.warn("Statement can not be closed."); } - }; + } + ; connectionPool.returnConnection(connection); } } diff --git a/src/com/epam/devteam/db/ConnectionPool.java b/src/com/epam/devteam/db/ConnectionPool.java index 46b3cba..b65af48 100644 --- a/src/com/epam/devteam/db/ConnectionPool.java +++ b/src/com/epam/devteam/db/ConnectionPool.java @@ -24,7 +24,7 @@ public class ConnectionPool { private static final Logger LOGGER = Logger.getLogger(ConnectionPool.class); private static volatile ConnectionPool instance; - private String driverName; + private String driver; private String url; private String user; private String password; @@ -55,7 +55,7 @@ private void init() throws ConnectionPoolException { try { PropertyManager propertyManager = PropertyManager.getInstance(); String db = "db." + propertyManager.getString("db.name"); - driverName = propertyManager.getString(db + ".driver"); + driver = propertyManager.getString(db + ".driver"); url = propertyManager.getString(db + ".url"); user = propertyManager.getString(db + ".user"); password = propertyManager.getString(db + ".password"); @@ -63,11 +63,11 @@ private void init() throws ConnectionPoolException { waitTime = propertyManager.getLong(db + ".waitTime"); LOGGER.debug("Connection pool fields were initialized."); } catch (PropertyManagerException e) { - LOGGER.error("Connection pool fields can not be initialized."); + LOGGER.error("Connection pool fields cannot be initialized."); throw new ConnectionPoolException(); } try { - Class.forName(driverName); + Class.forName(driver); LOGGER.debug("Database driver was initialized."); } catch (ClassNotFoundException e) { LOGGER.error("Data base driver was not found."); @@ -88,15 +88,15 @@ private void init() throws ConnectionPoolException { * return null. * * @return Free connection from the connection pool. - * @throws ConnectionPoolException If connection can not be taken or is not - * valid and can not be created. + * @throws ConnectionPoolException If connection cannot be taken or is not + * valid and cannot be created. */ public Connection takeConnection() throws ConnectionPoolException { Connection connection = null; try { connection = freeConnections.poll(waitTime, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - LOGGER.warn("Connection can not be taken: interrupted while waiting"); + LOGGER.warn("Interrupted while waiting"); throw new ConnectionPoolException(); } if (!isConnectionValid(connection)) { @@ -104,7 +104,7 @@ public Connection takeConnection() throws ConnectionPoolException { Connection newConnection = createConnection(); connection = newConnection; } - LOGGER.debug("Connection has been taken."); + //LOGGER.debug("Connection has been taken."); return connection; } @@ -118,7 +118,7 @@ public void returnConnection(Connection connection) { freeConnections.offer(connection, waitTime, TimeUnit.MILLISECONDS); LOGGER.debug("Connection has been returned."); } catch (InterruptedException e) { - LOGGER.debug("Connection can not be returned"); + LOGGER.debug("Connection cannot be returned"); } } @@ -131,7 +131,7 @@ public void closeConnections() { connection.close(); LOGGER.debug("Connection has been closed."); } catch (SQLException e) { - LOGGER.error("Connection can not be closed."); + LOGGER.error("Connection cannot be closed."); } } } @@ -140,7 +140,7 @@ public void closeConnections() { * Is used to create new connection. * * @return The new connection. - * @throws ConnectionPoolException If connection can not be created. + * @throws ConnectionPoolException If connection cannot be created. */ private Connection createConnection() throws ConnectionPoolException { Connection connection; diff --git a/src/com/epam/devteam/entity/Customer.java b/src/com/epam/devteam/entity/Customer.java new file mode 100644 index 0000000..3975fd2 --- /dev/null +++ b/src/com/epam/devteam/entity/Customer.java @@ -0,0 +1,5 @@ +package com.epam.devteam.entity; + +public class Customer { + +} diff --git a/src/com/epam/devteam/entity/Employee.java b/src/com/epam/devteam/entity/Employee.java new file mode 100644 index 0000000..c127064 --- /dev/null +++ b/src/com/epam/devteam/entity/Employee.java @@ -0,0 +1,91 @@ +package com.epam.devteam.entity; + +import java.io.Serializable; + +public class Employee extends User implements Serializable { + /** + * Serial version id. + */ + private static final long serialVersionUID = 1L; + private String position; + private String company; + + /** + * Returns the position field value. + * + * @return the position + */ + public String getPosition() { + return position; + } + + /** + * Sets the position field value. + * + * @param position the position to set + */ + public void setPosition(String position) { + this.position = position; + } + + /** + * Returns the company field value. + * + * @return the company + */ + public String getCompany() { + return company; + } + + /** + * Sets the company field value. + * + * @param company the company to set + */ + public void setCompany(String company) { + this.company = company; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj The reference object with which to compare. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() == obj.getClass()) { + Employee otherEmployee = (Employee) obj; + return (this.getId().equals(otherEmployee.getId())) + && (this.getEmail().equals(otherEmployee.getEmail())) + && (this.getPassword().equals(otherEmployee.getPassword())) + && (this.getFirstname() + .equals(otherEmployee.getFirstname())) + && (this.getLastname().equals(otherEmployee.getLastname())) + && (this.getPatronymic().equals(otherEmployee + .getPatronymic())) + && (this.getBirthdate() + .equals(otherEmployee.getBirthdate())) + && (this.company.equals(otherEmployee.company)) + && (this.position.equals(otherEmployee.position)); + } else { + return false; + } + } + + /** + * Returns a hash code value for the object. + */ + @Override + public int hashCode() { + return super.hashCode() + + ((position == null) ? 0 : position.hashCode()) + + ((company == null) ? 0 : company.hashCode()); + } + +} diff --git a/src/com/epam/devteam/entity/Request.java b/src/com/epam/devteam/entity/Request.java new file mode 100644 index 0000000..5311d3c --- /dev/null +++ b/src/com/epam/devteam/entity/Request.java @@ -0,0 +1,159 @@ +package com.epam.devteam.entity; + +import java.io.File; +import java.io.Serializable; +import java.sql.Date; + +public class Request implements Serializable { + public enum Status { + PENDING, IN_PROCESSING, RECEIVED, DENIED, UPDATED, TERMINATED + } + + /** + * Serial version id. + */ + private static final long serialVersionUID = 1L; + private Long id; + private Date date; + private Status status; + private File file; + private Long customerId; + private Long managerId; + + /** + * Initializes a newly created {@code Request} object. + */ + public Request() { + super(); + } + + /** + * Initializes a newly created {@code Request} object. + * + * @param id The request id. + * @param date The date of creation. + * @param status Current status. + * @param customer The customer who created the request. + * @param file The file. + * @param manager The manager who processes the request. + */ + public Request(Long id, Date date, Status status, File file, + Long customerId, Long managerId) { + super(); + this.id = id; + this.date = date; + this.status = status; + this.file = file; + this.customerId = customerId; + this.managerId = managerId; + } + + /** + * Returns the id field value. + * + * @return the id + */ + public Long getId() { + return id; + } + + /** + * Sets the id field value. + * + * @param id the id to set + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the date field value. + * + * @return the date + */ + public Date getDate() { + return date; + } + + /** + * Sets the date field value. + * + * @param date the date to set + */ + public void setDate(Date date) { + this.date = date; + } + + /** + * Returns the status field value. + * + * @return the status + */ + public Status getStatus() { + return status; + } + + /** + * Sets the status field value. + * + * @param status the status to set + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Returns the file field value. + * + * @return the file + */ + public File getFile() { + return file; + } + + /** + * Sets the file field value. + * + * @param file the file to set + */ + public void setFile(File file) { + this.file = file; + } + + /** + * Returns the customerId field value. + * + * @return the customerId + */ + public Long getCustomerId() { + return customerId; + } + + /** + * Sets the customerId field value. + * + * @param customerId the customerId to set + */ + public void setCustomerId(Long customerId) { + this.customerId = customerId; + } + + /** + * Returns the managerId field value. + * + * @return the managerId + */ + public Long getManagerId() { + return managerId; + } + + /** + * Sets the managerId field value. + * + * @param managerId the managerId to set + */ + public void setManagerId(Long managerId) { + this.managerId = managerId; + } + +} diff --git a/src/com/epam/devteam/entity/User.java b/src/com/epam/devteam/entity/User.java index 6f1e476..5619c6f 100644 --- a/src/com/epam/devteam/entity/User.java +++ b/src/com/epam/devteam/entity/User.java @@ -23,6 +23,8 @@ public class User implements Serializable { private String lastname; private String patronymic; private Date birthdate; + private String address; + private String phone; /** * Initializes a newly created {@code User} object with empty fields. @@ -181,6 +183,47 @@ public void setBirthdate(Date birthdate) { this.birthdate = birthdate; } + /** + * Returns the address field value. + * + * @return the address + */ + public String getAddress() { + return address; + } + + /** + * Sets the address field value. + * + * @param address the address to set + */ + public void setAddress(String address) { + this.address = address; + } + + /** + * Returns the phone field value. + * + * @return the phone + */ + public String getPhone() { + return phone; + } + + /** + * Sets the phone field value. + * + * @param phone the phone to set + */ + public void setPhone(String phone) { + this.phone = phone; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj The reference object with which to compare. + */ @Override public boolean equals(Object obj) { if (this == obj) { @@ -203,6 +246,9 @@ public boolean equals(Object obj) { } } + /** + * Returns a hash code value for the object. + */ @Override public int hashCode() { return (int) (31 * id.hashCode() @@ -219,7 +265,9 @@ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("user:").append(lastname).append(" ").append(firstname) .append(" ").append(patronymic).append(" birthdate:") - .append(birthdate).append(" email:").append(email); + .append(birthdate).append(" email:").append(email) + .append(" address:").append(address).append(" phone:") + .append(phone); return sb.toString(); } } From 9a23bfddfc017ade6f559e915cb1ea1ab31bb5d1 Mon Sep 17 00:00:00 2001 From: anjey Date: Fri, 3 Jan 2014 11:40:58 +0600 Subject: [PATCH 06/30] css added, request page added --- WebContent/WEB-INF/jsp/main.jsp | 63 +++- WebContent/WEB-INF/jsp/request.jsp | 111 ++++++ WebContent/css/960.css | 491 +++++++++++++++++++++++++++ WebContent/css/grid.css | 491 +++++++++++++++++++++++++++ WebContent/css/ie.css | 31 ++ WebContent/css/ie6.css | 31 ++ WebContent/css/layout.css | 519 +++++++++++++++++++++++++++++ WebContent/css/nav.css | 167 ++++++++++ WebContent/css/reset.css | 53 +++ WebContent/css/text.css | 98 ++++++ 10 files changed, 2050 insertions(+), 5 deletions(-) create mode 100644 WebContent/WEB-INF/jsp/request.jsp create mode 100644 WebContent/css/960.css create mode 100644 WebContent/css/grid.css create mode 100644 WebContent/css/ie.css create mode 100644 WebContent/css/ie6.css create mode 100644 WebContent/css/layout.css create mode 100644 WebContent/css/nav.css create mode 100644 WebContent/css/reset.css create mode 100644 WebContent/css/text.css diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index b0319a4..0b5e4b4 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -1,15 +1,68 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> + pageEncoding="UTF-8"%> Main + + + + + + - Hello from main page!
-
- -
+
+ + +
+ +
+ +
+

Welcome to the development + team site!

+
+
+ +
+

Page body

+
+
+ +
+
+ This site was developed by Andrey Kovalskiy for JavaLab + course. +
+
+
+
\ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/request.jsp b/WebContent/WEB-INF/jsp/request.jsp new file mode 100644 index 0000000..a130df3 --- /dev/null +++ b/WebContent/WEB-INF/jsp/request.jsp @@ -0,0 +1,111 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Online Request + + + + + + + + +
+ + +
+ +
+ +
+

Leave your request.

+
+
+ +
+
+
+
+ Request +

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ +

+

+ + +

+

+ +

+ + +
+
+
+
+
+ +
+
+ This site was developed by Andrey Kovalskiy for JavaLab + course. +
+
+
+
+ + \ No newline at end of file diff --git a/WebContent/css/960.css b/WebContent/css/960.css new file mode 100644 index 0000000..6db1bd3 --- /dev/null +++ b/WebContent/css/960.css @@ -0,0 +1,491 @@ +/* + 960 Grid System ~ Core CSS. + Learn more ~ http://960.gs/ + + Licensed under GPL and MIT. +*/ + +/* =Containers +--------------------------------------------------------------------------------*/ + +.container_12, +.container_16 +{ + margin-left: auto; + margin-right: auto; + width: 960px; +} + +/* =Grid >> Global +--------------------------------------------------------------------------------*/ + +.grid_1, +.grid_2, +.grid_3, +.grid_4, +.grid_5, +.grid_6, +.grid_7, +.grid_8, +.grid_9, +.grid_10, +.grid_11, +.grid_12, +.grid_13, +.grid_14, +.grid_15, +.grid_16 +{ + display: inline; + float: left; + margin-left: 10px; + margin-right: 10px; +} + +.container_12 .grid_3, +.container_16 .grid_4 +{ + width: 220px; +} + +.container_12 .grid_6, +.container_16 .grid_8 +{ + width: 460px; +} + +.container_12 .grid_9, +.container_16 .grid_12 +{ + width: 700px; +} + +.container_12 .grid_12, +.container_16 .grid_16 +{ + width: 940px; +} + +/* =Grid >> Children (Alpha ~ First, Omega ~ Last) +--------------------------------------------------------------------------------*/ + +.alpha +{ + margin-left: 0; +} + +.omega +{ + margin-right: 0; +} + +/* =Grid >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .grid_1 +{ + width: 60px; +} + +.container_12 .grid_2 +{ + width: 140px; +} + +.container_12 .grid_4 +{ + width: 300px; +} + +.container_12 .grid_5 +{ + width: 380px; +} + +.container_12 .grid_7 +{ + width: 540px; +} + +.container_12 .grid_8 +{ + width: 620px; +} + +.container_12 .grid_10 +{ + width: 780px; +} + +.container_12 .grid_11 +{ + width: 860px; +} + +/* =Grid >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .grid_1 +{ + width: 40px; +} + +.container_16 .grid_2 +{ + width: 100px; +} + +.container_16 .grid_3 +{ + width: 160px; +} + +.container_16 .grid_5 +{ + width: 280px; +} + +.container_16 .grid_6 +{ + width: 340px; +} + +.container_16 .grid_7 +{ + width: 400px; +} + +.container_16 .grid_9 +{ + width: 520px; +} + +.container_16 .grid_10 +{ + width: 580px; +} + +.container_16 .grid_11 +{ + width: 640px; +} + +.container_16 .grid_13 +{ + width: 760px; +} + +.container_16 .grid_14 +{ + width: 820px; +} + +.container_16 .grid_15 +{ + width: 880px; +} + +/* =Prefix Extra Space >> Global +--------------------------------------------------------------------------------*/ + +.container_12 .prefix_3, +.container_16 .prefix_4 +{ + padding-left: 240px; +} + +.container_12 .prefix_6, +.container_16 .prefix_8 +{ + padding-left: 480px; +} + +.container_12 .prefix_9, +.container_16 .prefix_12 +{ + padding-left: 720px; +} + +/* =Prefix Extra Space >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .prefix_1 +{ + padding-left: 80px; +} + +.container_12 .prefix_2 +{ + padding-left: 160px; +} + +.container_12 .prefix_4 +{ + padding-left: 320px; +} + +.container_12 .prefix_5 +{ + padding-left: 400px; +} + +.container_12 .prefix_7 +{ + padding-left: 560px; +} + +.container_12 .prefix_8 +{ + padding-left: 640px; +} + +.container_12 .prefix_10 +{ + padding-left: 800px; +} + +.container_12 .prefix_11 +{ + padding-left: 880px; +} + +/* =Prefix Extra Space >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .prefix_1 +{ + padding-left: 60px; +} + +.container_16 .prefix_2 +{ + padding-left: 120px; +} + +.container_16 .prefix_3 +{ + padding-left: 180px; +} + +.container_16 .prefix_5 +{ + padding-left: 300px; +} + +.container_16 .prefix_6 +{ + padding-left: 360px; +} + +.container_16 .prefix_7 +{ + padding-left: 420px; +} + +.container_16 .prefix_9 +{ + padding-left: 540px; +} + +.container_16 .prefix_10 +{ + padding-left: 600px; +} + +.container_16 .prefix_11 +{ + padding-left: 660px; +} + +.container_16 .prefix_13 +{ + padding-left: 780px; +} + +.container_16 .prefix_14 +{ + padding-left: 840px; +} + +.container_16 .prefix_15 +{ + padding-left: 900px; +} + +/* =Suffix Extra Space >> Global +--------------------------------------------------------------------------------*/ + +.container_12 .suffix_3, +.container_16 .suffix_4 +{ + padding-right: 240px; +} + +.container_12 .suffix_6, +.container_16 .suffix_8 +{ + padding-right: 480px; +} + +.container_12 .suffix_9, +.container_16 .suffix_12 +{ + padding-right: 720px; +} + +/* =Suffix Extra Space >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .suffix_1 +{ + padding-right: 80px; +} + +.container_12 .suffix_2 +{ + padding-right: 160px; +} + +.container_12 .suffix_4 +{ + padding-right: 320px; +} + +.container_12 .suffix_5 +{ + padding-right: 400px; +} + +.container_12 .suffix_7 +{ + padding-right: 560px; +} + +.container_12 .suffix_8 +{ + padding-right: 640px; +} + +.container_12 .suffix_10 +{ + padding-right: 800px; +} + +.container_12 .suffix_11 +{ + padding-right: 880px; +} + +/* =Suffix Extra Space >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .suffix_1 +{ + padding-right: 60px; +} + +.container_16 .suffix_2 +{ + padding-right: 120px; +} + +.container_16 .suffix_3 +{ + padding-right: 180px; +} + +.container_16 .suffix_5 +{ + padding-right: 300px; +} + +.container_16 .suffix_6 +{ + padding-right: 360px; +} + +.container_16 .suffix_7 +{ + padding-right: 420px; +} + +.container_16 .suffix_9 +{ + padding-right: 540px; +} + +.container_16 .suffix_10 +{ + padding-right: 600px; +} + +.container_16 .suffix_11 +{ + padding-right: 660px; +} + +.container_16 .suffix_13 +{ + padding-right: 780px; +} + +.container_16 .suffix_14 +{ + padding-right: 840px; +} + +.container_16 .suffix_15 +{ + padding-right: 900px; +} + +/* =Clear Floated Elements +--------------------------------------------------------------------------------*/ + +/* http://sonspring.com/journal/clearing-floats */ + +html body * span.clear, +html body * div.clear, +html body * li.clear, +html body * dd.clear +{ + background: none; + border: 0; + clear: both; + display: block; + float: none; + font-size: 0; + list-style: none; + margin: 0; + padding: 0; + overflow: hidden; + visibility: hidden; + width: 0; + height: 0; +} + +/* http://www.positioniseverything.net/easyclearing.html */ + +.clearfix:after +{ + clear: both; + content: '.'; + display: block; + visibility: hidden; + height: 0; +} + +.clearfix +{ + display: inline-block; +} + +* html .clearfix +{ + height: 1%; +} + +.clearfix +{ + display: block; +} \ No newline at end of file diff --git a/WebContent/css/grid.css b/WebContent/css/grid.css new file mode 100644 index 0000000..dd21d4e --- /dev/null +++ b/WebContent/css/grid.css @@ -0,0 +1,491 @@ +/* + 960 Grid System ~ Core CSS. + Learn more ~ http://960.gs/ + + Licensed under GPL and MIT. +*/ + +/* =Containers +--------------------------------------------------------------------------------*/ + +.container_12, +.container_16 +{ + width: 92%; + margin-left: 4%; + margin-right: 4%; +} + +/* =Grid >> Global +--------------------------------------------------------------------------------*/ + +.grid_1, +.grid_2, +.grid_3, +.grid_4, +.grid_5, +.grid_6, +.grid_7, +.grid_8, +.grid_9, +.grid_10, +.grid_11, +.grid_12, +.grid_13, +.grid_14, +.grid_15, +.grid_16 +{ + display: inline; + float: left; + margin-left: 1%; + margin-right: 1%; +} + +.container_12 .grid_3, +.container_16 .grid_4 +{ + width: 23%; +} + +.container_12 .grid_6, +.container_16 .grid_8 +{ + width: 48%; +} + +.container_12 .grid_9, +.container_16 .grid_12 +{ + width: 73%; +} + +.container_12 .grid_12, +.container_16 .grid_16 +{ + width: 98%; +} + +/* =Grid >> Children (Alpha ~ First, Omega ~ Last) +--------------------------------------------------------------------------------*/ + +.alpha +{ + margin-left: 0; +} + +.omega +{ + margin-right: 0; +} + +/* =Grid >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .grid_1 +{ + width: 6.333%; +} + +.container_12 .grid_2 +{ + width: 14.666%; +} + +.container_12 .grid_4 +{ + width: 31.333%; +} + +.container_12 .grid_5 +{ + width: 39.666%; +} + +.container_12 .grid_7 +{ + width: 56.333%; +} + +.container_12 .grid_8 +{ + width: 64.666%; +} + +.container_12 .grid_10 +{ + width: 81.333%; +} + +.container_12 .grid_11 +{ + width: 89.666%; +} + +/* =Grid >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .grid_1 +{ + width: 4.25%; +} + +.container_16 .grid_2 +{ + width: 10.5%; +} + +.container_16 .grid_3 +{ + width: 16.75%; +} + +.container_16 .grid_5 +{ + width: 29.25%; +} + +.container_16 .grid_6 +{ + width: 35.5%; +} + +.container_16 .grid_7 +{ + width: 41.75%; +} + +.container_16 .grid_9 +{ + width: 54.25%; +} + +.container_16 .grid_10 +{ + width: 60.5%; +} + +.container_16 .grid_11 +{ + width: 66.75%; +} + +.container_16 .grid_13 +{ + width: 79.25%; +} + +.container_16 .grid_14 +{ + width: 85.5%; +} + +.container_16 .grid_15 +{ + width: 91.75%; +} + +/* =Prefix Extra Space >> Global +--------------------------------------------------------------------------------*/ + +.container_12 .prefix_3, +.container_16 .prefix_4 +{ + padding-left: 25%; +} + +.container_12 .prefix_6, +.container_16 .prefix_8 +{ + padding-left: 50%; +} + +.container_12 .prefix_9, +.container_16 .prefix_12 +{ + padding-left: 75%; +} + +/* =Prefix Extra Space >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .prefix_1 +{ + padding-left: 8.333%; +} + +.container_12 .prefix_2 +{ + padding-left: 16.666%; +} + +.container_12 .prefix_4 +{ + padding-left: 33.333%; +} + +.container_12 .prefix_5 +{ + padding-left: 41.666%; +} + +.container_12 .prefix_7 +{ + padding-left: 58.333%; +} + +.container_12 .prefix_8 +{ + padding-left: 66.666%; +} + +.container_12 .prefix_10 +{ + padding-left: 83.333%; +} + +.container_12 .prefix_11 +{ + padding-left: 91.666%; +} + +/* =Prefix Extra Space >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .prefix_1 +{ + padding-left: 6.25%; +} + +.container_16 .prefix_2 +{ + padding-left: 12.5%; +} + +.container_16 .prefix_3 +{ + padding-left: 18.75%; +} + +.container_16 .prefix_5 +{ + padding-left: 31.25%; +} + +.container_16 .prefix_6 +{ + padding-left: 37.5%; +} + +.container_16 .prefix_7 +{ + padding-left: 43.75%; +} + +.container_16 .prefix_9 +{ + padding-left: 56.25%; +} + +.container_16 .prefix_10 +{ + padding-left: 62.5%; +} + +.container_16 .prefix_11 +{ + padding-left: 68.75%; +} + +.container_16 .prefix_13 +{ + padding-left: 81.25%; +} + +.container_16 .prefix_14 +{ + padding-left: 87.5%; +} + +.container_16 .prefix_15 +{ + padding-left: 93.75%; +} + +/* =Suffix Extra Space >> Global +--------------------------------------------------------------------------------*/ + +.container_12 .suffix_3, +.container_16 .suffix_4 +{ + padding-right: 25%; +} + +.container_12 .suffix_6, +.container_16 .suffix_8 +{ + padding-right: 50%; +} + +.container_12 .suffix_9, +.container_16 .suffix_12 +{ + padding-right: 75%; +} + +/* =Suffix Extra Space >> 12 Columns +--------------------------------------------------------------------------------*/ + +.container_12 .suffix_1 +{ + padding-right: 8.333%; +} + +.container_12 .suffix_2 +{ + padding-right: 16.666%; +} + +.container_12 .suffix_4 +{ + padding-right: 33.333%; +} + +.container_12 .suffix_5 +{ + padding-right: 41.666%; +} + +.container_12 .suffix_7 +{ + padding-right: 58.333%; +} + +.container_12 .suffix_8 +{ + padding-right: 66.666%; +} + +.container_12 .suffix_10 +{ + padding-right: 83.333%; +} + +.container_12 .suffix_11 +{ + padding-right: 91.666%; +} + +/* =Suffix Extra Space >> 16 Columns +--------------------------------------------------------------------------------*/ + +.container_16 .suffix_1 +{ + padding-right: 6.25%; +} + +.container_16 .suffix_2 +{ + padding-right: 16.5%; +} + +.container_16 .suffix_3 +{ + padding-right: 18.75%; +} + +.container_16 .suffix_5 +{ + padding-right: 31.25%; +} + +.container_16 .suffix_6 +{ + padding-right: 37.5%; +} + +.container_16 .suffix_7 +{ + padding-right: 43.75%; +} + +.container_16 .suffix_9 +{ + padding-right: 56.25%; +} + +.container_16 .suffix_10 +{ + padding-right: 62.5%; +} + +.container_16 .suffix_11 +{ + padding-right: 68.75%; +} + +.container_16 .suffix_13 +{ + padding-right: 81.25%; +} + +.container_16 .suffix_14 +{ + padding-right: 87.5%; +} + +.container_16 .suffix_15 +{ + padding-right: 93.75%; +} + +/* =Clear Floated Elements +--------------------------------------------------------------------------------*/ + +/* http://sonspring.com/journal/clearing-floats */ + +html body * span.clear, +html body * div.clear, +html body * li.clear, +html body * dd.clear +{ + background: none; + border: 0; + clear: both; + display: block; + float: none; + font-size: 0; + list-style: none; + margin: 0; + padding: 0; + overflow: hidden; + visibility: hidden; + width: 0; + height: 0; +} + +/* http://www.positioniseverything.net/easyclearing.html */ + +.clearfix:after +{ + clear: both; + content: '.'; + display: block; + visibility: hidden; + height: 0; +} + +.clearfix +{ + display: inline-block; +} + +* html .clearfix +{ + height: 1%; +} + +.clearfix +{ + display: block; +} \ No newline at end of file diff --git a/WebContent/css/ie.css b/WebContent/css/ie.css new file mode 100644 index 0000000..7fe61ff --- /dev/null +++ b/WebContent/css/ie.css @@ -0,0 +1,31 @@ +/* + Fluid 960 Grid System - IE Fixes (IE7 and greater) + Learn more ~ http://www.designinfluences.com/ + + Licensed under GPL and MIT. +*/ + +/* =Grid >> Global +--------------------------------------------------------------------------------*/ + +.grid_1, +.grid_2, +.grid_3, +.grid_4, +.grid_5, +.grid_6, +.grid_7, +.grid_8, +.grid_9, +.grid_10, +.grid_11, +.grid_12, +.grid_13, +.grid_14, +.grid_15, +.grid_16 +{ + margin-left: .92%; + margin-right: .92%; +} + diff --git a/WebContent/css/ie6.css b/WebContent/css/ie6.css new file mode 100644 index 0000000..b1ff5b5 --- /dev/null +++ b/WebContent/css/ie6.css @@ -0,0 +1,31 @@ +/* + Fluid 960 Grid System - IE6 Fixes + Learn more ~ http://www.designinfluences.com/ + + Licensed under GPL and MIT. +*/ + +/* =Grid >> Global +--------------------------------------------------------------------------------*/ + +.grid_1, +.grid_2, +.grid_3, +.grid_4, +.grid_5, +.grid_6, +.grid_7, +.grid_8, +.grid_9, +.grid_10, +.grid_11, +.grid_12, +.grid_13, +.grid_14, +.grid_15, +.grid_16 +{ + margin-left: .8%; + margin-right: .8%; +} + diff --git a/WebContent/css/layout.css b/WebContent/css/layout.css new file mode 100644 index 0000000..c5032de --- /dev/null +++ b/WebContent/css/layout.css @@ -0,0 +1,519 @@ +/* +----------------------------------------------- +Grey Box Method - Layout CSS +----------------------------------------------- */ + +body { + background: #eee; + border-top: 5px solid #000; + color: #333; + font-size: 11px; + padding: 0 0 40px; +} + + +/* anchors +----------------------------------------------- */ +a { + color: #ffffff;/*#000;*/ + font-weight:bold; + text-decoration: none; +} +a:hover { + color:#000000;/*#333;*/ +} + + +/* 960 grid system container background +----------------------------------------------- */ +.container_12, +.container_16 { + background:#fff; +} + +/* headings +----------------------------------------------- */ +h1, h2, h3, h4, h5, h6 {line-height:1.2em; margin-bottom:.3em;} +h2 {margin-top:1em;} +h5 {font-size:1.2em;} +h6 {font-size:1em; text-transform:uppercase;} + + +h1 a { + font-weight:normal; +} + + +/* branding +----------------------------------------------- */ +h1#branding { + font-weight:normal; + font-size:3em; + text-align:left; + background: #008080;/*#aaa;*/ + padding:.7em 1em; + margin-bottom:0; +} + + +/* page heading +----------------------------------------------- */ +h2#page-heading { + font-weight:normal; + padding:.5em; + margin:0 0 10px 0; + border-bottom:1px solid #ccc; +} + + +/* boxes +----------------------------------------------- */ +.box { + background:#ddd; + margin-bottom:20px; + padding:10px 10px 1px 10px; +} +.box h2 { + font-size:1em; + font-weight:normal; + text-transform:uppercase; + color:#fff; + background:#006060;/*#333;*/ + margin:-10px -10px 0 -10px; + padding:6px 12px; +} +.box h2 a, +.box h2 a.visible { + color:#fff; + background:#006060 /*#333*/ url("../img/switch_minus.gif") 97% 50% no-repeat; + display:block; + padding:6px 12px; + margin:-6px -12px; + border:none; +} +.grid_4 .box h2 a { + background-position: 97% 50%; +} +.grid_5 .box h2 a { + background-position: 98% 50%; +} +.grid_12 .box h2 a { + background-position: 99% 50%; +} + + +.box h2 a.hidden, +.box h2 a.hidden:hover { + background-image: url("../img/switch_plus.gif"); +} +.box h2 a:hover { + background-color:#008080;/*#111;*/ +} +.block { + padding-top:10px; +} +div.menu { + padding:0; +} +div.menu h2 { + margin:0; +} +div.menu .block { + padding-top:0; +} + + +/* paragraphs, quotes and lists +----------------------------------------------- */ +p { + margin-bottom:1em; +} +blockquote { + font-family: Georgia, 'Times New Roman', serif; + font-size:1.2em; + padding-left:1em; + border-left:4px solid #ccc; +} +blockquote cite { + font-size:.9em; +} +ul, ol { + padding-top:0; +} + + +/* menus +----------------------------------------------- */ +ul.menu { + list-style:none; + border-top:1px solid #bbb; +} +ul.menu li { + margin:0; +} +ul.menu li a { + display:block; + padding:4px 10px; + border-bottom:1px solid #ccc; +} +ul.menu li a:hover { + background:#eee; +} +ul.menu li a:active { + background:#ccc; +} + + +/* submenus +----------------------------------------------- */ +ul.menu ul { + list-style:none; + margin:0; +} +ul.menu ul li a { + padding-left:30px; +} + + +/* section menus +----------------------------------------------- */ +ul.section { + border-top:0; + margin-bottom:0; +} +ul.section li { + text-transform:uppercase; +} +ul.section li a { + background:#bbb; +} +ul.section li a:hover { + background:#aaa; +} +ul.section li a:active { + color:#fff; + background:#666; +} +ul.section li li a { + background:#ddd; + border-bottom:1px solid #eee; +} +ul.section li li a:hover { + background:#ccc; +} +ul.section li li a:active { + color:#000; + background:#fff; +} +ul.section ul li { + text-transform:none; +} +ul.section ul.current li a { + background:#eee; + border-bottom:1px solid #fff; +} +ul.section ul.current li a:hover { + background:#ddd; +} +ul.section ul.current li a:active { + background:#fff; +} +ul.section li a.current { + color:#fff; + background:#666; +} +ul.section li a.current:hover { + background:#555; +} +ul.section li a.current:active { + background:#444; +} +ul.section li a.active { + background:#fff; + cursor:default; +} +ul.section li.current > a.active, +ul.section li.current > a.active:hover { + color:#fff; + background:#666; + cursor:default; +} + + +/* table +----------------------------------------------- */ +table { + width:100%; + border:1px solid #bbb; + margin-bottom:10px; +} +col.colC { + width:8em; +} +th, td { + padding:.2em 1em; + text-align:left; +} +thead th { + border-bottom:2px solid #888; + background:#bbb; + padding:.4em 1em .2em; +} +thead th.table-head { + font-size:1em; + font-weight:normal; + text-transform:uppercase; + color:#fff; + background:#555; + border:1px solid #555; +} +tbody th, +tbody td { + border-top:1px solid #bbb; + border-bottom:1px solid #bbb; + background:#eee; +} +tbody tr.odd th, +tbody tr.odd td { + background:#fff; +} +tfoot th, +tfoot td { + border-top:2px solid #666; + background:#eee; +} +tfoot tr.total th, +tfoot tr.total td { + border-top:6px double #666; +} +tfoot tr.total th { + text-transform:uppercase; +} +th.currency, +td.currency { + text-align:right; +} + + +/* forms +----------------------------------------------- */ +form { + overflow:hidden; +} +fieldset { + border:1px solid #bbb; + padding:10px; + position:relative; + background:#e9e9e9; + margin-bottom:10px; +} +legend { + font-size:1.1em; + padding:.4em .8em; + background:#fff; + border:1px solid #bbb; +} +fieldset.login p { + margin-bottom:1em; + margin-top:0pt; +} +fieldset p label { + width:98%; +} +fieldset p input { + width:98%; +} +fieldset p select { + width:99%; +} +fieldset.login p label { + float:left; + line-height:2em; + margin-right:3%; + text-align:right; + width:32%; +} +fieldset.login p input { + width:60%; +} +fieldset.login input.button { + margin-left:35%; +} +form p.notice { + font-weight:bold; +} +input.search.text { + width:66%; +} +input.search.button { + width:28%; + margin-left:2%; +} + + +/* articles +----------------------------------------------- */ +.articles { + padding:0; +} +.articles h2 { + margin:0; +} +#articles { + padding-top:0; +} +.article { + border-top:1px solid #666; + padding-top:.5em; +} +.box .article { + border-top:3px solid #fff; + padding:13px 10px 0 10px; +} +.article h2 { + font-size:2em; + font-weight:normal; + text-transform:none; + color:#333; + background:transparent; + padding:0; + margin:0; + border:none; +} +.article h3 { + margin-bottom:.2em; + font-size:1.6em; +} +.box .first { + border-top:none; +} +.article h4 { + font-size:1.2em; + text-transform:uppercase; + margin-bottom:.5em; +} +.article a.image { + float:left; + margin:3px 10px 3px 0; + padding:4px; + border:1px solid #bbb; + background:#fff; +} +.article a.image:hover { + border:1px solid #666; +} +.article a.image img { + float:left; +} +.article p.meta { + color:#666; + border-top:1px dotted #999; + border-bottom:1px dotted #999; + padding:.3em 0; + margin-bottom:.8em; +} + + +/* site information +----------------------------------------------- */ +#site_info .box { + color:#ccc; + background:#006060;/*#666;*/ + margin-bottom:10px; +} +#site_info a { + color:#fff; +} +#site_info a:hover { + color:#000; +} + + +/* AJAX sliding shelf +----------------------------------------------- */ +#loading {float:right; margin-right:14px; margin-top:-2px;} +.block {padding-bottom:1px;} + + +/* Accordian +----------------------------------------------- */ +.toggler { + color: #222; + margin: 0; + padding: 2px 5px; + background: #eee; + border-bottom: 1px solid #ddd; + border-right: 1px solid #ddd; + border-top: 1px solid #f5f5f5; + border-left: 1px solid #f5f5f5; + font-size:1.1em; + font-weight: normal; +} +.element h4 { + margin: 0; + padding:4px; + line-height:1.2em; +} +.element p { + margin: 0; + padding: 4px; +} +.float-right { + padding:10px 20px; + float:right; +} + +#accordian-block { + padding-bottom:10px; +} + + +/* Mootools Kwicks +----------------------------------------------- */ +#kwick-box { + padding:0; + overflow:hidden; +} +#kwick-box h2 { + margin:0; +} +#kwick { + position: relative; +} +#kwick .kwicks { + display: block; + background: #999; + height: 120px; + list-style:none; + margin:0; + overflow:hidden; +} +#kwick li { + float: left; + margin:0; + padding:0; +} +#kwick .kwick { + display: block; + cursor: pointer; + overflow: hidden; + height: 100px; + width: 215px; + padding: 10px; + background: #fff; +} +#kwick .kwick span { + color:#fff; +} +#kwick .one { + background: #666; +} +#kwick .two { + background: #777; +} +#kwick .three { + background: #888; +} +#kwick .four { + background: #999; +} diff --git a/WebContent/css/nav.css b/WebContent/css/nav.css new file mode 100644 index 0000000..b6f1b86 --- /dev/null +++ b/WebContent/css/nav.css @@ -0,0 +1,167 @@ +/* +----------------------------------------------- +Navigation +----------------------------------------------- */ + +/* navigation (horizontal subnavigation) +----------------------------------------------- */ +ul.nav, +ul.nav * { margin:0;padding:0;} +ul.nav { + position:relative; + background:#666; + max-width:100%; + height:2.5em; + } +ul.nav li { + cursor:pointer; + float:left; + text-align:center; + list-style-type:none; + font-weight:normal; +} +ul.nav li ul { + cursor:default; + width:100%; + max-width:100%; + position:absolute; + height:auto; + top:2.5em; + background-position:0 0 !important; + left:-9000px; +} +ul.nav li ul li { + padding:0; + border:none; + width:auto; + max-width:none; +} +ul.nav li a { + color:#fff; + background:#666; + font-weight:bold; + text-decoration:none; + display:block; + float:left; + padding:0 1em; + height:2.4em; + line-height:2.5em; +} +ul.nav li ul li a { + position:relative !important; /* ie Mac */ + cursor:pointer !important; + white-space:nowrap; + line-height:2em; + height:2em; + font-weight:normal; + color:#666; + background-position:0 50% !important; +} + +ul.nav li:hover a, +ul.nav li a:hover, +ul.nav li a:focus {color:#000; background:#ccc;} +ul.nav li a:active {color:#666; background:#fff;} +ul.nav li:hover ul {left:0;z-index:10} +ul.nav li ul, +ul.nav li {background:#ccc !important} +ul.nav li:hover ul li a {color:#444;} +ul.nav li:hover ul li a:hover {color:#000; background:#fff;} +ul.nav li:hover ul li a:active {color:#666; background:#fff;} + +ul.nav li.current a {color:#666; background:#fff; cursor:default; font-weight:bold;} +ul.nav li.current ul {left:0;z-index:5} +ul.nav li.current ul, +ul.nav li.current {background:#ccc !important} +ul.nav li.current ul li a {color:#444; background:#ccc; font-weight:normal;} +ul.nav li.current ul li a:hover {color:#000; background:#fff;} +ul.nav li ul li.current a, +ul.nav li ul li.current a:hover, +ul.nav li.current:hover ul li a:active {color:#666; background:#fff;} + + +/* navigation (vertical subnavigation) +----------------------------------------------- */ +ul.nav { + background:#006060;/*#666; true*/ +} +ul.main li { + position:relative; + top:0; + left:0; +} +ul.main li ul { + border-top:0; +} +ul.main li ul li { + float:left; +} +ul.main li a { + height:2.5em; + line-height:2.5em; + border:0; + color:#fff; + background:#006060;/*#666; true*/ +} +ul.main li ul li a { + width:12em; + line-height:2em; + height:2em; + text-align:left; + color:#fff; + border-top:1px solid #444; + background:#444; +} +ul.main li a:focus {color:#fff; background:#666;} +ul.main li ul li a:hover { + color:#fff; + background:#555; +} +ul.main li:hover a { + color:#fff; + background:#008080;/*#555;*/ +} +ul.main li:hover ul li a {color:#fff;} +ul.main li:hover ul li a:hover {color:#fff; background:#006060;/*#444;*/} +ul.main li:hover a:active {background:#444;} +ul.main li:hover ul li a:active {color:#fff; background:#222;} + + +/* secondary list +----------------------------------------------- */ +ul.nav li.secondary { + float:right; + color:#cde; + background:transparent !important; +} +ul.nav li.secondary span.status { + float:left; + padding:0 1em; + line-height:2.77em; + height:2.77em; + font-size:0.9em; +} +ul.nav li.secondary span.status a { + float:none; + display:inline; + padding:0; + height:auto; + line-height:auto; + color:#cde; + background:transparent; +} +ul.nav li.secondary span.status a:hover { + color:#fff; + background:transparent; +} +ul.nav li.secondary span.status span { + text-transform:capitalize; +} +ul.nav li.secondary:hover a { + color:#fff; + background:#008080;/*#666;*/ +} +ul.nav li.secondary:hover a:hover { + background:#008080;/*#555;*/ +} +ul.nav li.secondary:hover a:active {background:#444;} diff --git a/WebContent/css/reset.css b/WebContent/css/reset.css new file mode 100644 index 0000000..3aadd3d --- /dev/null +++ b/WebContent/css/reset.css @@ -0,0 +1,53 @@ +/* http://meyerweb.com/eric/tools/css/reset/ */ +/* v1.0 | 20080212 */ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, font, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; + vertical-align: baseline; + background: transparent; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} + +/* remember to define focus styles! */ +:focus { + outline: 0; +} + +/* remember to highlight inserts somehow! */ +ins { + text-decoration: none; +} +del { + text-decoration: line-through; +} + +/* tables still need 'cellspacing="0"' in the markup */ +table { + border-collapse: collapse; + border-spacing: 0; +} \ No newline at end of file diff --git a/WebContent/css/text.css b/WebContent/css/text.css new file mode 100644 index 0000000..b6a687b --- /dev/null +++ b/WebContent/css/text.css @@ -0,0 +1,98 @@ +/* + 960 Grid System ~ Text CSS. + Learn more ~ http://960.gs/ + + Licensed under GPL and MIT. +*/ + +/* =Basic HTML +--------------------------------------------------------------------------------*/ + +body +{ + font: 13px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif; +} + +a:focus +{ + outline: 1px dotted invert; +} + +hr +{ + border-color: #ccc; + border-style: solid; + border-width: 1px 0 0; + clear: both; + height: 0; +} + +/* =Headings +--------------------------------------------------------------------------------*/ + +h1 +{ + font-size: 25px; +} + +h2 +{ + font-size: 23px; +} + +h3 +{ + font-size: 21px; +} + +h4 +{ + font-size: 19px; +} + +h5 +{ + font-size: 17px; +} + +h6 +{ + font-size: 15px; +} + +/* =Spacing +--------------------------------------------------------------------------------*/ + +ol +{ + list-style: decimal; +} + +ul +{ + list-style: square; +} + +li +{ + margin-left: 30px; +} + +p, +dl, +hr, +h1, +h2, +h3, +h4, +h5, +h6, +ol, +ul, +pre, +table, +address, +fieldset +{ + margin-bottom: 20px; +} \ No newline at end of file From cf3436257120ef6ce0827a1fb99be7fdfc6718fa Mon Sep 17 00:00:00 2001 From: anjey Date: Fri, 3 Jan 2014 12:33:09 +0600 Subject: [PATCH 07/30] main, request and signin jsp pages were added --- WebContent/WEB-INF/jsp/main.jsp | 20 ++++++++-------- WebContent/WEB-INF/jsp/request.jsp | 22 +++++++++-------- .../WEB-INF/jsp/{login.jsp => signin.jsp} | 0 .../epam/devteam/action/ActionFactory.java | 6 ++--- src/com/epam/devteam/action/HomeAction.java | 24 ------------------- .../{LoginAction.java => SigninAction.java} | 2 +- 6 files changed, 25 insertions(+), 49 deletions(-) rename WebContent/WEB-INF/jsp/{login.jsp => signin.jsp} (100%) delete mode 100644 src/com/epam/devteam/action/HomeAction.java rename src/com/epam/devteam/action/{LoginAction.java => SigninAction.java} (95%) diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index 0b5e4b4..9ea281d 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -5,23 +5,23 @@ Main - - - - - + - + + diff --git a/WebContent/WEB-INF/jsp/request.jsp b/WebContent/WEB-INF/jsp/request.jsp index a130df3..ab67c0b 100644 --- a/WebContent/WEB-INF/jsp/request.jsp +++ b/WebContent/WEB-INF/jsp/request.jsp @@ -5,23 +5,25 @@ Online Request - - - - - + + + - diff --git a/WebContent/WEB-INF/jsp/login.jsp b/WebContent/WEB-INF/jsp/signin.jsp similarity index 100% rename from WebContent/WEB-INF/jsp/login.jsp rename to WebContent/WEB-INF/jsp/signin.jsp diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java index 7b6abc4..8ebec68 100644 --- a/src/com/epam/devteam/action/ActionFactory.java +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -18,10 +18,8 @@ public static Action getAction(HttpServletRequest request) { req = request.getMethod() + request.getPathInfo(); System.out.println(req); } - if ("GET/login".equals(req) || "POST/login".equals(req)) { - action = new LoginAction(); - } else if ("GET/home".equals(req)) { - action = new HomeAction(); + if ("GET/signin".equals(req) || "POST/signin".equals(req)) { + action = new SigninAction(); } else if ("GET/request".equals(req)) { action = new RequestCreateAction(); } else { diff --git a/src/com/epam/devteam/action/HomeAction.java b/src/com/epam/devteam/action/HomeAction.java deleted file mode 100644 index 080119c..0000000 --- a/src/com/epam/devteam/action/HomeAction.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - */ -package com.epam.devteam.action; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @date Dec 14, 2013 - * @author anjey - * - */ -public class HomeAction implements Action{ - - @Override - public String execute(HttpServletRequest request, - HttpServletResponse response) throws ActionException { - return "home"; - } - - - -} diff --git a/src/com/epam/devteam/action/LoginAction.java b/src/com/epam/devteam/action/SigninAction.java similarity index 95% rename from src/com/epam/devteam/action/LoginAction.java rename to src/com/epam/devteam/action/SigninAction.java index 52b6b2a..3ce66a9 100644 --- a/src/com/epam/devteam/action/LoginAction.java +++ b/src/com/epam/devteam/action/SigninAction.java @@ -17,7 +17,7 @@ * @author anjey * */ -public class LoginAction implements Action { +public class SigninAction implements Action { @Override public String execute(HttpServletRequest request, From 3f3390b085cfa53edc64ac5611932b9ce27400b6 Mon Sep 17 00:00:00 2001 From: anjey Date: Fri, 3 Jan 2014 23:44:10 +0600 Subject: [PATCH 08/30] Header and ffoter jsp were added --- WebContent/WEB-INF/jsp/cssimport.jsp | 17 +++ WebContent/WEB-INF/jsp/footer.jsp | 14 +++ WebContent/WEB-INF/jsp/header.jsp | 35 ++++++ WebContent/WEB-INF/jsp/home.jsp | 12 -- WebContent/WEB-INF/jsp/main.jsp | 56 +-------- WebContent/WEB-INF/jsp/request.jsp | 116 ++++-------------- WebContent/WEB-INF/jsp/signin.jsp | 60 +++++++-- WebContent/WEB-INF/tld/devteamtaglib.tld | 0 .../epam/devteam/action/ActionFactory.java | 2 +- .../devteam/action/RequestCreateAction.java | 30 ++++- src/com/epam/devteam/action/SigninAction.java | 6 +- src/com/epam/devteam/dao/DaoFactory.java | 43 ++++--- .../dao/impl/PostgresqlDaoFactory.java | 21 +++- .../dao/impl/PostgresqlRequestDao.java | 2 - src/com/epam/devteam/tags/HeaderTag.java | 28 +++++ 15 files changed, 247 insertions(+), 195 deletions(-) create mode 100644 WebContent/WEB-INF/jsp/cssimport.jsp create mode 100644 WebContent/WEB-INF/jsp/footer.jsp create mode 100644 WebContent/WEB-INF/jsp/header.jsp delete mode 100644 WebContent/WEB-INF/jsp/home.jsp create mode 100644 WebContent/WEB-INF/tld/devteamtaglib.tld create mode 100644 src/com/epam/devteam/tags/HeaderTag.java diff --git a/WebContent/WEB-INF/jsp/cssimport.jsp b/WebContent/WEB-INF/jsp/cssimport.jsp new file mode 100644 index 0000000..0a19e0a --- /dev/null +++ b/WebContent/WEB-INF/jsp/cssimport.jsp @@ -0,0 +1,17 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/footer.jsp b/WebContent/WEB-INF/jsp/footer.jsp new file mode 100644 index 0000000..d080f45 --- /dev/null +++ b/WebContent/WEB-INF/jsp/footer.jsp @@ -0,0 +1,14 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/header.jsp b/WebContent/WEB-INF/jsp/header.jsp new file mode 100644 index 0000000..95c5914 --- /dev/null +++ b/WebContent/WEB-INF/jsp/header.jsp @@ -0,0 +1,35 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + +
+ \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/home.jsp b/WebContent/WEB-INF/jsp/home.jsp deleted file mode 100644 index 4328c5f..0000000 --- a/WebContent/WEB-INF/jsp/home.jsp +++ /dev/null @@ -1,12 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - -Home - - - Hello from home page! - - \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index 9ea281d..4ad6fa3 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -5,64 +5,16 @@ Main - - - - - - +<%@include file="cssimport.jsp"%> -
- - -
- -
- -
-

Welcome to the development - team site!

-
-
- + <%@include file="header.jsp"%> +

Page body

- -
-
- This site was developed by Andrey Kovalskiy for JavaLab - course. -
-
-
+ <%@include file="footer.jsp"%> \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/request.jsp b/WebContent/WEB-INF/jsp/request.jsp index ab67c0b..1a00c47 100644 --- a/WebContent/WEB-INF/jsp/request.jsp +++ b/WebContent/WEB-INF/jsp/request.jsp @@ -5,109 +5,47 @@ Online Request - - - - - - +<%@include file="cssimport.jsp"%> -
- - -
- -
- -
-

Leave your request.

-
+ <%@include file="header.jsp"%> +
-
+
+
Request -

- -

-

- -

-

- -

-

- -

-

- -

-

- -

-

- -

-

- -

-

- - -

-

- -

- + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
- -
-
- This site was developed by Andrey Kovalskiy for JavaLab - course.
+
+ <%@include file="footer.jsp"%> \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/signin.jsp b/WebContent/WEB-INF/jsp/signin.jsp index 5483c43..ff777f5 100644 --- a/WebContent/WEB-INF/jsp/signin.jsp +++ b/WebContent/WEB-INF/jsp/signin.jsp @@ -1,19 +1,59 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> + pageEncoding="UTF-8"%> -Login +Sign in +<%@include file="cssimport.jsp"%> - Hello from login page! -
- - Input your username and password:
-
-
- -
+ <%@include file="header.jsp"%> +
+
+
+
+
+
+ Sign in +
+
+
+
+ +
+
+
+
+ Sign up +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ <%@include file="footer.jsp"%> \ No newline at end of file diff --git a/WebContent/WEB-INF/tld/devteamtaglib.tld b/WebContent/WEB-INF/tld/devteamtaglib.tld new file mode 100644 index 0000000..e69de29 diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java index 8ebec68..4f406b4 100644 --- a/src/com/epam/devteam/action/ActionFactory.java +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -20,7 +20,7 @@ public static Action getAction(HttpServletRequest request) { } if ("GET/signin".equals(req) || "POST/signin".equals(req)) { action = new SigninAction(); - } else if ("GET/request".equals(req)) { + } else if ("GET/request".equals(req) || "POST/request_create".equals(req)) { action = new RequestCreateAction(); } else { action = new MainAction(); diff --git a/src/com/epam/devteam/action/RequestCreateAction.java b/src/com/epam/devteam/action/RequestCreateAction.java index bb1ec70..03bd3a2 100644 --- a/src/com/epam/devteam/action/RequestCreateAction.java +++ b/src/com/epam/devteam/action/RequestCreateAction.java @@ -6,18 +6,36 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.log4j.Logger; + +import com.epam.devteam.dao.DaoException; +import com.epam.devteam.dao.DaoFactory; +import com.epam.devteam.dao.RequestDao; +import com.epam.devteam.entity.Request; + /** - * @date Jan 2, 2014 + * @date Jan 2, 2014 * @author anjey - * + * */ -public class RequestCreateAction implements Action{ - +public class RequestCreateAction implements Action { + private static final Logger LOGGER = Logger.getLogger(RequestCreateAction.class); + @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { - // TODO Auto-generated method stub + if ("request_create".equals(request.getParameter("command"))) { + try { + DaoFactory df = DaoFactory.takeDaoFactory(); + RequestDao rd = df.getRequestDao(); + Request onlineRequest = new Request(); + + } catch (DaoException e) { + LOGGER.warn("Failed."); + } + + } return "request"; } - + } diff --git a/src/com/epam/devteam/action/SigninAction.java b/src/com/epam/devteam/action/SigninAction.java index 3ce66a9..e42c88e 100644 --- a/src/com/epam/devteam/action/SigninAction.java +++ b/src/com/epam/devteam/action/SigninAction.java @@ -22,7 +22,7 @@ public class SigninAction implements Action { @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { - if ("login".equals(request.getParameter("command"))) { + /*if ("login".equals(request.getParameter("command"))) { System.out.println(request.getParameter("username")); System.out.println(request.getParameter("password")); System.out.println("Welcome user!"); @@ -38,8 +38,8 @@ public String execute(HttpServletRequest request, } catch (Exception e) { System.out.println("You fucking failed!"); e.printStackTrace(); - } + }*/ - return "login"; + return "signin"; } } diff --git a/src/com/epam/devteam/dao/DaoFactory.java b/src/com/epam/devteam/dao/DaoFactory.java index e064583..0ff9f61 100644 --- a/src/com/epam/devteam/dao/DaoFactory.java +++ b/src/com/epam/devteam/dao/DaoFactory.java @@ -19,22 +19,7 @@ */ public abstract class DaoFactory { private static final Logger LOGGER = Logger.getLogger(DaoFactory.class); - private static DatabaseType databaseType = null; - - /** - * Is used to set connection pool to the dao factory. - * - * @param connectionPool The connection pool to set. - */ - public abstract void setConnectionPool(ConnectionPool connectionPool); - - /** - * Is used to take user dao. - * - * @return The user dao implementation. - * @throws DaoException If something fails. - */ - public abstract UserDao takeUserDao() throws DaoException; + private static DatabaseType databaseType; /** * Is used to take dao factory implementation to work with required @@ -76,7 +61,7 @@ public static DaoFactory takeDaoFactory() throws DaoException { * database property is wrong. * @see DatabaseType */ - public static void initDatabaseType() throws DaoException { + private static void initDatabaseType() throws DaoException { try { PropertyManager propertyManager = PropertyManager.getInstance(); databaseType = DatabaseType.valueOf(propertyManager.getString( @@ -87,4 +72,28 @@ public static void initDatabaseType() throws DaoException { throw new DaoException(); } } + + /** + * Is used to set connection pool to the dao factory. + * + * @param connectionPool The connection pool to set. + */ + public abstract void setConnectionPool(ConnectionPool connectionPool); + + /** + * Is used to get user dao. + * + * @return The user dao implementation. + * @throws DaoException If something fails. + */ + public abstract UserDao getUserDao() throws DaoException; + + /** + * Is used to get request dao. + * + * @return The request dao implementation. + * @throws DaoException If something fails. + */ + public abstract RequestDao getRequestDao() throws DaoException; + } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java index 724580d..1074e82 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java @@ -5,6 +5,7 @@ import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.DaoFactory; +import com.epam.devteam.dao.RequestDao; import com.epam.devteam.dao.UserDao; import com.epam.devteam.db.ConnectionPool; @@ -33,13 +34,27 @@ public PostgresqlDaoFactory() { public void setConnectionPool(ConnectionPool connectionPool) { this.connectionPool = connectionPool; } - + /** - * Is used to take user dao. + * Is used to get user dao. + * * @return The user dao implementation. + * @throws DaoException If something fails. */ @Override - public UserDao takeUserDao() throws DaoException { + public UserDao getUserDao() throws DaoException { return new PostgresqlUserDao(connectionPool); } + + /** + * Is used to get request dao. + * + * @return The request dao implementation. + * @throws DaoException If something fails. + */ + @Override + public RequestDao getRequestDao() throws DaoException { + return new PostgresqlRequestDao(); + } + } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java index 3e4379e..264b045 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java @@ -44,8 +44,6 @@ public void create(Request object) throws DaoException { throw new DaoException(); } try { - Request object1 = new Request(1L,new Date(new java.util.Date().getTime()),Request.Status.PENDING,null,123L,321L); - object = object1; statement.setDate(1, object.getDate()); statement.setString(2, object.getStatus().toString()); statement.setLong(3, object.getCustomerId()); diff --git a/src/com/epam/devteam/tags/HeaderTag.java b/src/com/epam/devteam/tags/HeaderTag.java new file mode 100644 index 0000000..48ac19c --- /dev/null +++ b/src/com/epam/devteam/tags/HeaderTag.java @@ -0,0 +1,28 @@ +/** + * + */ +package com.epam.devteam.tags; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +/** + * @date Jan 3, 2014 + * @author anjey + * + */ +public class HeaderTag extends TagSupport{ + /** + * Serial version id. + */ + private static final long serialVersionUID = 1L; + + @Override + public int doStartTag() throws JspException { + + + return super.doStartTag(); + } + + +} From 7c922459beb0f7054fa0d860e9841ff3678b9d7a Mon Sep 17 00:00:00 2001 From: anjey Date: Mon, 6 Jan 2014 00:53:26 +0600 Subject: [PATCH 09/30] users and signin feature were added --- WebContent/WEB-INF/jsp/error.jsp | 20 ++ WebContent/WEB-INF/jsp/header.jsp | 7 +- WebContent/WEB-INF/jsp/signin.jsp | 20 +- WebContent/WEB-INF/tld/devteamtaglib.tld | 0 src/com/epam/devteam/action/Action.java | 26 +-- .../epam/devteam/action/ActionFactory.java | 40 ++-- .../devteam/action/CreateAccountAction.java | 59 ++++++ src/com/epam/devteam/action/MainAction.java | 24 --- .../devteam/action/RequestCreateAction.java | 41 ---- .../devteam/action/ShowErrorPageAction.java | 22 ++ .../devteam/action/ShowMainPageAction.java | 22 ++ .../devteam/action/ShowSigninPageAction.java | 24 +++ src/com/epam/devteam/action/SigninAction.java | 58 ++++-- src/com/epam/devteam/dao/CustomerDao.java | 9 + src/com/epam/devteam/dao/DaoFactory.java | 43 ++-- .../dao/impl/PostgresqlCustomerDao.java | 175 ++++++++++++++++ .../dao/impl/PostgresqlDaoFactory.java | 29 +-- .../dao/impl/PostgresqlRequestDao.java | 18 ++ .../devteam/dao/impl/PostgresqlUserDao.java | 4 +- src/com/epam/devteam/entity/Customer.java | 123 ++++++++++- src/com/epam/devteam/entity/Employee.java | 85 ++++---- src/com/epam/devteam/entity/User.java | 192 +++++++++++------- src/com/epam/devteam/entity/UserRole.java | 18 ++ src/com/epam/devteam/servlet/Controller.java | 7 +- 24 files changed, 785 insertions(+), 281 deletions(-) create mode 100644 WebContent/WEB-INF/jsp/error.jsp delete mode 100644 WebContent/WEB-INF/tld/devteamtaglib.tld create mode 100644 src/com/epam/devteam/action/CreateAccountAction.java delete mode 100644 src/com/epam/devteam/action/MainAction.java delete mode 100644 src/com/epam/devteam/action/RequestCreateAction.java create mode 100644 src/com/epam/devteam/action/ShowErrorPageAction.java create mode 100644 src/com/epam/devteam/action/ShowMainPageAction.java create mode 100644 src/com/epam/devteam/action/ShowSigninPageAction.java create mode 100644 src/com/epam/devteam/dao/CustomerDao.java create mode 100644 src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java create mode 100644 src/com/epam/devteam/entity/UserRole.java diff --git a/WebContent/WEB-INF/jsp/error.jsp b/WebContent/WEB-INF/jsp/error.jsp new file mode 100644 index 0000000..4127baa --- /dev/null +++ b/WebContent/WEB-INF/jsp/error.jsp @@ -0,0 +1,20 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8" errorPage="true"%> + + + + +Error +<%@include file="cssimport.jsp"%> + + + <%@include file="header.jsp"%> +
+
+

Error!

+
+
+
+ <%@include file="footer.jsp"%> + + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/header.jsp b/WebContent/WEB-INF/jsp/header.jsp index 95c5914..2e9d4b1 100644 --- a/WebContent/WEB-INF/jsp/header.jsp +++ b/WebContent/WEB-INF/jsp/header.jsp @@ -1,7 +1,3 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - -
- \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/signin.jsp b/WebContent/WEB-INF/jsp/signin.jsp index ff777f5..b2bf4c6 100644 --- a/WebContent/WEB-INF/jsp/signin.jsp +++ b/WebContent/WEB-INF/jsp/signin.jsp @@ -13,19 +13,19 @@
-
+
Sign in
-
+


-
+
- Sign up + Create account


@@ -36,16 +36,16 @@


+
+




-
-
+
+
+
+
diff --git a/WebContent/WEB-INF/tld/devteamtaglib.tld b/WebContent/WEB-INF/tld/devteamtaglib.tld deleted file mode 100644 index e69de29..0000000 diff --git a/src/com/epam/devteam/action/Action.java b/src/com/epam/devteam/action/Action.java index a490530..733ceb1 100644 --- a/src/com/epam/devteam/action/Action.java +++ b/src/com/epam/devteam/action/Action.java @@ -7,18 +7,20 @@ import javax.servlet.http.HttpServletResponse; /** - * @date Dec 14, 2013 - * @author anjey - * + * @date Dec 14, 2013 + * @author Andrey Kovalskiy + * */ public interface Action { - - /** - * Is used to make required action and get view where to redirect user. - * @param request Request to process. - * @param response Response to send. - * @return View where to redirect user - * @throws ActionException - */ - public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException; + + /** + * Is used to make required action and get view where to redirect user. + * + * @param request Request to process. + * @param response Response to send. + * @return View where to redirect user + * @throws ActionException + */ + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException; } diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java index 4f406b4..190dd52 100644 --- a/src/com/epam/devteam/action/ActionFactory.java +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -3,27 +3,39 @@ */ package com.epam.devteam.action; +import java.util.HashMap; +import java.util.Map; + import javax.servlet.http.HttpServletRequest; +import org.apache.log4j.Logger; + /** - * @date Dec 14, 2013 - * @author anjey + * @date Jan 5, 2014 + * @author Andrey Kovalskiy * */ public class ActionFactory { + private static final Logger LOGGER = Logger.getLogger(ActionFactory.class); + private static Map actions = createInitialMap(); + + private static Map createInitialMap(){ + Map actions = new HashMap(); + actions.put("GET/", new ShowMainPageAction()); + actions.put("GET/main", new ShowMainPageAction()); + actions.put("GET/error", new ShowErrorPageAction()); + actions.put("GET/signin", new ShowSigninPageAction()); + actions.put("POST/signin", new SigninAction()); + return actions; + } + public static Action getAction(HttpServletRequest request) { - Action action = null; - String req = null; - if (request != null) { - req = request.getMethod() + request.getPathInfo(); - System.out.println(req); - } - if ("GET/signin".equals(req) || "POST/signin".equals(req)) { - action = new SigninAction(); - } else if ("GET/request".equals(req) || "POST/request_create".equals(req)) { - action = new RequestCreateAction(); - } else { - action = new MainAction(); + String req = request.getMethod() + request.getPathInfo(); + System.out.println(req); + Action action = actions.get(req); + if (action == null) { + action = actions.get("GET/error"); + LOGGER.warn("Unknown request was detected:" + req); } return action; } diff --git a/src/com/epam/devteam/action/CreateAccountAction.java b/src/com/epam/devteam/action/CreateAccountAction.java new file mode 100644 index 0000000..94f0f41 --- /dev/null +++ b/src/com/epam/devteam/action/CreateAccountAction.java @@ -0,0 +1,59 @@ +/** + * + */ +package com.epam.devteam.action; + +import java.sql.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.epam.devteam.dao.CustomerDao; +import com.epam.devteam.dao.DaoException; +import com.epam.devteam.dao.DaoFactory; +import com.epam.devteam.entity.Customer; +import com.epam.devteam.entity.UserRole; + +/** + * @date Jan 4, 2014 + * @author Andrey Kovalskiy + * + */ +public class CreateAccountAction implements Action{ + private static final Logger LOGGER = Logger.getLogger(CreateAccountAction.class); + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + Customer customer = new Customer(); + customer.setEmail(request.getParameter("email")); + customer.setPassword(request.getParameter("password")); + customer.setRegistrationDate(new Date(new java.util.Date().getTime())); + customer.setRole(UserRole.CUSTOMER); + customer.setFirstName(request.getParameter("first_name")); + customer.setLastName(request.getParameter("last_name")); + customer.setBirthDate(null); + customer.setAddress(request.getParameter("address")); + customer.setPhone(request.getParameter("phone")); + customer.setCompany(request.getParameter("company")); + customer.setPosition(request.getParameter("position")); + DaoFactory factory; + try { + factory = DaoFactory.getDaoFactory(); + } catch (DaoException e) { + LOGGER.warn("Dao factory cannot be geted."); + throw new ActionException(); + } + CustomerDao dao = factory.getCustomerDao(); + try { + dao.create(customer); + } catch (DaoException e) { + LOGGER.warn("Customer cannot be created."); + throw new ActionException(); + } + return "main"; + } + +} diff --git a/src/com/epam/devteam/action/MainAction.java b/src/com/epam/devteam/action/MainAction.java deleted file mode 100644 index 370cff0..0000000 --- a/src/com/epam/devteam/action/MainAction.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - */ -package com.epam.devteam.action; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @date Dec 14, 2013 - * @author anjey - * - */ -public class MainAction implements Action{ - - @Override - public String execute(HttpServletRequest request, - HttpServletResponse response) throws ActionException { - return "main"; - } - - - -} diff --git a/src/com/epam/devteam/action/RequestCreateAction.java b/src/com/epam/devteam/action/RequestCreateAction.java deleted file mode 100644 index 03bd3a2..0000000 --- a/src/com/epam/devteam/action/RequestCreateAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - */ -package com.epam.devteam.action; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; - -import com.epam.devteam.dao.DaoException; -import com.epam.devteam.dao.DaoFactory; -import com.epam.devteam.dao.RequestDao; -import com.epam.devteam.entity.Request; - -/** - * @date Jan 2, 2014 - * @author anjey - * - */ -public class RequestCreateAction implements Action { - private static final Logger LOGGER = Logger.getLogger(RequestCreateAction.class); - - @Override - public String execute(HttpServletRequest request, - HttpServletResponse response) throws ActionException { - if ("request_create".equals(request.getParameter("command"))) { - try { - DaoFactory df = DaoFactory.takeDaoFactory(); - RequestDao rd = df.getRequestDao(); - Request onlineRequest = new Request(); - - } catch (DaoException e) { - LOGGER.warn("Failed."); - } - - } - return "request"; - } - -} diff --git a/src/com/epam/devteam/action/ShowErrorPageAction.java b/src/com/epam/devteam/action/ShowErrorPageAction.java new file mode 100644 index 0000000..c4809ba --- /dev/null +++ b/src/com/epam/devteam/action/ShowErrorPageAction.java @@ -0,0 +1,22 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Jan 5, 2014 + * @author Andrey Kovalskiy + * + */ +public class ShowErrorPageAction implements Action { + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + return "error"; + } + +} diff --git a/src/com/epam/devteam/action/ShowMainPageAction.java b/src/com/epam/devteam/action/ShowMainPageAction.java new file mode 100644 index 0000000..712b27a --- /dev/null +++ b/src/com/epam/devteam/action/ShowMainPageAction.java @@ -0,0 +1,22 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Jan 5, 2014 + * @author anjey + * + */ +public class ShowMainPageAction implements Action { + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + return "main"; + } + +} diff --git a/src/com/epam/devteam/action/ShowSigninPageAction.java b/src/com/epam/devteam/action/ShowSigninPageAction.java new file mode 100644 index 0000000..319ab38 --- /dev/null +++ b/src/com/epam/devteam/action/ShowSigninPageAction.java @@ -0,0 +1,24 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Jan 5, 2014 + * @author Andrey Kovalskiy + * + */ +public class ShowSigninPageAction implements Action { + + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + + return "signin"; + } + +} diff --git a/src/com/epam/devteam/action/SigninAction.java b/src/com/epam/devteam/action/SigninAction.java index e42c88e..bdcadac 100644 --- a/src/com/epam/devteam/action/SigninAction.java +++ b/src/com/epam/devteam/action/SigninAction.java @@ -3,43 +3,57 @@ */ package com.epam.devteam.action; -import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import com.epam.devteam.dao.CustomerDao; +import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.DaoFactory; -import com.epam.devteam.dao.UserDao; -import com.epam.devteam.entity.User; +import com.epam.devteam.entity.Customer; /** - * @date Dec 14, 2013 - * @author anjey + * @date Jan 5, 2014 + * @author Andrey Kovalskiy * */ public class SigninAction implements Action { + private static final Logger LOGGER = Logger.getLogger(SigninAction.class); @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { - /*if ("login".equals(request.getParameter("command"))) { - System.out.println(request.getParameter("username")); - System.out.println(request.getParameter("password")); - System.out.println("Welcome user!"); - return "home"; + Customer customer = null; + HttpSession session = request.getSession(); + DaoFactory factory; + CustomerDao dao =null; + try { + factory = DaoFactory.getDaoFactory(); + dao = factory.getCustomerDao(); + } catch (DaoException e) { + LOGGER.warn("Dao cannot be created."); + //throw new ActionException(); + return "error"; } try { - DaoFactory df = DaoFactory.takeDaoFactory(); - UserDao ud = df.takeUserDao(); - List users = ud.listUsers(); - for (User user : users) { - System.out.println(user); - } - } catch (Exception e) { - System.out.println("You fucking failed!"); - e.printStackTrace(); - }*/ + customer = dao.find(request.getParameter("email"), + request.getParameter("password")); + } catch (DaoException e) { + LOGGER.warn("Request cannot be executed."); + //throw new ActionException(); + return "error"; + } + if (customer == null) { + System.out.println("User not found."); + return "signin"; + } else { + session.setAttribute("user", customer); + System.out.println("welcome: " + customer.getEmail()); + return "main"; + } - return "signin"; } + } diff --git a/src/com/epam/devteam/dao/CustomerDao.java b/src/com/epam/devteam/dao/CustomerDao.java new file mode 100644 index 0000000..087f810 --- /dev/null +++ b/src/com/epam/devteam/dao/CustomerDao.java @@ -0,0 +1,9 @@ +package com.epam.devteam.dao; + +import com.epam.devteam.entity.Customer; + +public abstract class CustomerDao extends AbstractDao { + + public abstract Customer find(String email, String password) throws DaoException; + +} diff --git a/src/com/epam/devteam/dao/DaoFactory.java b/src/com/epam/devteam/dao/DaoFactory.java index 0ff9f61..b3ab2e6 100644 --- a/src/com/epam/devteam/dao/DaoFactory.java +++ b/src/com/epam/devteam/dao/DaoFactory.java @@ -22,8 +22,8 @@ public abstract class DaoFactory { private static DatabaseType databaseType; /** - * Is used to take dao factory implementation to work with required - * database. Database type is defined in property file. + * Is used to get dao factory implementation to work with required database. + * Database type is defined in property file. * * @param daoFactoryTypes The implementation type. * @return The dao factory instance. @@ -31,25 +31,27 @@ public abstract class DaoFactory { * fails with connection pool. * @see DatabaseType */ - public static DaoFactory takeDaoFactory() throws DaoException { + public static DaoFactory getDaoFactory() throws DaoException { DaoFactory daoFactory = null; + ConnectionPool connectionPool = null; if (databaseType == null) { initDatabaseType(); } + try { + connectionPool = ConnectionPool.getInstance(); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection pool cannot be initialized."); + throw new DaoException(); + } switch (databaseType) { case POSTGRESQL: - daoFactory = new PostgresqlDaoFactory(); + daoFactory = new PostgresqlDaoFactory(connectionPool); break; default: - LOGGER.warn("Database type is defined but not available!"); - throw new DaoException(); - } - try { - daoFactory.setConnectionPool(ConnectionPool.getInstance()); - } catch (ConnectionPoolException e) { - LOGGER.error("Connection pool can not be initialized"); + LOGGER.warn("Database type is defined but not available."); throw new DaoException(); } + return daoFactory; } @@ -68,25 +70,26 @@ private static void initDatabaseType() throws DaoException { "db.name").toUpperCase()); LOGGER.debug("Database type was initialized as " + databaseType); } catch (PropertyManagerException e) { - LOGGER.error("Database type can not be initialized."); + LOGGER.warn("Database type can not be initialized."); throw new DaoException(); } } /** - * Is used to set connection pool to the dao factory. + * Is used to get user dao. * - * @param connectionPool The connection pool to set. + * @return The user dao implementation. + * @throws DaoException If something fails. */ - public abstract void setConnectionPool(ConnectionPool connectionPool); + public abstract UserDao getUserDao(); /** - * Is used to get user dao. + * Is used to get customer dao. * - * @return The user dao implementation. + * @return The request dao implementation. * @throws DaoException If something fails. */ - public abstract UserDao getUserDao() throws DaoException; + public abstract CustomerDao getCustomerDao(); /** * Is used to get request dao. @@ -94,6 +97,6 @@ private static void initDatabaseType() throws DaoException { * @return The request dao implementation. * @throws DaoException If something fails. */ - public abstract RequestDao getRequestDao() throws DaoException; - + public abstract RequestDao getRequestDao(); + } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java b/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java new file mode 100644 index 0000000..585967c --- /dev/null +++ b/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java @@ -0,0 +1,175 @@ +/** + * + */ +package com.epam.devteam.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.epam.devteam.dao.CustomerDao; +import com.epam.devteam.dao.DaoException; +import com.epam.devteam.db.ConnectionPool; +import com.epam.devteam.db.ConnectionPoolException; +import com.epam.devteam.entity.Customer; + +/** + * @date Jan 4, 2014 + * @author Andrey Kovalskiy + * + */ +public class PostgresqlCustomerDao extends CustomerDao { + private static final Logger LOGGER = Logger + .getLogger(PostgresqlCustomerDao.class); + /* + * private static PropertyManager propertyManager = + * PropertyManager.getInstance(); private static String sqlCustomerCreate = + * propertyManager.getString("sql.customer.create"); + */ + private String sqlCustomerCreate = "INSERT INTO users (email,password,registration_date,role,first_name,last_name,birth_date,address,phone,company,position) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; + + /** + * Initializes a newly created {@code PostgresqlCustomerDao} object. + */ + public PostgresqlCustomerDao() { + super(); + } + + /** + * Initializes a newly created {@code PostgresqlCustomerDao} object and + * connection with the given connection value. + * + * @param connection The connection to use to connect to the database. + */ + public PostgresqlCustomerDao(ConnectionPool connectionPool) { + setConnectionPool(connectionPool); + } + + @Override + public void create(Customer object) throws DaoException { + Customer customer = object; + Connection connection; + PreparedStatement statement; + try { + connection = getConnectionPool().takeConnection(); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection cannot be taken."); + throw new DaoException(); + } + try { + statement = connection.prepareStatement(sqlCustomerCreate); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be created."); + throw new DaoException(); + } + try { + statement.setString(1, customer.getEmail()); + statement.setString(2, customer.getPassword()); + statement.setDate(3, customer.getRegistrationDate()); + statement.setString(4, customer.getRole().toString()); + statement.setString(5, customer.getFirstName()); + statement.setString(6, customer.getLastName()); + statement.setDate(7, customer.getBirthDate()); + statement.setString(8, customer.getAddress()); + statement.setString(9, customer.getPhone()); + statement.setString(10, customer.getCompany()); + statement.setString(11, customer.getPosition()); + statement.execute(); + } catch (SQLException e) { + e.printStackTrace(); + LOGGER.warn("Statement cannot be executed."); + throw new DaoException(); + } + freeConnection(connection, statement); + } + + @Override + public Customer find(Long id) throws DaoException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void update(Customer object) throws DaoException { + // TODO Auto-generated method stub + + } + + @Override + public void delete(Customer object) throws DaoException { + // TODO Auto-generated method stub + + } + + @Override + public List list() throws DaoException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Customer find(String email, String password) throws DaoException { + Customer customer = null; + Connection connection; + PreparedStatement statement; + ResultSet resultSet; + try { + connection = getConnectionPool().takeConnection(); + } catch (ConnectionPoolException e) { + LOGGER.warn("Connection cannot be taken."); + throw new DaoException(); + } + try { + statement = connection + .prepareStatement("SELECT * FROM users WHERE (users.email=? AND users.password=?)"); + System.out.println(email + " " + password); + statement.setString(1, email); + statement.setString(2, password); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be created."); + throw new DaoException(); + } + try { + resultSet = statement.executeQuery(); + LOGGER.debug("Query was executed."); + if (resultSet.next()) { + System.out.println("yep!"); + customer = new Customer(); + customer.setEmail(resultSet.getString("email")); + customer.setPassword(resultSet.getString("password")); + } + } catch (SQLException e) { + e.printStackTrace(); + LOGGER.warn("Statement cannot be executed."); + throw new DaoException(); + } + + freeConnection(connection, statement); + + return customer; + } + + /** + * Is used to close statement and return connection to the connection pool. + * + * @param connection The connection to return. + * @param statement The statement to close. + */ + private void freeConnection(Connection connection, Statement statement) { + if (statement != null) { + try { + statement.close(); + LOGGER.debug("Statement has been closed."); + } catch (SQLException e) { + LOGGER.warn("Statement cannot be closed."); + } + } + getConnectionPool().returnConnection(connection); + } + +} diff --git a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java index 1074e82..6444586 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlDaoFactory.java @@ -3,6 +3,7 @@ */ package com.epam.devteam.dao.impl; +import com.epam.devteam.dao.CustomerDao; import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.DaoFactory; import com.epam.devteam.dao.RequestDao; @@ -19,31 +20,32 @@ public class PostgresqlDaoFactory extends DaoFactory { private ConnectionPool connectionPool; /** - * Initializes a newly created {@code Object} object. + * Initializes a newly created {@code PostgresqlDaoFactory} object. */ - public PostgresqlDaoFactory() { - super(); + public PostgresqlDaoFactory(ConnectionPool connectionPool) { + this.connectionPool = connectionPool; } /** - * Is used to set connection pool to the dao factory. + * Is used to get user dao. * - * @param connectionPool The connection pool to set. + * @return The user dao implementation. + * @throws DaoException If something fails. */ @Override - public void setConnectionPool(ConnectionPool connectionPool) { - this.connectionPool = connectionPool; + public UserDao getUserDao() { + return new PostgresqlUserDao(connectionPool); } /** - * Is used to get user dao. + * Is used to get customer dao. * - * @return The user dao implementation. + * @return The request dao implementation. * @throws DaoException If something fails. */ @Override - public UserDao getUserDao() throws DaoException { - return new PostgresqlUserDao(connectionPool); + public CustomerDao getCustomerDao() { + return new PostgresqlCustomerDao(connectionPool); } /** @@ -53,8 +55,7 @@ public UserDao getUserDao() throws DaoException { * @throws DaoException If something fails. */ @Override - public RequestDao getRequestDao() throws DaoException { - return new PostgresqlRequestDao(); + public RequestDao getRequestDao() { + return new PostgresqlRequestDao(connectionPool); } - } diff --git a/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java index 264b045..ee0d52a 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlRequestDao.java @@ -11,13 +11,31 @@ import com.epam.devteam.dao.DaoException; import com.epam.devteam.dao.RequestDao; +import com.epam.devteam.db.ConnectionPool; import com.epam.devteam.db.ConnectionPoolException; import com.epam.devteam.entity.Request; public class PostgresqlRequestDao extends RequestDao { private static final Logger LOGGER = Logger .getLogger(PostgresqlRequestDao.class); + + /** + * Initializes a newly created {@code PostgresqlRequestDao} object. + */ + public PostgresqlRequestDao() { + super(); + } + /** + * Initializes a newly created {@code PostgresqlRequestDao} object and + * connection with the given connection value. + * + * @param connection The connection to use to connect to the database. + */ + public PostgresqlRequestDao(ConnectionPool connectionPool) { + setConnectionPool(connectionPool); + } + /** * Is used to create given request in the database. * diff --git a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java index db55bf2..b90634f 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlUserDao.java @@ -134,13 +134,13 @@ public List listUsers() throws DaoException { users = new ArrayList(); while (resultSet.next()) { user = new User(); - user.setId(resultSet.getLong("id")); + /*user.setId(resultSet.getLong("id")); user.setEmail(resultSet.getString("email")); user.setPassword(resultSet.getString("password")); user.setFirstname(resultSet.getString("firstname")); user.setLastname(resultSet.getString("lastname")); user.setPatronymic(resultSet.getString("patronymic")); - user.setBirthdate(resultSet.getDate("birthdate")); + user.setBirthdate(resultSet.getDate("birthdate"));*/ users.add(user); } } catch (SQLException e) { diff --git a/src/com/epam/devteam/entity/Customer.java b/src/com/epam/devteam/entity/Customer.java index 3975fd2..530e29f 100644 --- a/src/com/epam/devteam/entity/Customer.java +++ b/src/com/epam/devteam/entity/Customer.java @@ -1,5 +1,126 @@ package com.epam.devteam.entity; -public class Customer { +import java.sql.Date; +/** + * @date Jan 4, 2014 + * @author Andrey Kovalskiy + */ +public class Customer extends User { + + private static final long serialVersionUID = 1L; + private String company; + private String position; + + /** + * Initializes a newly created {@code Customer} object. + */ + public Customer() { + super(); + } + + /** + * Initializes a newly created {@code Customer} object with the given + * values. + * + * @param id The user id. + * @param email The user email. + * @param password The user password. + * @param registrationDate The date of registration. + * @param firstName The user first name. + * @param lastName The user last name. + * @param birthDate The user birth date. + * @param phone The contact phone number + * @param company The company where the customer works. + * @param position The position of the customer. + */ + public Customer(Integer id, String email, String password, + Date registrationDate, UserRole role, String firstName, + String lastName, Date birthDate, String address, String phone, + String company, String position) { + super(id, email, password, registrationDate, role, firstName, lastName, + birthDate, address, phone); + this.company = company; + this.position = position; + } + + /** + * Returns the company field value. + * + * @return The company. + */ + public String getCompany() { + return company; + } + + /** + * Sets the company field value. + * + * @param company The company to set. + */ + public void setCompany(String company) { + this.company = company; + } + + /** + * Returns the position field value. + * + * @return The position. + */ + public String getPosition() { + return position; + } + + /** + * Sets the position field value. + * + * @param position The position to set. + */ + public void setPosition(String position) { + this.position = position; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj The reference object with which to compare. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() == obj.getClass()) { + Customer otherCustomer = (Customer) obj; + return (this.getId().equals(otherCustomer.getId())) + && (this.getEmail().equals(otherCustomer.getEmail())) + && (this.getPassword().equals(otherCustomer.getPassword())) + && (this.getRegistrationDate().equals(otherCustomer + .getRegistrationDate())) + && (this.getRole().equals(otherCustomer.getRole())) + && (this.getFirstName() + .equals(otherCustomer.getFirstName())) + && (this.getLastName().equals(otherCustomer.getLastName())) + && (this.getBirthDate() + .equals(otherCustomer.getBirthDate())) + && (this.getAddress().equals(otherCustomer.getAddress())) + && (this.getPhone().equals(otherCustomer.getPhone())) + && (this.company.equals(otherCustomer.company)) + && (this.position.equals(otherCustomer.position)); + } else { + return false; + } + } + + /** + * Returns a hash code value for the object. + */ + @Override + public int hashCode() { + return super.hashCode() + ((company == null) ? 0 : company.hashCode()) + + ((position == null) ? 0 : position.hashCode()); + } } diff --git a/src/com/epam/devteam/entity/Employee.java b/src/com/epam/devteam/entity/Employee.java index c127064..05558a4 100644 --- a/src/com/epam/devteam/entity/Employee.java +++ b/src/com/epam/devteam/entity/Employee.java @@ -1,49 +1,63 @@ package com.epam.devteam.entity; -import java.io.Serializable; +import java.sql.Date; + +/** + * @date Jan 4, 2014 + * @author Andrey Kovalskiy + */ +public class Employee extends User { -public class Employee extends User implements Serializable { - /** - * Serial version id. - */ private static final long serialVersionUID = 1L; - private String position; - private String company; + private String qualification; /** - * Returns the position field value. - * - * @return the position + * Initializes a newly created {@code Employee} object. */ - public String getPosition() { - return position; + public Employee() { + super(); } /** - * Sets the position field value. + * Initializes a newly created {@code Employee} object with the given field + * values. * - * @param position the position to set + * @param id The user id. + * @param email The user email. + * @param password The user password. + * @param registrationDate The date of registration. + * @param firstName The user first name. + * @param lastName The user last name. + * @param birthDate The user birth date. + * @param phone The contact phone number. + * @param role The employee role {@link UserRole}. + * @param qualifiaction The employee qualification. */ - public void setPosition(String position) { - this.position = position; + public Employee(Integer id, String email, String password, + Date registrationDate, UserRole role, String firstName, + String lastName, Date birthDate, String address, String phone, + String qualification) { + super(id, email, password, registrationDate, role, firstName, lastName, + birthDate, address, phone); + this.qualification = qualification; } /** - * Returns the company field value. + * Returns the qualification field value. * - * @return the company + * @return The qualification. */ - public String getCompany() { - return company; + public String getQualification() { + return qualification; } /** - * Sets the company field value. + * Sets the qualification field value. * - * @param company the company to set + * @param qualification The qualification to set. */ - public void setCompany(String company) { - this.company = company; + public void setQualification(String qualification) { + this.qualification = qualification; } /** @@ -64,15 +78,17 @@ public boolean equals(Object obj) { return (this.getId().equals(otherEmployee.getId())) && (this.getEmail().equals(otherEmployee.getEmail())) && (this.getPassword().equals(otherEmployee.getPassword())) - && (this.getFirstname() - .equals(otherEmployee.getFirstname())) - && (this.getLastname().equals(otherEmployee.getLastname())) - && (this.getPatronymic().equals(otherEmployee - .getPatronymic())) - && (this.getBirthdate() - .equals(otherEmployee.getBirthdate())) - && (this.company.equals(otherEmployee.company)) - && (this.position.equals(otherEmployee.position)); + && (this.getRegistrationDate().equals(otherEmployee + .getRegistrationDate())) + && (this.getRole().equals(otherEmployee.getRole())) + && (this.getFirstName() + .equals(otherEmployee.getFirstName())) + && (this.getLastName().equals(otherEmployee.getLastName())) + && (this.getBirthDate() + .equals(otherEmployee.getBirthDate())) + && (this.getAddress().equals(otherEmployee.getAddress())) + && (this.getPhone().equals(otherEmployee.getPhone())) + && (this.qualification.equals(otherEmployee.qualification)); } else { return false; } @@ -84,8 +100,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { return super.hashCode() - + ((position == null) ? 0 : position.hashCode()) - + ((company == null) ? 0 : company.hashCode()); + + ((qualification == null) ? 0 : qualification.hashCode()); } } diff --git a/src/com/epam/devteam/entity/User.java b/src/com/epam/devteam/entity/User.java index 5619c6f..c317d44 100644 --- a/src/com/epam/devteam/entity/User.java +++ b/src/com/epam/devteam/entity/User.java @@ -4,7 +4,7 @@ package com.epam.devteam.entity; import java.io.Serializable; -import java.util.Date; +import java.sql.Date; /** * @date Dec 15, 2013 @@ -12,17 +12,16 @@ * */ public class User implements Serializable { - /** - * Serial version id. - */ + private static final long serialVersionUID = 1L; - private Long id; + private Integer id; private String email; private String password; - private String firstname; - private String lastname; - private String patronymic; - private Date birthdate; + private Date registrationDate; + private UserRole role; + private String firstName; + private String lastName; + private Date birthDate; private String address; private String phone; @@ -37,48 +36,55 @@ public User() { * Initializes a newly created {@code User} object with the given field * values. * - * @param id the user id. - * @param email the user email. - * @param password the user password. - * @param firstname the user first name. - * @param lastname the user last name. - * @param patronymic the user patronymic. - * @param birthdate the user birthdate. + * @param id The user id. + * @param email The user email. + * @param password The user password. + * @param registrationDate The date of registration. + * @param role The user role. + * @param firstName The user first name. + * @param lastName The user last name. + * @param birthDate The user birth date. + * @param address The user address. + * @param phone The contact phone number */ - public User(long id, String email, String password, String firstname, - String lastname, String patronymic, Date birthdate) { + public User(Integer id, String email, String password, + Date registrationDate, UserRole role, String firstName, + String lastName, Date birthDate, String address, String phone) { super(); this.id = id; this.email = email; this.password = password; - this.firstname = firstname; - this.lastname = lastname; - this.patronymic = patronymic; - this.birthdate = birthdate; + this.registrationDate = registrationDate; + this.role = role; + this.firstName = firstName; + this.lastName = lastName; + this.birthDate = birthDate; + this.address = address; + this.phone = phone; } /** * Returns the id field value. * - * @return the id + * @return The id. */ - public Long getId() { + public Integer getId() { return id; } /** * Sets the id field value. * - * @param id the id to set + * @param id The id to set. */ - public void setId(Long id) { + public void setId(Integer id) { this.id = id; } /** * Returns the email field value. * - * @return the email + * @return The email. */ public String getEmail() { return email; @@ -87,7 +93,7 @@ public String getEmail() { /** * Sets the email field value. * - * @param email the email to set + * @param email The email to set. */ public void setEmail(String email) { this.email = email; @@ -96,7 +102,7 @@ public void setEmail(String email) { /** * Returns the password field value. * - * @return the password + * @return The password. */ public String getPassword() { return password; @@ -105,88 +111,106 @@ public String getPassword() { /** * Sets the password field value. * - * @param password the password to set + * @param password The password to set. */ public void setPassword(String password) { this.password = password; } /** - * Returns the firstname field value. + * Returns the registrationDate field value. + * + * @return The registrationDate. + */ + public Date getRegistrationDate() { + return registrationDate; + } + + /** + * Sets the registrationDate field value. * - * @return the firstname + * @param registrationDate The registrationDate to set. */ - public String getFirstname() { - return firstname; + public void setRegistrationDate(Date registrationDate) { + this.registrationDate = registrationDate; } /** - * Sets the firstname field value. + * Returns the user role field value. * - * @param firstname the firstname to set + * @return The user role. */ - public void setFirstname(String firstname) { - this.firstname = firstname; + public UserRole getRole() { + return role; } /** - * Returns the lastname field value. + * Sets the role field value. * - * @return the lastname + * @param role The role to set. */ - public String getLastname() { - return lastname; + public void setRole(UserRole role) { + this.role = role; } /** - * Sets the lastname field value. + * Returns the firstName field value. * - * @param lastname the lastname to set + * @return The firstName. */ - public void setLastname(String lastname) { - this.lastname = lastname; + public String getFirstName() { + return firstName; } /** - * Returns the patronymic field value. + * Sets the firstName field value. * - * @return the patronymic + * @param firstName The firstName to set. */ - public String getPatronymic() { - return patronymic; + public void setFirstName(String firstName) { + this.firstName = firstName; } /** - * Sets the patronymic field value. + * Returns the lastName field value. * - * @param patronymic the patronymic to set + * @return The lastName. */ - public void setPatronymic(String patronymic) { - this.patronymic = patronymic; + public String getLastName() { + return lastName; } /** - * Returns the birthdate field value. + * Sets the lastName field value. * - * @return the birthdate + * @param lastName The lastName to set. */ - public Date getBirthdate() { - return birthdate; + public void setLastName(String lastName) { + this.lastName = lastName; } /** - * Sets the birthdate field value. + * Returns the birthDate field value. * - * @param birthdate the birthdate to set + * @return The birthDate. */ - public void setBirthdate(Date birthdate) { - this.birthdate = birthdate; + public Date getBirthDate() { + return birthDate; + } + + /** + * Sets the birthDate field value. + * + * @param birthDate The birthDate to set. + */ + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; } /** * Returns the address field value. * - * @return the address + * @return The address. */ public String getAddress() { return address; @@ -195,7 +219,7 @@ public String getAddress() { /** * Sets the address field value. * - * @param address the address to set + * @param address The address to set. */ public void setAddress(String address) { this.address = address; @@ -204,7 +228,7 @@ public void setAddress(String address) { /** * Returns the phone field value. * - * @return the phone + * @return The phone. */ public String getPhone() { return phone; @@ -213,7 +237,7 @@ public String getPhone() { /** * Sets the phone field value. * - * @param phone the phone to set + * @param phone The phone to set. */ public void setPhone(String phone) { this.phone = phone; @@ -237,10 +261,15 @@ public boolean equals(Object obj) { return (this.id.equals(otherUser.id)) && (this.email.equals(otherUser.email)) && (this.password.equals(otherUser.password)) - && (this.firstname.equals(otherUser.firstname)) - && (this.lastname.equals(otherUser.lastname)) - && (this.patronymic.equals(otherUser.patronymic)) - && (this.birthdate.equals(otherUser.birthdate)); + && (this.registrationDate + .equals(otherUser.registrationDate)) + && (this.role.equals(otherUser.role)) + && (this.firstName.equals(otherUser.firstName)) + && (this.lastName.equals(otherUser.lastName)) + && (this.birthDate.equals(otherUser.birthDate)) + && (this.address.equals(otherUser.address)) + && (this.phone.equals(otherUser.phone)); + } else { return false; } @@ -254,20 +283,27 @@ public int hashCode() { return (int) (31 * id.hashCode() + ((email == null) ? 0 : email.hashCode()) + ((password == null) ? 0 : password.hashCode())) - + ((firstname == null) ? 0 : firstname.hashCode()) - + ((lastname == null) ? 0 : lastname.hashCode()) - + ((patronymic == null) ? 0 : patronymic.hashCode()) - + ((birthdate == null) ? 0 : birthdate.hashCode()); + + ((registrationDate == null) ? 0 : registrationDate.hashCode()) + + ((role == null) ? 0 : role.hashCode()) + + ((firstName == null) ? 0 : firstName.hashCode()) + + ((lastName == null) ? 0 : lastName.hashCode()) + + ((birthDate == null) ? 0 : birthDate.hashCode()) + + ((address == null) ? 0 : address.hashCode()) + + ((phone == null) ? 0 : phone.hashCode()); } + /** + * Returns a string representation of the object. + */ @Override public String toString() { StringBuffer sb = new StringBuffer(); - sb.append("user:").append(lastname).append(" ").append(firstname) - .append(" ").append(patronymic).append(" birthdate:") - .append(birthdate).append(" email:").append(email) + sb.append("user:").append(lastName).append(" ").append(firstName) + .append(" role:").append(role).append(" birthdate:") + .append(birthDate).append(" email:").append(email) .append(" address:").append(address).append(" phone:") - .append(phone); + .append(phone).append(" registered:").append(registrationDate) + .append(" id:").append(id); return sb.toString(); } } diff --git a/src/com/epam/devteam/entity/UserRole.java b/src/com/epam/devteam/entity/UserRole.java new file mode 100644 index 0000000..73fc8e0 --- /dev/null +++ b/src/com/epam/devteam/entity/UserRole.java @@ -0,0 +1,18 @@ +/** + * + */ +package com.epam.devteam.entity; + +/** + * @date Jan 4, 2014 + * @author anjey + * + */ +public enum UserRole { + ADMINISTRATOR, MANAGER, DEVELOPER, CUSTOMER; + + @Override + public String toString() { + return this.name().toLowerCase(); + } +} diff --git a/src/com/epam/devteam/servlet/Controller.java b/src/com/epam/devteam/servlet/Controller.java index 8d987ea..f77a75e 100644 --- a/src/com/epam/devteam/servlet/Controller.java +++ b/src/com/epam/devteam/servlet/Controller.java @@ -7,6 +7,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.log4j.Logger; + import com.epam.devteam.action.Action; import com.epam.devteam.action.ActionFactory; @@ -14,6 +16,7 @@ * Servlet implementation class Controller */ public class Controller extends HttpServlet { + private static final Logger LOGGER = Logger.getLogger(Controller.class); private static final long serialVersionUID = 1L; /** @@ -53,8 +56,8 @@ protected void doAction(HttpServletRequest request, response.sendRedirect(view); } } catch (Exception e) { - throw new ServletException("Executing action failed.", e); + LOGGER.error("Executing action failed.", e); } } - + } From 67644b1a2a4ab265f53f2869561d36716f5cd878 Mon Sep 17 00:00:00 2001 From: anjey Date: Mon, 6 Jan 2014 14:08:45 +0600 Subject: [PATCH 10/30] signin, signout and loginfo tags were added --- .classpath | 1 + WebContent/WEB-INF/jsp/header.jsp | 5 +-- WebContent/WEB-INF/jsp/main.jsp | 2 + WebContent/WEB-INF/tld/devteamtaglib.tld | 19 ++++++++ WebContent/WEB-INF/web.xml | 12 +++++- .../epam/devteam/action/ActionFactory.java | 2 + .../devteam/action/CreateAccountAction.java | 11 ++--- .../devteam/action/ShowMainPageAction.java | 8 ++-- src/com/epam/devteam/action/SigninAction.java | 8 ++-- .../epam/devteam/action/SignoutAction.java | 23 ++++++++++ .../dao/impl/PostgresqlCustomerDao.java | 11 ++++- src/com/epam/devteam/servlet/Controller.java | 23 +++++----- src/com/epam/devteam/tag/LogInfoTag.java | 42 ++++++++++++++++++ src/com/epam/devteam/tag/SigninTag.java | 43 +++++++++++++++++++ src/com/epam/devteam/tags/HeaderTag.java | 28 ------------ 15 files changed, 181 insertions(+), 57 deletions(-) create mode 100644 WebContent/WEB-INF/tld/devteamtaglib.tld create mode 100644 src/com/epam/devteam/action/SignoutAction.java create mode 100644 src/com/epam/devteam/tag/LogInfoTag.java create mode 100644 src/com/epam/devteam/tag/SigninTag.java delete mode 100644 src/com/epam/devteam/tags/HeaderTag.java diff --git a/.classpath b/.classpath index b82e428..c294155 100644 --- a/.classpath +++ b/.classpath @@ -16,5 +16,6 @@ + diff --git a/WebContent/WEB-INF/jsp/header.jsp b/WebContent/WEB-INF/jsp/header.jsp index 2e9d4b1..529f2da 100644 --- a/WebContent/WEB-INF/jsp/header.jsp +++ b/WebContent/WEB-INF/jsp/header.jsp @@ -19,12 +19,11 @@
  • Documentation
  • Online request
  • -
  • Sign - in
  • +
  • -

    Page Title

    +

    diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index 4ad6fa3..042f5b6 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -1,5 +1,7 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib uri="/WEB-INF/tld/devteamtaglib.tld" prefix="tlib"%> diff --git a/WebContent/WEB-INF/tld/devteamtaglib.tld b/WebContent/WEB-INF/tld/devteamtaglib.tld new file mode 100644 index 0000000..650de19 --- /dev/null +++ b/WebContent/WEB-INF/tld/devteamtaglib.tld @@ -0,0 +1,19 @@ + + + 1.0 + tlib + /WEB-INF/tld/devteam.tld + + signin + com.epam.devteam.tag.SigninTag + empty + + + loginfo + com.epam.devteam.tag.LogInfoTag + empty + + \ No newline at end of file diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index dde9b9c..fa3f690 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -12,7 +12,17 @@ default.htm default.jsp - + + + + /WEB-INF/tld/devteamtaglib.tld + + + /WEB-INF/tld/devteamtaglib.tld + + + + Controller diff --git a/src/com/epam/devteam/action/ActionFactory.java b/src/com/epam/devteam/action/ActionFactory.java index 190dd52..99edb10 100644 --- a/src/com/epam/devteam/action/ActionFactory.java +++ b/src/com/epam/devteam/action/ActionFactory.java @@ -25,7 +25,9 @@ private static Map createInitialMap(){ actions.put("GET/main", new ShowMainPageAction()); actions.put("GET/error", new ShowErrorPageAction()); actions.put("GET/signin", new ShowSigninPageAction()); + actions.put("GET/signout", new SignoutAction()); actions.put("POST/signin", new SigninAction()); + actions.put("POST/create_account", new CreateAccountAction()); return actions; } diff --git a/src/com/epam/devteam/action/CreateAccountAction.java b/src/com/epam/devteam/action/CreateAccountAction.java index 94f0f41..363b52e 100644 --- a/src/com/epam/devteam/action/CreateAccountAction.java +++ b/src/com/epam/devteam/action/CreateAccountAction.java @@ -17,13 +17,14 @@ import com.epam.devteam.entity.UserRole; /** - * @date Jan 4, 2014 + * @date Jan 4, 2014 * @author Andrey Kovalskiy - * + * */ -public class CreateAccountAction implements Action{ - private static final Logger LOGGER = Logger.getLogger(CreateAccountAction.class); - +public class CreateAccountAction implements Action { + private static final Logger LOGGER = Logger + .getLogger(CreateAccountAction.class); + @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { diff --git a/src/com/epam/devteam/action/ShowMainPageAction.java b/src/com/epam/devteam/action/ShowMainPageAction.java index 712b27a..e9b70ff 100644 --- a/src/com/epam/devteam/action/ShowMainPageAction.java +++ b/src/com/epam/devteam/action/ShowMainPageAction.java @@ -7,16 +7,16 @@ import javax.servlet.http.HttpServletResponse; /** - * @date Jan 5, 2014 + * @date Jan 5, 2014 * @author anjey - * + * */ public class ShowMainPageAction implements Action { - @Override + @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { + System.out.println(request.getSession().getAttribute("user")); return "main"; } - } diff --git a/src/com/epam/devteam/action/SigninAction.java b/src/com/epam/devteam/action/SigninAction.java index bdcadac..5756953 100644 --- a/src/com/epam/devteam/action/SigninAction.java +++ b/src/com/epam/devteam/action/SigninAction.java @@ -28,22 +28,20 @@ public String execute(HttpServletRequest request, Customer customer = null; HttpSession session = request.getSession(); DaoFactory factory; - CustomerDao dao =null; + CustomerDao dao = null; try { factory = DaoFactory.getDaoFactory(); dao = factory.getCustomerDao(); } catch (DaoException e) { LOGGER.warn("Dao cannot be created."); - //throw new ActionException(); - return "error"; + throw new ActionException(); } try { customer = dao.find(request.getParameter("email"), request.getParameter("password")); } catch (DaoException e) { LOGGER.warn("Request cannot be executed."); - //throw new ActionException(); - return "error"; + throw new ActionException(); } if (customer == null) { System.out.println("User not found."); diff --git a/src/com/epam/devteam/action/SignoutAction.java b/src/com/epam/devteam/action/SignoutAction.java new file mode 100644 index 0000000..ffd6b62 --- /dev/null +++ b/src/com/epam/devteam/action/SignoutAction.java @@ -0,0 +1,23 @@ +/** + * + */ +package com.epam.devteam.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @date Jan 6, 2014 + * @author anjey + * + */ +public class SignoutAction implements Action { + + @Override + public String execute(HttpServletRequest request, + HttpServletResponse response) throws ActionException { + request.getSession().removeAttribute("user"); + return "main"; + } + +} diff --git a/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java b/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java index 585967c..b9e231b 100644 --- a/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java +++ b/src/com/epam/devteam/dao/impl/PostgresqlCustomerDao.java @@ -140,8 +140,17 @@ public Customer find(String email, String password) throws DaoException { if (resultSet.next()) { System.out.println("yep!"); customer = new Customer(); + customer.setId(resultSet.getInt("id")); customer.setEmail(resultSet.getString("email")); - customer.setPassword(resultSet.getString("password")); + //customer.setPassword(resultSet.getString("password")); + customer.setRegistrationDate(resultSet.getDate("registration_date")); + customer.setFirstName(resultSet.getString("first_name")); + customer.setLastName(resultSet.getString("last_name")); + customer.setBirthDate(resultSet.getDate("birth_date")); + customer.setAddress(resultSet.getString("address")); + customer.setPhone(resultSet.getString("phone")); + customer.setCompany(resultSet.getString("company")); + customer.setPosition(resultSet.getString("position")); } } catch (SQLException e) { e.printStackTrace(); diff --git a/src/com/epam/devteam/servlet/Controller.java b/src/com/epam/devteam/servlet/Controller.java index f77a75e..276d2c0 100644 --- a/src/com/epam/devteam/servlet/Controller.java +++ b/src/com/epam/devteam/servlet/Controller.java @@ -10,6 +10,7 @@ import org.apache.log4j.Logger; import com.epam.devteam.action.Action; +import com.epam.devteam.action.ActionException; import com.epam.devteam.action.ActionFactory; /** @@ -46,18 +47,20 @@ protected void doPost(HttpServletRequest request, protected void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Action action = ActionFactory.getAction(request); + String view; try { - Action action = ActionFactory.getAction(request); - String view = action.execute(request, response); - if (view.equals(request.getPathInfo().substring(1))) { - request.getRequestDispatcher("/WEB-INF/jsp/" + view + ".jsp") - .forward(request, response); - } else { - response.sendRedirect(view); - } - } catch (Exception e) { + view = action.execute(request, response); + } catch (ActionException e) { LOGGER.error("Executing action failed.", e); + view = "error"; + } + if (view.equals(request.getPathInfo().substring(1))) { + request.getRequestDispatcher("/WEB-INF/jsp/" + view + ".jsp") + .forward(request, response); + } else { + response.sendRedirect(view); } - } + } } diff --git a/src/com/epam/devteam/tag/LogInfoTag.java b/src/com/epam/devteam/tag/LogInfoTag.java new file mode 100644 index 0000000..c6f23a1 --- /dev/null +++ b/src/com/epam/devteam/tag/LogInfoTag.java @@ -0,0 +1,42 @@ +/** + * + */ +package com.epam.devteam.tag; + +import java.io.IOException; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.log4j.Logger; + +import com.epam.devteam.entity.User; + +/** + * @date Jan 6, 2014 + * @author Andrey Kovalskiy + * + */ +public class LogInfoTag extends TagSupport { + private static final Logger LOGGER = Logger.getLogger(SigninTag.class); + private static final long serialVersionUID = 1L; + + @Override + public int doStartTag() throws JspException { + User user = (User) pageContext.getSession().getAttribute("user"); + String str; + if (user == null) { + str = "Please authorise to get access to all features."; + } else { + str = "Welcome: " + user.getFirstName() + " " + user.getLastName() + ""; + } + try { + JspWriter out = pageContext.getOut(); + out.print(str); + } catch (IOException e) { + LOGGER.warn("Jsp write failed."); + } + return SKIP_BODY; + } +} diff --git a/src/com/epam/devteam/tag/SigninTag.java b/src/com/epam/devteam/tag/SigninTag.java new file mode 100644 index 0000000..58c27b7 --- /dev/null +++ b/src/com/epam/devteam/tag/SigninTag.java @@ -0,0 +1,43 @@ +/** + * + */ +package com.epam.devteam.tag; + +import java.io.IOException; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.log4j.Logger; + +import com.epam.devteam.entity.User; + +/** + * @date Jan 6, 2014 + * @author Andrey Kovalskiy + * + */ +public class SigninTag extends TagSupport { + private static final Logger LOGGER = Logger.getLogger(SigninTag.class); + private static final long serialVersionUID = 1L; + + @Override + public int doStartTag() throws JspException { + User user = (User) pageContext.getSession().getAttribute("user"); + String str; + if (user == null) { + str = "Sign in"; + } else { + str = "Sign out"; + } + try { + JspWriter out = pageContext.getOut(); + out.print(str); + } catch (IOException e) { + LOGGER.warn("Jsp write failed."); + } + return SKIP_BODY; + } + +} diff --git a/src/com/epam/devteam/tags/HeaderTag.java b/src/com/epam/devteam/tags/HeaderTag.java deleted file mode 100644 index 48ac19c..0000000 --- a/src/com/epam/devteam/tags/HeaderTag.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - */ -package com.epam.devteam.tags; - -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.tagext.TagSupport; - -/** - * @date Jan 3, 2014 - * @author anjey - * - */ -public class HeaderTag extends TagSupport{ - /** - * Serial version id. - */ - private static final long serialVersionUID = 1L; - - @Override - public int doStartTag() throws JspException { - - - return super.doStartTag(); - } - - -} From 6f8c930315ede33d74e16c5db9d15481e1930955 Mon Sep 17 00:00:00 2001 From: anjey Date: Tue, 7 Jan 2014 10:23:53 +0600 Subject: [PATCH 11/30] base directive was added --- WebContent/WEB-INF/jsp/cssimport.jsp | 17 ++++------ WebContent/WEB-INF/jsp/error.jsp | 1 + WebContent/WEB-INF/jsp/header.jsp | 4 +-- WebContent/WEB-INF/jsp/main.jsp | 31 +++++++------------ WebContent/WEB-INF/jsp/signin.jsp | 5 +-- WebContent/WEB-INF/tags/genericpage.tag | 21 +++++++++++++ WebContent/WEB-INF/tags/wrapper.tag | 6 ++++ WebContent/WEB-INF/tld/devteamtaglib.tld | 1 + WebContent/WEB-INF/web.xml | 5 --- .../devteam/action/ShowSigninPageAction.java | 1 - src/com/epam/devteam/servlet/Controller.java | 1 + src/com/epam/devteam/tag/SigninTag.java | 4 +-- 12 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 WebContent/WEB-INF/tags/genericpage.tag create mode 100644 WebContent/WEB-INF/tags/wrapper.tag diff --git a/WebContent/WEB-INF/jsp/cssimport.jsp b/WebContent/WEB-INF/jsp/cssimport.jsp index 0a19e0a..fb47a84 100644 --- a/WebContent/WEB-INF/jsp/cssimport.jsp +++ b/WebContent/WEB-INF/jsp/cssimport.jsp @@ -1,17 +1,12 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - - - - - - \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/error.jsp b/WebContent/WEB-INF/jsp/error.jsp index 4127baa..3a4f2f9 100644 --- a/WebContent/WEB-INF/jsp/error.jsp +++ b/WebContent/WEB-INF/jsp/error.jsp @@ -3,6 +3,7 @@ + Error <%@include file="cssimport.jsp"%> diff --git a/WebContent/WEB-INF/jsp/header.jsp b/WebContent/WEB-INF/jsp/header.jsp index 529f2da..26201e7 100644 --- a/WebContent/WEB-INF/jsp/header.jsp +++ b/WebContent/WEB-INF/jsp/header.jsp @@ -1,7 +1,7 @@ diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index 042f5b6..e04b198 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -1,22 +1,15 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> -<%@ taglib uri="/WEB-INF/tld/devteamtaglib.tld" prefix="tlib"%> +<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> - - - -Main -<%@include file="cssimport.jsp"%> - - - <%@include file="header.jsp"%> -
    -
    -

    Page body

    -
    -
    -
    - <%@include file="footer.jsp"%> - - \ No newline at end of file + + +

    Welcome

    +
    + + + + +

    Hi I'm the heart of the message

    +
    +
    \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/signin.jsp b/WebContent/WEB-INF/jsp/signin.jsp index b2bf4c6..06f5c1d 100644 --- a/WebContent/WEB-INF/jsp/signin.jsp +++ b/WebContent/WEB-INF/jsp/signin.jsp @@ -3,6 +3,7 @@ + Sign in <%@include file="cssimport.jsp"%> @@ -13,7 +14,7 @@
    -
    +
    Sign in
    @@ -23,7 +24,7 @@
    -
    +
    Create account
    diff --git a/WebContent/WEB-INF/tags/genericpage.tag b/WebContent/WEB-INF/tags/genericpage.tag new file mode 100644 index 0000000..d55ba50 --- /dev/null +++ b/WebContent/WEB-INF/tags/genericpage.tag @@ -0,0 +1,21 @@ +<%@ tag language="java" pageEncoding="UTF-8"%> +<%@ attribute name="header" fragment="true"%> +<%@ attribute name="footer" fragment="true"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + +<%@include file="/WEB-INF/jsp/cssimport.jsp"%> + + + +
    + +
    + + + diff --git a/WebContent/WEB-INF/tags/wrapper.tag b/WebContent/WEB-INF/tags/wrapper.tag new file mode 100644 index 0000000..84ee143 --- /dev/null +++ b/WebContent/WEB-INF/tags/wrapper.tag @@ -0,0 +1,6 @@ +<%@ tag language="java" pageEncoding="UTF-8"%> + + + + + diff --git a/WebContent/WEB-INF/tld/devteamtaglib.tld b/WebContent/WEB-INF/tld/devteamtaglib.tld index 650de19..f46d074 100644 --- a/WebContent/WEB-INF/tld/devteamtaglib.tld +++ b/WebContent/WEB-INF/tld/devteamtaglib.tld @@ -16,4 +16,5 @@ com.epam.devteam.tag.LogInfoTag empty + \ No newline at end of file diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index fa3f690..a3a3c43 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -5,12 +5,7 @@ id="WebApp_ID" version="3.0"> devteam - index.html - index.htm index.jsp - default.html - default.htm - default.jsp diff --git a/src/com/epam/devteam/action/ShowSigninPageAction.java b/src/com/epam/devteam/action/ShowSigninPageAction.java index 319ab38..5ff3c48 100644 --- a/src/com/epam/devteam/action/ShowSigninPageAction.java +++ b/src/com/epam/devteam/action/ShowSigninPageAction.java @@ -13,7 +13,6 @@ */ public class ShowSigninPageAction implements Action { - @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ActionException { diff --git a/src/com/epam/devteam/servlet/Controller.java b/src/com/epam/devteam/servlet/Controller.java index 276d2c0..4758207 100644 --- a/src/com/epam/devteam/servlet/Controller.java +++ b/src/com/epam/devteam/servlet/Controller.java @@ -63,4 +63,5 @@ protected void doAction(HttpServletRequest request, } } + } diff --git a/src/com/epam/devteam/tag/SigninTag.java b/src/com/epam/devteam/tag/SigninTag.java index 58c27b7..96870f1 100644 --- a/src/com/epam/devteam/tag/SigninTag.java +++ b/src/com/epam/devteam/tag/SigninTag.java @@ -27,9 +27,9 @@ public int doStartTag() throws JspException { User user = (User) pageContext.getSession().getAttribute("user"); String str; if (user == null) { - str = "Sign in"; + str = "Sign in"; } else { - str = "Sign out"; + str = "Sign out"; } try { JspWriter out = pageContext.getOut(); From 6ac2d4707b6734e354cf1979cee7d265b244997d Mon Sep 17 00:00:00 2001 From: anjey Date: Wed, 8 Jan 2014 01:48:08 +0600 Subject: [PATCH 12/30] css was changed at blueprint; login feature was added --- WebContent/WEB-INF/jsp/account.jsp | 9 + WebContent/WEB-INF/jsp/cssimport.jsp | 12 - WebContent/WEB-INF/jsp/error.jsp | 21 - WebContent/WEB-INF/jsp/footer.jsp | 14 - WebContent/WEB-INF/jsp/header.jsp | 29 - WebContent/WEB-INF/jsp/main.jsp | 54 +- WebContent/WEB-INF/jsp/request.jsp | 51 -- WebContent/WEB-INF/jsp/signin.jsp | 60 -- WebContent/WEB-INF/tags/account-manage.tag | 77 +++ WebContent/WEB-INF/tags/date.tag | 157 ++++++ WebContent/WEB-INF/tags/genericpage.tag | 45 +- .../WEB-INF/tags/{wrapper.tag => header.tag} | 8 +- WebContent/WEB-INF/tags/sidebar.tag | 4 + WebContent/WEB-INF/tags/signin.tag | 46 ++ WebContent/css/960.css | 491 ----------------- WebContent/css/grid.css | 491 ----------------- WebContent/css/ie.css | 31 -- WebContent/css/ie6.css | 31 -- WebContent/css/layout.css | 519 ------------------ WebContent/css/nav.css | 167 ------ WebContent/css/print.css | 29 + WebContent/css/reset.css | 53 -- WebContent/css/screen.css | 265 +++++++++ WebContent/css/text.css | 98 ---- .../epam/devteam/action/ActionFactory.java | 13 +- .../action/account/CreateAccountAction.java | 87 +++ .../ShowAccountPageAction.java} | 15 +- .../action/{ => account}/SigninAction.java | 40 +- .../action/{ => account}/SignoutAction.java | 5 +- .../UpdateAccountAction.java} | 43 +- .../dao/impl/PostgresqlCustomerDao.java | 75 ++- src/com/epam/devteam/entity/Customer.java | 11 +- src/com/epam/devteam/entity/Employee.java | 11 +- src/com/epam/devteam/entity/User.java | 27 +- src/com/epam/devteam/servlet/Controller.java | 2 +- 35 files changed, 923 insertions(+), 2168 deletions(-) create mode 100644 WebContent/WEB-INF/jsp/account.jsp delete mode 100644 WebContent/WEB-INF/jsp/cssimport.jsp delete mode 100644 WebContent/WEB-INF/jsp/error.jsp delete mode 100644 WebContent/WEB-INF/jsp/footer.jsp delete mode 100644 WebContent/WEB-INF/jsp/header.jsp delete mode 100644 WebContent/WEB-INF/jsp/request.jsp delete mode 100644 WebContent/WEB-INF/jsp/signin.jsp create mode 100644 WebContent/WEB-INF/tags/account-manage.tag create mode 100644 WebContent/WEB-INF/tags/date.tag rename WebContent/WEB-INF/tags/{wrapper.tag => header.tag} (51%) create mode 100644 WebContent/WEB-INF/tags/sidebar.tag create mode 100644 WebContent/WEB-INF/tags/signin.tag delete mode 100644 WebContent/css/960.css delete mode 100644 WebContent/css/grid.css delete mode 100644 WebContent/css/ie.css delete mode 100644 WebContent/css/ie6.css delete mode 100644 WebContent/css/layout.css delete mode 100644 WebContent/css/nav.css create mode 100644 WebContent/css/print.css delete mode 100644 WebContent/css/reset.css create mode 100644 WebContent/css/screen.css delete mode 100644 WebContent/css/text.css create mode 100644 src/com/epam/devteam/action/account/CreateAccountAction.java rename src/com/epam/devteam/action/{ShowSigninPageAction.java => account/ShowAccountPageAction.java} (51%) rename src/com/epam/devteam/action/{ => account}/SigninAction.java (55%) rename src/com/epam/devteam/action/{ => account}/SignoutAction.java (75%) rename src/com/epam/devteam/action/{CreateAccountAction.java => account/UpdateAccountAction.java} (51%) diff --git a/WebContent/WEB-INF/jsp/account.jsp b/WebContent/WEB-INF/jsp/account.jsp new file mode 100644 index 0000000..8358897 --- /dev/null +++ b/WebContent/WEB-INF/jsp/account.jsp @@ -0,0 +1,9 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + +<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%> + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/cssimport.jsp b/WebContent/WEB-INF/jsp/cssimport.jsp deleted file mode 100644 index fb47a84..0000000 --- a/WebContent/WEB-INF/jsp/cssimport.jsp +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/WebContent/WEB-INF/jsp/error.jsp b/WebContent/WEB-INF/jsp/error.jsp deleted file mode 100644 index 3a4f2f9..0000000 --- a/WebContent/WEB-INF/jsp/error.jsp +++ /dev/null @@ -1,21 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8" errorPage="true"%> - - - - - -Error -<%@include file="cssimport.jsp"%> - - - <%@include file="header.jsp"%> -
    -
    -

    Error!

    -
    -
    -
    - <%@include file="footer.jsp"%> - - \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/footer.jsp b/WebContent/WEB-INF/jsp/footer.jsp deleted file mode 100644 index d080f45..0000000 --- a/WebContent/WEB-INF/jsp/footer.jsp +++ /dev/null @@ -1,14 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/header.jsp b/WebContent/WEB-INF/jsp/header.jsp deleted file mode 100644 index 26201e7..0000000 --- a/WebContent/WEB-INF/jsp/header.jsp +++ /dev/null @@ -1,29 +0,0 @@ - -
    diff --git a/WebContent/WEB-INF/jsp/main.jsp b/WebContent/WEB-INF/jsp/main.jsp index e04b198..ccd7190 100644 --- a/WebContent/WEB-INF/jsp/main.jsp +++ b/WebContent/WEB-INF/jsp/main.jsp @@ -1,15 +1,47 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> - - -

    Welcome

    -
    - - - - -

    Hi I'm the heart of the message

    -
    +<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%> + + +

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus + sem est, bibendum ac purus sit amet, aliquam bibendum mi. Sed feugiat + dapibus nibh quis egestas. Sed dapibus velit vestibulum eros mattis + sodales. Aenean diam ante, porta eu sem ut, sagittis laoreet ante. + Pellentesque urna nibh, blandit nec odio iaculis, blandit semper + turpis. Pellentesque eu augue ullamcorper, adipiscing tortor ut, + vestibulum purus. Fusce consectetur sollicitudin nisi sed ultricies. + Quisque vel diam et dolor placerat sagittis quis eget purus. Praesent + magna tortor, viverra in semper non, viverra ac dui. Donec at quam + ipsum. Nunc congue, urna nec pretium pellentesque, magna felis + elementum libero, ac venenatis purus nunc in odio. Morbi vel dui + rutrum eros placerat dapibus eu quis dui. Quisque egestas vitae est + vel semper. Etiam mattis vulputate nibh. Curabitur in risus gravida, + interdum metus id, accumsan mauris. Integer consectetur, magna eu + venenatis varius, ante lorem tincidunt nisl, sed ornare nibh mauris + non quam. Nulla aliquet sit amet ipsum eget cursus. Cras id massa mi. + Maecenas eget nisl vel velit ultrices tempor ut vel mauris. Vivamus + sem tellus, semper sed scelerisque in, porta a odio. Sed porttitor + urna et felis posuere volutpat. Suspendisse luctus, lorem non porta + sodales, enim ipsum iaculis tortor, volutpat faucibus justo elit id + orci. Suspendisse potenti. Curabitur sed condimentum tortor, nec + molestie orci. Morbi a bibendum sapien. Nunc eu tempus purus, vel + ullamcorper erat. Nullam eget metus lobortis, vehicula lorem sed, + dignissim purus. Integer non luctus metus. Nulla facilisi. Nulla + tempus eget purus sed cursus. Aenean sed purus magna. Mauris porta mi + non ipsum cursus, sed consectetur quam volutpat. Fusce et suscipit + libero. Duis vel dui varius, venenatis risus ac, sollicitudin est. + Nullam pharetra a neque vel rutrum. Pellentesque habitant morbi + tristique senectus et netus et malesuada fames ac turpis egestas. + Morbi quis purus vel felis blandit lobortis. Maecenas dignissim + venenatis lorem. Vivamus hendrerit rhoncus dui, a placerat erat + aliquet a. Vivamus cursus, velit at consectetur faucibus, leo purus + laoreet arcu, ut aliquet risus metus at ipsum. In quam nisl, mollis ut + lacinia nec, pretium eget mauris. Nulla aliquam blandit arcu, ac + porttitor mi pulvinar vitae. Donec velit nibh, tempus eget nisi sit + amet, pharetra sollicitudin metus. In ligula felis, sodales ac viverra + sit amet, feugiat nec urna. Morbi vel est porttitor, pellentesque diam + vel, posuere nulla. Donec consectetur quam quis fringilla semper. + Curabitur tempor convallis lacus, eu vestibulum sem rutrum id.

    +
    \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/request.jsp b/WebContent/WEB-INF/jsp/request.jsp deleted file mode 100644 index 1a00c47..0000000 --- a/WebContent/WEB-INF/jsp/request.jsp +++ /dev/null @@ -1,51 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - -Online Request -<%@include file="cssimport.jsp"%> - - - <%@include file="header.jsp"%> -
    -
    - -
    -
    -
    - -
    - Request - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    - -
    -
    -
    -
    -
    - <%@include file="footer.jsp"%> - - \ No newline at end of file diff --git a/WebContent/WEB-INF/jsp/signin.jsp b/WebContent/WEB-INF/jsp/signin.jsp deleted file mode 100644 index 06f5c1d..0000000 --- a/WebContent/WEB-INF/jsp/signin.jsp +++ /dev/null @@ -1,60 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - - -Sign in -<%@include file="cssimport.jsp"%> - - - <%@include file="header.jsp"%> -
    -
    -
    -
    -
    -
    - Sign in -
    -
    -
    -
    - -
    -
    -
    -
    - Create account -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    - <%@include file="footer.jsp"%> - - \ No newline at end of file diff --git a/WebContent/WEB-INF/tags/account-manage.tag b/WebContent/WEB-INF/tags/account-manage.tag new file mode 100644 index 0000000..d35984b --- /dev/null +++ b/WebContent/WEB-INF/tags/account-manage.tag @@ -0,0 +1,77 @@ +<%@ tag language="java" pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%> +
    + + <%=session.getAttribute("accountError")%> + + + <%=session.getAttribute("message")%> + + + +
    +
    + + User* + +
    +

    + +

    +

    + +

    +

    + +

    + +
    +
    +
    +
    + +
    +
    + + Name* + +
    +
    + +
    +
    + +
    +
    +
    +
    + + Company & Position* + +
    + +
    +
    + +
    +
    +
    + + Address & Phone* + +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    +
    diff --git a/WebContent/WEB-INF/tags/date.tag b/WebContent/WEB-INF/tags/date.tag new file mode 100644 index 0000000..1fc7d1e --- /dev/null +++ b/WebContent/WEB-INF/tags/date.tag @@ -0,0 +1,157 @@ +<%@ tag language="java" pageEncoding="UTF-8"%> + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/tags/genericpage.tag b/WebContent/WEB-INF/tags/genericpage.tag index d55ba50..bab7531 100644 --- a/WebContent/WEB-INF/tags/genericpage.tag +++ b/WebContent/WEB-INF/tags/genericpage.tag @@ -1,21 +1,44 @@ <%@ tag language="java" pageEncoding="UTF-8"%> -<%@ attribute name="header" fragment="true"%> -<%@ attribute name="footer" fragment="true"%> +<%@ attribute name="sidebar" required="true"%> +<%@ attribute name="title" required="true"%> +<%@ attribute name="body" fragment="true"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%> +${title} -<%@include file="/WEB-INF/jsp/cssimport.jsp"%> + + - -
    - -
    -
    \ No newline at end of file diff --git a/WebContent/WEB-INF/tags/date.tag b/WebContent/WEB-INF/tags/date.tag index 1fc7d1e..2423c1f 100644 --- a/WebContent/WEB-INF/tags/date.tag +++ b/WebContent/WEB-INF/tags/date.tag @@ -1,37 +1,38 @@ <%@ tag language="java" pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + +
    diff --git a/WebContent/WEB-INF/tags/genericpage.tag b/WebContent/WEB-INF/tags/genericpage.tag index cbb3409..86ee389 100644 --- a/WebContent/WEB-INF/tags/genericpage.tag +++ b/WebContent/WEB-INF/tags/genericpage.tag @@ -2,9 +2,11 @@ <%@ attribute name="sidebar" required="true"%> <%@ attribute name="title" required="true"%> <%@ attribute name="body" fragment="true"%> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="t" tagdir="/WEB-INF/tags"%> - +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + ${title} @@ -14,9 +16,9 @@ media="print"> -
    +
    -