Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions README-Jodi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Jodi Mitchell

This is my Readme for my first commit.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/edu/.DS_Store
Binary file not shown.
Binary file added src/main/java/edu/uark/.DS_Store
Binary file not shown.
Binary file added src/main/java/edu/uark/registerapp/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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> 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;
}
Original file line number Diff line number Diff line change
@@ -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<ActiveUserEntity> {
@Override
public ActiveUserEntity execute() {
final Optional<ActiveUserEntity> 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.uark.registerapp.commands.employees;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.uark.registerapp.commands.VoidCommandInterface;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.models.repositories.EmployeeRepository;

@Service
public class ActiveEmployeeExistsQuery implements VoidCommandInterface {
@Override
public void execute() {
if (!this.employeeRepository.existsByIsActive(true)) {
throw new NotFoundException("Employee");
}
}

@Autowired
private EmployeeRepository employeeRepository;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// This will create a new employee

package edu.uark.registerapp.commands.employees;

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.UnprocessableEntityException;
import edu.uark.registerapp.models.api.Employee;
import edu.uark.registerapp.models.entities.EmployeeEntity;
import edu.uark.registerapp.models.enums.EmployeeClassification;
import edu.uark.registerapp.models.repositories.EmployeeRepository;

@Service
public class EmployeeCreateCommand implements ResultCommandInterface<Employee> {
@Override
public Employee execute() {
this.validateProperties();

// If this is the first employee to be added and make them the general manager
if (this.isInitialEmployee) {
this.apiEmployee.setClassification(
EmployeeClassification.GENERAL_MANAGER.getClassification());
}

// Create a new ENTITY object from the API object details.
final EmployeeEntity employeeEntity =
this.employeeRepository.save(new EmployeeEntity(this.apiEmployee));

// Synchronize information generated by the database upon INSERT.
this.apiEmployee.setId(employeeEntity.getId());
// Only send the password over the network when modifying the database.
this.apiEmployee.setPassword(StringUtils.EMPTY);
// Only send the password over the network when modifying the database.
this.apiEmployee.setCreatedOn(employeeEntity.getCreatedOn());
this.apiEmployee.setEmployeeId(
EmployeeHelper.padEmployeeId(
employeeEntity.getEmployeeId()));

return this.apiEmployee;
}

// Helper methods
// This checks the fields on the view.
// Will not accept if any of the fields are blank.
private void validateProperties() {
if (StringUtils.isBlank(this.apiEmployee.getFirstName())) {
throw new UnprocessableEntityException("first name");
}
if (StringUtils.isBlank(this.apiEmployee.getLastName())) {
throw new UnprocessableEntityException("last name");
}
if (StringUtils.isBlank(this.apiEmployee.getPassword())) {
throw new UnprocessableEntityException("password");
}

// If there is a single employee in the DB then select a position for the new addition
if (!this.isInitialEmployee
&& (EmployeeClassification.map(this.apiEmployee.getClassification()) == EmployeeClassification.NOT_DEFINED)) {

throw new UnprocessableEntityException("classification");
}
}

// Getters and Setters for the new employee
private Employee apiEmployee;
public Employee getApiEmployee() {
return this.apiEmployee;
}
public EmployeeCreateCommand setApiEmployee(final Employee apiEmployee) {
this.apiEmployee = apiEmployee;
return this;
}

// Getters and Setters for the first employee, the general manager.
private boolean isInitialEmployee;
public boolean getIsInitialEmployee() {
return this.isInitialEmployee;
}
public EmployeeCreateCommand setIsInitialEmployee(
final boolean isInitialEmployee
) {

this.isInitialEmployee = isInitialEmployee;
return this;
}

@Autowired
private EmployeeRepository employeeRepository;

public EmployeeCreateCommand() {
this.isInitialEmployee = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This will delete an employee by their employee ID

package edu.uark.registerapp.commands.employees;

import java.util.Optional;
import java.util.UUID;

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.NotFoundException;
import edu.uark.registerapp.models.entities.EmployeeEntity;
import edu.uark.registerapp.models.repositories.EmployeeRepository;

@Service
public class EmployeeDeleteCommand implements VoidCommandInterface {
@Transactional
@Override
public void execute() {
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findById(this.employeeId);// Find the employee first

if (!employeeEntity.isPresent()) { // No record with the associated record ID exists in the database.
throw new NotFoundException("Product");
}

this.employeeRepository.delete(employeeEntity.get()); // Delete the employee if found
}

// Getters and Setters
private UUID employeeId;
public UUID getEmployeeId() {
return this.employeeId;
}
public EmployeeDeleteCommand setEmployeeId(final UUID productId) {
this.employeeId = productId;
return this;
}

@Autowired
private EmployeeRepository employeeRepository;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Find employee by Id

package edu.uark.registerapp.commands.employees;

import java.util.Optional;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.uark.registerapp.commands.ResultCommandInterface;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.models.api.Employee;
import edu.uark.registerapp.models.entities.EmployeeEntity;
import edu.uark.registerapp.models.repositories.EmployeeRepository;

@Service
public class EmployeeQuery implements ResultCommandInterface<Employee> {
@Override
public Employee execute() {
final Optional<EmployeeEntity> employeeEntity =
this.employeeRepository.findById(this.employeeId);

if (employeeEntity.isPresent()) {
return new Employee(employeeEntity.get());
} else {
throw new NotFoundException("Employee");
}
}

// Getters and setters
private UUID employeeId;
public UUID getEmployeeId() {
return this.employeeId;
}
public EmployeeQuery setEmployeeId(final UUID employeeId) {
this.employeeId = employeeId;
return this;
}

@Autowired
private EmployeeRepository employeeRepository;
}
Loading