diff --git a/LegoHouseDB.sql b/LegoHouseDB.sql new file mode 100644 index 0000000..51c6d3d --- /dev/null +++ b/LegoHouseDB.sql @@ -0,0 +1,87 @@ +CREATE DATABASE IF NOT EXISTS `LegoDB` /*!40100 DEFAULT CHARACTER SET latin1 */; +USE `LegoDB`; +-- MySQL dump 10.16 Distrib 10.1.26-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: localhost Database: LegoDB +-- ------------------------------------------------------ +-- Server version 5.7.21-0ubuntu0.16.04.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `Orders` +-- + +DROP TABLE IF EXISTS `Orders`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Orders` ( + `Order_Id` int(11) NOT NULL AUTO_INCREMENT, + `Length` int(11) NOT NULL, + `Width` int(11) NOT NULL, + `Height` int(11) NOT NULL, + `User_Id` int(11) NOT NULL, + `Status` varchar(15) NOT NULL DEFAULT 'Pending', + PRIMARY KEY (`Order_Id`), + UNIQUE KEY `Orders_UNIQUE` (`Order_Id`), + KEY `fk_Users_idx` (`User_Id`), + CONSTRAINT `fk_Users_Id` FOREIGN KEY (`User_Id`) REFERENCES `Users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `Orders` +-- + +LOCK TABLES `Orders` WRITE; +/*!40000 ALTER TABLE `Orders` DISABLE KEYS */; +INSERT INTO `Orders` VALUES (1,10,10,10,1,'Afsendt'),(2,20,20,20,1,'Afsendt'),(3,30,30,30,2,'Afsendt'),(21,20,25,10,1,'Pending'),(22,23,34,5,1,'Afsendt'),(23,40,30,10,6,'Pending'),(24,20,15,15,1,'Pending'); +/*!40000 ALTER TABLE `Orders` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `Users` +-- + +DROP TABLE IF EXISTS `Users`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `email` varchar(90) NOT NULL, + `password` varchar(45) NOT NULL, + `role` varchar(20) NOT NULL DEFAULT 'customer', + PRIMARY KEY (`id`), + UNIQUE KEY `email_UNIQUE` (`email`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `Users` +-- + +LOCK TABLES `Users` WRITE; +/*!40000 ALTER TABLE `Users` DISABLE KEYS */; +INSERT INTO `Users` VALUES (1,'jens@somewhere.com','jensen','customer'),(2,'ken@somewhere.com','kensen','customer'),(3,'robin@somewhere.com','batman','employee'),(4,'someone@nowhere.com','sesam','customer'),(6,'muller4681@hotmail.com','246Hjalmar','customer'); +/*!40000 ALTER TABLE `Users` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2018-03-27 17:24:23 diff --git a/pom.xml b/pom.xml index d0d0ff8..9b8d9be 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,11 @@ 4.0.0 kasper.osterbye - LogInSample + LegoHouse 0.1-Test war - LogInSample + LegoHouse ${project.build.directory}/endorsed diff --git a/src/main/java/DBAccess/Connector.java b/src/main/java/DBAccess/Connector.java index 87e4d57..ec57d61 100644 --- a/src/main/java/DBAccess/Connector.java +++ b/src/main/java/DBAccess/Connector.java @@ -11,9 +11,10 @@ */ public class Connector { - private static final String URL = "jdbc:mysql://46.101.253.149:3306/useradmin"; - private static final String USERNAME = "doorkeeper"; - private static final String PASSWORD = "bank3*andyouarein"; + //private static final String URL = "jdbc:mysql://46.101.253.149:3306/useradmin"; + private static final String URL = "jdbc:mysql://138.68.103.105:3306/LegoDB?autoReconnect=true&serverTimezone=CET"; + private static final String USERNAME = "legoboi"; + private static final String PASSWORD = "lego"; private static Connection singleton; diff --git a/src/main/java/DBAccess/OrderMapper.java b/src/main/java/DBAccess/OrderMapper.java new file mode 100644 index 0000000..e75664a --- /dev/null +++ b/src/main/java/DBAccess/OrderMapper.java @@ -0,0 +1,127 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package DBAccess; + +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import FunctionLayer.User; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +/** + * + * @author juanni420 + */ +public class OrderMapper { + + public static ArrayList getOrders(int userId) throws OrderException { + ArrayList orderList = new ArrayList<>(); + try { + Connection con = Connector.connection(); + String SQL = "SELECT Orders.Order_Id, Orders.Length, Orders.Width, " + + "Orders.Height, Orders.Status FROM LegoDB.Orders" + + " inner join LegoDB.Users on LegoDB.Orders.User_Id = LegoDB.Users.id " + + "where Orders.User_Id =? order by Orders.Order_Id"; + PreparedStatement ps = con.prepareStatement(SQL); + ps.setInt(1, userId); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + int id = rs.getInt("Order_Id"); + int length = rs.getInt("length"); + int width = rs.getInt("width"); + int height = rs.getInt("height"); + String status = rs.getString("status"); + OrderEntity order = new OrderEntity(id, height, length, width, status); + orderList.add(order); + } + return orderList; + } catch (ClassNotFoundException | SQLException ex) { + throw new OrderException(ex.getMessage()); + } + } + + public static ArrayList getEmployeeOrders() throws OrderException { + ArrayList orderList = new ArrayList<>(); + try { + Connection con = Connector.connection(); + String SQL = "SELECT Orders.Order_Id, Orders.Height, Orders.Length, " + + "Orders.Width, Orders.Status, Users.email FROM LegoDB.Orders" + + " inner join LegoDB.Users on LegoDB.Orders.User_Id = LegoDB.Users.id order by Orders.Order_Id;"; + PreparedStatement ps = con.prepareStatement(SQL); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + int id = rs.getInt("Order_Id"); + int width = rs.getInt("width"); + int length = rs.getInt("length"); + int height = rs.getInt("height"); + String status = rs.getString("status"); + String email = rs.getString("email"); + OrderEntity order = new OrderEntity(id, height, length, width, status, email); + orderList.add(order); + } + return orderList; + } catch (ClassNotFoundException | SQLException ex) { + throw new OrderException(ex.getMessage()); + } + } + + public static OrderEntity getOrder(int orderId) throws OrderException { + OrderEntity order = null; + try { + Connection con = Connector.connection(); + String SQL = "SELECT Orders.Order_Id, Orders.Length, Orders.Width, " + + "Orders.Height FROM LegoDB.Orders where Orders.Order_Id =?;"; + PreparedStatement ps = con.prepareStatement(SQL); + ps.setInt(1, orderId); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + int length = rs.getInt("length"); + int width = rs.getInt("width"); + int height = rs.getInt("height"); + order = new OrderEntity(height, length, width); + } + return order; + } catch (ClassNotFoundException | SQLException ex) { + throw new OrderException(ex.getMessage()); + } + } + + public static boolean changeStatus(int orderId) throws OrderException { + try { + Connection con = Connector.connection(); + String SQL = "UPDATE LegoDB.Orders SET Orders.status = 'Afsendt' " + + "where Orders.Order_Id =?"; + PreparedStatement ps = con.prepareStatement(SQL); + ps.setInt(1, orderId); + ps.executeUpdate(); + return true; + } catch (ClassNotFoundException | SQLException ex) { + throw new OrderException(ex.getMessage()); + } + } + + public static boolean createOrder(int width, int length, int height, int userId) throws OrderException { + try { + Connection con = Connector.connection(); + String SQL = "INSERT INTO Orders (length, width, height, user_id) VALUES (?, ?, ?, ?)"; + PreparedStatement ps = con.prepareStatement(SQL); + ps.setInt(1, length); + ps.setInt(2, width); + ps.setInt(3, height); + ps.setInt(4, userId); + ps.executeUpdate(); + return true; + } catch (ClassNotFoundException | SQLException ex) { + throw new OrderException(ex.getMessage()); + } + } + +} diff --git a/src/main/java/DBAccess/dbInit.sql b/src/main/java/DBAccess/dbInit.sql index bc626cd..1107d8d 100644 --- a/src/main/java/DBAccess/dbInit.sql +++ b/src/main/java/DBAccess/dbInit.sql @@ -1,10 +1,10 @@ -CREATE DATABASE IF NOT EXISTS `useradmin`; +CREATE DATABASE IF NOT EXISTS `LegoDB`; -USE `useradmin`; +USE `LegoDB`; -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `email` varchar(90) NOT NULL, `password` varchar(45) NOT NULL, @@ -13,8 +13,8 @@ CREATE TABLE `user` ( UNIQUE KEY `email_UNIQUE` (`email`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -LOCK TABLES `user` WRITE; -INSERT INTO `user` VALUES +LOCK TABLES `users` WRITE; +INSERT INTO `users` VALUES (1,'jens@somewhere.com','jensen','customer'), (2,'ken@somewhere.com','kensen','customer'), (3,'robin@somewhere.com','batman','employee'); diff --git a/src/main/java/FunctionLayer/Brick.java b/src/main/java/FunctionLayer/Brick.java new file mode 100644 index 0000000..04d81ae --- /dev/null +++ b/src/main/java/FunctionLayer/Brick.java @@ -0,0 +1,64 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package FunctionLayer; + +/** + * + * @author juanni420 + */ +public class Brick { + + int width,length, height; + String name; + + public Brick(int x, int y, String name) { + this.width = x; + this.length = y; + this.name = name; + } + + public Brick(int width, int length, int height, String name) { + this.width = width; + this.length = length; + this.height = height; + this.name = name; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + +} diff --git a/src/main/java/FunctionLayer/LogicFacade.java b/src/main/java/FunctionLayer/LogicFacade.java index fbf0c2d..9e14164 100644 --- a/src/main/java/FunctionLayer/LogicFacade.java +++ b/src/main/java/FunctionLayer/LogicFacade.java @@ -1,21 +1,348 @@ package FunctionLayer; +import DBAccess.OrderMapper; import DBAccess.UserMapper; +import java.util.ArrayList; /** * The purpose of LogicFacade is to... + * * @author kasper */ public class LogicFacade { - public static User login( String email, String password ) throws LoginSampleException { - return UserMapper.login( email, password ); - } + public static User login(String email, String password) throws LoginSampleException { + return UserMapper.login(email, password); + } - public static User createUser( String email, String password ) throws LoginSampleException { + public static User createUser(String email, String password) throws LoginSampleException { User user = new User(email, password, "customer"); - UserMapper.createUser( user ); + UserMapper.createUser(user); return user; } + public static ArrayList getOrders(int userId) throws OrderException { + return OrderMapper.getOrders(userId); + } + + public static ArrayList getEmployeeOrders() throws OrderException { + return OrderMapper.getEmployeeOrders(); + } + + public static OrderEntity getOrder(int orderId) throws OrderException { + return OrderMapper.getOrder(orderId); + } + + public static boolean changeStatus(int orderId) throws OrderException { + return OrderMapper.changeStatus(orderId); + } + + public static boolean createOrder(int width, int length, int height, int userId) throws OrderException { + return OrderMapper.createOrder(width, length, height, userId); + } + + public static ArrayList getBricks(int width, int length, int height) throws LoginSampleException { + ArrayList brickList = new ArrayList<>(); + ArrayList sidesList = new ArrayList<>(); + + Brick Onex2 = new Brick(1, 2, "1x2"); + Brick Twox2 = new Brick(2, 2, "2x2"); + Brick Twox4 = new Brick(2, 4, "2x4"); + Brick door = new Brick(1, 2, 3, "Door"); + Brick window = new Brick(1, 2, 1, "Window"); + + int sidea = length; + int sideb = width - 4; + int longest, shortest; + + //figures out which side is longest so i know where to add the door and window + if (sidea > sideb) { + longest = sidea; + shortest = sideb; + } else { + longest = sideb; + shortest = sidea; + } + + //calculates bricks for sidea and sidec + //i find out if the entire length can be filled with 2x4's + int remaining = longest % Twox4.getLength(); + if (remaining == 0) { + //finds out how manybricks are needed + int numBricks = longest / Twox4.getLength(); + //if theres need an od number of bricks i fill the side with + //as many 2x4 as possible -1 and then use 2x2 to fill the rest + if (numBricks % 2 != 0) { + //fills sideA + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + brickList.add(door); + sidesList.add(new Side(brickList, "sideA")); + brickList = new ArrayList(); + //fills sideC + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + brickList.add(window); + sidesList.add(new Side(brickList, "sideC")); + brickList = new ArrayList(); + } else { + //if theres needed an even number of bricks i fill half the length with 2x4's + //and the rest with 2x2's + //fills sideA + int numBricks2 = numBricks / 2; + for (int i = 0; i < numBricks2; i++) { + brickList.add(Twox4); + } + for (int i = 0; i < (numBricks2 * 2) - 1; i++) { + brickList.add(Twox2); + } + brickList.add(Twox2); + brickList.add(door); + sidesList.add(new Side(brickList, "sideA")); + brickList = new ArrayList(); + //fills sideC + for (int i = 0; i < numBricks2; i++) { + brickList.add(Twox4); + } + for (int i = 0; i < (numBricks2 * 2); i++) { + brickList.add(Twox2); + } + brickList.add(Twox2); + brickList.add(window); + sidesList.add(new Side(brickList, "sideC")); + brickList = new ArrayList(); + } + + //if the entire length can't be filled with 2x4's + //here there is 1 dot left so i fill the side with as many + //2x4's as possible and a single 1x2 + } else if (remaining == 1) { + //fills sideA + int numBricks = longest / Twox4.getLength(); + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + brickList.add(Onex2); + brickList.add(door); + sidesList.add(new Side(brickList, "sideA")); + brickList = new ArrayList(); + + //does it again for sideC + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + brickList.add(Onex2); + brickList.add(window); + sidesList.add(new Side(brickList, "sideC")); + brickList = new ArrayList(); + + //here i fill the side with as many 2x4's as possible and a single 2x2 + } else if (remaining == 2) { + //fills sideA + int numBricks = longest / Twox4.getLength(); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(door); + sidesList.add(new Side(brickList, "sideA")); + brickList = new ArrayList(); + //fills sideC + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(window); + sidesList.add(new Side(brickList, "sideC")); + brickList = new ArrayList(); + + //here i fill the side with as many 2x4's as possible, and one 2x2 and 1x2 + } else if (remaining == 3) { + //fills sideA + int numBricks = longest / Twox4.getLength(); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + brickList.add(Onex2); + brickList.add(Twox2); + brickList.add(door); + sidesList.add(new Side(brickList, "sideA")); + brickList = new ArrayList(); + //fills sideC + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + brickList.add(Onex2); + brickList.add(Twox2); + brickList.add(window); + sidesList.add(new Side(brickList, "sideC")); + brickList = new ArrayList(); + } + + //calculates bricks for sideb and sided + remaining = shortest % Twox4.getLength(); + if (remaining == 0) { + int numBricks = shortest / Twox4.getLength(); + if (numBricks % 2 != 0) { + //if there's needed 3 or more bricks for this side + //i fill it with 2x4's and 2x2's + if (numBricks >= 3) { + //fills sideB + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + //fills sideD + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox4); + } + brickList.add(Twox2); + brickList.add(Twox2); + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + + //if there's needed 2 or less bricks i fill the side with 2x2's and 1x2's + } else { + //fills sideB + numBricks = shortest / Twox2.getLength(); + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox2); + } + brickList.add(Onex2); + brickList.add(Onex2); + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + //fills sideD + for (int i = 0; i < numBricks - 1; i++) { + brickList.add(Twox2); + } + brickList.add(Onex2); + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + } + + } else { + //the same as above. If there's needed 2 or less bricks + //i fill the side with 2x2's and 1x2's + if (numBricks <= 2) { + //fills sideB + numBricks = shortest / Twox2.getLength(); + for (int i = 0; i < numBricks / 2; i++) { + brickList.add(Twox2); + } + for (int i = 0; i < numBricks; i++) { + brickList.add(Onex2); + } + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + //fills sideD + for (int i = 0; i < numBricks / 2; i++) { + brickList.add(Twox2); + } + for (int i = 0; i < numBricks; i++) { + brickList.add(Onex2); + } + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + //if there's neeeded 3 or more bricks i fill the side with 2x4's and 2x2's + } else { + //fills sideB + int numBricks2 = numBricks / 2; + for (int i = 0; i < numBricks2; i++) { + brickList.add(Twox4); + } + for (int i = 0; i < numBricks2 * 2; i++) { + brickList.add(Twox2); + } + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + //fills sideD + for (int i = 0; i < numBricks2; i++) { + brickList.add(Twox4); + } + for (int i = 0; i < numBricks2 * 2; i++) { + brickList.add(Twox2); + } + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + } + + } + //if the entire length can't be filled with 2x4's + //here there is 1 dot left so i fill the side with as many + //2x4's as possible and a single 1x2 + } else if (remaining == 1) { + //fills sideB + int numBricks = shortest / Twox4.getLength(); + brickList.add(Onex2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + + //fills sideD + brickList.add(Onex2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + + //here i fill the side with as many 2x4's as possible and a single 2x2 + } else if (remaining == 2) { + //fills sideB + int numBricks = shortest / Twox4.getLength(); + brickList.add(Twox2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + + //fills sideD + brickList.add(Twox2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + //here i fill the side with as many 2x4's as possible, and one 2x2 and 1x2 + } else if (remaining == 3) { + //fills sideB + int numBricks = shortest / Twox4.getLength(); + brickList.add(Onex2); + brickList.add(Twox2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideB")); + brickList = new ArrayList(); + + //fills sideD + brickList.add(Onex2); + brickList.add(Twox2); + for (int i = 0; i < numBricks; i++) { + brickList.add(Twox4); + } + sidesList.add(new Side(brickList, "sideD")); + brickList = new ArrayList(); + } + + return sidesList; + } + } diff --git a/src/main/java/FunctionLayer/OrderEntity.java b/src/main/java/FunctionLayer/OrderEntity.java new file mode 100644 index 0000000..3524530 --- /dev/null +++ b/src/main/java/FunctionLayer/OrderEntity.java @@ -0,0 +1,93 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package FunctionLayer; + +/** + * + * @author juanni420 + */ +public class OrderEntity { + + public OrderEntity(int id, int height, int length, int width, String status) { + this.id = id; + this.height = height; + this.length = length; + this.width = width; + this.status = status; + } + + public OrderEntity(int id, int height, int length, int width, String status, String email) { + this.id = id; + this.height = height; + this.length = length; + this.width = width; + this.status = status; + this.email = email; + } + + public OrderEntity(int height, int length, int width) { + this.height = height; + this.length = length; + this.width = width; + } + + private int id, height, length, width; + private String status, email; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Override + public String toString() { + return "OrderEntity{" + "id=" + id + ", height=" + height + ", length=" + length + ", width=" + width + ", status=" + status + ", email=" + email + '}'; + } + +} diff --git a/src/main/java/FunctionLayer/OrderException.java b/src/main/java/FunctionLayer/OrderException.java new file mode 100644 index 0000000..451c3f2 --- /dev/null +++ b/src/main/java/FunctionLayer/OrderException.java @@ -0,0 +1,19 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package FunctionLayer; + +/** + * + * @author juanni420 + */ +public class OrderException extends Exception{ + + public OrderException(String msg) { + super(msg); + } + + +} diff --git a/src/main/java/FunctionLayer/Side.java b/src/main/java/FunctionLayer/Side.java new file mode 100644 index 0000000..b6b9579 --- /dev/null +++ b/src/main/java/FunctionLayer/Side.java @@ -0,0 +1,40 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package FunctionLayer; + +import java.util.ArrayList; + +/** + * + * @author juanni420 + */ +public class Side { + ArrayList bricks; + String name; + + public Side(ArrayList bricks, String name) { + this.bricks = bricks; + this.name = name; + } + + public ArrayList getBricks() { + return bricks; + } + + public void setBricks(ArrayList bricks) { + this.bricks = bricks; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + +} diff --git a/src/main/java/PresentationLayer/Command.java b/src/main/java/PresentationLayer/Command.java index b1cc93a..9b5378a 100644 --- a/src/main/java/PresentationLayer/Command.java +++ b/src/main/java/PresentationLayer/Command.java @@ -1,6 +1,7 @@ package PresentationLayer; import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderException; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -11,8 +12,20 @@ abstract class Command { private static void initCommands() { commands = new HashMap<>(); - commands.put( "login", new Login() ); + commands.put( "Login", new Login() ); commands.put( "register", new Register() ); + commands.put( "help", new Help() ); + commands.put( "order", new Order() ); + commands.put( "customer", new Customer() ); + commands.put( "employee", new Employee() ); + commands.put( "orders", new Orders() ); + commands.put( "emporders", new EmpOrders() ); + commands.put( "changeStatus", new changeStatus() ); + commands.put( "createOrder", new createOrder() ); + commands.put( "logout", new logout() ); + commands.put( "loginpage", new loginPage() ); + commands.put( "confirmOrder", new confirmOrder() ); + commands.put( "viewPieces", new viewPieces() ); } static Command from( HttpServletRequest request ) { @@ -24,6 +37,6 @@ static Command from( HttpServletRequest request ) { } abstract String execute( HttpServletRequest request, HttpServletResponse response ) - throws LoginSampleException; + throws LoginSampleException, OrderException; } diff --git a/src/main/java/PresentationLayer/Customer.java b/src/main/java/PresentationLayer/Customer.java new file mode 100644 index 0000000..118018a --- /dev/null +++ b/src/main/java/PresentationLayer/Customer.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.User; +import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class Customer extends Command { + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + return "customerpage"; + } + +} diff --git a/src/main/java/PresentationLayer/EmpOrders.java b/src/main/java/PresentationLayer/EmpOrders.java new file mode 100644 index 0000000..79b79f3 --- /dev/null +++ b/src/main/java/PresentationLayer/EmpOrders.java @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import FunctionLayer.User; +import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class EmpOrders extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException , OrderException{ + ArrayList orderList = new ArrayList<>(); + HttpSession session = request.getSession(); + orderList = LogicFacade.getEmployeeOrders(); + session.setAttribute("emporders", orderList); + return "employeeOrders"; + } + +} diff --git a/src/main/java/PresentationLayer/Employee.java b/src/main/java/PresentationLayer/Employee.java new file mode 100644 index 0000000..3f8c240 --- /dev/null +++ b/src/main/java/PresentationLayer/Employee.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LoginSampleException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author juanni420 + */ +public class Employee extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + return "employeepage"; + } + +} diff --git a/src/main/java/PresentationLayer/FrontController.java b/src/main/java/PresentationLayer/FrontController.java index 9fc03e9..4cf78a0 100644 --- a/src/main/java/PresentationLayer/FrontController.java +++ b/src/main/java/PresentationLayer/FrontController.java @@ -6,74 +6,92 @@ package PresentationLayer; import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderException; import java.io.IOException; +import static java.lang.System.out; 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 javax.servlet.http.HttpSession; /** - - @author kasper + * + * @author kasper */ -@WebServlet( name = "FrontController", urlPatterns = { "/FrontController" } ) +@WebServlet(name = "FrontController", urlPatterns = {"/FrontController"}) public class FrontController extends HttpServlet { /** - Processes requests for both HTTP GET and POST - methods. - - @param request servlet request - @param response servlet response - @throws ServletException if a servlet-specific error occurs - @throws IOException if an I/O error occurs + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs */ - protected void processRequest( HttpServletRequest request, HttpServletResponse response ) + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { - Command action = Command.from( request ); - String view = action.execute( request, response ); - request.getRequestDispatcher( "/WEB-INF/" + view + ".jsp" ).forward( request, response ); - } catch ( LoginSampleException ex ) { - request.setAttribute( "error", ex.getMessage() ); - request.getRequestDispatcher( "index.jsp" ).forward( request, response ); + /*HttpSession session = request.getSession(); + String msg = (String) session.getAttribute("msg"); + if (msg != null) { + out.println(""); + session.setAttribute("msg", null); + }*/ + + Command action = Command.from(request); + String view = action.execute(request, response); + request.getRequestDispatcher("/WEB-INF/" + view + ".jsp").forward(request, response); + } catch (LoginSampleException ex) { + request.setAttribute("error", ex.getMessage()); + request.getRequestDispatcher("index.jsp").forward(request, response); + } + catch (OrderException oex) { + request.setAttribute("error",oex.getMessage()); + request.getRequestDispatcher("index.jsp").forward(request, response); } + } // /** - Handles the HTTP GET method. - - @param request servlet request - @param response servlet response - @throws ServletException if a servlet-specific error occurs - @throws IOException if an I/O error occurs + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs */ @Override - protected void doGet( HttpServletRequest request, HttpServletResponse response ) + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - processRequest( request, response ); + processRequest(request, response); } /** - Handles the HTTP POST method. - - @param request servlet request - @param response servlet response - @throws ServletException if a servlet-specific error occurs - @throws IOException if an I/O error occurs + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs */ @Override - protected void doPost( HttpServletRequest request, HttpServletResponse response ) + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - processRequest( request, response ); + processRequest(request, response); } /** - Returns a short description of the servlet. - - @return a String containing servlet description + * Returns a short description of the servlet. + * + * @return a String containing servlet description */ @Override public String getServletInfo() { diff --git a/src/main/java/PresentationLayer/Help.java b/src/main/java/PresentationLayer/Help.java new file mode 100644 index 0000000..a67f39e --- /dev/null +++ b/src/main/java/PresentationLayer/Help.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.User; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class Help extends Command { + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + return "help"; + } + +} diff --git a/src/main/java/PresentationLayer/Login.java b/src/main/java/PresentationLayer/Login.java index ffe06f5..f674697 100644 --- a/src/main/java/PresentationLayer/Login.java +++ b/src/main/java/PresentationLayer/Login.java @@ -9,7 +9,6 @@ /** The purpose of Login is to... - @author kasper */ public class Login extends Command { @@ -25,4 +24,4 @@ String execute( HttpServletRequest request, HttpServletResponse response ) throw return user.getRole() + "page"; } -} +} \ No newline at end of file diff --git a/src/main/java/PresentationLayer/Order.java b/src/main/java/PresentationLayer/Order.java new file mode 100644 index 0000000..1b2c4ad --- /dev/null +++ b/src/main/java/PresentationLayer/Order.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.User; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class Order extends Command { + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + return "order"; + } + +} diff --git a/src/main/java/PresentationLayer/Orders.java b/src/main/java/PresentationLayer/Orders.java new file mode 100644 index 0000000..8f51477 --- /dev/null +++ b/src/main/java/PresentationLayer/Orders.java @@ -0,0 +1,35 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import FunctionLayer.User; +import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class Orders extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException, OrderException { + ArrayList orderList = new ArrayList<>(); + HttpSession session = request.getSession(); + User user = (User) session.getAttribute("user"); + int userId = user.getId(); + orderList = LogicFacade.getOrders(userId); + session.setAttribute("orders", orderList); + return "orders"; + } + +} diff --git a/src/main/java/PresentationLayer/changeStatus.java b/src/main/java/PresentationLayer/changeStatus.java new file mode 100644 index 0000000..9aa6550 --- /dev/null +++ b/src/main/java/PresentationLayer/changeStatus.java @@ -0,0 +1,29 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import DBAccess.OrderMapper; +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author juanni420 + */ +public class changeStatus extends Command { + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException, OrderException { + int orderId = Integer.parseInt(request.getParameter("orderId")); + LogicFacade.changeStatus(orderId); + return "employeeOrders"; + } + +} diff --git a/src/main/java/PresentationLayer/confirmOrder.java b/src/main/java/PresentationLayer/confirmOrder.java new file mode 100644 index 0000000..ba64e30 --- /dev/null +++ b/src/main/java/PresentationLayer/confirmOrder.java @@ -0,0 +1,37 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.Side; +import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class confirmOrder extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + HttpSession session = request.getSession(); + int length = Integer.parseInt(request.getParameter("length")); + int width = Integer.parseInt(request.getParameter("width")); + int height = Integer.parseInt(request.getParameter("height")); + OrderEntity singleOrder = new OrderEntity(height, length, width); + session.setAttribute("singleOrder", singleOrder); + ArrayList sidesList = LogicFacade.getBricks(width, length, height); + session.setAttribute("sideList", sidesList); + + return "confirmOrder"; + } + +} diff --git a/src/main/java/PresentationLayer/createOrder.java b/src/main/java/PresentationLayer/createOrder.java new file mode 100644 index 0000000..59a5178 --- /dev/null +++ b/src/main/java/PresentationLayer/createOrder.java @@ -0,0 +1,36 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import FunctionLayer.User; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class createOrder extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException, OrderException { + HttpSession session = request.getSession(); + User user = (User) session.getAttribute("user"); + OrderEntity order = (OrderEntity) session.getAttribute("singleOrder"); + int userId = user.getId(); + int length = order.getLength(); + int width = order.getWidth(); + int height = order.getHeight(); + LogicFacade.createOrder(width, length, height, userId); + return user.getRole() + "page"; + } + +} diff --git a/src/main/java/PresentationLayer/loginPage.java b/src/main/java/PresentationLayer/loginPage.java new file mode 100644 index 0000000..e4d1483 --- /dev/null +++ b/src/main/java/PresentationLayer/loginPage.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LoginSampleException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author juanni420 + */ +public class loginPage extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + return "login"; + } + +} \ No newline at end of file diff --git a/src/main/java/PresentationLayer/logout.java b/src/main/java/PresentationLayer/logout.java new file mode 100644 index 0000000..ccc6f61 --- /dev/null +++ b/src/main/java/PresentationLayer/logout.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LoginSampleException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author juanni420 + */ +public class logout extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException { + request.getSession().invalidate(); + return "login"; + } + +} diff --git a/src/main/java/PresentationLayer/viewPieces.java b/src/main/java/PresentationLayer/viewPieces.java new file mode 100644 index 0000000..e32d742 --- /dev/null +++ b/src/main/java/PresentationLayer/viewPieces.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package PresentationLayer; + +import FunctionLayer.LogicFacade; +import FunctionLayer.LoginSampleException; +import FunctionLayer.OrderEntity; +import FunctionLayer.OrderException; +import FunctionLayer.Side; +import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author juanni420 + */ +public class viewPieces extends Command{ + + @Override + String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException, OrderException { + int orderId = Integer.parseInt(request.getParameter("orderId")); + HttpSession session = request.getSession(); + OrderEntity order = LogicFacade.getOrder(orderId); + int width = order.getWidth(); + int length = order.getLength(); + int height = order.getHeight(); + ArrayList sidesList = LogicFacade.getBricks(width, length, height); + session.setAttribute("sideList", sidesList); + session.setAttribute("piecesOrder", order); + return "viewPieces"; + } + +} diff --git a/src/main/webapp/WEB-INF/confirmOrder.jsp b/src/main/webapp/WEB-INF/confirmOrder.jsp new file mode 100644 index 0000000..2b3f58e --- /dev/null +++ b/src/main/webapp/WEB-INF/confirmOrder.jsp @@ -0,0 +1,96 @@ +<%-- + Document : confirmOrder + Created on : Mar 22, 2018, 1:13:20 PM + Author : juanni420 +--%> + +<%@page import="FunctionLayer.Brick"%> +<%@page import="FunctionLayer.Side"%> +<%@page import="java.util.ArrayList"%> +<%@page import="FunctionLayer.OrderEntity"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Confirm Order + + + + <%@include file="nav.jsp" %> + <% OrderEntity order = (OrderEntity) session.getAttribute("singleOrder"); + ArrayList sideList = (ArrayList) session.getAttribute("sideList");%> +

Confirm Order

+
+

Order

+ <%out.println("

Length: " + order.getLength() + + ", Width: " + order.getWidth() + ", Height: " + order.getHeight() + "

");%> +

The door and window are both 2 dots wide

+

The door is 3 bricks high; The window is 1 brick high.

+

If you'll notice am i only subtracting the door and window height from 2x2 bricks. + That's because both the window and door is 2 dots wide, so we've swapped 4 2x2 bricks in place for the door and window.

+

Styk liste

+ + + + + + + + + <% int brick1sum = 0, brick2sum = 0, brick3sum = 0; + int door = 0, window = 0, doorheight = 0, windowheight = 0; + for (Side side : sideList) { + int brick1 = 0, brick2 = 0, brick3 = 0; + door = 0; + window = 0; + out.println(""); + for (Brick brick : side.getBricks()) { + if (brick.getName().equals("1x2")) { + brick1++; + brick1sum++; + } + if (brick.getName().equals("2x2")) { + brick2++; + brick2sum++; + } + if (brick.getName().equals("2x4")) { + brick3++; + brick3sum++; + } + if (brick.getName().equals("Door")) { + door++; + doorheight = brick.getHeight(); + } + if (brick.getName().equals("Window")) { + window++; + windowheight = brick.getHeight(); + } + } + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + + } + %> + + + + + + + +
Side1x22x22x4DørVindue
" + side.getName() + "" + brick1 + "" + brick2 + "" + brick3 + "" + door + "" + window + "
(ialt x H) - dørH - vindueH<%= (brick1sum * order.getHeight())%><%= (brick2sum * order.getHeight() - doorheight - windowheight)%><%= (brick3sum * order.getHeight())%>
+
+ + +
+
+ + +
+
+ + diff --git a/src/main/webapp/WEB-INF/customerpage.jsp b/src/main/webapp/WEB-INF/customerpage.jsp index 3fea18d..e8ad0ef 100644 --- a/src/main/webapp/WEB-INF/customerpage.jsp +++ b/src/main/webapp/WEB-INF/customerpage.jsp @@ -4,15 +4,25 @@ Author : kasper --%> +<%@page import="java.util.ArrayList"%> +<%@page import="FunctionLayer.OrderEntity"%> +<%@page import="FunctionLayer.User"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> Customer home page + -

Hello <%=request.getParameter( "email" )%>

- You are now logged in as a customer of our wonderful site. + <%@include file="nav.jsp" %> + <% User user = (User) session.getAttribute("user");%> +

Hello <%= user.getEmail()%>

+
+

You are now logged in as a customer of our wonderful site.

+ Klik her får at komme til bestillingssiden + Klik her får at se dine bestillinger +
diff --git a/src/main/webapp/WEB-INF/employeeOrders.jsp b/src/main/webapp/WEB-INF/employeeOrders.jsp new file mode 100644 index 0000000..c03e3c8 --- /dev/null +++ b/src/main/webapp/WEB-INF/employeeOrders.jsp @@ -0,0 +1,52 @@ +<%-- + Document : employeeOrders + Created on : Mar 21, 2018, 7:36:41 PM + Author : juanni420 +--%> + +<%@page import="java.util.ArrayList"%> +<%@page import="FunctionLayer.OrderEntity"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Employee Orders Page + + + + <%@include file="nav.jsp" %> + <% ArrayList ordersList = (ArrayList) session.getAttribute("emporders"); + %> +

Here you can view all orders

+
+ <% for (OrderEntity order : ordersList) { + out.println("

Order Id: " + order.getId() + ", Length: " + order.getLength() + + ", Width: " + order.getWidth() + ", Height: " + order.getHeight() + + ", User Email: " + order.getEmail() + ", Status: " + order.getStatus() + "

"); + } + %> +

View pieces list of orders below

+
+ + + +
+

Change order status below

+
+ + + +
+ Refresh +
+ + diff --git a/src/main/webapp/WEB-INF/employeepage.jsp b/src/main/webapp/WEB-INF/employeepage.jsp index 573548c..d1d8573 100644 --- a/src/main/webapp/WEB-INF/employeepage.jsp +++ b/src/main/webapp/WEB-INF/employeepage.jsp @@ -4,16 +4,23 @@ Author : kasper --%> +<%@page import="FunctionLayer.User"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> Employee home page + - -

Hello <%=request.getParameter( "email")%>

- You are now logged in as a EMPLOYEE of our wonderful site. + <%@include file="nav.jsp" %> + <% User user = (User) session.getAttribute("user");%> +

Hello <%= user.getEmail()%>

+
+

You are now logged in as a EMPLOYEE of our wonderful site.

+ Klik her får at se alle bestillinger +
+ diff --git a/src/main/webapp/WEB-INF/help.jsp b/src/main/webapp/WEB-INF/help.jsp new file mode 100644 index 0000000..087e987 --- /dev/null +++ b/src/main/webapp/WEB-INF/help.jsp @@ -0,0 +1,25 @@ +<%-- + Document : help + Created on : Mar 19, 2018, 11:14:40 AM + Author : juanni420 +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Help + + + + <%@include file="nav.jsp" %> +

Sådan bestiller du et Lego hus

+
+

Du skal først og fremest logge ind på siden, og hvis ikke du har en bruger skal du oprette dig.
+ Klik på 'Order LegoHouse' oppe i menuen.
+ Når du så er på siden skal du bare indtaste en bredde, længde og højde af det hus du vil have.
+ Så udgiver vores system en liste af de klodser der skal bruges til at bygge huset.

+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/login.jsp b/src/main/webapp/WEB-INF/login.jsp new file mode 100644 index 0000000..4a89b42 --- /dev/null +++ b/src/main/webapp/WEB-INF/login.jsp @@ -0,0 +1,61 @@ +<%-- + Document : login + Created on : Mar 22, 2018, 8:38:17 AM + Author : juanni420 +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + + <%@include file="nav.jsp" %> +
+

Login Page

+ <% if (session.getAttribute("user") == null) { + %> + + + + + + +
Login +
+ + Email:
+ +
+ Password:
+ +
+ +
+
Or Register +
+ + Email:
+ +
+ Password:
+ +
+ Retype Password:
+ +
+ +
+
+ <% + } else { + out.println("

Du er logget ind og klar til at bestille Lego!

"); + }%> + + + Få hjælp til din bestilling +
+ + diff --git a/src/main/webapp/WEB-INF/nav.jsp b/src/main/webapp/WEB-INF/nav.jsp new file mode 100644 index 0000000..ea7c1a4 --- /dev/null +++ b/src/main/webapp/WEB-INF/nav.jsp @@ -0,0 +1,27 @@ +<%-- + Document : nav + Created on : Mar 21, 2018, 2:10:44 PM + Author : juanni420 +--%> + +<%@page import="FunctionLayer.User"%> + diff --git a/src/main/webapp/WEB-INF/order.jsp b/src/main/webapp/WEB-INF/order.jsp new file mode 100644 index 0000000..f6412a8 --- /dev/null +++ b/src/main/webapp/WEB-INF/order.jsp @@ -0,0 +1,39 @@ +<%-- + Document : order + Created on : Mar 21, 2018, 1:33:17 PM + Author : juanni420 +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Order Page + + + + <%@include file="nav.jsp" %> +

Welcome to the order page!

+ + + + +
Order +
+ + Length:
+ +
+ Width:
+ +
+ Height:
+ +
+ + +
+
+ + diff --git a/src/main/webapp/WEB-INF/orders.jsp b/src/main/webapp/WEB-INF/orders.jsp new file mode 100644 index 0000000..cacdfae --- /dev/null +++ b/src/main/webapp/WEB-INF/orders.jsp @@ -0,0 +1,42 @@ +<%-- + Document : orders + Created on : Mar 21, 2018, 7:05:52 PM + Author : juanni420 +--%> + +<%@page import="java.util.ArrayList"%> +<%@page import="FunctionLayer.OrderEntity"%> +<%@page import="FunctionLayer.User"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Orders Page + + + + + <%@include file="nav.jsp" %> + <% ArrayList ordersList = (ArrayList) session.getAttribute("orders");%> +

Here you can view your orders

+
+ <% for (OrderEntity order : ordersList) { + out.println("

Order Id: " + order.getId() + ", Length: " + order.getLength() + + ", Width: " + order.getWidth() + ", Height: " + order.getHeight() + + ", Status: " + order.getStatus() + "

"); + } + %> +

View pieces list of orders below

+
+ + + +
+
+ + diff --git a/src/main/webapp/WEB-INF/viewPieces.jsp b/src/main/webapp/WEB-INF/viewPieces.jsp new file mode 100644 index 0000000..6fdf678 --- /dev/null +++ b/src/main/webapp/WEB-INF/viewPieces.jsp @@ -0,0 +1,96 @@ +<%-- + Document : viewPieces + Created on : Mar 22, 2018, 2:09:59 PM + Author : juanni420 +--%> + +<%@page import="FunctionLayer.Brick"%> +<%@page import="FunctionLayer.Side"%> +<%@page import="java.util.ArrayList"%> +<%@page import="FunctionLayer.OrderEntity"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + View Pieces + + + <%@include file="nav.jsp" %> + <% OrderEntity order = (OrderEntity) session.getAttribute("piecesOrder"); + ArrayList sideList = (ArrayList) session.getAttribute("sideList"); + User user = (User) session.getAttribute("user");%> +

Here you can see the pieces needed for your house

+
+

Order

+ <%out.println("

Length: " + order.getLength() + + ", Width: " + order.getWidth() + ", Height: " + order.getHeight() + "

");%> +

The door and window are both 2 dots wide

+

The door is 3 bricks high; The window is 1 brick high.

+

If you'll notice am i only subtracting the door and window height from 2x2 bricks. + That's because both the window and door is 2 dots wide, so we've swapped 4 2x2 bricks in place for the door and window.

+

Styk liste

+ + + + + + + + + <% int brick1sum = 0, brick2sum = 0, brick3sum = 0; + int door = 0, window = 0, doorheight = 0, windowheight = 0; + for (Side side : sideList) { + int brick1 = 0, brick2 = 0, brick3 = 0; + door = 0; + window = 0; + out.println(""); + for (Brick brick : side.getBricks()) { + if (brick.getName().equals("1x2")) { + brick1++; + brick1sum++; + } + if (brick.getName().equals("2x2")) { + brick2++; + brick2sum++; + } + if (brick.getName().equals("2x4")) { + brick3++; + brick3sum++; + } + if (brick.getName().equals("Door")) { + door++; + doorheight = brick.getHeight(); + } + if (brick.getName().equals("Window")) { + window++; + windowheight = brick.getHeight(); + } + } + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + + } + %> + + + + + + + +
Side1x22x22x4DørVindue
" + side.getName() + "" + brick1 + "" + brick2 + "" + brick3 + "" + door + "" + window + "
(ialt x H) - dørH - vindueH<%= (brick1sum * order.getHeight())%><%= (brick2sum * order.getHeight() - doorheight - windowheight)%><%= (brick3sum * order.getHeight())%>
+
+ <% if (user.getRole().equals("employee")) {%> + + <% } else { %> + + <% }%> + +
+
+ + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 06b4f9c..d950274 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -10,47 +10,22 @@ Welcome page + -

Welcome to Sem 2

- - - - - - - -
Login -
- - Email:
- -
- Password:
- -
- -
-
Or Register -
- - Email:
- -
- Password:
- -
- Retype Password:
- -
- -
-
- <% String error = (String) request.getAttribute( "error"); - if ( error != null) { %> -

Error!!

-

<%= error %> - <% } - %> + <%@include file="WEB-INF/nav.jsp" %> +

Welcome to LegoHouse

+
+

This is the front page of my Lego House site.

+ + Få hjælp til din bestilling + + <% String error = (String) request.getAttribute("error"); + if (error != null) {%> +

Error!!

+

<%= error%> + <% } + %> +

diff --git a/src/main/webapp/stylesheet.css b/src/main/webapp/stylesheet.css new file mode 100644 index 0000000..a4be728 --- /dev/null +++ b/src/main/webapp/stylesheet.css @@ -0,0 +1,104 @@ +/* +To change this license header, choose License Headers in Project Properties. +To change this template file, choose Tools | Templates +and open the template in the editor. +*/ +/* + Created on : Mar 21, 2018, 1:37:54 PM + Author : juanni420 +*/ + +html { + height: 100%; + width: 100%; +} + +body{ + height: 100%; + width: 100%; + margin: 0; + background-color: lightblue; +} + +table { + font-family: arial, sans-serif; + border-collapse: collapse; + min-width: 40%; + max-width: 80%; + margin:auto; + margin-bottom: 1%; +} + +td, th { + border: 1px dashed black; + text-align: left; + padding: 8px; +} + +tr:nth-child(even) { + background-color: #dddddd; +} + +.nav { + width: 100%; + height: 4%; + background-color: darkblue; + color: white; + font-size: 16pt; + text-align: center; +} + +form +{ + margin: 10px 0px; +} + +a { + color: white; + text-decoration: none; + margin-right:20px; + margin-top: 0; + margin-bottom: 0; +} + +p { + margin-top: 0; + margin-bottom: 0; + max-width: 80%; +} + +h1, h2 { + max-width: 60%; text-align: center; margin-top: 4%; +} + +.button { + display: block; + max-width: 285px; + height: 20px; + background: #dddddd; + text-align: center; + color: black; + border: 1px grey solid; + margin-top: 1%; + margin-bottom: 1%; +} + +.wrapper{ + min-width: 40%; + max-width: 70%; + min-height: 22%; + margin: auto; + margin-top: 1%; + border: black 2px dashed; + padding: 5px; +} + +.center{ + margin-left: auto; + margin-right: auto; + text-align: center; +} + +.top{ + margin-top: 4%; +} \ No newline at end of file