From 09779ffde6b2c431b1fdc2d181cbaa39718d50c9 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Thu, 18 Feb 2021 15:27:33 -0600 Subject: [PATCH 01/32] commiting new test branch --- .project | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.project b/.project index b51ee30c..817a9dd6 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1613683508768 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + From 29b200f35401ead630a5533e00dfa32a5fd2cb3c Mon Sep 17 00:00:00 2001 From: Nicholas Beck Date: Thu, 18 Feb 2021 17:08:40 -0600 Subject: [PATCH 02/32] able to run locally with Allison's URL- must change later! --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 301f32d2..34478806 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.session.store-type=HAZELCAST -spring.datasource.url=${JDBC_DATABASE_URL} +spring.datasource.url=jdbc:postgresql://ec2-54-205-248-255.compute-1.amazonaws.com:5432/dd1ld7m9hk46hj?password=80fe595d2bbe8d08025453a68d9f6a939544373b6ea7f4e130652837d0d49be7&sslmode=require&user=cozrtdqnqusfpf spring.datasource.username=${JDBC_DATABASE_USERNAME} spring.datasource.password=${JDBC_DATABASE_PASSWORD} spring.datasource.driverClassName=org.postgresql.Driver From 9b1a46ae61473f5b395d3ed7b5e280b516954a75 Mon Sep 17 00:00:00 2001 From: Nicholas Beck Date: Thu, 18 Feb 2021 17:13:30 -0600 Subject: [PATCH 03/32] Nicholas commit! --- test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 00000000..b87bca2a --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +Hhello!!! \ No newline at end of file From 299b13d22cb3e3c5f1b4cd4c597fe149454b141e Mon Sep 17 00:00:00 2001 From: Nicholas Beck Date: Fri, 19 Feb 2021 10:40:03 -0600 Subject: [PATCH 04/32] Changed Allison's url to groups db url --- .project | 11 +++++++++++ src/main/resources/application.properties | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.project b/.project index b51ee30c..198ac7f2 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1613690915857 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 34478806..bb5fbad9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.session.store-type=HAZELCAST -spring.datasource.url=jdbc:postgresql://ec2-54-205-248-255.compute-1.amazonaws.com:5432/dd1ld7m9hk46hj?password=80fe595d2bbe8d08025453a68d9f6a939544373b6ea7f4e130652837d0d49be7&sslmode=require&user=cozrtdqnqusfpf +spring.datasource.url=jdbc:postgresql://ec2-3-213-102-175.compute-1.amazonaws.com:5432/dn9o10t6ampfu?password=70e6b479d4d3508904613d71173b12e78a6e3bf0fe2de09816397d3f88069102&sslmode=require&user=sdikxqjdmelzwx spring.datasource.username=${JDBC_DATABASE_USERNAME} spring.datasource.password=${JDBC_DATABASE_PASSWORD} spring.datasource.driverClassName=org.postgresql.Driver From 55904058e3962721b976ae76883f1f482c0cb159 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Fri, 19 Feb 2021 10:55:34 -0600 Subject: [PATCH 05/32] change database url --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 301f32d2..c5b119d1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,7 @@ spring.session.store-type=HAZELCAST -spring.datasource.url=${JDBC_DATABASE_URL} +# spring.datasource.url=${JDBC_DATABASE_URL} +spring.datasource.url=jdbc:postgresql://ec2-3-213-102-175.compute-1.amazonaws.com:5432/dn9o10t6ampfu?password=70e6b479d4d3508904613d71173b12e78a6e3bf0fe2de09816397d3f88069102&sslmode=require&user=sdikxqjdmelzwx spring.datasource.username=${JDBC_DATABASE_USERNAME} spring.datasource.password=${JDBC_DATABASE_PASSWORD} spring.datasource.driverClassName=org.postgresql.Driver From 23b641ee4fbb3a626f094dd5ec2206e3d4076303 Mon Sep 17 00:00:00 2001 From: ndbeck <77121745+ndbeck@users.noreply.github.com> Date: Fri, 19 Feb 2021 11:05:52 -0600 Subject: [PATCH 06/32] Delete test.txt --- test.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test.txt diff --git a/test.txt b/test.txt deleted file mode 100644 index b87bca2a..00000000 --- a/test.txt +++ /dev/null @@ -1 +0,0 @@ -Hhello!!! \ No newline at end of file From 5981a0eeac52970b0f579ab282178ad248a9f6af Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sat, 20 Feb 2021 10:23:44 -0600 Subject: [PATCH 07/32] created basic route to Main Menu --- .../employees/ActiveEmployeeExistsQuery.java | 5 ++++ .../employees/EmployeeSignInCommand.java | 5 ++++ .../controllers/MainMenuRouteController.java | 30 +++++++++++++++++++ .../controllers/enums/ViewNames.java | 3 +- src/main/resources/templates/mainMenu.html | 7 +++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java create mode 100644 src/main/resources/templates/mainMenu.html diff --git a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java new file mode 100644 index 00000000..85ced4af --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java @@ -0,0 +1,5 @@ +package edu.uark.registerapp.commands.employees; + +public class ActiveEmployeeExistsQuery { + +} diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java new file mode 100644 index 00000000..71a23ad8 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -0,0 +1,5 @@ +package edu.uark.registerapp.commands.employees; + +public class EmployeeSignInCommand { + +} diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java new file mode 100644 index 00000000..1fb3e0bb --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -0,0 +1,30 @@ +package edu.uark.registerapp.controllers; + +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.controllers.enums.ViewNames; + +@Controller +@RequestMapping(value="/mainMenu") +public class MainMenuRouteController { + @RequestMapping(method = RequestMethod.GET) + public ModelAndView start( + @RequestParam Map queryParameters, + final HttpServletRequest httpServletRequest + ) { + ModelAndView modelAndView = new ModelAndView(ViewNames.MAIN_MENU.getViewName()); + + return modelAndView; + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java index cd1a1246..b3e5e766 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java @@ -2,7 +2,8 @@ public enum ViewNames { PRODUCT_DETAIL("productDetail"), - PRODUCT_LISTING("productListing", "/"); + PRODUCT_LISTING("productListing", "/"), + MAIN_MENU("mainMenu"); public String getRoute() { return this.route; diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html new file mode 100644 index 00000000..1b7631a3 --- /dev/null +++ b/src/main/resources/templates/mainMenu.html @@ -0,0 +1,7 @@ + + + Main Menu + + + this is the main menu + \ No newline at end of file From 0b2df11c0a8568bc3d61cb291dd2142724bbaa93 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sat, 20 Feb 2021 11:15:57 -0600 Subject: [PATCH 08/32] changed default web page to Main Menu --- .../uark/registerapp/controllers/MainMenuRouteController.java | 4 ++-- .../controllers/ProductListingRouteController.java | 2 +- .../edu/uark/registerapp/controllers/enums/ViewNames.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java index 1fb3e0bb..2fea3524 100644 --- a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -16,7 +16,7 @@ import edu.uark.registerapp.controllers.enums.ViewNames; @Controller -@RequestMapping(value="/mainMenu") +@RequestMapping(value={"/mainMenu", "/"}) public class MainMenuRouteController { @RequestMapping(method = RequestMethod.GET) public ModelAndView start( @@ -24,7 +24,7 @@ public ModelAndView start( final HttpServletRequest httpServletRequest ) { ModelAndView modelAndView = new ModelAndView(ViewNames.MAIN_MENU.getViewName()); - + // modelAndView.addObject(ERROR_MESSAGE, attributeValue) return modelAndView; } } diff --git a/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java b/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java index 3c2a1178..e96a45fb 100644 --- a/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java @@ -12,7 +12,7 @@ import edu.uark.registerapp.models.api.Product; @Controller -@RequestMapping(value = "/") +@RequestMapping(value = "/productListing") public class ProductListingRouteController { @RequestMapping(method = RequestMethod.GET) public ModelAndView showProductListing() { diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java index b3e5e766..1fd34bf0 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java @@ -2,8 +2,8 @@ public enum ViewNames { PRODUCT_DETAIL("productDetail"), - PRODUCT_LISTING("productListing", "/"), - MAIN_MENU("mainMenu"); + PRODUCT_LISTING("productListing"), + MAIN_MENU("mainMenu", "/"); public String getRoute() { return this.route; From a8c98edbad445aadf5b687397f9c6911a0ec77c1 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sat, 20 Feb 2021 12:19:32 -0600 Subject: [PATCH 09/32] slight text changes --- .../uark/registerapp/controllers/MainMenuRouteController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java index 2fea3524..2b3b658e 100644 --- a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -23,7 +23,7 @@ public ModelAndView start( @RequestParam Map queryParameters, final HttpServletRequest httpServletRequest ) { - ModelAndView modelAndView = new ModelAndView(ViewNames.MAIN_MENU.getViewName()); + ModelAndView modelAndView = new ModelAndView(ViewNames.MAIN_MENU.getViewName(), queryParameters); // modelAndView.addObject(ERROR_MESSAGE, attributeValue) return modelAndView; } From f8aac54c8d96db62c6249715387357747b3dc198 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Thu, 25 Feb 2021 13:21:52 -0600 Subject: [PATCH 10/32] created mainmenu script --- src/main/resources/static/scripts/mainMenu.js | 4 ++++ src/main/resources/templates/mainMenu.html | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 src/main/resources/static/scripts/mainMenu.js diff --git a/src/main/resources/static/scripts/mainMenu.js b/src/main/resources/static/scripts/mainMenu.js new file mode 100644 index 00000000..8609a921 --- /dev/null +++ b/src/main/resources/static/scripts/mainMenu.js @@ -0,0 +1,4 @@ +document.addEventListener("DOMContentLoaded", () => { + const productListElements = document.getElementById("productsListing").children; + +}); \ No newline at end of file diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index 1b7631a3..86f42aff 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -1,7 +1,9 @@ + Main Menu this is the main menu + \ No newline at end of file From 467e50e063eab407b1b4c50bf40a2440aaf2ef4f Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Fri, 26 Feb 2021 17:51:04 -0600 Subject: [PATCH 11/32] redirects to View Products --- src/main/resources/static/scripts/mainMenu.js | 12 ++++++++--- src/main/resources/templates/mainMenu.html | 20 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/resources/static/scripts/mainMenu.js b/src/main/resources/static/scripts/mainMenu.js index 8609a921..5c419ec6 100644 --- a/src/main/resources/static/scripts/mainMenu.js +++ b/src/main/resources/static/scripts/mainMenu.js @@ -1,4 +1,10 @@ document.addEventListener("DOMContentLoaded", () => { - const productListElements = document.getElementById("productsListing").children; - -}); \ No newline at end of file + getViewProductsActionElement().addEventListener( + "click", + () => { window.location.assign("/productListing"); console.log("shrekswasf");}); +}); + +function getViewProductsActionElement() { + return document.getElementById("viewProductsButton"); +} + diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index 86f42aff..3901ed05 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -1,9 +1,23 @@ - Main Menu + + + + + + - this is the main menu - +
+

