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/helpers/EmployeeHelper.java b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java
new file mode 100644
index 00000000..5b9ddc71
--- /dev/null
+++ b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java
@@ -0,0 +1,23 @@
+package edu.uark.registerapp.commands.employees.helpers;
+
+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) {
+ // TODO: Hash the password using a MessageDigest. An example can be found at http://tutorials.jenkov.com/java-cryptography/messagedigest.html
+ return new byte[0];
+ }
+
+ private static final int EMPLOYEE_ID_MAXIMUM_LENGTH = 5;
+}
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/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/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java
new file mode 100644
index 00000000..9a3cda2d
--- /dev/null
+++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java
@@ -0,0 +1,45 @@
+package edu.uark.registerapp.controllers;
+
+import java.util.Map;
+import java.util.Optional;
+
+import javax.servlet.http.HttpServletRequest;
+
+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.controllers.enums.ViewModelNames;
+import edu.uark.registerapp.controllers.enums.ViewNames;
+import edu.uark.registerapp.models.entities.ActiveUserEntity;
+
+@Controller
+@RequestMapping(value = "/mainMenu")
+public class MainMenuRouteController extends BaseRouteController {
+ @RequestMapping(method = RequestMethod.GET)
+ public ModelAndView start(
+ @RequestParam final Map queryParameters,
+ final HttpServletRequest request
+ ) {
+
+ final Optional activeUserEntity =
+ this.getCurrentUser(request);
+ if (!activeUserEntity.isPresent()) {
+ return this.buildInvalidSessionResponse();
+ }
+
+ ModelAndView modelAndView =
+ this.setErrorMessageFromQueryString(
+ new ModelAndView(ViewNames.MAIN_MENU.getViewName()),
+ queryParameters);
+
+ // TODO: Examine the ActiveUser classification if you want this information
+ modelAndView.addObject(
+ ViewModelNames.IS_ELEVATED_USER.getValue(),
+ true);
+
+ return modelAndView;
+ }
+}
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..c7694c61
--- /dev/null
+++ b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java
@@ -0,0 +1,32 @@
+package edu.uark.registerapp.controllers;
+
+import javax.servlet.http.HttpServletRequest;
+
+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 org.springframework.beans.factory.annotation.Autowired;
+
+import edu.uark.registerapp.controllers.enums.ViewNames;
+import edu.uark.registerapp.models.api.ApiResponse;
+import edu.uark.registerapp.commands.activeUsers.ActiveUserDeleteCommand;
+
+@RestController
+@RequestMapping(value = "/api")
+public class SignInRestController extends BaseRestController {
+ @RequestMapping(value="/signOut", method = RequestMethod.DELETE)
+ public @ResponseBody ApiResponse removeActiveUser(
+ final HttpServletRequest request
+ ) {
+
+ this.deleteUserCommand
+ .setSessionKey(request.getSession().getId())
+ .execute();
+
+ return (new ApiResponse())
+ .setRedirectUrl(ViewNames.SIGN_IN.getRoute());
+ }
+ @Autowired
+ private DeleteUserCommand deleteUserCommand;
+}
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..306f98fb
--- /dev/null
+++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java
@@ -0,0 +1,32 @@
+package edu.uark.registerapp.controllers;
+
+import javax.servlet.http.HttpServletRequest;
+
+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.servlet.ModelAndView;
+
+import edu.uark.registerapp.controllers.enums.ViewNames;
+
+@Controller
+@RequestMapping(value = "/")
+public class SignInRouteController extends BaseRouteController {
+ // TODO: Route for initial page load
+
+ @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+ public ModelAndView performSignIn(
+ // TODO: Define an object that will represent the sign in request and add it as a parameter here
+ HttpServletRequest request
+ ) {
+
+ // TODO: Use the credentials provided in the request body
+ // and the "id" property of the (HttpServletRequest)request.getSession() variable
+ // to sign in the user
+
+ return new ModelAndView(
+ REDIRECT_PREPEND.concat(
+ ViewNames.MAIN_MENU.getRoute()));
+ }
+}
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/ViewModelNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java
index 7c39b102..6ee26935 100644
--- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java
+++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java
@@ -3,6 +3,7 @@
public enum ViewModelNames {
NOT_DEFINED(""),
ERROR_MESSAGE("errorMessage"),
+ IS_ELEVATED_USER("isElevatedUser"),
PRODUCTS("products"), // Product listing
PRODUCT("product"); // Product detail
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..3e3e2ca2 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 {
+ SIGN_IN("signIn", "/"),
+ MAIN_MENU("mainMenu"),
PRODUCT_DETAIL("productDetail"),
- PRODUCT_LISTING("productListing", "/");
+ EMPLOYEE_DETAIL("employeeDetail"),
+ PRODUCT_LISTING("productListing");
public String getRoute() {
return this.route;
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/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/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/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);
+}
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);
+}
diff --git a/src/main/resources/static/scripts/master.js b/src/main/resources/static/scripts/master.js
index 88b039d0..c61d3563 100644
--- a/src/main/resources/static/scripts/master.js
+++ b/src/main/resources/static/scripts/master.js
@@ -1,3 +1,10 @@
+document.addEventListener("DOMContentLoaded", () => {
+ const signOutActionElement = getSignOutActionElement();
+ if (signOutActionElement != null) {
+ signOutActionElement.addEventListener("click", signOutActionClickHandler);
+ }
+});
+
// AJAX
function ajaxGet(resourceRelativeUri, callback) {
return ajax(resourceRelativeUri, "GET", null, callback);
@@ -158,6 +165,10 @@ function displayError(errorMessage) {
// End display error message
//Getters and setters
+function getSignOutActionElement() {
+ return document.getElementById("signOutImage");
+}
+
function getErrorMessageContainerElement() {
return document.getElementById("error");
}
@@ -166,3 +177,18 @@ function getErrorMessageDisplayElement() {
return document.getElementById("errorMessage");
}
// End getters and setters
+
+//Sign out
+function signOutActionClickHandler() {
+ ajaxDelete("/api/signOut", (callbackResponse) => {
+ if ((callbackResponse.data != null)
+ && (callbackResponse.data.redirectUrl != null)
+ && (callbackResponse.data.redirectUrl !== "")) {
+
+ window.location.replace(callbackResponse.data.redirectUrl);
+ } else {
+ window.location.replace("/");
+ }
+ });
+}
+//End sign out
\ No newline at end of file
diff --git a/src/main/resources/static/scripts/signIn.js b/src/main/resources/static/scripts/signIn.js
new file mode 100644
index 00000000..0cb0f343
--- /dev/null
+++ b/src/main/resources/static/scripts/signIn.js
@@ -0,0 +1,24 @@
+document.addEventListener("DOMContentLoaded", function(event) {
+ // TODO: Anything you want to do when the page is loaded?
+});
+
+function validateForm() {
+ // TODO: Validate the user input
+ //get value of Employee ID and Password
+ var employeeId = document.getElementById("employeeId").value;
+ var password = document.getElementById("password").value;
+
+ if (employeeId != '' && password != ''){
+ if (isNaN(employeeId)) {
+ document.getElementById("errorMessage").innerHTML = "You can use only index"
+ }
+ else {
+ document.getElementById("errorMessage").innerHTML = "Sign in successful!!"
+ return true;
+ }
+ }
+ else{
+ document.getElementById("errorMessage").innerHTML = "Please do not keep blank Employee ID & Password"
+ return false;
+ }
+}
diff --git a/src/main/resources/static/styles/master.css b/src/main/resources/static/styles/master.css
index 2b060e6d..f35bb48a 100644
--- a/src/main/resources/static/styles/master.css
+++ b/src/main/resources/static/styles/master.css
@@ -30,6 +30,24 @@ td.hidden {
display: none
}
+div.footer {
+ left: 0;
+ right: 0;
+ bottom: 0;
+ position: absolute;
+}
+
+img.footer {
+ z-index: 1;
+ height: 50px;
+ text-decoration: none;
+ display: inline-block;
+ cursor: pointer;
+ position: fixed;
+ right: 20;
+ bottom: 20;
+}
+
div.inputContent,
form.inputContent {
display: inline-block;
diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html
new file mode 100644
index 00000000..7d1abb27
--- /dev/null
+++ b/src/main/resources/templates/mainMenu.html
@@ -0,0 +1,57 @@
+
+
+
+ Register - Main Menu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html
index c4b758ae..fe73240e 100644
--- a/src/main/resources/templates/productListing.html
+++ b/src/main/resources/templates/productListing.html
@@ -25,8 +25,14 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html
new file mode 100644
index 00000000..0459b0bd
--- /dev/null
+++ b/src/main/resources/templates/signIn.html
@@ -0,0 +1,62 @@
+
+
+