From bfb7f0ebd2c19b0fdd729de526e36794812c35cd Mon Sep 17 00:00:00 2001 From: Tharre Date: Sun, 29 Apr 2018 00:56:09 +0200 Subject: Implement interfaces and the correspondant DTOs --- .../einsatzverwaltung/dao/EmployeeDAO.java | 44 +++++++++++++ .../einsatzverwaltung/dao/OperationDAO.java | 48 ++++++++++++++ .../einsatzverwaltung/dao/RegistrationDAO.java | 27 ++++++++ .../einsatzverwaltung/dao/VehicleDAO.java | 44 +++++++++++++ .../groupphase/einsatzverwaltung/dto/Employee.java | 51 +++++++++++++++ .../einsatzverwaltung/dto/Operation.java | 68 ++++++++++++++++++++ .../einsatzverwaltung/dto/Registration.java | 34 ++++++++++ .../groupphase/einsatzverwaltung/dto/Vehicle.java | 73 ++++++++++++++++++++++ .../einsatzverwaltung/service/EmployeeService.java | 46 ++++++++++++++ .../service/OperationService.java | 70 +++++++++++++++++++++ .../service/RegistrationService.java | 31 +++++++++ .../einsatzverwaltung/service/VehicleService.java | 49 +++++++++++++++ .../exception/ElementNotFoundException.java | 16 +++++ .../exception/InvalidEmployeeException.java | 16 +++++ .../exception/InvalidOperationException.java | 16 +++++ .../exception/InvalidRegistrationException.java | 16 +++++ .../exception/InvalidVehicleException.java | 16 +++++ .../groupphase/exception/PersistenceException.java | 16 +++++ .../groupphase/exception/ServiceException.java | 16 +++++ 19 files changed, 697 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeService.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationService.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleService.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ElementNotFoundException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidEmployeeException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidOperationException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidRegistrationException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidVehicleException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/PersistenceException.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ServiceException.java (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAO.java new file mode 100644 index 0000000..564ce7c --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAO.java @@ -0,0 +1,44 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import java.util.List; + +public interface EmployeeDAO { + + /** + * Persist the given employee. + * + * @param employee that should be stored + * @return the id that was assigned + * @throws PersistenceException if the employee could not be persisted + */ + long add(Employee employee) throws PersistenceException; + + /** + * Update the given employee. + * + * @param employee that should be updated + * @throws ElementNotFoundException if no employee with the given id exists + * @throws PersistenceException if the employee could not be updated + */ + void update(Employee employee) throws ElementNotFoundException, PersistenceException; + + /** + * Get all stored employees. + * + * @return list containing all stored employees + * @throws PersistenceException if loading the stored employees failed + */ + List list() throws PersistenceException; + + /** + * Remove employee with the given id from the store. + * + * @param id of the employee that should be removed + * @throws ElementNotFoundException if no employee with the given id exists + * @throws PersistenceException if the employee could not be removed + */ + void remove(long id) throws ElementNotFoundException, PersistenceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java new file mode 100644 index 0000000..7f28005 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java @@ -0,0 +1,48 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import java.util.EnumSet; +import java.util.List; + +public interface OperationDAO { + + /** + * Persist the given operation. + * + * @param operation that should be stored + * @return the id that was assigned + * @throws PersistenceException if the operation could not be persisted + */ + long add(Operation operation) throws PersistenceException; + + /** + * Update the given operation. + * + * @param operation that should be updated + * @throws ElementNotFoundException if no operation with the given id exists + * @throws PersistenceException if the operation could not be updated + */ + void update(Operation operation) throws ElementNotFoundException, PersistenceException; + + /** + * Returns the operation with the given id. + * + * @param operationId id of the operation that should be returned + * @return operation with the given id + * @throws ElementNotFoundException if no operation with the given id exists + * @throws PersistenceException if the operation could not be loaded + */ + Operation get(long operationId) throws ElementNotFoundException, PersistenceException; + + /** + * Get all stored operations with matching status. + * + * @param statuses set containing all statuses that should be matched + * @return list containing all matched operations + * @throws PersistenceException if loading the stored operations failed + */ + List list(EnumSet statuses) throws PersistenceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java new file mode 100644 index 0000000..f2c461a --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java @@ -0,0 +1,27 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; + +public interface RegistrationDAO { + + /** + * Persist the given registration. + * + * @param vehicleId the id of the target vehicle + * @param registration that should be stored + * @return the id that was assigned + * @throws PersistenceException if the registration could not be persisted + */ + long add(long vehicleId, Registration registration) throws PersistenceException; + + /** + * Make registration with the given id inactive. + * + * @param id of the registration that should be made inactive + * @throws ElementNotFoundException if no registration with the given id exists + * @throws PersistenceException if the registration could not be made inactive + */ + void remove(long id) throws ElementNotFoundException, PersistenceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAO.java new file mode 100644 index 0000000..fe12952 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAO.java @@ -0,0 +1,44 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import java.util.List; + +public interface VehicleDAO { + + /** + * Persist the given vehicle. + * + * @param vehicle that should be stored + * @return the id that was assigned + * @throws PersistenceException if the vehicle could not be persisted + */ + long add(Vehicle vehicle) throws PersistenceException; + + /** + * Update the given vehicle. + * + * @param vehicle that should be updated + * @throws ElementNotFoundException if no vehicle with the given id exists + * @throws PersistenceException if the vehicle could not be updated + */ + void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException; + + /** + * Get all stored vehicles. + * + * @return list containing all stored vehicles + * @throws PersistenceException if loading the stored vehicles failed + */ + List list() throws PersistenceException; + + /** + * Remove vehicle with the given id from the store. + * + * @param id of the vehicle that should be removed + * @throws ElementNotFoundException if no vehicle with the given id exists + * @throws PersistenceException if the vehicle could not be removed + */ + void remove(long id) throws ElementNotFoundException, PersistenceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java new file mode 100644 index 0000000..bbb5117 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java @@ -0,0 +1,51 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; + +import com.google.auto.value.AutoValue; +import java.time.LocalDate; + +@AutoValue +public abstract class Employee { + public enum EducationLevel { + RS, + NFS, + NKV, + NKA, + NKI, + NA + } + + abstract long id(); + + abstract String name(); + + abstract LocalDate birthday(); + + abstract EducationLevel educationLevel(); + + abstract boolean isDriver(); + + abstract boolean isPilot(); + + public static Builder builder() { + return new AutoValue_Employee.Builder().id(0); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder id(long id); + + public abstract Builder name(String name); + + public abstract Builder birthday(LocalDate birthday); + + public abstract Builder educationLevel(EducationLevel educationLevel); + + public abstract Builder isDriver(boolean isDriver); + + public abstract Builder isPilot(boolean isPilot); + + public abstract Employee build(); + } + + public abstract Builder toBuilder(); +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java new file mode 100644 index 0000000..bfb03c7 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java @@ -0,0 +1,68 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; + +import com.google.auto.value.AutoValue; +import java.time.Instant; +import java.util.List; +import javax.annotation.Nullable; + +@AutoValue +public abstract class Operation { + public enum Severity { + A, + B, + C, + D, + E, + O, + } + + public enum Status { + ACTIVE, + COMPLETED, + CANCELLED, + } + + abstract long id(); + + abstract String opCode(); + + abstract Severity severity(); + + abstract Status status(); + + abstract List vehicles(); + + @Nullable + abstract Instant created(); + + abstract String destination(); + + abstract String additionalInfo(); + + public static Builder builder() { + return new AutoValue_Operation.Builder().id(0); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder id(long id); + + public abstract Builder opCode(String opCode); + + public abstract Builder severity(Severity severity); + + public abstract Builder status(Status status); + + public abstract Builder vehicles(List vehicles); + + public abstract Builder created(Instant created); + + public abstract Builder destination(String destination); + + public abstract Builder additionalInfo(String additionalInfo); + + public abstract Operation build(); + } + + public abstract Builder toBuilder(); +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java new file mode 100644 index 0000000..f917406 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java @@ -0,0 +1,34 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; + +import com.google.auto.value.AutoValue; +import java.time.Instant; + +@AutoValue +public abstract class Registration { + abstract long id(); + + abstract Instant start(); + + abstract Instant end(); + + abstract Employee employee(); + + public static Builder builder() { + return new AutoValue_Registration.Builder().id(0); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder id(long id); + + public abstract Builder start(Instant start); + + public abstract Builder end(Instant end); + + public abstract Builder employee(Employee employee); + + public abstract Registration build(); + } + + public abstract Builder toBuilder(); +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java new file mode 100644 index 0000000..29698da --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java @@ -0,0 +1,73 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; + +import com.google.auto.value.AutoValue; +import java.util.List; +import javax.annotation.Nullable; + +@AutoValue +public abstract class Vehicle { + public enum ConstructionType { + NORMAL, + HOCHDACH, + MITTELHOCHDACH, + } + + public enum VehicleType { + BKTW, + KTW_B, + KTW, + RTW, + NEF, + NAH, + } + + public enum Status { + ABGEMELDET, + FREI_WACHE, + ZUM_BERUFUNGSORT, + AM_BERUFUNGSORT, + ZUM_ZIELORT, + AM_ZIELORT, + FREI_FUNK, + } + + abstract long id(); + + abstract String name(); + + abstract ConstructionType constructionType(); + + abstract VehicleType type(); + + abstract Status status(); + + abstract boolean hasNef(); + + @Nullable + abstract List registrations(); + + public static Builder builder() { + return new AutoValue_Vehicle.Builder().id(0); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder id(long id); + + public abstract Builder name(String name); + + public abstract Builder constructionType(ConstructionType constructionType); + + public abstract Builder type(VehicleType type); + + public abstract Builder status(Status status); + + public abstract Builder hasNef(boolean hasNef); + + public abstract Builder registrations(List registrations); + + public abstract Vehicle build(); + } + + public abstract Builder toBuilder(); +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeService.java new file mode 100644 index 0000000..8753504 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeService.java @@ -0,0 +1,46 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.List; + +public interface EmployeeService { + + /** + * Add given employee to the store. + * + * @param employee that should be added to the store + * @return the id that was assigned + * @throws InvalidEmployeeException if the employee is invalid + * @throws ServiceException if the employee could not be persisted + */ + long add(Employee employee) throws InvalidEmployeeException, ServiceException; + + /** + * Update the given employee. + * + * @param employee that should be updated + * @return the updated employee + * @throws InvalidEmployeeException if the employee is invalid + * @throws ServiceException if the updated employee could not be persisted + */ + Employee update(Employee employee) throws InvalidEmployeeException, ServiceException; + + /** + * Get all stored employees. + * + * @return list containing all stored employees + * @throws ServiceException if loading the stored employees failed + */ + List list() throws ServiceException; + + /** + * Remove employee with the given id from the store. + * + * @param id of the employee that should be removed + * @throws InvalidEmployeeException if given employee id is invalid or does not exist + * @throws ServiceException if the employee could not be removed from the store + */ + void remove(long id) throws InvalidEmployeeException, ServiceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationService.java new file mode 100644 index 0000000..e21c10b --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationService.java @@ -0,0 +1,70 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.EnumSet; +import java.util.List; +import javafx.collections.transformation.SortedList; + +public interface OperationService { + + /** + * Add given operation to the store. + * + * @param operation that should be added to the store + * @return the id that was assigned + * @throws InvalidOperationException if the operation is invalid + * @throws ServiceException if the operation could not be persisted + */ + long add(Operation operation) throws InvalidOperationException, ServiceException; + + /** + * Request new vehicles to the given operation. + * + * @param operationId id of the operation that the vehicles should be send to + * @param vehicleIds the ids of the vehicles that should be send to the given operation + * @throws InvalidOperationException if the operationId is invalid or does not exist + * @throws InvalidVehicleException if one of the vehicle ids is invalid or does not exist + * @throws ServiceException if the vehicles could not be loaded or the operation could not be + * persisted + */ + void requestVehicles(long operationId, List vehicleIds) + throws InvalidOperationException, InvalidVehicleException, ServiceException; + + /** + * Completes the given operation with the specified status. + * + * @param operationId id of the operation that should be completed + * @param status of the completed operation, either {@link Status#COMPLETED} or {@link + * Status#CANCELLED} + * @throws InvalidOperationException if the operationId is invalid or does not exist + * @throws ServiceException if the operation could not be persisted + */ + void complete(long operationId, Status status) + throws InvalidOperationException, ServiceException; + + /** + * Get all available vehicles, sorted by how well they fit to the given operation, starting with + * the best fitting. + * + * @param operationId id of the operation that is used to determine the ranking + * @return a sorted list containing all available vehicles + * @throws InvalidOperationException if the operationId is invalid or does not exist + * @throws ServiceException if loading the stored vehicles failed + */ + SortedList rankVehicles(long operationId) + throws InvalidOperationException, ServiceException; + + /** + * Get all stored operations with matching status. + * + * @param statuses set containing all statuses that should be matched + * @return list containing all matched operations + * @throws ServiceException if loading the stored operations failed + */ + List list(EnumSet statuses) throws ServiceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java new file mode 100644 index 0000000..6723f32 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java @@ -0,0 +1,31 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidRegistrationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; + +public interface RegistrationService { + + /** + * Register employee to a vehicle. + * + * @param vehicleId the id of the target vehicle + * @param registration that should be added to the vehicle + * @return the id that was assigned + * @throws InvalidVehicleException if the vehicleId is invalid or does not exist + * @throws InvalidRegistrationException if the registration is invalid + * @throws ServiceException if the registration could not be persisted + */ + long add(long vehicleId, Registration registration) + throws InvalidVehicleException, InvalidRegistrationException, ServiceException; + + /** + * Remove given registration from the store. + * + * @param registrationId the id of the registration that should be removed + * @throws InvalidRegistrationException if the registration is invalid or does not exist + * @throws ServiceException if the registration could not be removed from the store + */ + void remove(long registrationId) throws InvalidRegistrationException, ServiceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleService.java new file mode 100644 index 0000000..6a96bc5 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleService.java @@ -0,0 +1,49 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.EnumSet; +import java.util.List; + +public interface VehicleService { + + /** + * Add given vehicle to the store. + * + * @param vehicle that should be added to the store + * @return the id that was assigned + * @throws InvalidVehicleException if the vehicle is invalid + * @throws ServiceException if the vehicle could not be persisted + */ + long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException; + + /** + * Update the given vehicle. + * + * @param vehicle that should be updated + * @return the updated vehicle + * @throws InvalidVehicleException if the vehicle is invalid + * @throws ServiceException if the updated vehicle could not be persisted + */ + Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException; + + /** + * Get all stored vehicles with matching status. + * + * @param statuses set containing all statuses that should be matched + * @return list containing all stored vehicles + * @throws ServiceException if loading the stored vehicles failed + */ + List list(EnumSet statuses) throws ServiceException; + + /** + * Remove vehicle with the given id from the store. + * + * @param id of the vehicle that should be removed + * @throws InvalidVehicleException if given vehicle id is invalid or does not exist + * @throws ServiceException if the vehicle could not be removed from the store + */ + void remove(long id) throws InvalidVehicleException, ServiceException; +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ElementNotFoundException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ElementNotFoundException.java new file mode 100644 index 0000000..97fb6c4 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ElementNotFoundException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class ElementNotFoundException extends Exception { + + public ElementNotFoundException(String message) { + super(message); + } + + public ElementNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public ElementNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidEmployeeException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidEmployeeException.java new file mode 100644 index 0000000..cd86cea --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidEmployeeException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class InvalidEmployeeException extends Exception { + + public InvalidEmployeeException(String message) { + super(message); + } + + public InvalidEmployeeException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidEmployeeException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidOperationException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidOperationException.java new file mode 100644 index 0000000..11fe2b5 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidOperationException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class InvalidOperationException extends Exception { + + public InvalidOperationException(String message) { + super(message); + } + + public InvalidOperationException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidOperationException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidRegistrationException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidRegistrationException.java new file mode 100644 index 0000000..7aa25f6 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidRegistrationException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class InvalidRegistrationException extends Exception { + + public InvalidRegistrationException(String message) { + super(message); + } + + public InvalidRegistrationException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidRegistrationException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidVehicleException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidVehicleException.java new file mode 100644 index 0000000..a7642f9 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/InvalidVehicleException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class InvalidVehicleException extends Exception { + + public InvalidVehicleException(String message) { + super(message); + } + + public InvalidVehicleException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidVehicleException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/PersistenceException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/PersistenceException.java new file mode 100644 index 0000000..33024b0 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/PersistenceException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class PersistenceException extends Exception { + + public PersistenceException(String message) { + super(message); + } + + public PersistenceException(String message, Throwable cause) { + super(message, cause); + } + + public PersistenceException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ServiceException.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ServiceException.java new file mode 100644 index 0000000..2222cb5 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/exception/ServiceException.java @@ -0,0 +1,16 @@ +package at.ac.tuwien.sepm.assignment.groupphase.exception; + +public class ServiceException extends Exception { + + public ServiceException(String message) { + super(message); + } + + public ServiceException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceException(Throwable cause) { + super(cause); + } +} -- cgit v1.2.3-70-g09d2 From 9619cd0deb2dce30bb6cc92ea2c05b73c4ca892c Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 1 May 2018 22:42:46 +0200 Subject: Add JDBCConnectionManager --- .../groupphase/util/JDBCConnectionManager.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/util/JDBCConnectionManager.java (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/util/JDBCConnectionManager.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/util/JDBCConnectionManager.java new file mode 100644 index 0000000..5494471 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/util/JDBCConnectionManager.java @@ -0,0 +1,45 @@ +package at.ac.tuwien.sepm.assignment.groupphase.util; + +import java.lang.invoke.MethodHandles; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class JDBCConnectionManager { + + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final String CONNECTION_URL = + "jdbc:h2:~/sepm;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; + + private Connection connection; + + public JDBCConnectionManager() { + try { + Class.forName("org.h2.Driver"); + } catch (ClassNotFoundException e) { + LOG.error("Failed to load H2 JDBC driver '{}'", e.getMessage(), e); + throw new IllegalStateException(e); + } + } + + public Connection getConnection() throws SQLException { + if (connection == null) connection = DriverManager.getConnection(CONNECTION_URL); + + return connection; + } + + public void closeConnection() { + if (connection == null) return; + + try { + connection.close(); + } catch (SQLException e) { + LOG.error("Failed to close connection '{}'", e.getMessage(), e); + } + connection = null; + } +} -- cgit v1.2.3-70-g09d2 From 5403d03b79a60d74bc942a982f31ba969e0171ca Mon Sep 17 00:00:00 2001 From: Tharre Date: Wed, 2 May 2018 16:23:11 +0200 Subject: DTO getters should be public, not package-private --- .../groupphase/einsatzverwaltung/dto/Employee.java | 12 ++++++------ .../groupphase/einsatzverwaltung/dto/Operation.java | 16 ++++++++-------- .../groupphase/einsatzverwaltung/dto/Registration.java | 8 ++++---- .../groupphase/einsatzverwaltung/dto/Vehicle.java | 14 +++++++------- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java index bbb5117..583bf5b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java @@ -14,17 +14,17 @@ public abstract class Employee { NA } - abstract long id(); + public abstract long id(); - abstract String name(); + public abstract String name(); - abstract LocalDate birthday(); + public abstract LocalDate birthday(); - abstract EducationLevel educationLevel(); + public abstract EducationLevel educationLevel(); - abstract boolean isDriver(); + public abstract boolean isDriver(); - abstract boolean isPilot(); + public abstract boolean isPilot(); public static Builder builder() { return new AutoValue_Employee.Builder().id(0); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java index bfb03c7..6641437 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java @@ -22,22 +22,22 @@ public abstract class Operation { CANCELLED, } - abstract long id(); + public abstract long id(); - abstract String opCode(); + public abstract String opCode(); - abstract Severity severity(); + public abstract Severity severity(); - abstract Status status(); + public abstract Status status(); - abstract List vehicles(); + public abstract List vehicles(); @Nullable - abstract Instant created(); + public abstract Instant created(); - abstract String destination(); + public abstract String destination(); - abstract String additionalInfo(); + public abstract String additionalInfo(); public static Builder builder() { return new AutoValue_Operation.Builder().id(0); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java index f917406..8551266 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java @@ -5,13 +5,13 @@ import java.time.Instant; @AutoValue public abstract class Registration { - abstract long id(); + public abstract long id(); - abstract Instant start(); + public abstract Instant start(); - abstract Instant end(); + public abstract Instant end(); - abstract Employee employee(); + public abstract Employee employee(); public static Builder builder() { return new AutoValue_Registration.Builder().id(0); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java index 29698da..84d9c92 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java @@ -31,20 +31,20 @@ public abstract class Vehicle { FREI_FUNK, } - abstract long id(); + public abstract long id(); - abstract String name(); + public abstract String name(); - abstract ConstructionType constructionType(); + public abstract ConstructionType constructionType(); - abstract VehicleType type(); + public abstract VehicleType type(); - abstract Status status(); + public abstract Status status(); - abstract boolean hasNef(); + public abstract boolean hasNef(); @Nullable - abstract List registrations(); + public abstract List registrations(); public static Builder builder() { return new AutoValue_Vehicle.Builder().id(0); -- cgit v1.2.3-70-g09d2 From 1426adba7e44cefbd8e4579b0c5bd03be8a57605 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 3 May 2018 20:00:55 +0200 Subject: Allow multiple registrations at once Otherwise, proper validation wouldn't be possible. --- .../groupphase/einsatzverwaltung/dao/RegistrationDAO.java | 7 ++++--- .../groupphase/einsatzverwaltung/service/RegistrationService.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java index f2c461a..ba8f909 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java @@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import java.util.List; public interface RegistrationDAO { @@ -10,11 +11,11 @@ public interface RegistrationDAO { * Persist the given registration. * * @param vehicleId the id of the target vehicle - * @param registration that should be stored - * @return the id that was assigned + * @param registrations that should be stored + * @return a list of the ids that were assigned * @throws PersistenceException if the registration could not be persisted */ - long add(long vehicleId, Registration registration) throws PersistenceException; + List add(long vehicleId, List registrations) throws PersistenceException; /** * Make registration with the given id inactive. diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java index 6723f32..801148c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationService.java @@ -4,6 +4,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registratio import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidRegistrationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.List; public interface RegistrationService { @@ -11,13 +12,13 @@ public interface RegistrationService { * Register employee to a vehicle. * * @param vehicleId the id of the target vehicle - * @param registration that should be added to the vehicle - * @return the id that was assigned + * @param registrations that should be added to the vehicle + * @return a list of the ids that were assigned * @throws InvalidVehicleException if the vehicleId is invalid or does not exist * @throws InvalidRegistrationException if the registration is invalid * @throws ServiceException if the registration could not be persisted */ - long add(long vehicleId, Registration registration) + List add(long vehicleId, List registrations) throws InvalidVehicleException, InvalidRegistrationException, ServiceException; /** -- cgit v1.2.3-70-g09d2 From 1bb6757f9b66efba22f08c9650a0f8591a8b9c9e Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Tue, 1 May 2018 11:46:20 +0200 Subject: add CreateNewEmployeeController and set on-click methods --- .../controller/CreateNewEmployeeController.java | 28 ++++++++++++++++++++++ src/main/resources/fxml/createNewEmployee.fxml | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java new file mode 100644 index 0000000..eaf016c --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java @@ -0,0 +1,28 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.controller; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.Hyperlink; +import javafx.scene.control.TextField; + +public class CreateNewEmployeeController { + + @FXML private CheckBox inputIsDriver; + @FXML private CheckBox inputIsPilot; + @FXML private Hyperlink btnCancel; + @FXML private Button btnCreate; + @FXML private TextField inputName; + @FXML private ChoiceBox inputQualification; + + @FXML + public void onCancelClicked() { + throw new UnsupportedOperationException(); + } + + @FXML + public void onCreateClicked() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/resources/fxml/createNewEmployee.fxml b/src/main/resources/fxml/createNewEmployee.fxml index 3acc7d1..5fa1ca9 100644 --- a/src/main/resources/fxml/createNewEmployee.fxml +++ b/src/main/resources/fxml/createNewEmployee.fxml @@ -16,8 +16,8 @@