Main Menu

+
+ +
+
    +
  • + +
  • +
+
\ No newline at end of file From 751f8841900813f7d065a9e9e4bbc576fd124ca1 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sat, 27 Feb 2021 19:34:21 -0600 Subject: [PATCH 12/32] copied over necessary files from the completed sprint 2 --- .../employees/ActiveEmployeeExistsQuery.java | 5 + .../employees/helpers/EmployeeHelper.java | 34 ++++ .../uark/registerapp/models/api/Employee.java | 145 ++++++++++++++++ .../models/entities/EmployeeEntity.java | 164 ++++++++++++++++++ .../repositories/EmployeeRepository.java | 15 ++ 5 files changed, 363 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java create mode 100644 src/main/java/edu/uark/registerapp/models/api/Employee.java create mode 100644 src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java create mode 100644 src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java diff --git a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java new file mode 100644 index 00000000..85ced4af --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java @@ -0,0 +1,5 @@ +package edu.uark.registerapp.commands.employees; + +public class ActiveEmployeeExistsQuery { + +} diff --git a/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java new file mode 100644 index 00000000..e6f54d73 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java @@ -0,0 +1,34 @@ +package edu.uark.registerapp.commands.employees.helpers; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.lang3.StringUtils; + +public class EmployeeHelper { + public static String padEmployeeId(final int employeeId) { + final String employeeIdAsString = Integer.toString(employeeId); + + return ((employeeIdAsString.length() < EMPLOYEE_ID_MAXIMUM_LENGTH) + ? StringUtils.leftPad( + employeeIdAsString, + EMPLOYEE_ID_MAXIMUM_LENGTH, + "0") + : employeeIdAsString); + } + + public static byte[] hashPassword(final String password) { + try { + final MessageDigest messageDigest = + MessageDigest.getInstance("SHA-256"); + + messageDigest.update(password.getBytes()); + + return messageDigest.digest(); + } catch (final NoSuchAlgorithmException e) { + return new byte[0]; + } + } + + private static final int EMPLOYEE_ID_MAXIMUM_LENGTH = 5; +} diff --git a/src/main/java/edu/uark/registerapp/models/api/Employee.java b/src/main/java/edu/uark/registerapp/models/api/Employee.java new file mode 100644 index 00000000..6e313bfc --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/api/Employee.java @@ -0,0 +1,145 @@ +package edu.uark.registerapp.models.api; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; + +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.models.entities.EmployeeEntity; + +public class Employee extends ApiResponse { + private UUID id; + public UUID getId() { + return this.id; + } + public Employee setId(final UUID id) { + this.id = id; + return this; + } + + private String employeeId; + public String getEmployeeId() { + return this.employeeId; + } + public Employee setEmployeeId(final int employeeId) { + this.employeeId = EmployeeHelper.padEmployeeId(employeeId); + return this; + } + public Employee setEmployeeId(final String employeeId) { + this.employeeId = employeeId; + return this; + } + + private String firstName; + public String getFirstName() { + return this.firstName; + } + public Employee setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + private String lastName; + public String getLastName() { + return this.lastName; + } + public Employee setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + private String password; + public String getPassword() { + return this.password; + } + public Employee setPassword(final String password) { + this.password = password; + return this; + } + + private boolean isActive; + public boolean getIsActive() { + return this.isActive; + } + public Employee setIsActive(final boolean isActive) { + this.isActive = isActive; + return this; + } + + private int classification; + public int getClassification() { + return this.classification; + } + public Employee setClassification(final int classification) { + this.classification = classification; + return this; + } + + private UUID managerId; + public UUID getManagerId() { + return this.managerId; + } + public Employee setManagerId(final UUID managerId) { + this.managerId = managerId; + return this; + } + + private String createdOn; + public String getCreatedOn() { + return this.createdOn; + } + public Employee setCreatedOn(final String createdOn) { + this.createdOn = createdOn; + return this; + } + public Employee setCreatedOn(final LocalDateTime createdOn) { + this.createdOn = + createdOn.format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); + + return this; + } + + private boolean isInitialEmployee; + public boolean getIsInitialEmployee() { + return this.isInitialEmployee; + } + public Employee setIsInitialEmployee(final boolean isInitialEmployee) { + this.isInitialEmployee = isInitialEmployee; + return this; + } + + public Employee() { + super(); + + this.isActive = true; + this.id = new UUID(0, 0); + this.classification = -1; + this.isInitialEmployee = false; + this.managerId = new UUID(0, 0); + this.lastName = StringUtils.EMPTY; + this.password = StringUtils.EMPTY; + this.firstName = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + + this.setCreatedOn(LocalDateTime.now()); + } + + public Employee(final EmployeeEntity employeeEntity) { + super(false); + + this.isInitialEmployee = false; + this.id = employeeEntity.getId(); + this.password = StringUtils.EMPTY; + this.isActive = employeeEntity.getIsActive(); + this.lastName = employeeEntity.getLastName(); + this.firstName = employeeEntity.getFirstName(); + this.managerId = employeeEntity.getManagerId(); + this.classification = employeeEntity.getClassification(); + this.employeeId = + EmployeeHelper.padEmployeeId(employeeEntity.getEmployeeId()); + + this.setCreatedOn(employeeEntity.getCreatedOn()); + } +} diff --git a/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java b/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java new file mode 100644 index 00000000..324e5b31 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java @@ -0,0 +1,164 @@ +package edu.uark.registerapp.models.entities; + +import java.time.LocalDateTime; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.models.api.Employee; + +@Entity +@Table(name="employee") +public class EmployeeEntity { + @Id + @Column(name="id", updatable = false) + @GeneratedValue(strategy=GenerationType.AUTO) + private final UUID id; + + public UUID getId() { + return this.id; + } + + @Column(name = "employeeid", insertable = false, updatable = false) + @Generated(GenerationTime.INSERT) + private int employeeId; + + public int getEmployeeId() { + return this.employeeId; + } + + @Column(name = "firstname") + private String firstName; + + public String getFirstName() { + return this.firstName; + } + + public EmployeeEntity setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + @Column(name = "lastname") + private String lastName; + + public String getLastName() { + return this.lastName; + } + + public EmployeeEntity setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + @Column(name = "password") + private byte[] password; + + public byte[] getPassword() { + return this.password; + } + + public EmployeeEntity setPassword(final byte[] password) { + this.password = password; + return this; + } + + @Column(name = "active") + private boolean isActive; + + public boolean getIsActive() { + return this.isActive; + } + + public EmployeeEntity setIsActive(final boolean isActive) { + this.isActive = isActive; + return this; + } + + @Column(name = "classification") + private int classification; + + public int getClassification() { + return this.classification; + } + + public EmployeeEntity setClassification(final int classification) { + this.classification = classification; + return this; + } + + @Column(name = "managerid") + private UUID managerId; + + public UUID getManagerId() { + return this.managerId; + } + + public EmployeeEntity setManagerId(final UUID managerId) { + this.managerId = managerId; + return this; + } + + @Column(name = "createdon", insertable = false, updatable = false) + @Generated(GenerationTime.INSERT) + private LocalDateTime createdOn; + + public LocalDateTime getCreatedOn() { + return this.createdOn; + } + + public Employee synchronize(final Employee apiEmployee) { + this.setIsActive(apiEmployee.getIsActive()); + this.setLastName(apiEmployee.getLastName()); + this.setFirstName(apiEmployee.getFirstName()); + this.setClassification(apiEmployee.getClassification()); + if (apiEmployee.getManagerId() != null) { + this.setManagerId(apiEmployee.getManagerId()); + } + if (!StringUtils.isBlank(apiEmployee.getPassword())) { + this.setPassword( + EmployeeHelper.hashPassword( + apiEmployee.getPassword())); + } + + apiEmployee.setId(this.getId()); + apiEmployee.setCreatedOn(this.getCreatedOn()); + apiEmployee.setEmployeeId(this.getEmployeeId()); + + return apiEmployee; + } + + public EmployeeEntity() { + this.employeeId = -1; + this.isActive = false; + this.id = new UUID(0, 0); + this.classification = -1; + this.password = new byte[0]; + this.managerId = new UUID(0, 0); + this.lastName = StringUtils.EMPTY; + this.firstName = StringUtils.EMPTY; + } + + public EmployeeEntity(final Employee apiEmployee) { + this.id = new UUID(0, 0); + this.isActive = apiEmployee.getIsActive(); + this.lastName = apiEmployee.getLastName(); + this.firstName = apiEmployee.getFirstName(); + this.classification = apiEmployee.getClassification(); + this.password = EmployeeHelper.hashPassword(apiEmployee.getPassword()); + this.managerId = ( + (apiEmployee.getManagerId() != null) + ? apiEmployee.getManagerId() + : new UUID(0, 0)); + } +} diff --git a/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java b/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java new file mode 100644 index 00000000..8ba4b81f --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java @@ -0,0 +1,15 @@ +package edu.uark.registerapp.models.repositories; + +import java.util.Optional; +import java.util.UUID; + +import org.springframework.data.repository.CrudRepository; + +import edu.uark.registerapp.models.entities.EmployeeEntity; + +public interface EmployeeRepository extends CrudRepository { + boolean existsByIsActive(boolean isActive); + boolean existsByEmployeeId(int employeeId); + Optional findById(UUID id); + Optional findByEmployeeId(int employeeId); +} From bd64d21e0e024e8cb533eaa298c815aa2cfb9ae2 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sat, 27 Feb 2021 20:01:48 -0600 Subject: [PATCH 13/32] copied over necessary files from the completed sprint 2 --- src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java new file mode 100644 index 00000000..e69de29b From 14281146a3508fc189415dbabd947061127516ba Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 28 Feb 2021 10:42:58 -0600 Subject: [PATCH 14/32] Created EmployeeSignIn Class --- .../models/api/EmployeeSignIn.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java new file mode 100644 index 00000000..e1ef5098 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java @@ -0,0 +1,29 @@ +package edu.uark.registerapp.models.api; + +import org.apache.commons.lang3.StringUtils; +public class EmployeeSignIn { + private String employeeId; + private String password; + + public EmployeeSignIn(){ + this.password = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + } + public String getEmployeeId() { + return this.employeeId; + } + + public EmployeeSignIn setEmployeeId(final String employeeId) { + this.employeeId = employeeId; + return this; + } + + public String getPassword() { + return this.password; + } + + public EmployeeSignIn setPassword(final String password) { + this.password = password; + return this; + } +} From 71322f364ea787a507a243f7d9f4c718ba9dbb39 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Sun, 28 Feb 2021 15:34:21 -0600 Subject: [PATCH 15/32] finished active employee query --- .../employees/ActiveEmployeeExistsQuery.java | 17 ++++++++++++++++- .../employees/EmployeeSignInCommand.java | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java diff --git a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java index 85ced4af..c4df2462 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java @@ -1,5 +1,20 @@ package edu.uark.registerapp.commands.employees; -public class ActiveEmployeeExistsQuery { +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.uark.registerapp.commands.VoidCommandInterface; +import edu.uark.registerapp.models.repositories.EmployeeRepository; +import edu.uark.registerapp.commands.exceptions.NotFoundException; +@Service +public class ActiveEmployeeExistsQuery implements VoidCommandInterface{ + @Override + public void execute() { + if (!this.employeerepository.existsByIsActive(true)) { + throw new NotFoundException("Employee"); + } + } + @Autowired + private EmployeeRepository employeerepository; } diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java new file mode 100644 index 00000000..71a23ad8 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -0,0 +1,5 @@ +package edu.uark.registerapp.commands.employees; + +public class EmployeeSignInCommand { + +} From 5d9c8f4eb79f64db33f8a1eff50769ad050ec4b2 Mon Sep 17 00:00:00 2001 From: annicolee Date: Sun, 28 Feb 2021 16:50:46 -0600 Subject: [PATCH 16/32] signIn-An --- src/main/resources/static/scripts/signIn.js | 32 ++++++++++++++++++++ src/main/resources/templates/signIn.html | 33 +++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/main/resources/static/scripts/signIn.js create mode 100644 src/main/resources/templates/signIn.html diff --git a/src/main/resources/static/scripts/signIn.js b/src/main/resources/static/scripts/signIn.js new file mode 100644 index 00000000..ac891898 --- /dev/null +++ b/src/main/resources/static/scripts/signIn.js @@ -0,0 +1,32 @@ +function validateForm(){ + + var id = document.getElementById('employeeId') //sets the variable to the employeeId + var pwd = document.getElementById('password') //sets the variable to the password + + if(id != null && pwd != null ) //makes sure that the employeeId and password are not blank + { + if(isNaN(Number(id.value))) //checks to see if the emplyeeId is a number + { + if(isNaN(Number(id.value) > 0)) //checks to see if the id value is greater than 0 + { + if(pwd.value.trim() !=='') //checks to see if the pwd value doesn't equal a blank after triming the whitespaces + { + return true; + }else{ + alert("Please fill out a valid Password."); //alerts the user if the password they've typed in doesn't meet the requirements. + return false; + } + } + else{ + alert("Please fill out a valid EmployeeId."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. + return false; + } + }else{ + alert("Please fill out a valid EmployeeId."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. + return false; + } + }else{ + alert("Please fill out a valid EmployeeId and Password."); //alerts the user if the password & employeeId they've typed in doesn't meet the requirements. + return false; + } +} \ No newline at end of file diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html new file mode 100644 index 00000000..1a36d39d --- /dev/null +++ b/src/main/resources/templates/signIn.html @@ -0,0 +1,33 @@ + + + Register - Sign In + + + + + + +
+

Employee Sign In

+
+ +
+
+

+
+ +
+
+ + + + + + + +
+
+ +
+ + \ No newline at end of file From b2981dba086164272331ed1781f351eae00b9ec1 Mon Sep 17 00:00:00 2001 From: annicolee Date: Sun, 28 Feb 2021 17:21:33 -0600 Subject: [PATCH 17/32] signIn --- src/main/resources/templates/signIn.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 1a36d39d..a1d5ac39 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -8,7 +8,7 @@
-

Employee Sign In

+

Employee Sign In

@@ -22,7 +22,7 @@

- +
From 81ca39492e71bf465e1c27815827edb02f858df8 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Mon, 1 Mar 2021 08:35:39 -0600 Subject: [PATCH 18/32] employee sign in partial functionality --- .../employees/EmployeeSignInCommand.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index 71a23ad8..de4d59dd 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -1,5 +1,51 @@ package edu.uark.registerapp.commands.employees; -public class EmployeeSignInCommand { - +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; +import edu.uark.registerapp.models.api.EmployeeSignIn; +import edu.uark.registerapp.models.repositories.EmployeeRepository; +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; +import edu.uark.registerapp.models.api.Employee; + +@Service +public class EmployeeSignInCommand implements ResultCommandInterface{ + //properties + private EmployeeSignIn employeeSignIn; + private String sessionId; //session key + @Autowired + private EmployeeRepository employeeRepository; + @Autowired + public String getSessionId() { + return this.sessionId; + } + + public Employee execute() { + return null; + } + + private void validateProperties() { + //ID should not be blank. Should be a number + if (StringUtils.isBlank(this.employeeSignIn.getEmployeeId())) { + throw new UnprocessableEntityException("employee ID"); + } + + //ID should only be a number + try { + Integer.parseInt(this.employeeSignIn.getEmployeeId()); + } catch (NumberFormatException e) { + throw new UnprocessableEntityException("employee ID"); + } + + if (StringUtils.isBlank(this.employeeSignIn.getPassword())){ + throw new UnprocessableEntityException("password"); + } + } + + private void queryEmployeebyID() { + + } + } From 1cfd6cfce6c998218e142400ad371d7a59a1ef9e Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 1 Mar 2021 16:21:37 -0600 Subject: [PATCH 19/32] Finsished the SignInRouteController --- .../activeUsers/ActiveUserDeleteCommand.java | 38 ++++++ .../ValidateActiveUserCommand.java | 41 ++++++ .../employees/ActiveEmployeeExistsQuery.java | 1 + .../controllers/BaseRouteController.java | 117 ++++++++++++++++++ .../controllers/SignInRouteController.java | 51 ++++++++ .../enums/QueryParameterMessages.java | 45 +++++++ .../enums/QueryParameterNames.java | 5 +- .../controllers/enums/ViewModelNames.java | 5 +- .../controllers/enums/ViewNames.java | 7 +- .../models/api/EmployeeSignIn.java | 45 ++++--- .../models/entities/ActiveUserEntity.java | 91 ++++++++++++++ .../models/enums/EmployeeClassification.java | 58 +++++++++ .../repositories/ActiveUserRepository.java | 13 ++ 13 files changed, 489 insertions(+), 28 deletions(-) create mode 100644 src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java create mode 100644 src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java create mode 100644 src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java create mode 100644 src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java create mode 100644 src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java new file mode 100644 index 00000000..ccd22837 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -0,0 +1,38 @@ +package edu.uark.registerapp.commands.activeUsers; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import edu.uark.registerapp.commands.VoidCommandInterface; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; + +@Service +public class ActiveUserDeleteCommand implements VoidCommandInterface { + @Transactional + @Override + public void execute() { + final Optional activeUserEntity = + this.activeUserRepository.findBySessionKey(this.sessionKey); + + if (activeUserEntity.isPresent()) { + this.activeUserRepository.delete(activeUserEntity.get()); + } + } + + // Properties + private String sessionKey; + public String getSessionKey() { + return this.sessionKey; + } + public ActiveUserDeleteCommand setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Autowired + private ActiveUserRepository activeUserRepository; +} diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java new file mode 100644 index 00000000..d04784cb --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java @@ -0,0 +1,41 @@ +package edu.uark.registerapp.commands.activeUsers; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; + +@Service +public class ValidateActiveUserCommand implements ResultCommandInterface { + @Override + public ActiveUserEntity execute() { + final Optional activeUserEntity = + this.activeUserRepository.findBySessionKey(this.sessionKey); + + if (!activeUserEntity.isPresent()) { + throw new UnauthorizedException(); + } + + return activeUserEntity.get(); + } + + // Properties + private String sessionKey; + + public String getSessionKey() { + return this.sessionKey; + } + + public ValidateActiveUserCommand setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Autowired + private ActiveUserRepository activeUserRepository; +} diff --git a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java index c4df2462..d738f5e0 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/ActiveEmployeeExistsQuery.java @@ -6,6 +6,7 @@ import edu.uark.registerapp.commands.VoidCommandInterface; import edu.uark.registerapp.models.repositories.EmployeeRepository; import edu.uark.registerapp.commands.exceptions.NotFoundException; + @Service public class ActiveEmployeeExistsQuery implements VoidCommandInterface{ @Override diff --git a/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java b/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java new file mode 100644 index 00000000..58774f84 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java @@ -0,0 +1,117 @@ +package edu.uark.registerapp.controllers; + +import java.util.Map; +import java.util.Optional; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.commands.activeUsers.ValidateActiveUserCommand; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.controllers.enums.ViewModelNames; +import edu.uark.registerapp.controllers.enums.QueryParameterMessages; +import edu.uark.registerapp.controllers.enums.QueryParameterNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.enums.EmployeeClassification; + +public abstract class BaseRouteController extends BaseController { + protected ModelAndView setErrorMessageFromQueryString( + ModelAndView modelAndView, + final Map queryParameters + ) { + + if (!queryParameters.containsKey(QueryParameterNames.ERROR_CODE.getValue())) { + return modelAndView; + } + + try { + modelAndView = + this.setErrorMessageFromQueryString( + modelAndView, + Integer.parseInt( + queryParameters.get( + QueryParameterNames.ERROR_CODE.getValue()))); + } catch (final NumberFormatException e) { } + + return modelAndView; + } + protected ModelAndView setErrorMessageFromQueryString( + final ModelAndView modelAndView, + final Optional errorCode + ) { + + if (!errorCode.isPresent()) { + return modelAndView; + } + + return this.setErrorMessageFromQueryString(modelAndView, errorCode.get()); + } + + protected Optional getCurrentUser( + final HttpServletRequest request + ) { + + try { + return Optional.of( + this.validateActiveUserCommand + .setSessionKey(request.getSession().getId()) + .execute()); + } catch (final UnauthorizedException e) { + return Optional.ofNullable(null); + } + } + + protected ModelAndView buildInvalidSessionResponse() { + return new ModelAndView( + REDIRECT_PREPEND.concat( + ViewNames.SIGN_IN.getRoute().concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.SESSION_NOT_ACTIVE.getKeyAsString())))); + } + + protected boolean isElevatedUser(final ActiveUserEntity activeUserEntity) { + return EmployeeClassification.isElevatedUser( + activeUserEntity.getClassification()); + } + + protected ModelAndView buildNoPermissionsResponse() { + return this.buildNoPermissionsResponse(ViewNames.MAIN_MENU.getRoute()); + } + + protected ModelAndView buildNoPermissionsResponse(final String redirectRoute) { + return new ModelAndView( + REDIRECT_PREPEND.concat( + redirectRoute.concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.NO_PERMISSIONS_TO_VIEW.getKeyAsString())))); + } + + protected static final String REDIRECT_PREPEND = "redirect:"; + + // Helper methods + private ModelAndView setErrorMessageFromQueryString( + final ModelAndView modelAndView, + final int errorCode + ) { + + final String errorMessage = QueryParameterMessages.mapMessage(errorCode); + + if (!StringUtils.isBlank(errorMessage)) { + modelAndView.addObject( + ViewModelNames.ERROR_MESSAGE.getValue(), + errorMessage); + } + + return modelAndView; + } + + // Properties + @Autowired + private ValidateActiveUserCommand validateActiveUserCommand; +} diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java new file mode 100644 index 00000000..c2769624 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java @@ -0,0 +1,51 @@ +package edu.uark.registerapp.controllers; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.commands.employees.ActiveEmployeeExistsQuery; +import edu.uark.registerapp.commands.employees.EmployeeSignInCommand; +import edu.uark.registerapp.commands.exceptions.NotFoundException; +import edu.uark.registerapp.controllers.enums.QueryParameterNames; +import edu.uark.registerapp.controllers.enums.ViewModelNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.api.EmployeeSignIn; + +@Controller +@RequestMapping(value = "/") +public class SignInRouteController extends BaseRouteController { + @RequestMapping(method = RequestMethod.GET) + public ModelAndView showSignIn( + @RequestParam final Map queryParameters) + { + try { + this.activeEmployeeExistsQuery.execute(); + } catch (NotFoundException e) { + return new ModelAndView( + REDIRECT_PREPEND.concat( + ViewNames.EMPLOYEE_DETAIL.getRoute())); + } + + ModelAndView modelAndView = + this.setErrorMessageFromQueryString( + new ModelAndView(ViewNames.SIGN_IN.getViewName()), + queryParameters); + + if (queryParameters.containsKey(QueryParameterNames.EMPLOYEE_ID.getValue())) { + modelAndView.addObject( + ViewModelNames.EMPLOYEE_ID.getValue(), + queryParameters.get(QueryParameterNames.EMPLOYEE_ID.getValue())); + } + + return modelAndView; + } +} \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java new file mode 100644 index 00000000..3f1bed87 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java @@ -0,0 +1,45 @@ +package edu.uark.registerapp.controllers.enums; + +import java.util.HashMap; +import java.util.Map; + +public enum QueryParameterMessages { + NOT_DEFINED(-1, ""), + SESSION_NOT_ACTIVE(1001, "The current user's session is no longer active."), + NO_PERMISSIONS_TO_VIEW(1101, "You do not have permission to view this resource."), + NO_PERMISSIONS_FOR_ACTION(1102, "You do not have permission to perform this action."); + + public int getKey() { + return this.key; + } + public String getKeyAsString() { + return Integer.toString(this.key); + } + public String getMessage() { + return this.message; + } + + public static String mapMessage(final int key) { + if (valueMap == null) { + valueMap = new HashMap(); + + for (final QueryParameterMessages status : QueryParameterMessages.values()) { + valueMap.put(status.getKey(), status.getMessage()); + } + } + + return (valueMap.containsKey(key) + ? valueMap.get(key) + : QueryParameterMessages.NOT_DEFINED.getMessage()); + } + + private int key; + private String message; + + private static Map valueMap = null; + + private QueryParameterMessages(final int key, final String message) { + this.key = key; + this.message = message; + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterNames.java index 988a9c79..deb1ea41 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterNames.java @@ -2,8 +2,9 @@ public enum QueryParameterNames { NOT_DEFINED(""), - ERROR_CODE("errorCode"); - + ERROR_CODE("errorCode"), + EMPLOYEE_ID("employeeId"); + public String getValue() { return value; } diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java index 7c39b102..cfb6d841 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java @@ -4,7 +4,10 @@ public enum ViewModelNames { NOT_DEFINED(""), ERROR_MESSAGE("errorMessage"), PRODUCTS("products"), // Product listing - PRODUCT("product"); // Product detail + PRODUCT("product"), // Product detail + EMPLOYEE_ID("employeeId"), // Sign in + EMPLOYEE("employee"), // Employee detail + EMPLOYEE_TYPES("employeeTypes"); public String getValue() { return value; diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java index cd1a1246..9c68f8d5 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java @@ -1,8 +1,11 @@ package edu.uark.registerapp.controllers.enums; public enum ViewNames { - PRODUCT_DETAIL("productDetail"), - PRODUCT_LISTING("productListing", "/"); + SIGN_IN("signIn", "/"), + MAIN_MENU("mainMenu"), + PRODUCT_DETAIL("productDetail"), + EMPLOYEE_DETAIL("employeeDetail"), + PRODUCT_LISTING("productListing"); public String getRoute() { return this.route; diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java index e1ef5098..e01e4f6c 100644 --- a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java +++ b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java @@ -1,29 +1,28 @@ package edu.uark.registerapp.models.api; import org.apache.commons.lang3.StringUtils; + public class EmployeeSignIn { - private String employeeId; - private String password; - - public EmployeeSignIn(){ - this.password = StringUtils.EMPTY; - this.employeeId = StringUtils.EMPTY; - } - public String getEmployeeId() { - return this.employeeId; - } - - public EmployeeSignIn setEmployeeId(final String employeeId) { - this.employeeId = employeeId; - return this; - } - - public String getPassword() { - return this.password; - } + private String employeeId; + public String getEmployeeId() { + return this.employeeId; + } + public EmployeeSignIn setEmployeeId(final String employeeId) { + this.employeeId = employeeId; + return this; + } - public EmployeeSignIn setPassword(final String password) { - this.password = password; - return this; - } + private String password; + public String getPassword() { + return this.password; + } + public EmployeeSignIn setPassword(final String password) { + this.password = password; + return this; + } + + public EmployeeSignIn() { + this.password = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + } } diff --git a/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java b/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java new file mode 100644 index 00000000..6eba3528 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java @@ -0,0 +1,91 @@ +package edu.uark.registerapp.models.entities; + +import java.time.LocalDateTime; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +@Entity +@Table(name="activeuser") +public class ActiveUserEntity { + @Id + @Column(name="id", updatable = false) + @GeneratedValue(strategy=GenerationType.AUTO) + private final UUID id; + + public UUID getId() { + return this.id; + } + + @Column(name = "employeeid") + private UUID employeeId; + + public UUID getEmployeeId() { + return this.employeeId; + } + + public ActiveUserEntity setEmployeeId(final UUID employeeId) { + this.employeeId = employeeId; + return this; + } + + @Column(name = "name") + private String name; + + public String getName() { + return this.name; + } + + public ActiveUserEntity setName(final String name) { + this.name = name; + return this; + } + + @Column(name = "classification") + private int classification; + + public int getClassification() { + return this.classification; + } + + public ActiveUserEntity setClassification(final int classification) { + this.classification = classification; + return this; + } + + @Column(name = "sessionkey") + private String sessionKey; + + public String getSessionKey() { + return this.sessionKey; + } + + public ActiveUserEntity setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Column(name="createdon", insertable=false, updatable = false) + @Generated(GenerationTime.INSERT) + private LocalDateTime createdOn; + public LocalDateTime getCreatedOn() { + return this.createdOn; + } + + public ActiveUserEntity() { + this.id = new UUID(0, 0); + this.classification = -1; + this.name = StringUtils.EMPTY; + this.employeeId = new UUID(0, 0); + this.sessionKey = StringUtils.EMPTY; + } +} diff --git a/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java b/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java new file mode 100644 index 00000000..751c80ef --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java @@ -0,0 +1,58 @@ +package edu.uark.registerapp.models.enums; + +import java.util.HashMap; +import java.util.Map; + +public enum EmployeeClassification { + NOT_DEFINED(-1, "Not Selected"), + CASHIER(101, "Cashier"), + SHIFT_MANAGER(501, "Shift Manager"), + GENERAL_MANAGER(701, "General Manager"); + + public int getClassification() { + return this.classification; + } + + public String getDisplayLabel() { + return this.displayLabel; + } + + public static EmployeeClassification map(final int key) { + if (valueMap == null) { + valueMap = new HashMap(); + + for (final EmployeeClassification employeeClassification : EmployeeClassification.values()) { + valueMap.put( + employeeClassification.getClassification(), + employeeClassification); + } + } + + return ((valueMap.containsKey(key) + ? valueMap.get(key) + : EmployeeClassification.NOT_DEFINED)); + } + + public static boolean isElevatedUser(final int classification) { + final EmployeeClassification employeeClassification = + EmployeeClassification.map(classification); + + return ( + (employeeClassification == EmployeeClassification.GENERAL_MANAGER) + || (employeeClassification == EmployeeClassification.SHIFT_MANAGER)); + } + + private int classification; + private String displayLabel; + + private static Map valueMap = null; + + private EmployeeClassification( + final int classification, + final String displayLabel + ) { + + this.displayLabel = displayLabel; + this.classification = classification; + } +} diff --git a/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java b/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java new file mode 100644 index 00000000..53746cee --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java @@ -0,0 +1,13 @@ +package edu.uark.registerapp.models.repositories; + +import java.util.Optional; +import java.util.UUID; + +import org.springframework.data.repository.CrudRepository; + +import edu.uark.registerapp.models.entities.ActiveUserEntity; + +public interface ActiveUserRepository extends CrudRepository { + Optional findByEmployeeId(UUID employeeId); + Optional findBySessionKey(String sessionKey); +} From 4913478fd7cc708108df002e98c1d7c76361c77b Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Mon, 1 Mar 2021 16:44:08 -0600 Subject: [PATCH 20/32] alterred the routing on product listing --- .../employees/EmployeeSignInCommand.java | 67 +++++++++++++++++-- .../ProductListingRouteController.java | 2 +- .../controllers/SignInRouteController.java | 4 ++ 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index de4d59dd..d8708c50 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -4,11 +4,22 @@ import org.springframework.stereotype.Service; import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.Optional; + +import javax.transaction.Transactional; + import edu.uark.registerapp.models.api.EmployeeSignIn; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; import edu.uark.registerapp.models.repositories.EmployeeRepository; import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; import edu.uark.registerapp.models.api.Employee; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.entities.EmployeeEntity; @Service public class EmployeeSignInCommand implements ResultCommandInterface{ @@ -18,12 +29,11 @@ public class EmployeeSignInCommand implements ResultCommandInterface{ @Autowired private EmployeeRepository employeeRepository; @Autowired - public String getSessionId() { - return this.sessionId; - } + private ActiveUserRepository activeUserRepository; public Employee execute() { - return null; + this.validateProperties(); + return new Employee(this.SignInActiveUser()); } private void validateProperties() { @@ -44,8 +54,53 @@ private void validateProperties() { } } - private void queryEmployeebyID() { - + private Optional queryEmployeeUsingID() { + int employeeID = Integer.parseInt(this.getEmployeeId()); + String password = this.getPassword(); + Optional employeeEntity = this.employeeRepository.findByEmployeeId(employeeID); + if (!employeeEntity.isPresent() || !Arrays.equals(employeeEntity.get().getPassword(), EmployeeHelper.hashPassword(password))) + { + throw new UnauthorizedException(); + } + + return employeeEntity; } + @Transactional + private EmployeeEntity SignInActiveUser(){ + Optional employeeEntity = queryEmployeeUsingID(); + + //query the activeuser table for a record with the employee ID + Optional activeUserEntity = + this.activeUserRepository.findByEmployeeId(employeeEntity.get().getId()); + + //create a new active user in the record in the database if there isn't one already + if(!activeUserEntity.isPresent()) { + this.activeUserRepository.save( + (new ActiveUserEntity()) + .setSessionKey(this.getSessionId()) + .setEmployeeId(employeeEntity.get().getId()) + .setClassification(employeeEntity.get().getClassification()) + .setName(employeeEntity.get().getFirstName().concat(" ").concat(employeeEntity.get().getLastName())) + ); + } + else { + this.activeUserRepository.save( + activeUserEntity.get().setSessionKey(this.getSessionId()) + ); + } + return employeeEntity.get(); + } + + public String getEmployeeId(){ + return this.employeeSignIn.getEmployeeId(); + } + + public String getPassword(){ + return this.employeeSignIn.getPassword(); + } + + public String getSessionId() { + return this.sessionId; + } } diff --git a/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java b/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java index 3c2a1178..e96a45fb 100644 --- a/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/ProductListingRouteController.java @@ -12,7 +12,7 @@ import edu.uark.registerapp.models.api.Product; @Controller -@RequestMapping(value = "/") +@RequestMapping(value = "/productListing") public class ProductListingRouteController { @RequestMapping(method = RequestMethod.GET) public ModelAndView showProductListing() { diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java index c2769624..b942943e 100644 --- a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java @@ -19,10 +19,14 @@ import edu.uark.registerapp.controllers.enums.ViewModelNames; import edu.uark.registerapp.controllers.enums.ViewNames; import edu.uark.registerapp.models.api.EmployeeSignIn; +import net.bytebuddy.dynamic.TypeResolutionStrategy.Active; @Controller @RequestMapping(value = "/") public class SignInRouteController extends BaseRouteController { + @Autowired + ActiveEmployeeExistsQuery activeEmployeeExistsQuery; + @RequestMapping(method = RequestMethod.GET) public ModelAndView showSignIn( @RequestParam final Map queryParameters) From 99397eeda50346f1d66f2f375ca7a4d98b048a4b Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 1 Mar 2021 17:42:03 -0600 Subject: [PATCH 21/32] Testing Push --- .../employees/EmployeeSignInCommand.java | 103 ++++++++++++++---- .../controllers/SignInRouteController.java | 42 ++++++- 2 files changed, 120 insertions(+), 25 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index de4d59dd..ad757154 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -1,51 +1,108 @@ package edu.uark.registerapp.commands.employees; +import java.util.Arrays; +import java.util.Optional; + +import javax.transaction.Transactional; + +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.apache.commons.lang3.StringUtils; -import edu.uark.registerapp.models.api.EmployeeSignIn; -import edu.uark.registerapp.models.repositories.EmployeeRepository; import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; import edu.uark.registerapp.models.api.Employee; +import edu.uark.registerapp.models.api.EmployeeSignIn; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.entities.EmployeeEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; +import edu.uark.registerapp.models.repositories.EmployeeRepository; @Service -public class EmployeeSignInCommand implements ResultCommandInterface{ - //properties - private EmployeeSignIn employeeSignIn; - private String sessionId; //session key - @Autowired - private EmployeeRepository employeeRepository; - @Autowired - public String getSessionId() { - return this.sessionId; - } - +public class EmployeeSignInCommand implements ResultCommandInterface { + @Override public Employee execute() { - return null; + this.validateProperties(); + + return new Employee(this.SignInEmployee()); } + // Helper methods private void validateProperties() { - //ID should not be blank. Should be a number if (StringUtils.isBlank(this.employeeSignIn.getEmployeeId())) { throw new UnprocessableEntityException("employee ID"); } - - //ID should only be a number try { Integer.parseInt(this.employeeSignIn.getEmployeeId()); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { throw new UnprocessableEntityException("employee ID"); } - - if (StringUtils.isBlank(this.employeeSignIn.getPassword())){ + if (StringUtils.isBlank(this.employeeSignIn.getPassword())) { throw new UnprocessableEntityException("password"); } } - private void queryEmployeebyID() { - + @Transactional + private EmployeeEntity SignInEmployee() { + final Optional employeeEntity = + this.employeeRepository.findByEmployeeId( + Integer.parseInt(this.employeeSignIn.getEmployeeId())); + + if (!employeeEntity.isPresent() + || !Arrays.equals( + employeeEntity.get().getPassword(), + EmployeeHelper.hashPassword(this.employeeSignIn.getPassword())) + ) { + + throw new UnauthorizedException(); + } + + final Optional activeUserEntity = + this.activeUserRepository + .findByEmployeeId(employeeEntity.get().getId()); + + if (!activeUserEntity.isPresent()) { + this.activeUserRepository.save( + (new ActiveUserEntity()) + .setSessionKey(this.sessionId) + .setEmployeeId(employeeEntity.get().getId()) + .setClassification( + employeeEntity.get().getClassification()) + .setName( + employeeEntity.get().getFirstName() + .concat(" ") + .concat(employeeEntity.get().getLastName()))); + } else { + this.activeUserRepository.save( + activeUserEntity.get().setSessionKey(this.sessionId)); + } + + return employeeEntity.get(); } + // Properties + private EmployeeSignIn employeeSignIn; + public EmployeeSignIn getEmployeeSignIn() { + return this.employeeSignIn; + } + public EmployeeSignInCommand setEmployeeSignIn(final EmployeeSignIn employeeSignIn) { + this.employeeSignIn = employeeSignIn; + return this; + } + + private String sessionId; + public String getSessionId() { + return this.sessionId; + } + public EmployeeSignInCommand setSessionId(final String sessionId) { + this.sessionId = sessionId; + return this; + } + + @Autowired + private EmployeeRepository employeeRepository; + @Autowired + private ActiveUserRepository activeUserRepository; } diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java index c2769624..5e9ead63 100644 --- a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java @@ -23,10 +23,11 @@ @Controller @RequestMapping(value = "/") public class SignInRouteController extends BaseRouteController { - @RequestMapping(method = RequestMethod.GET) + @RequestMapping(method = RequestMethod.GET) public ModelAndView showSignIn( @RequestParam final Map queryParameters) { + try { this.activeEmployeeExistsQuery.execute(); } catch (NotFoundException e) { @@ -48,4 +49,41 @@ public ModelAndView showSignIn( return modelAndView; } -} \ No newline at end of file + + @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) + public ModelAndView performSignIn( + EmployeeSignIn employeeSignIn, + HttpServletRequest request + ) { + + try { + this.employeeSignInCommand + .setSessionId(request.getSession().getId()) + .setEmployeeSignIn(employeeSignIn) + .execute(); + } catch (Exception e) { + ModelAndView modelAndView = + new ModelAndView(ViewNames.SIGN_IN.getViewName()); + + modelAndView.addObject( + ViewModelNames.ERROR_MESSAGE.getValue(), + e.getMessage()); + modelAndView.addObject( + ViewModelNames.EMPLOYEE_ID.getValue(), + employeeSignIn.getEmployeeId()); + + return modelAndView; + } + + return new ModelAndView( + REDIRECT_PREPEND.concat( + ViewNames.MAIN_MENU.getRoute())); + } + + // Properties + @Autowired + private EmployeeSignInCommand employeeSignInCommand; + + @Autowired + private ActiveEmployeeExistsQuery activeEmployeeExistsQuery; +} From cf5f3f6ae792e5949c672037707e0c6a269e1f2d Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Tue, 2 Mar 2021 20:26:23 -0600 Subject: [PATCH 22/32] pls work --- .../uark/registerapp/controllers/MainMenuRouteController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java index 2b3b658e..9b497ae3 100644 --- a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -16,7 +16,7 @@ import edu.uark.registerapp.controllers.enums.ViewNames; @Controller -@RequestMapping(value={"/mainMenu", "/"}) +@RequestMapping(value="/mainMenu") public class MainMenuRouteController { @RequestMapping(method = RequestMethod.GET) public ModelAndView start( From 56dd6009d0562201d47c2cd8fef6fe6a06385e04 Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 2 Mar 2021 20:38:12 -0600 Subject: [PATCH 23/32] SignInRestController added --- .../controllers/BaseRestController.java | 89 +++++++++++++++++++ .../controllers/SignInRestController.java | 34 +++++++ .../models/api/EmployeeSignIn.java | 10 ++- 3 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 src/main/java/edu/uark/registerapp/controllers/BaseRestController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/SignInRestController.java diff --git a/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java b/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java new file mode 100644 index 00000000..0f39f55f --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java @@ -0,0 +1,89 @@ +package edu.uark.registerapp.controllers; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import edu.uark.registerapp.commands.activeUsers.ValidateActiveUserCommand; +import edu.uark.registerapp.commands.exceptions.ConflictException; +import edu.uark.registerapp.commands.exceptions.NotFoundException; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; +import edu.uark.registerapp.controllers.enums.QueryParameterMessages; +import edu.uark.registerapp.controllers.enums.QueryParameterNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.api.ApiResponse; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.enums.EmployeeClassification; + +public class BaseRestController extends BaseController { + protected ApiResponse redirectSessionNotActive( + final HttpServletResponse response + ) { + + response.setStatus(HttpStatus.FOUND.value()); + return (new ApiResponse()) + .setRedirectUrl( + ViewNames.SIGN_IN.getRoute().concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.SESSION_NOT_ACTIVE.getKeyAsString()))); + } + + protected ApiResponse redirectUserNotElevated( + final HttpServletRequest request, + final HttpServletResponse response + ) { + + return this.redirectUserNotElevated(request, response, ViewNames.MAIN_MENU.getRoute()); + } + + protected ApiResponse redirectUserNotElevated( + final HttpServletRequest request, + final HttpServletResponse response, + final String redirectRoute + ) { + + try { + final ActiveUserEntity activeUserEntity = + this.validateActiveUserCommand + .setSessionKey(request.getSession().getId()) + .execute(); + + if (activeUserEntity == null) { + return this.redirectSessionNotActive(response); + } else if (!EmployeeClassification.isElevatedUser(activeUserEntity.getClassification())) { + response.setStatus(HttpStatus.FOUND.value()); + + return (new ApiResponse()) + .setRedirectUrl( + redirectRoute.concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.NO_PERMISSIONS_FOR_ACTION.getKeyAsString()))); + } + } catch (final UnauthorizedException e) { + return this.redirectSessionNotActive(response); + } + + return new ApiResponse(); + } + + @ExceptionHandler({ + ConflictException.class, + NotFoundException.class, + UnauthorizedException.class, + UnprocessableEntityException.class + }) + public @ResponseBody ApiResponse handleError(final Exception e) { + return (new ApiResponse()).setErrorMessage(e.getMessage()); + } + + // Properties + @Autowired + private ValidateActiveUserCommand validateActiveUserCommand; +} diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java new file mode 100644 index 00000000..8ec7ef25 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java @@ -0,0 +1,34 @@ +package edu.uark.registerapp.controllers; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import edu.uark.registerapp.commands.activeUsers.ActiveUserDeleteCommand; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.api.ApiResponse; + +@RestController +@RequestMapping(value = "/api") +public class SignInRestController extends BaseRestController { + @RequestMapping(value="/signOut", method = RequestMethod.DELETE) + public @ResponseBody ApiResponse removeActiveUser( + final HttpServletRequest request + ) { + + this.activeUserDeleteCommand + .setSessionKey(request.getSession().getId()) + .execute(); + + return (new ApiResponse()) + .setRedirectUrl(ViewNames.SIGN_IN.getRoute()); + } + + // Properties + @Autowired + private ActiveUserDeleteCommand activeUserDeleteCommand; +} diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java index e01e4f6c..fbefe176 100644 --- a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java +++ b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java @@ -3,6 +3,12 @@ import org.apache.commons.lang3.StringUtils; public class EmployeeSignIn { + + public EmployeeSignIn() { + this.password = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + } + private String employeeId; public String getEmployeeId() { return this.employeeId; @@ -21,8 +27,4 @@ public EmployeeSignIn setPassword(final String password) { return this; } - public EmployeeSignIn() { - this.password = StringUtils.EMPTY; - this.employeeId = StringUtils.EMPTY; - } } From 49770558df3ae263d113e49ec22f6f427da752df Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Tue, 2 Mar 2021 20:39:02 -0600 Subject: [PATCH 24/32] got rid of errors added setter methods --- .../employees/EmployeeSignInCommand.java | 117 ++++++++++-------- 1 file changed, 63 insertions(+), 54 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index ad757154..51070de8 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -1,108 +1,117 @@ package edu.uark.registerapp.commands.employees; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; + import java.util.Arrays; import java.util.Optional; import javax.transaction.Transactional; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - +import edu.uark.registerapp.models.api.EmployeeSignIn; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; +import edu.uark.registerapp.models.repositories.EmployeeRepository; import edu.uark.registerapp.commands.ResultCommandInterface; import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; import edu.uark.registerapp.commands.exceptions.UnauthorizedException; import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; import edu.uark.registerapp.models.api.Employee; -import edu.uark.registerapp.models.api.EmployeeSignIn; import edu.uark.registerapp.models.entities.ActiveUserEntity; import edu.uark.registerapp.models.entities.EmployeeEntity; -import edu.uark.registerapp.models.repositories.ActiveUserRepository; -import edu.uark.registerapp.models.repositories.EmployeeRepository; @Service -public class EmployeeSignInCommand implements ResultCommandInterface { - @Override +public class EmployeeSignInCommand implements ResultCommandInterface{ + public Employee execute() { this.validateProperties(); - - return new Employee(this.SignInEmployee()); + return new Employee(this.SignInActiveUser()); } - // Helper methods private void validateProperties() { + //ID should not be blank. Should be a number if (StringUtils.isBlank(this.employeeSignIn.getEmployeeId())) { throw new UnprocessableEntityException("employee ID"); } + + //ID should only be a number try { Integer.parseInt(this.employeeSignIn.getEmployeeId()); - } catch (final NumberFormatException e) { + } catch (NumberFormatException e) { throw new UnprocessableEntityException("employee ID"); } - if (StringUtils.isBlank(this.employeeSignIn.getPassword())) { + + if (StringUtils.isBlank(this.employeeSignIn.getPassword())){ throw new UnprocessableEntityException("password"); } } - @Transactional - private EmployeeEntity SignInEmployee() { - final Optional employeeEntity = - this.employeeRepository.findByEmployeeId( - Integer.parseInt(this.employeeSignIn.getEmployeeId())); - - if (!employeeEntity.isPresent() - || !Arrays.equals( - employeeEntity.get().getPassword(), - EmployeeHelper.hashPassword(this.employeeSignIn.getPassword())) - ) { - + private Optional queryEmployeeUsingID() { + int employeeID = Integer.parseInt(this.getEmployeeId()); + String password = this.getPassword(); + Optional employeeEntity = this.employeeRepository.findByEmployeeId(employeeID); + if (!employeeEntity.isPresent() || !Arrays.equals(employeeEntity.get().getPassword(), EmployeeHelper.hashPassword(password))) + { throw new UnauthorizedException(); } - final Optional activeUserEntity = - this.activeUserRepository - .findByEmployeeId(employeeEntity.get().getId()); + return employeeEntity; + } + + @Transactional + private EmployeeEntity SignInActiveUser(){ + Optional employeeEntity = queryEmployeeUsingID(); + + //query the activeuser table for a record with the employee ID + Optional activeUserEntity = + this.activeUserRepository.findByEmployeeId(employeeEntity.get().getId()); - if (!activeUserEntity.isPresent()) { + //create a new active user in the record in the database if there isn't one already + if(!activeUserEntity.isPresent()) { this.activeUserRepository.save( - (new ActiveUserEntity()) - .setSessionKey(this.sessionId) - .setEmployeeId(employeeEntity.get().getId()) - .setClassification( - employeeEntity.get().getClassification()) - .setName( - employeeEntity.get().getFirstName() - .concat(" ") - .concat(employeeEntity.get().getLastName()))); - } else { + (new ActiveUserEntity()) + .setSessionKey(this.getSessionId()) + .setEmployeeId(employeeEntity.get().getId()) + .setClassification(employeeEntity.get().getClassification()) + .setName(employeeEntity.get().getFirstName().concat(" ").concat(employeeEntity.get().getLastName())) + ); + } + else { this.activeUserRepository.save( - activeUserEntity.get().setSessionKey(this.sessionId)); + activeUserEntity.get().setSessionKey(this.getSessionId()) + ); } - return employeeEntity.get(); } - // Properties + + //properties + @Autowired + private EmployeeRepository employeeRepository; + @Autowired + private ActiveUserRepository activeUserRepository; + private EmployeeSignIn employeeSignIn; - public EmployeeSignIn getEmployeeSignIn() { - return this.employeeSignIn; - } - public EmployeeSignInCommand setEmployeeSignIn(final EmployeeSignIn employeeSignIn) { - this.employeeSignIn = employeeSignIn; - return this; + public String getEmployeeId(){ + return this.employeeSignIn.getEmployeeId(); } - private String sessionId; + public String getPassword(){ + return this.employeeSignIn.getPassword(); + } + private String sessionId; //session key public String getSessionId() { return this.sessionId; } + public EmployeeSignInCommand setSessionId(final String sessionId) { this.sessionId = sessionId; return this; } - @Autowired - private EmployeeRepository employeeRepository; - @Autowired - private ActiveUserRepository activeUserRepository; + public EmployeeSignInCommand setEmployeeSignIn(final EmployeeSignIn employeeSignIn) { + this.employeeSignIn = employeeSignIn; + return this; + } } From c4bc2c4607a072914e595bcb42621e3946efaa1d Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Tue, 2 Mar 2021 20:52:15 -0600 Subject: [PATCH 25/32] fixing an error --- .../models/api/EmployeeSignIn.Java | 0 .../models/api/EmployeeSignIn.java | 28 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java delete mode 100644 src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.Java deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java deleted file mode 100644 index e01e4f6c..00000000 --- a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.uark.registerapp.models.api; - -import org.apache.commons.lang3.StringUtils; - -public class EmployeeSignIn { - private String employeeId; - public String getEmployeeId() { - return this.employeeId; - } - public EmployeeSignIn setEmployeeId(final String employeeId) { - this.employeeId = employeeId; - return this; - } - - private String password; - public String getPassword() { - return this.password; - } - public EmployeeSignIn setPassword(final String password) { - this.password = password; - return this; - } - - public EmployeeSignIn() { - this.password = StringUtils.EMPTY; - this.employeeId = StringUtils.EMPTY; - } -} From 2cd6c108e353dbb10dcb4d0a2edacb7a518a7224 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Tue, 2 Mar 2021 20:52:52 -0600 Subject: [PATCH 26/32] fixing an error --- .../models/api/EmployeeSignIn.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java new file mode 100644 index 00000000..e01e4f6c --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java @@ -0,0 +1,28 @@ +package edu.uark.registerapp.models.api; + +import org.apache.commons.lang3.StringUtils; + +public class EmployeeSignIn { + private String employeeId; + public String getEmployeeId() { + return this.employeeId; + } + public EmployeeSignIn setEmployeeId(final String employeeId) { + this.employeeId = employeeId; + return this; + } + + private String password; + public String getPassword() { + return this.password; + } + public EmployeeSignIn setPassword(final String password) { + this.password = password; + return this; + } + + public EmployeeSignIn() { + this.password = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + } +} From 51f439f162ed5ffd7049803340d4b1ff9a6a1676 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Tue, 2 Mar 2021 23:18:25 -0600 Subject: [PATCH 27/32] Added some new comments --- .../commands/activeUsers/ActiveUserDeleteCommand.java | 2 ++ .../registerapp/commands/employees/EmployeeSignInCommand.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java index ccd22837..42fbd1fa 100644 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -12,12 +12,14 @@ @Service public class ActiveUserDeleteCommand implements VoidCommandInterface { + @Transactional @Override public void execute() { final Optional activeUserEntity = this.activeUserRepository.findBySessionKey(this.sessionKey); + //removes active user if (activeUserEntity.isPresent()) { this.activeUserRepository.delete(activeUserEntity.get()); } diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index 51070de8..3aa05ccd 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -67,7 +67,7 @@ private EmployeeEntity SignInActiveUser(){ Optional activeUserEntity = this.activeUserRepository.findByEmployeeId(employeeEntity.get().getId()); - //create a new active user in the record in the database if there isn't one already + //create a new active user in the record in the database if there isn't one that matches if(!activeUserEntity.isPresent()) { this.activeUserRepository.save( (new ActiveUserEntity()) From e077e2b14f4ca28d8957da6f1fc3065c9faf68c8 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Wed, 3 Mar 2021 17:53:29 -0600 Subject: [PATCH 28/32] added validation to the activeuserdeletecommand file --- .../commands/activeUsers/ActiveUserDeleteCommand.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java index 42fbd1fa..21ee7dd0 100644 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -19,12 +19,20 @@ public void execute() { final Optional activeUserEntity = this.activeUserRepository.findBySessionKey(this.sessionKey); - //removes active user + validateEmployeeRequestObject(activeUserEntity); + + //removes active user if (activeUserEntity.isPresent()) { this.activeUserRepository.delete(activeUserEntity.get()); } } + private void validateEmployeeRequestObject(Optional activeUserEntity){ + String [] name = activeUserEntity.get().getName().split(" ", 2); + if (name[0].isBlank()) {throw new UnprocessableEntityException("First Name");} + if (name[1].isBlank()) {throw new UnprocessableEntityException("Last Name");} + } + // Properties private String sessionKey; public String getSessionKey() { From a2597d16ff30b0e8f35d988a3fcd8430ef8bc0fb Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Wed, 3 Mar 2021 18:08:18 -0600 Subject: [PATCH 29/32] added validation to the activeuserdeletecommand file --- .../commands/activeUsers/ActiveUserDeleteCommand.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java index 21ee7dd0..14b90276 100644 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -28,9 +28,12 @@ public void execute() { } private void validateEmployeeRequestObject(Optional activeUserEntity){ + if (StringUtils.isBlank(activeUserEntity.get().name())) { + throw new UnprocessableEntityException("Name"); + } String [] name = activeUserEntity.get().getName().split(" ", 2); - if (name[0].isBlank()) {throw new UnprocessableEntityException("First Name");} - if (name[1].isBlank()) {throw new UnprocessableEntityException("Last Name");} + if (StringUtils.isBlank(name[0])) {throw new UnprocessableEntityException("First Name");} + if (StringUtils.isBlank(name[1])) {throw new UnprocessableEntityException("Last Name");} } // Properties From 81b2cc8af89f5e5cbfc6a4750d045bb1097c4d76 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Wed, 3 Mar 2021 18:11:56 -0600 Subject: [PATCH 30/32] added validation to the activeuserdeletecommand file --- .../commands/activeUsers/ActiveUserDeleteCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java index 14b90276..367548e2 100644 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -2,11 +2,13 @@ import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import edu.uark.registerapp.commands.VoidCommandInterface; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; import edu.uark.registerapp.models.entities.ActiveUserEntity; import edu.uark.registerapp.models.repositories.ActiveUserRepository; @@ -28,7 +30,7 @@ public void execute() { } private void validateEmployeeRequestObject(Optional activeUserEntity){ - if (StringUtils.isBlank(activeUserEntity.get().name())) { + if (StringUtils.isBlank(activeUserEntity.get().getName())) { throw new UnprocessableEntityException("Name"); } String [] name = activeUserEntity.get().getName().split(" ", 2); From 07c9ff0bdf075ca9fcc77020e292663318983567 Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Wed, 3 Mar 2021 22:03:23 -0600 Subject: [PATCH 31/32] fixed the errors --- .../employees/EmployeeSignInCommand.java | 121 +++++++++--------- .../controllers/SignInRouteController.java | 1 - src/main/resources/static/scripts/signIn.js | 120 ++++++++++++----- src/main/resources/templates/signIn.html | 6 +- 4 files changed, 149 insertions(+), 99 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java index 3aa05ccd..d6e122a1 100644 --- a/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/employees/EmployeeSignInCommand.java @@ -1,117 +1,112 @@ package edu.uark.registerapp.commands.employees; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import org.apache.commons.lang3.StringUtils; - import java.util.Arrays; import java.util.Optional; import javax.transaction.Transactional; -import edu.uark.registerapp.models.api.EmployeeSignIn; -import edu.uark.registerapp.models.repositories.ActiveUserRepository; -import edu.uark.registerapp.models.repositories.EmployeeRepository; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + import edu.uark.registerapp.commands.ResultCommandInterface; import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; import edu.uark.registerapp.commands.exceptions.UnauthorizedException; import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; import edu.uark.registerapp.models.api.Employee; +import edu.uark.registerapp.models.api.EmployeeSignIn; import edu.uark.registerapp.models.entities.ActiveUserEntity; import edu.uark.registerapp.models.entities.EmployeeEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; +import edu.uark.registerapp.models.repositories.EmployeeRepository; @Service -public class EmployeeSignInCommand implements ResultCommandInterface{ - +public class EmployeeSignInCommand implements ResultCommandInterface { + @Override public Employee execute() { this.validateProperties(); - return new Employee(this.SignInActiveUser()); + return new Employee(this.SignInEmployee()); } + // Helper methods private void validateProperties() { - //ID should not be blank. Should be a number + //check if employeeID is blank if (StringUtils.isBlank(this.employeeSignIn.getEmployeeId())) { throw new UnprocessableEntityException("employee ID"); } - - //ID should only be a number + //check if you can get only a number out of the ID try { Integer.parseInt(this.employeeSignIn.getEmployeeId()); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { + //throw an exception if the ID is not just numbers throw new UnprocessableEntityException("employee ID"); } - - if (StringUtils.isBlank(this.employeeSignIn.getPassword())){ + if (StringUtils.isBlank(this.employeeSignIn.getPassword())) { + //throw exception if the password is blank throw new UnprocessableEntityException("password"); } } - private Optional queryEmployeeUsingID() { - int employeeID = Integer.parseInt(this.getEmployeeId()); - String password = this.getPassword(); - Optional employeeEntity = this.employeeRepository.findByEmployeeId(employeeID); - if (!employeeEntity.isPresent() || !Arrays.equals(employeeEntity.get().getPassword(), EmployeeHelper.hashPassword(password))) - { + @Transactional + private EmployeeEntity SignInEmployee() { + //tries to find existing employee using the id + final Optional employeeEntity = + this.employeeRepository.findByEmployeeId( + Integer.parseInt(this.employeeSignIn.getEmployeeId())); + //verifies ifthe employee exists + if (!employeeEntity.isPresent() + || !Arrays.equals( + employeeEntity.get().getPassword(), + EmployeeHelper.hashPassword(this.employeeSignIn.getPassword())) + ) { + throw new UnauthorizedException(); } - return employeeEntity; - } - - @Transactional - private EmployeeEntity SignInActiveUser(){ - Optional employeeEntity = queryEmployeeUsingID(); - - //query the activeuser table for a record with the employee ID - Optional activeUserEntity = - this.activeUserRepository.findByEmployeeId(employeeEntity.get().getId()); + final Optional activeUserEntity = + this.activeUserRepository + .findByEmployeeId(employeeEntity.get().getId()); - //create a new active user in the record in the database if there isn't one that matches - if(!activeUserEntity.isPresent()) { + if (!activeUserEntity.isPresent()) { this.activeUserRepository.save( - (new ActiveUserEntity()) - .setSessionKey(this.getSessionId()) - .setEmployeeId(employeeEntity.get().getId()) - .setClassification(employeeEntity.get().getClassification()) - .setName(employeeEntity.get().getFirstName().concat(" ").concat(employeeEntity.get().getLastName())) - ); - } - else { + (new ActiveUserEntity()) + .setSessionKey(this.sessionId) + .setEmployeeId(employeeEntity.get().getId()) + .setClassification( + employeeEntity.get().getClassification()) + .setName( + employeeEntity.get().getFirstName() + .concat(" ") + .concat(employeeEntity.get().getLastName()))); + } else { this.activeUserRepository.save( - activeUserEntity.get().setSessionKey(this.getSessionId()) - ); + activeUserEntity.get().setSessionKey(this.sessionId)); } + return employeeEntity.get(); } - - //properties - @Autowired - private EmployeeRepository employeeRepository; - @Autowired - private ActiveUserRepository activeUserRepository; - + // Properties private EmployeeSignIn employeeSignIn; - public String getEmployeeId(){ - return this.employeeSignIn.getEmployeeId(); + public EmployeeSignIn getEmployeeSignIn() { + return this.employeeSignIn; } - - public String getPassword(){ - return this.employeeSignIn.getPassword(); + public EmployeeSignInCommand setEmployeeSignIn(final EmployeeSignIn employeeSignIn) { + this.employeeSignIn = employeeSignIn; + return this; } - private String sessionId; //session key + + private String sessionId; public String getSessionId() { return this.sessionId; } - public EmployeeSignInCommand setSessionId(final String sessionId) { this.sessionId = sessionId; return this; } - public EmployeeSignInCommand setEmployeeSignIn(final EmployeeSignIn employeeSignIn) { - this.employeeSignIn = employeeSignIn; - return this; - } + @Autowired + private EmployeeRepository employeeRepository; + @Autowired + private ActiveUserRepository activeUserRepository; } diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java index 5e9ead63..0f033b67 100644 --- a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java @@ -55,7 +55,6 @@ public ModelAndView performSignIn( EmployeeSignIn employeeSignIn, HttpServletRequest request ) { - try { this.employeeSignInCommand .setSessionId(request.getSession().getId()) diff --git a/src/main/resources/static/scripts/signIn.js b/src/main/resources/static/scripts/signIn.js index ac891898..8872d9fc 100644 --- a/src/main/resources/static/scripts/signIn.js +++ b/src/main/resources/static/scripts/signIn.js @@ -1,32 +1,88 @@ -function validateForm(){ - - var id = document.getElementById('employeeId') //sets the variable to the employeeId - var pwd = document.getElementById('password') //sets the variable to the password - - if(id != null && pwd != null ) //makes sure that the employeeId and password are not blank - { - if(isNaN(Number(id.value))) //checks to see if the emplyeeId is a number - { - if(isNaN(Number(id.value) > 0)) //checks to see if the id value is greater than 0 - { - if(pwd.value.trim() !=='') //checks to see if the pwd value doesn't equal a blank after triming the whitespaces - { - return true; - }else{ - alert("Please fill out a valid Password."); //alerts the user if the password they've typed in doesn't meet the requirements. - return false; - } - } - else{ - alert("Please fill out a valid EmployeeId."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. - return false; - } - }else{ - alert("Please fill out a valid EmployeeId."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. - return false; - } - }else{ - alert("Please fill out a valid EmployeeId and Password."); //alerts the user if the password & employeeId they've typed in doesn't meet the requirements. - return false; - } -} \ No newline at end of file +// document.addEventListener("DOMContentLoaded", function(event) { +// const employeeIdEditElement = document.getElementById('employeeId'); + +// employeeIdEditElement.focus(); +// employeeIdEditElement.select(); +// }); + + + +// function validateForm(){ + +// const id = document.getElementById('employeeId') //sets the variable to the employeeId +// const pwd = document.getElementById('password') //sets the variable to the password +// console.log(id.value); + +// if(id != null && pwd != null ) //makes sure that the employeeId and password are not blank +// { +// console.log("!isNaN(Number(id.value)" + (!isNaN(Number(id.value)))); +// if(!isNaN(Number(id.value))) //checks to see if the emplyeeId is a number +// { +// console.log("id.value" + Number(id.value)); +// if(Number(id.value) > 0) //checks to see if the id value is greater than 0 +// { +// if(pwd.value.trim() !=='') //checks to see if the pwd value doesn't equal a blank after triming the whitespaces +// { +// return true; +// }else{ +// alert("Please fill out a valid Password."); //alerts the user if the password they've typed in doesn't meet the requirements. +// return false; +// } +// } +// else{ +// alert("Please fill out a valid EmployeeId1."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. +// return false; +// } +// }else{ +// alert("Please fill out a valid EmployeeId."); //alerts the user if the EmployeeId they've typed in doesn't meet the requirements. +// return false; +// } +// }else{ +// alert("Please fill out a valid EmployeeId and Password."); //alerts the user if the password & employeeId they've typed in doesn't meet the requirements. +// return false; +// } +// } + +document.addEventListener("DOMContentLoaded", function(event) { + const employeeIdEditElement = getEmployeeIdEditElement(); + employeeIdEditElement.focus(); + employeeIdEditElement.select(); +}); + +function validateForm() { + const employeeIdEditElement = getEmployeeIdEditElement(); + if (isNaN(Number(employeeIdEditElement.value)) + || (Number(employeeIdEditElement.value) <= 0)) { + + displayError("Please provide a valid employee ID."); + + employeeIdEditElement.focus(); + employeeIdEditElement.select(); + + return false; + } + + const passwordEditElement = getPasswordEditElement(); + if ((passwordEditElement.value == null) + || (passwordEditElement.value.trim() === "")) { + + displayError("Please provide a valid password. It may not be blank."); + + passwordEditElement.focus(); + passwordEditElement.select(); + + return false; + } + + return true; +} + +//Getters and setters +function getPasswordEditElement() { + return document.getElementById("password"); +} + +function getEmployeeIdEditElement() { + return document.getElementById("employeeId"); +} +//End getters and setters \ No newline at end of file diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index a1d5ac39..b66ac151 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -19,12 +19,12 @@

- + - + - +
From 5a27c9147a50195841516ecddba359cb489528bf Mon Sep 17 00:00:00 2001 From: nathan fredricks Date: Wed, 3 Mar 2021 22:15:58 -0600 Subject: [PATCH 32/32] need to test --- .../controllers/MainMenuRouteController.java | 17 +++++- src/main/resources/static/scripts/mainMenu.js | 37 +++++++++++- src/main/resources/templates/mainMenu.html | 57 ++++++++++++++++--- 3 files changed, 99 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java index 9b497ae3..af408a6c 100644 --- a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -3,6 +3,7 @@ import java.util.UUID; import javax.servlet.http.HttpServletRequest; import java.util.Map; +import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; import edu.uark.registerapp.controllers.enums.ViewNames; @Controller @@ -24,7 +26,20 @@ public ModelAndView start( final HttpServletRequest httpServletRequest ) { ModelAndView modelAndView = new ModelAndView(ViewNames.MAIN_MENU.getViewName(), queryParameters); - // modelAndView.addObject(ERROR_MESSAGE, attributeValue) + final Optional ActiveUserEntity = + this.getCurrentUser(httpServletRequest); return modelAndView; } + + protected Optional getCurrentUser(final HttpServletRequest request) + { + try { + return Optional.of( + this.validateActiveUserCommand + .setSessionKey(request.getSession().getId()) + .execute()); + } catch (final UnauthorizedException e) { + return Optional.ofNullable(null); + } + } } diff --git a/src/main/resources/static/scripts/mainMenu.js b/src/main/resources/static/scripts/mainMenu.js index 5c419ec6..3b16c3f7 100644 --- a/src/main/resources/static/scripts/mainMenu.js +++ b/src/main/resources/static/scripts/mainMenu.js @@ -1,10 +1,43 @@ -document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", function(event) { + getStartTransactionActionElement().addEventListener( + "click", + () => { displayError("Functionality has not yet been implemented."); }); + getViewProductsActionElement().addEventListener( "click", - () => { window.location.assign("/productListing"); console.log("shrekswasf");}); + () => { window.location.assign("/productListing"); }); + + getCreateEmployeeActionElement().addEventListener( + "click", + () => { window.location.assign("/employeeDetail"); }); + + getProductSalesReportActionElement().addEventListener( + "click", + () => { displayError("Functionality has not yet been implemented."); }); + + getCashierSalesReportActionElement().addEventListener( + "click", + () => { displayError("Functionality has not yet been implemented."); }); }); +// Getters and setters function getViewProductsActionElement() { return document.getElementById("viewProductsButton"); } +function getCreateEmployeeActionElement() { + return document.getElementById("createEmployeeButton"); +} + +function getStartTransactionActionElement() { + return document.getElementById("startTransactionButton"); +} + +function getProductSalesReportActionElement() { + return document.getElementById("productSalesReportButton"); +} + +function getCashierSalesReportActionElement() { + return document.getElementById("cashierSalesReportButton"); +} +// End getters and setters diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index 3901ed05..706fc531 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -1,7 +1,9 @@ + - Main Menu - + Register - Main Menu + + @@ -9,15 +11,52 @@ +

Main Menu

- +
-
    -
  • - -
  • -
+
+

+
+ + +
+ + - \ No newline at end of file + + + + + + \ No newline at end of file