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') 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 708ed158c41ee2ee5dfce64fdecf89aed4c17685 Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 1 May 2018 22:36:49 +0200 Subject: Add sql database schema --- src/main/resources/sql/database.sql | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/resources/sql/database.sql (limited to 'src') diff --git a/src/main/resources/sql/database.sql b/src/main/resources/sql/database.sql new file mode 100644 index 0000000..9d1b0e1 --- /dev/null +++ b/src/main/resources/sql/database.sql @@ -0,0 +1,57 @@ +CREATE TABLE IF NOT EXISTS VehicleVersion ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + constructionType ENUM('Normal', 'Hochdach', 'Mittelhochdach') NOT NULL, + type ENUM('BKTW', 'KTW-B', 'KTW', 'RTW', 'NEF', 'NAH') NOT NULL, +); + +CREATE TABLE IF NOT EXISTS Vehicle ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + version BIGINT NOT NULL, + status ENUM('abgemeldet', 'frei_wache', 'zum_berufungsort', 'am_berufungsort', 'zum_zielort', + 'am_zielort', 'frei_funk', 'deleted') NOT NULL, + FOREIGN KEY (version) REFERENCES VehicleVersion(id), +); + +CREATE TABLE IF NOT EXISTS EmployeeVersion ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + birthday DATE NOT NULL, + educationLevel ENUM('RS', 'NFS', 'NKV', 'NKA', 'NKI', 'NA') NOT NULL, + isDriver BOOLEAN NOT NULL, + isPilot BOOLEAN NOT NULL, +); + +CREATE TABLE IF NOT EXISTS Employee ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + version BIGINT NOT NULL, + FOREIGN KEY (version) REFERENCES EmployeeVersion(id), +); + +CREATE TABLE IF NOT EXISTS Registration ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + vehicleId BIGINT NOT NULL, + employeeId BIGINT NOT NULL, + start TIMESTAMP NOT NULL, + end TIMESTAMP NOT NULL, + active BOOLEAN NOT NULL, + FOREIGN KEY (vehicleId) REFERENCES VehicleVersion(id), + FOREIGN KEY (employeeId) REFERENCES EmployeeVersion(id), +); + +CREATE TABLE IF NOT EXISTS Operation ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + opCode VARCHAR(20) NOT NULL, + severity ENUM('A', 'B', 'C', 'D', 'E', 'O') NOT NULL, + created TIMESTAMP NOT NULL, + destination VARCHAR(100) NOT NULL, + additionalInfo VARCHAR(100), +); + +CREATE TABLE IF NOT EXISTS VehicleOperation ( + vehicleId BIGINT NOT NULL, + operationId BIGINT NOT NULL, + FOREIGN KEY (vehicleId) REFERENCES VehicleVersion(id), + FOREIGN KEY (operationId) REFERENCES Operation(id), + PRIMARY KEY (vehicleId, operationId), +); -- 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') 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') 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') 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 4849e2fdcdbaca390f427e13a45de9015c2e8752 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Tue, 1 May 2018 11:41:23 +0200 Subject: create first version of createNewEmployee-UI --- src/main/resources/fxml/createNewEmployee.fxml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/resources/fxml/createNewEmployee.fxml (limited to 'src') diff --git a/src/main/resources/fxml/createNewEmployee.fxml b/src/main/resources/fxml/createNewEmployee.fxml new file mode 100644 index 0000000..3acc7d1 --- /dev/null +++ b/src/main/resources/fxml/createNewEmployee.fxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2 From 3cf6a6ad7c46b82a77691f7c42e2e9b53967570c Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 22:08:25 +0200 Subject: Added Vehicle DAO and Vehicle Service Impl, started implementing needed methods --- .../einsatzverwaltung/dao/DBOperationDAO.java | 17 ++++-- .../einsatzverwaltung/dao/DBVehicleDAO.java | 62 ++++++++++++++++++++++ .../service/OperationServiceImpl.java | 14 ++--- .../service/VehicleServiceImpl.java | 31 +++++++++++ 4 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index c68b795..7036a1b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -4,6 +4,7 @@ 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 at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,12 +14,19 @@ import java.util.List; public class DBOperationDAO implements OperationDAO { + private JDBCConnectionManager jdbcConnectionManager; + + public DBOperationDAO(JDBCConnectionManager j) { + jdbcConnectionManager = j; + } + @Override public long add(Operation operation) throws PersistenceException { PreparedStatement pstmt = null; try { pstmt = - H2Handler.getConnection() + jdbcConnectionManager + .getConnection() .prepareStatement( "INSERT INTO operation(opCode, severity, " + "created, destination, additionalInfo, status) values (?,?,?,?,?,?)"); @@ -84,7 +92,7 @@ public class DBOperationDAO implements OperationDAO { ResultSet rs = pstmt.getGeneratedKeys(); if (rs.next()) return rs.getInt(1); else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); - } catch (SQLException | ClassNotFoundException e) { + } catch (SQLException e) { throw new PersistenceException(e); } finally { if (pstmt != null) { @@ -117,7 +125,8 @@ public class DBOperationDAO implements OperationDAO { PreparedStatement pstmt = null; try { pstmt = - H2Handler.getConnection() + jdbcConnectionManager + .getConnection() .prepareStatement( "insert into VehicleOperation(vehicleId, operationId)" + "values (?,?)"); @@ -129,7 +138,7 @@ public class DBOperationDAO implements OperationDAO { else throw new PersistenceException( "Fahrzeug für die Operation konnte nicht abgespeichert werden!"); - } catch (SQLException | ClassNotFoundException e) { + } catch (SQLException e) { throw new PersistenceException(e); } finally { if (pstmt != null) { diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java new file mode 100644 index 0000000..57a94de --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java @@ -0,0 +1,62 @@ +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.Nullable; + +public class DBVehicleDAO implements VehicleDAO { + + private JDBCConnectionManager jdbcConnectionManager; + + public DBVehicleDAO(JDBCConnectionManager j) { + jdbcConnectionManager = j; + } + + @Override + public long add(Vehicle vehicle) throws PersistenceException { + return 0; + } + + @Override + public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException { + + } + + @Override + public List list() throws PersistenceException { + PreparedStatement pstmt = null; + List result = new LinkedList<>(); + try { + pstmt = jdbcConnectionManager.getConnection().prepareStatement("Select * from VehicleVersion, " + + "Vehicle where VehicleVersion.id=Vehicle.version"); + //TODO: CORRECT? + pstmt.executeQuery(); + + ResultSet rs = pstmt.getResultSet(); + while (rs.next()){ + //TODO: HAS NEF?, Registrations + Vehicle vehicle = Vehicle.builder().name(rs.getString(2)). + constructionType(ConstructionType.valueOf(rs.getString(2))). + status(Status.valueOf(rs.getString(7))).id(rs.getInt(1)).build(); + result.add(vehicle); + } + } catch (SQLException e) { + //TODO + } + return null; + } + + @Override + public void remove(long id) throws ElementNotFoundException, PersistenceException { + + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index f705084..eee158b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -10,6 +10,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh 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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; @@ -20,7 +21,7 @@ public class OperationServiceImpl implements OperationService { private OperationDAO operationDAO = new DBOperationDAO(); @Override - public long add(Operation operation) throws InvalidOperationException, PersistenceException { + public long add(Operation operation) throws InvalidOperationException, ServiceException { List vehicles = operation.vehicles(); boolean rtw = false; for (Vehicle vehicle : vehicles) { @@ -46,6 +47,7 @@ public class OperationServiceImpl implements OperationService { } } if (!rtw) + //TODO: NUR WARNUNG AUSGEBEN throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NAH muss auch ein Fahrzeug des Typs RTW geschickt werden!"); } @@ -68,25 +70,25 @@ public class OperationServiceImpl implements OperationService { operationDAO.connectVehicleToOperation(vehicle.id(), operation.id()); } return operationDAO.add(operation); - // TODO: CODE VALIDIEREN, Adresse nach vierstelliger Nummer suchen, + // TODO: CODE VALIDIEREN? } @Override public void requestVehicles(long operationId, List vehicleIds) - throws InvalidOperationException, InvalidVehicleException, PersistenceException {} + throws InvalidOperationException, InvalidVehicleException, ServiceException {} @Override public void complete(long operationId, Status status) - throws InvalidOperationException, PersistenceException {} + throws InvalidOperationException, ServiceException {} @Override public SortedList rankVehicles(long operationId) - throws InvalidOperationException, PersistenceException { + throws InvalidOperationException, ServiceException { return null; } @Override - public List list(EnumSet statuses) throws PersistenceException { + public List list(EnumSet statuses) throws ServiceException { return null; } } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java new file mode 100644 index 0000000..80d7432 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -0,0 +1,31 @@ +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 class VehicleServiceImpl implements VehicleService { + + @Override + public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return 0; + } + + @Override + public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return null; + } + + @Override + public List list(EnumSet statuses) throws ServiceException { + return null; + } + + @Override + public void remove(long id) throws InvalidVehicleException, ServiceException { + + } +} -- cgit v1.2.3-70-g09d2 From fa0991ed6d68e8658f7e413f4a765f12791486bf Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Fri, 4 May 2018 12:06:52 +0200 Subject: Finished implementing needed methods in Persistence layer, added some validation factors for operation validation; Added methods to ui to add/remove vehicles to operation, created dummy vehicles --- .../einsatzverwaltung/dao/DBOperationDAO.java | 19 ++-- .../einsatzverwaltung/dao/DBVehicleDAO.java | 49 ++++++--- .../service/OperationServiceImpl.java | 40 +++++-- .../service/VehicleServiceImpl.java | 18 +++- .../userInterface/CreateOperationController.java | 117 +++++++++++++++++++-- .../resources/fxml/CreateOperationController.fxml | 94 +++++++++++++++++ .../fxmlFiles/CreateOperationController.fxml | 94 ----------------- 7 files changed, 293 insertions(+), 138 deletions(-) create mode 100644 src/main/resources/fxml/CreateOperationController.fxml delete mode 100644 src/main/resources/fxmlFiles/CreateOperationController.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index 7036a1b..707d346 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,6 +5,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -29,7 +30,8 @@ public class DBOperationDAO implements OperationDAO { .getConnection() .prepareStatement( "INSERT INTO operation(opCode, severity, " - + "created, destination, additionalInfo, status) values (?,?,?,?,?,?)"); + + "created, destination, additionalInfo, status) values (?,?,?,?,?,?)", + java.sql.Statement.RETURN_GENERATED_KEYS); if (operation.opCode() == null) { throw new PersistenceException("Code darf nicht null sein!"); @@ -79,18 +81,19 @@ public class DBOperationDAO implements OperationDAO { throw new PersistenceException( "Länge der zusätzlichen Information überschreitet erlaubte Länge von 100 Zeichen!"); else pstmt.setString(5, operation.additionalInfo()); - if (operation.status() != null) { - pstmt.setString(6, operation.status().toString()); + if (operation.status() == null) { + throw new PersistenceException("Status darf nicht null sein!"); } else if (operation.status().toString().length() > 100) { throw new PersistenceException( "Länge des Status überschreitet erlaubte Länge von 100 Zeichen!"); } else { - throw new PersistenceException("Status darf nicht null sein!"); + pstmt.setString(6, operation.status().toString()); } - - pstmt.executeQuery(); + pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) return rs.getInt(1); + if (rs.next()) { + return rs.getInt(1); + } else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); @@ -132,7 +135,7 @@ public class DBOperationDAO implements OperationDAO { + "values (?,?)"); pstmt.setLong(1, vehicleID); pstmt.setLong(2, operationID); - pstmt.executeQuery(); + pstmt.execute(); ResultSet rs = pstmt.getGeneratedKeys(); if (rs.next()) return rs.getInt(1); else diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java index 57a94de..e1b8c21 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java @@ -3,6 +3,7 @@ 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.einsatzverwaltung.dto.Vehicle.ConstructionType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; @@ -11,7 +12,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import javax.annotation.Nullable; public class DBVehicleDAO implements VehicleDAO { @@ -27,36 +27,51 @@ public class DBVehicleDAO implements VehicleDAO { } @Override - public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException { - - } + public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException {} @Override public List list() throws PersistenceException { PreparedStatement pstmt = null; List result = new LinkedList<>(); try { - pstmt = jdbcConnectionManager.getConnection().prepareStatement("Select * from VehicleVersion, " - + "Vehicle where VehicleVersion.id=Vehicle.version"); - //TODO: CORRECT? + pstmt = + jdbcConnectionManager + .getConnection() + .prepareStatement( + "Select * from VehicleVersion, " + + "Vehicle where VehicleVersion.id=Vehicle.version"); + // TODO: CORRECT? pstmt.executeQuery(); ResultSet rs = pstmt.getResultSet(); - while (rs.next()){ - //TODO: HAS NEF?, Registrations - Vehicle vehicle = Vehicle.builder().name(rs.getString(2)). - constructionType(ConstructionType.valueOf(rs.getString(2))). - status(Status.valueOf(rs.getString(7))).id(rs.getInt(1)).build(); + while (rs.next()) { + // TODO: Registrations + Vehicle vehicle = + Vehicle.builder() + .name(rs.getString(2)) + .constructionType(ConstructionType.valueOf(rs.getString(3))) + .status(Status.valueOf(rs.getString(8))) + .id(rs.getInt(6)) + .hasNef(rs.getBoolean(5)) + .type(VehicleType.valueOf(rs.getString(4))) + .build(); result.add(vehicle); } } catch (SQLException e) { - //TODO + throw new PersistenceException("Die Werte konnten nicht geladen werden.", e); + } finally { + if (pstmt != null) { + try { + pstmt.close(); + } catch (SQLException e) { + throw new PersistenceException( + "Verbindung zur Datenbank konnte nicht geschlossen werden!", e); + } + } } - return null; + return result; } @Override - public void remove(long id) throws ElementNotFoundException, PersistenceException { - - } + public void remove(long id) throws ElementNotFoundException, PersistenceException {} } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index eee158b..9ba3a63 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -11,6 +11,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; @@ -18,12 +19,22 @@ import javafx.collections.transformation.SortedList; public class OperationServiceImpl implements OperationService { // TODO: anders? - private OperationDAO operationDAO = new DBOperationDAO(); + private OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); @Override public long add(Operation operation) throws InvalidOperationException, ServiceException { List vehicles = operation.vehicles(); boolean rtw = false; + if (operation.vehicles().size() == 0) { + throw new InvalidOperationException( + "Es muss mindestens ein Fahrzeug ausgewählt werden!"); + } + if (faultyInput(operation.destination())){ + throw new InvalidOperationException("Adresse ist ungültig!"); + } + if (faultyInput(operation.opCode())){ + throw new InvalidOperationException("Code ist ungültig!"); + } for (Vehicle vehicle : vehicles) { if (vehicle.status() == Vehicle.Status.ABGEMELDET) throw new InvalidOperationException( @@ -47,7 +58,7 @@ public class OperationServiceImpl implements OperationService { } } if (!rtw) - //TODO: NUR WARNUNG AUSGEBEN + // TODO: NUR WARNUNG AUSGEBEN throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NAH muss auch ein Fahrzeug des Typs RTW geschickt werden!"); } @@ -55,7 +66,7 @@ public class OperationServiceImpl implements OperationService { String[] codeParts = operation.opCode().split("\\-"); String severity = ""; for (int i = 0; i < codeParts[1].length(); i++) { - if ((int) (codeParts[1].charAt(i)) > 101 && (int) (codeParts[1].charAt(i)) < 117) { + if (((int) (codeParts[1].charAt(i)) >= 65 && (int) (codeParts[1].charAt(i)) <= 79) || ((int) (codeParts[1].charAt(i)) >= 97 && (int) (codeParts[1].charAt(i))<=111)) { severity = "" + codeParts[1].charAt(i); break; } @@ -66,11 +77,28 @@ public class OperationServiceImpl implements OperationService { throw new InvalidOperationException( "Der Schweregrad des Einsatzes konnte nicht ausgelesen werden!"); } + operation = operation.toBuilder().status(Status.ACTIVE).build(); for (Vehicle vehicle : vehicles) { - operationDAO.connectVehicleToOperation(vehicle.id(), operation.id()); + try { + operationDAO.connectVehicleToOperation(vehicle.id(), operation.id()); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + } + try { + return operationDAO.add(operation); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + } + + private boolean faultyInput(String name) { + if (name == null) return true; + else if (name.isEmpty()) return true; + for (int i = 0; i < name.length(); i++) { + if (name.charAt(i) != ' ') return false; } - return operationDAO.add(operation); - // TODO: CODE VALIDIEREN? + return true; } @Override diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java index 80d7432..f21ae9a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -1,14 +1,21 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; 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.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; public class VehicleServiceImpl implements VehicleService { + // TODO + private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); + @Override public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { return 0; @@ -21,11 +28,14 @@ public class VehicleServiceImpl implements VehicleService { @Override public List list(EnumSet statuses) throws ServiceException { - return null; + // TODO: IMPLEMENT SEARCH WITH STATUS + try { + return vehicleDAO.list(); + } catch (PersistenceException e) { + throw new ServiceException(e); + } } @Override - public void remove(long id) throws InvalidVehicleException, ServiceException { - - } + public void remove(long id) throws InvalidVehicleException, ServiceException {} } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 10f9f03..8df8acc 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -1,19 +1,27 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; 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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; +import java.util.EnumSet; import java.util.LinkedList; import java.util.List; +import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; @@ -28,8 +36,9 @@ public class CreateOperationController { public ListView lvVehicles; public ListView lvActiveOperations; public Label lblChosenVehicles; - public LinkedList chosenVehicles; + public LinkedList chosenVehicles = new LinkedList<>(); + // TODO: Anders? OperationService operationService = new OperationServiceImpl(); VehicleService vehicleService = new VehicleServiceImpl(); @@ -37,14 +46,104 @@ public class CreateOperationController { @FXML public void initialize() { + lblChosenVehicles.setText("keine ausgewählt"); + lvVehicles.setCellFactory( + param -> + new ListCell() { + @Override + protected void updateItem(Vehicle item, boolean empty) { + super.updateItem(item, empty); + + if (empty || item == null || item.name() == null) { + setText(null); + } else { + setText(item.name()); + } + } + }); + lvVehicles.setOnMouseClicked( event -> { if (event.getClickCount() == 2) { - chosenVehicles.add(lvVehicles.getSelectionModel().getSelectedItem()); + boolean remove = false; + for (int i = 0; i < chosenVehicles.size(); i++) { + if (lvVehicles + .getSelectionModel() + .getSelectedItem() + .equals(chosenVehicles.get(i))) { + remove = true; + break; + } + } + if (!remove) { + chosenVehicles.add(lvVehicles.getSelectionModel().getSelectedItem()); + + } + else { + chosenVehicles.remove(lvVehicles.getSelectionModel().getSelectedItem()); + + } + String result = ""; + for (int i = 0; i < chosenVehicles.size(); i++) { + if (i == chosenVehicles.size() - 1) { + result += chosenVehicles.get(i).name(); + } else { + result += chosenVehicles.get(i).name() + ", "; + } + } + if (result.equals("")){ + lblChosenVehicles.setText("keine ausgewählt"); + } + else { + lblChosenVehicles.setText(result); + } } }); } + public void fillList() { + // TODO: Zu anderem Zeitpunkt aktualisieren. + /*try { + this.lvVehicles.setItems( + //TODO: ALLE FREI STATI Frei FUnk Frei Wache + FXCollections.observableArrayList( + vehicleService.list(EnumSet.of(Vehicle.Status.FREI_FUNK)))); + } catch (ServiceException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Fehler"); + alert.setHeaderText("Fehler!"); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + }*/ + + this.lvVehicles.setItems(FXCollections.observableArrayList(mylist())); + } + + private LinkedList mylist() { + Vehicle vehicle = + Vehicle.builder() + .name("Test-KTW") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.KTW) + .status(Vehicle.Status.FREI_WACHE) + .hasNef(true) + .build(); + + Vehicle vehicle1 = + Vehicle.builder() + .name("Test-NEF") + .constructionType(ConstructionType.NORMAL) + .type(VehicleType.NEF) + .status(Vehicle.Status.FREI_FUNK) + .hasNef(true) + .build(); + LinkedList list = new LinkedList<>(); + list.add(vehicle); + list.add(vehicle1); + // this.lvVehicles.setItems(FXCollections.observableArrayList(list)); + return list; + } + @FXML protected void createOperationClicked() { Vehicle[] vehicles = new Vehicle[chosenVehicles.size()]; @@ -59,16 +158,16 @@ public class CreateOperationController { .opCode(txtCode.getText()) .status(Status.ACTIVE) .vehicles(List.of(vehicles)) + .severity(Severity.A) .build(); - try { operationService.add(operation); - } catch (InvalidOperationException e) { - //TODO - } catch (ServiceException e) { - e.printStackTrace(); + } catch (ServiceException | InvalidOperationException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Fehler"); + alert.setHeaderText("Fehler!"); + alert.setContentText(e.getMessage()); + alert.showAndWait(); } } - - } diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml new file mode 100644 index 0000000..949d4ec --- /dev/null +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxmlFiles/CreateOperationController.fxml b/src/main/resources/fxmlFiles/CreateOperationController.fxml deleted file mode 100644 index 7b188fd..0000000 --- a/src/main/resources/fxmlFiles/CreateOperationController.fxml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2 From 952a105f83f3c15d304293b6997f47aa9331947d Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:03:19 +0200 Subject: Small Changes (deleted Comments and TODOs) added an Alert if Operation was saved successfully --- .../groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 8 ++------ .../einsatzverwaltung/service/OperationServiceImpl.java | 15 +++++++-------- .../userInterface/CreateOperationController.java | 11 +++++++++-- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index 707d346..485d6fa 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,7 +5,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -62,7 +61,6 @@ public class DBOperationDAO implements OperationDAO { throw new PersistenceException( "Schwere des Einsatzes konnte nicht validiert werden!"); } - // TODO: CHECK IF TIME ZONE CORRECT if (operation.created() != null) { pstmt.setTimestamp(3, Timestamp.from(operation.created())); } else { @@ -91,9 +89,7 @@ public class DBOperationDAO implements OperationDAO { } pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) { - return rs.getInt(1); - } + if (rs.next()) return rs.getInt(1); else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); @@ -142,7 +138,7 @@ public class DBOperationDAO implements OperationDAO { throw new PersistenceException( "Fahrzeug für die Operation konnte nicht abgespeichert werden!"); } catch (SQLException e) { - throw new PersistenceException(e); + throw new PersistenceException("Die Werte konnten nicht gespeichert werden!"); } finally { if (pstmt != null) { try { diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 9ba3a63..10eef78 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -25,18 +25,18 @@ public class OperationServiceImpl implements OperationService { public long add(Operation operation) throws InvalidOperationException, ServiceException { List vehicles = operation.vehicles(); boolean rtw = false; - if (operation.vehicles().size() == 0) { - throw new InvalidOperationException( - "Es muss mindestens ein Fahrzeug ausgewählt werden!"); + if (faultyInput(operation.opCode())){ + throw new InvalidOperationException("Code ist ungültig!"); } if (faultyInput(operation.destination())){ throw new InvalidOperationException("Adresse ist ungültig!"); } - if (faultyInput(operation.opCode())){ - throw new InvalidOperationException("Code ist ungültig!"); + if (operation.vehicles().size() == 0) { + throw new InvalidOperationException( + "Es muss mindestens ein Fahrzeug ausgewählt werden!"); } for (Vehicle vehicle : vehicles) { - if (vehicle.status() == Vehicle.Status.ABGEMELDET) + if (vehicle.status() == Vehicle.Status.ABGEMELDET || (vehicle.status()!=Vehicle.Status.FREI_FUNK && vehicle.status()!=Vehicle.Status.FREI_WACHE)) throw new InvalidOperationException( "Abgemeldete Fahrzeuge dürfen nicht zu einem Einsatz geschickt werden!"); if (vehicle.type() == VehicleType.NEF && !rtw) { @@ -58,12 +58,11 @@ public class OperationServiceImpl implements OperationService { } } if (!rtw) - // TODO: NUR WARNUNG AUSGEBEN throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NAH muss auch ein Fahrzeug des Typs RTW geschickt werden!"); } } - String[] codeParts = operation.opCode().split("\\-"); + String[] codeParts = operation.opCode().split("-"); String severity = ""; for (int i = 0; i < codeParts[1].length(); i++) { if (((int) (codeParts[1].charAt(i)) >= 65 && (int) (codeParts[1].charAt(i)) <= 79) || ((int) (codeParts[1].charAt(i)) >= 97 && (int) (codeParts[1].charAt(i))<=111)) { diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 8df8acc..919e187 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -19,6 +19,7 @@ import java.util.List; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; @@ -40,7 +41,6 @@ public class CreateOperationController { // TODO: Anders? OperationService operationService = new OperationServiceImpl(); - VehicleService vehicleService = new VehicleServiceImpl(); public CreateOperationController() {} @@ -107,7 +107,7 @@ public class CreateOperationController { this.lvVehicles.setItems( //TODO: ALLE FREI STATI Frei FUnk Frei Wache FXCollections.observableArrayList( - vehicleService.list(EnumSet.of(Vehicle.Status.FREI_FUNK)))); + vehicleService.list(EnumSet.of(Vehicle.Status.FREI_FUNK, Vehicle.Status.FREI_WACHE)))); } catch (ServiceException e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Fehler"); @@ -168,6 +168,13 @@ public class CreateOperationController { alert.setHeaderText("Fehler!"); alert.setContentText(e.getMessage()); alert.showAndWait(); + return; } + Alert alert = new Alert(AlertType.CONFIRMATION); + alert.setTitle("Erfolg"); + alert.setHeaderText("Erfolgreich gespeichert"); + alert.setContentText("Der Einsatz wurde erfolgreich gespeichert."); + alert.showAndWait(); + fillList(); } } -- cgit v1.2.3-70-g09d2 From 79f72588c730e47eca62ce7a7fb753038f58dfea Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:29:43 +0200 Subject: Added file for unit tests --- .../groupphase/operation/OperationServiceTest.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java new file mode 100644 index 0000000..9b9fc03 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -0,0 +1,49 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.time.LocalDate; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(); + + @Test + public void addOperationTest() { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .build(); + try{ + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From cfdf2023fe2171cff0fbc3776cd9c1a060ae6160 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:31:55 +0200 Subject: formated CodeV --- .../einsatzverwaltung/service/OperationServiceImpl.java | 16 ++++++++++------ .../userInterface/CreateOperationController.java | 12 +++--------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 10eef78..0e850e7 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -25,10 +25,10 @@ public class OperationServiceImpl implements OperationService { public long add(Operation operation) throws InvalidOperationException, ServiceException { List vehicles = operation.vehicles(); boolean rtw = false; - if (faultyInput(operation.opCode())){ + if (faultyInput(operation.opCode())) { throw new InvalidOperationException("Code ist ungültig!"); } - if (faultyInput(operation.destination())){ + if (faultyInput(operation.destination())) { throw new InvalidOperationException("Adresse ist ungültig!"); } if (operation.vehicles().size() == 0) { @@ -36,7 +36,9 @@ public class OperationServiceImpl implements OperationService { "Es muss mindestens ein Fahrzeug ausgewählt werden!"); } for (Vehicle vehicle : vehicles) { - if (vehicle.status() == Vehicle.Status.ABGEMELDET || (vehicle.status()!=Vehicle.Status.FREI_FUNK && vehicle.status()!=Vehicle.Status.FREI_WACHE)) + if (vehicle.status() == Vehicle.Status.ABGEMELDET + || (vehicle.status() != Vehicle.Status.FREI_FUNK + && vehicle.status() != Vehicle.Status.FREI_WACHE)) throw new InvalidOperationException( "Abgemeldete Fahrzeuge dürfen nicht zu einem Einsatz geschickt werden!"); if (vehicle.type() == VehicleType.NEF && !rtw) { @@ -65,7 +67,9 @@ public class OperationServiceImpl implements OperationService { String[] codeParts = operation.opCode().split("-"); String severity = ""; for (int i = 0; i < codeParts[1].length(); i++) { - if (((int) (codeParts[1].charAt(i)) >= 65 && (int) (codeParts[1].charAt(i)) <= 79) || ((int) (codeParts[1].charAt(i)) >= 97 && (int) (codeParts[1].charAt(i))<=111)) { + if (((int) (codeParts[1].charAt(i)) >= 65 && (int) (codeParts[1].charAt(i)) <= 79) + || ((int) (codeParts[1].charAt(i)) >= 97 + && (int) (codeParts[1].charAt(i)) <= 111)) { severity = "" + codeParts[1].charAt(i); break; } @@ -92,8 +96,8 @@ public class OperationServiceImpl implements OperationService { } private boolean faultyInput(String name) { - if (name == null) return true; - else if (name.isEmpty()) return true; + if (name == null) return true; + else if (name.isEmpty()) return true; for (int i = 0; i < name.length(); i++) { if (name.charAt(i) != ' ') return false; } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 919e187..502324a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -8,12 +8,9 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Con import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; -import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; @@ -78,10 +75,8 @@ public class CreateOperationController { if (!remove) { chosenVehicles.add(lvVehicles.getSelectionModel().getSelectedItem()); - } - else { + } else { chosenVehicles.remove(lvVehicles.getSelectionModel().getSelectedItem()); - } String result = ""; for (int i = 0; i < chosenVehicles.size(); i++) { @@ -91,10 +86,9 @@ public class CreateOperationController { result += chosenVehicles.get(i).name() + ", "; } } - if (result.equals("")){ + if (result.equals("")) { lblChosenVehicles.setText("keine ausgewählt"); - } - else { + } else { lblChosenVehicles.setText(result); } } -- cgit v1.2.3-70-g09d2 From 240d36968540100861fb501c95fbf60f9e1fe80e Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:10:56 +0200 Subject: Added constructor to create persistence instance --- .../einsatzverwaltung/service/OperationServiceImpl.java | 15 +++++++++------ .../userInterface/CreateOperationController.java | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 0e850e7..854f2e7 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -6,7 +6,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; 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.einsatzverwaltung.dto.Vehicle.VehicleType; 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.PersistenceException; @@ -19,7 +18,11 @@ import javafx.collections.transformation.SortedList; public class OperationServiceImpl implements OperationService { // TODO: anders? - private OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private OperationDAO operationDAO; + + public OperationServiceImpl(OperationDAO dao){ + this.operationDAO = dao; + } @Override public long add(Operation operation) throws InvalidOperationException, ServiceException { @@ -41,7 +44,7 @@ public class OperationServiceImpl implements OperationService { && vehicle.status() != Vehicle.Status.FREI_WACHE)) throw new InvalidOperationException( "Abgemeldete Fahrzeuge dürfen nicht zu einem Einsatz geschickt werden!"); - if (vehicle.type() == VehicleType.NEF && !rtw) { + /*if (vehicle.type() == VehicleType.NEF && !rtw) { for (Vehicle vehicleA : vehicles) { if (vehicleA.type() == VehicleType.RTW && vehicleA.hasNef()) { rtw = true; @@ -51,8 +54,8 @@ public class OperationServiceImpl implements OperationService { if (!rtw) throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NEF muss auch ein Fahrzeug des Typs RTW mit NEF-Halterung geschickt werden!"); - } - if (vehicle.type() == VehicleType.NAH && !rtw) { + }*/ + /* if (vehicle.type() == VehicleType.NAH && !rtw) { for (Vehicle vehicleA : vehicles) { if (vehicleA.type() == VehicleType.RTW) { rtw = true; @@ -62,7 +65,7 @@ public class OperationServiceImpl implements OperationService { if (!rtw) throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NAH muss auch ein Fahrzeug des Typs RTW geschickt werden!"); - } + }*/ } String[] codeParts = operation.opCode().split("-"); String severity = ""; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 502324a..af4b205 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -1,5 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; @@ -10,6 +11,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Operati import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; import java.util.LinkedList; import java.util.List; @@ -37,7 +39,7 @@ public class CreateOperationController { public LinkedList chosenVehicles = new LinkedList<>(); // TODO: Anders? - OperationService operationService = new OperationServiceImpl(); + OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); public CreateOperationController() {} -- cgit v1.2.3-70-g09d2 From 9949b592dfa39684d6a6fac380522a949321e4f7 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:12:53 +0200 Subject: Added unit tests --- .../groupphase/operation/OperationServiceTest.java | 122 +++++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java index 9b9fc03..aa89a85 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -7,30 +7,42 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; -import java.time.LocalDate; +import java.util.List; import org.junit.Assert; import org.junit.Test; public class OperationServiceTest { private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(); + private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Operation operation = Operation.builder() .status(Status.ACTIVE) @@ -39,11 +51,105 @@ public class OperationServiceTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) + .vehicles(List.of(vehicle)) .build(); - try{ + try { Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); } } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } } -- cgit v1.2.3-70-g09d2 From 28e547e56ad3376bc1168711f1973d8f3f54019f Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:02:12 +0200 Subject: Small Changes --- .../service/OperationServiceImpl.java | 6 +- .../userInterface/CreateOperationController.java | 7 +- .../groupphase/operation/OperationServiceTest.java | 155 --------------------- .../operation/OperationServiceUnitTest.java | 155 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 162 deletions(-) delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 854f2e7..74cb7a7 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -1,6 +1,5 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; @@ -10,7 +9,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; @@ -20,7 +18,7 @@ public class OperationServiceImpl implements OperationService { // TODO: anders? private OperationDAO operationDAO; - public OperationServiceImpl(OperationDAO dao){ + public OperationServiceImpl(OperationDAO dao) { this.operationDAO = dao; } @@ -55,7 +53,7 @@ public class OperationServiceImpl implements OperationService { throw new InvalidOperationException( "Zu einem Fahrzeug des Typs NEF muss auch ein Fahrzeug des Typs RTW mit NEF-Halterung geschickt werden!"); }*/ - /* if (vehicle.type() == VehicleType.NAH && !rtw) { + /* if (vehicle.type() == VehicleType.NAH && !rtw) { for (Vehicle vehicleA : vehicles) { if (vehicleA.type() == VehicleType.RTW) { rtw = true; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index af4b205..9f4a62d 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -39,7 +39,8 @@ public class CreateOperationController { public LinkedList chosenVehicles = new LinkedList<>(); // TODO: Anders? - OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); + OperationService operationService = + new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); public CreateOperationController() {} @@ -97,7 +98,7 @@ public class CreateOperationController { }); } - public void fillList() { + public void updateList() { // TODO: Zu anderem Zeitpunkt aktualisieren. /*try { this.lvVehicles.setItems( @@ -171,6 +172,6 @@ public class CreateOperationController { alert.setHeaderText("Erfolgreich gespeichert"); alert.setContentText("Der Einsatz wurde erfolgreich gespeichert."); alert.showAndWait(); - fillList(); + updateList(); } } diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java deleted file mode 100644 index aa89a85..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java new file mode 100644 index 0000000..866f759 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceUnitTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3-70-g09d2 From 2abb36456fb2e3584b06bef163481500c894707e Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:07:40 +0200 Subject: Added some component tests, mocking of database still necessary --- .../operation/OperationServiceComponentTest.java | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java new file mode 100644 index 0000000..fc3ea54 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceComponentTest { + + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + //TODO: MOCK H2 + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + +} -- cgit v1.2.3-70-g09d2 From 498d5fae8589d515eb9ec5d46f75b80361ee09b7 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:47:39 +0200 Subject: Mocked H2 --- .../groupphase/operation/OperationServiceComponentTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java index fc3ea54..aeee11f 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -17,7 +17,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; @@ -27,12 +26,11 @@ import org.junit.Test; public class OperationServiceComponentTest { - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { - //TODO: MOCK H2 Vehicle vehicle = Vehicle.builder() .status(Vehicle.Status.FREI_FUNK) @@ -53,6 +51,7 @@ public class OperationServiceComponentTest { .vehicles(List.of(vehicle)) .build(); try { + //TODO: OPERATION DOES NOT WORK Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); -- cgit v1.2.3-70-g09d2 From 0c6f26791e8b336c4899737a71decf147639f6dc Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 21:05:15 +0200 Subject: Small Changes --- .../einsatzverwaltung/dao/DBVehicleDAO.java | 3 -- .../userInterface/CreateOperationController.java | 38 ++++++++++------------ 2 files changed, 17 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java index e1b8c21..d966dc5 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java @@ -40,12 +40,9 @@ public class DBVehicleDAO implements VehicleDAO { .prepareStatement( "Select * from VehicleVersion, " + "Vehicle where VehicleVersion.id=Vehicle.version"); - // TODO: CORRECT? pstmt.executeQuery(); - ResultSet rs = pstmt.getResultSet(); while (rs.next()) { - // TODO: Registrations Vehicle vehicle = Vehicle.builder() .name(rs.getString(2)) diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 9f4a62d..7e6722c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -5,14 +5,14 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; 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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; +import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; @@ -41,6 +41,7 @@ public class CreateOperationController { // TODO: Anders? OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); + VehicleService vehicleService; public CreateOperationController() {} @@ -66,11 +67,8 @@ public class CreateOperationController { event -> { if (event.getClickCount() == 2) { boolean remove = false; - for (int i = 0; i < chosenVehicles.size(); i++) { - if (lvVehicles - .getSelectionModel() - .getSelectedItem() - .equals(chosenVehicles.get(i))) { + for (Vehicle vehicle : chosenVehicles) { + if (lvVehicles.getSelectionModel().getSelectedItem().equals(vehicle)) { remove = true; break; } @@ -81,42 +79,40 @@ public class CreateOperationController { } else { chosenVehicles.remove(lvVehicles.getSelectionModel().getSelectedItem()); } - String result = ""; + StringBuilder result = new StringBuilder(); for (int i = 0; i < chosenVehicles.size(); i++) { if (i == chosenVehicles.size() - 1) { - result += chosenVehicles.get(i).name(); + result.append(chosenVehicles.get(i).name()); } else { - result += chosenVehicles.get(i).name() + ", "; + result.append(chosenVehicles.get(i).name()).append(", "); } } - if (result.equals("")) { + if (result.toString().equals("")) { lblChosenVehicles.setText("keine ausgewählt"); } else { - lblChosenVehicles.setText(result); + lblChosenVehicles.setText(result.toString()); } } }); } public void updateList() { - // TODO: Zu anderem Zeitpunkt aktualisieren. - /*try { + try { this.lvVehicles.setItems( - //TODO: ALLE FREI STATI Frei FUnk Frei Wache FXCollections.observableArrayList( - vehicleService.list(EnumSet.of(Vehicle.Status.FREI_FUNK, Vehicle.Status.FREI_WACHE)))); + vehicleService.list( + EnumSet.of( + Vehicle.Status.FREI_FUNK, Vehicle.Status.FREI_WACHE)))); } catch (ServiceException e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Fehler"); alert.setHeaderText("Fehler!"); alert.setContentText(e.getMessage()); alert.showAndWait(); - }*/ - - this.lvVehicles.setItems(FXCollections.observableArrayList(mylist())); + } } - private LinkedList mylist() { + /*private LinkedList mylist() { Vehicle vehicle = Vehicle.builder() .name("Test-KTW") @@ -139,7 +135,7 @@ public class CreateOperationController { list.add(vehicle1); // this.lvVehicles.setItems(FXCollections.observableArrayList(list)); return list; - } + }*/ @FXML protected void createOperationClicked() { -- cgit v1.2.3-70-g09d2 From e11c9cac13b49514b253eae9a8bbc0c8d47961c4 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 22:32:42 +0200 Subject: Added test for persistence layer --- .../operation/OperationPersistenceTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java new file mode 100644 index 0000000..ecc0486 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java @@ -0,0 +1,67 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.mock; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.Instant; +import java.util.List; +import org.junit.BeforeClass; +import org.junit.Test; + +public class OperationPersistenceTest { + + private final OperationDAO operationDAO = + new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); + + @BeforeClass + public static void createSchema() throws SQLException { + /*RunScript.execute( + "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", + "", + "", + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false);*/ + } + + @Test + public void addOperation() { + //TODO + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + operationDAO.add(operation); + } catch (PersistenceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From c35e67aee984312cdc7f2447a73df7fae7f851ca Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 11:46:00 +0200 Subject: Added some test for persistence layer/small changes --- .../einsatzverwaltung/dao/DBOperationDAO.java | 3 + .../service/VehicleServiceImpl.java | 41 ------ .../operation/OperationPersistenceTest.java | 67 --------- .../operation/OperationServiceComponentTest.java | 154 -------------------- .../operation/OperationServiceUnitTest.java | 155 --------------------- .../operation/OperationPersistenceTest.java | 128 +++++++++++++++++ .../operation/OperationServiceComponentTest.java | 151 ++++++++++++++++++++ .../operation/OperationServiceUnitTest.java | 155 +++++++++++++++++++++ 8 files changed, 437 insertions(+), 417 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index 485d6fa..d332acc 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -22,6 +22,9 @@ public class DBOperationDAO implements OperationDAO { @Override public long add(Operation operation) throws PersistenceException { + if (operation == null) { + throw new PersistenceException("Das der Datenbank übergebene Objekt ist fehlerhaft!"); + } PreparedStatement pstmt = null; try { pstmt = diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java deleted file mode 100644 index f21ae9a..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.util.EnumSet; -import java.util.List; - -public class VehicleServiceImpl implements VehicleService { - - // TODO - private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); - - @Override - public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return 0; - } - - @Override - public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return null; - } - - @Override - public List list(EnumSet statuses) throws ServiceException { - // TODO: IMPLEMENT SEARCH WITH STATUS - try { - return vehicleDAO.list(); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - } - - @Override - public void remove(long id) throws InvalidVehicleException, ServiceException {} -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java deleted file mode 100644 index ecc0486..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.mockito.Mockito.mock; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperationPersistenceTest { - - private final OperationDAO operationDAO = - new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - - @BeforeClass - public static void createSchema() throws SQLException { - /*RunScript.execute( - "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", - "", - "", - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false);*/ - } - - @Test - public void addOperation() { - //TODO - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - operationDAO.add(operation); - } catch (PersistenceException e) { - fail(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java deleted file mode 100644 index aeee11f..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceComponentTest { - - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - //TODO: OPERATION DOES NOT WORK - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java deleted file mode 100644 index 866f759..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceUnitTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java new file mode 100644 index 0000000..575588e --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java @@ -0,0 +1,128 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.Instant; +import java.util.List; +import org.h2.tools.RunScript; +import org.junit.BeforeClass; +import org.junit.Test; + +public class OperationPersistenceTest { + + private final OperationDAO operationDAO = + new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); + + @BeforeClass + public static void createSchema() throws SQLException { + RunScript.execute( + "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", + "", + "", + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false); + } + + @Test + public void addOperationTest() { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + operationDAO.add(operation); + } catch (PersistenceException e) { + fail(); + } + } + + /*@Test(expected = PersistenceException.class) + public void addFaultyOperationTest() throws PersistenceException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + operationDAO.add(operation); + }*/ + + @Test(expected = PersistenceException.class) + public void addFaultyOperation1Test() throws PersistenceException { + operationDAO.add(null); + } + + @Test(expected = PersistenceException.class) + public void addFaultyOperation2Test() throws PersistenceException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination( + "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + operationDAO.add(operation); + } + + @Test(expected = PersistenceException.class) + public void addConnectionTest() throws PersistenceException { + operationDAO.connectVehicleToOperation(-1, 0); + } + + // TODO: ADD CONNECTION TESTS + // KOMMT ID ZURÜCK? +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java new file mode 100644 index 0000000..7ffe135 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -0,0 +1,151 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceComponentTest { + + private final OperationDAO operationDAO = + new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + // TODO: OPERATION DOES NOT WORK + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java new file mode 100644 index 0000000..fc10553 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceUnitTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3-70-g09d2 From 1e97c30c0df8afaa116d328294b6a2df120f34f4 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 13:09:47 +0200 Subject: Added Operation DAO and -Service for Operation, implemented needed methods. --- .../groupphase/einsatzverwaltung/service/OperationServiceImpl.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 74cb7a7..fbb41da 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -1,5 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; @@ -9,6 +10,10 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +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.PersistenceException; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; -- cgit v1.2.3-70-g09d2 From 26112a42b3608c919fefe9e2d4ba02a6d4e15b86 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 21:18:20 +0200 Subject: Created first (unfinished) version for operation UI, started implementing Controller --- .../userInterface/CreateOperationController.java | 7 ++ .../fxmlFiles/CreateOperationController.fxml | 94 ++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/main/resources/fxmlFiles/CreateOperationController.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 7e6722c..b5a8cf1 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.service.OperationService; @@ -22,6 +23,12 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; +import java.time.Instant; +import java.util.LinkedList; +import java.util.List; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; diff --git a/src/main/resources/fxmlFiles/CreateOperationController.fxml b/src/main/resources/fxmlFiles/CreateOperationController.fxml new file mode 100644 index 0000000..7b188fd --- /dev/null +++ b/src/main/resources/fxmlFiles/CreateOperationController.fxml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2 From bc0ee5f3fda95f9a0c4d0436400b1a449d54947e Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 22:08:25 +0200 Subject: Added Vehicle DAO and Vehicle Service Impl, started implementing needed methods --- .../einsatzverwaltung/dao/DBVehicleDAO.java | 1 + .../service/OperationServiceImpl.java | 1 + .../service/VehicleServiceImpl.java | 31 ++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java index d966dc5..a2cd486 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java @@ -12,6 +12,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; +import javax.annotation.Nullable; public class DBVehicleDAO implements VehicleDAO { diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index fbb41da..4d5fb68 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -14,6 +14,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh 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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java new file mode 100644 index 0000000..80d7432 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -0,0 +1,31 @@ +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 class VehicleServiceImpl implements VehicleService { + + @Override + public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return 0; + } + + @Override + public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return null; + } + + @Override + public List list(EnumSet statuses) throws ServiceException { + return null; + } + + @Override + public void remove(long id) throws InvalidVehicleException, ServiceException { + + } +} -- cgit v1.2.3-70-g09d2 From d77d9625cb4cd05d2b746c721b65f0f32313fab8 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Fri, 4 May 2018 12:06:52 +0200 Subject: Finished implementing needed methods in Persistence layer, added some validation factors for operation validation; Added methods to ui to add/remove vehicles to operation, created dummy vehicles --- .../einsatzverwaltung/dao/DBOperationDAO.java | 5 +- .../einsatzverwaltung/dao/DBVehicleDAO.java | 1 - .../service/OperationServiceImpl.java | 1 + .../service/VehicleServiceImpl.java | 18 ++++- .../userInterface/CreateOperationController.java | 8 ++ .../fxmlFiles/CreateOperationController.fxml | 94 ---------------------- 6 files changed, 27 insertions(+), 100 deletions(-) delete mode 100644 src/main/resources/fxmlFiles/CreateOperationController.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index d332acc..aaf7631 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,6 +5,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -92,7 +93,9 @@ public class DBOperationDAO implements OperationDAO { } pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) return rs.getInt(1); + if (rs.next()) { + return rs.getInt(1); + } else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java index a2cd486..d966dc5 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java @@ -12,7 +12,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import javax.annotation.Nullable; public class DBVehicleDAO implements VehicleDAO { diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 4d5fb68..e0fd824 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -15,6 +15,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java index 80d7432..f21ae9a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -1,14 +1,21 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; 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.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; public class VehicleServiceImpl implements VehicleService { + // TODO + private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); + @Override public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { return 0; @@ -21,11 +28,14 @@ public class VehicleServiceImpl implements VehicleService { @Override public List list(EnumSet statuses) throws ServiceException { - return null; + // TODO: IMPLEMENT SEARCH WITH STATUS + try { + return vehicleDAO.list(); + } catch (PersistenceException e) { + throw new ServiceException(e); + } } @Override - public void remove(long id) throws InvalidVehicleException, ServiceException { - - } + public void remove(long id) throws InvalidVehicleException, ServiceException {} } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index b5a8cf1..ab761e3 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -4,11 +4,15 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperation import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; 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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; @@ -24,11 +28,15 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import java.time.Instant; +import java.util.EnumSet; import java.util.LinkedList; import java.util.List; +import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; diff --git a/src/main/resources/fxmlFiles/CreateOperationController.fxml b/src/main/resources/fxmlFiles/CreateOperationController.fxml deleted file mode 100644 index 7b188fd..0000000 --- a/src/main/resources/fxmlFiles/CreateOperationController.fxml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2 From e3c37e6ea7b39970b03ab1cb76cc0b8b65923953 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:03:19 +0200 Subject: Small Changes (deleted Comments and TODOs) added an Alert if Operation was saved successfully --- .../assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 5 +---- .../einsatzverwaltung/userInterface/CreateOperationController.java | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index aaf7631..d332acc 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,7 +5,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -93,9 +92,7 @@ public class DBOperationDAO implements OperationDAO { } pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) { - return rs.getInt(1); - } + if (rs.next()) return rs.getInt(1); else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index ab761e3..b6305a5 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -34,6 +34,7 @@ import java.util.List; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; -- cgit v1.2.3-70-g09d2 From 37fc43a661dd9d170970c40499ca1939ccf3fb7e Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:29:43 +0200 Subject: Added file for unit tests --- .../groupphase/operation/OperationServiceTest.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java new file mode 100644 index 0000000..9b9fc03 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -0,0 +1,49 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.time.LocalDate; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(); + + @Test + public void addOperationTest() { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .build(); + try{ + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From b7ac1dcc5932df9d595ee896dfc880d6e0172b74 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:31:55 +0200 Subject: formated CodeV --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index b6305a5..99bfb2d 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -12,7 +12,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; @@ -28,7 +27,6 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import java.time.Instant; -import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; -- cgit v1.2.3-70-g09d2 From ff3bfe5b4f53a54eedceedfc819054577079363a Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:10:56 +0200 Subject: Added constructor to create persistence instance --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 99bfb2d..d9d4cc8 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; @@ -15,6 +16,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; -- cgit v1.2.3-70-g09d2 From c8edaf33ac66502618bb56024832ca1113c6a0ae Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:12:53 +0200 Subject: Added unit tests --- .../groupphase/operation/OperationServiceTest.java | 122 +++++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java index 9b9fc03..aa89a85 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -7,30 +7,42 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; -import java.time.LocalDate; +import java.util.List; import org.junit.Assert; import org.junit.Test; public class OperationServiceTest { private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(); + private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Operation operation = Operation.builder() .status(Status.ACTIVE) @@ -39,11 +51,105 @@ public class OperationServiceTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) + .vehicles(List.of(vehicle)) .build(); - try{ + try { Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); } } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } } -- cgit v1.2.3-70-g09d2 From 160e236d8f1e92b7c59b0bb6dc3a7b5aaefe33ac Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:02:12 +0200 Subject: Small Changes --- .../service/OperationServiceImpl.java | 1 - .../groupphase/operation/OperationServiceTest.java | 155 --------------------- .../operation/OperationServiceUnitTest.java | 155 +++++++++++++++++++++ 3 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index e0fd824..9e4aaaa 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -1,6 +1,5 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java deleted file mode 100644 index aa89a85..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java new file mode 100644 index 0000000..866f759 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceUnitTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3-70-g09d2 From 2ba1998d8c1152537e16fcc7f5caf683f20a2574 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:07:40 +0200 Subject: Added some component tests, mocking of database still necessary --- .../operation/OperationServiceComponentTest.java | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java new file mode 100644 index 0000000..fc3ea54 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceComponentTest { + + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + //TODO: MOCK H2 + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + +} -- cgit v1.2.3-70-g09d2 From 276ccb0cebfa58f9dff6ddeaa4a215bca62d5fc5 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:47:39 +0200 Subject: Mocked H2 --- .../groupphase/operation/OperationServiceComponentTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java index fc3ea54..aeee11f 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -17,7 +17,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; @@ -27,12 +26,11 @@ import org.junit.Test; public class OperationServiceComponentTest { - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { - //TODO: MOCK H2 Vehicle vehicle = Vehicle.builder() .status(Vehicle.Status.FREI_FUNK) @@ -53,6 +51,7 @@ public class OperationServiceComponentTest { .vehicles(List.of(vehicle)) .build(); try { + //TODO: OPERATION DOES NOT WORK Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); -- cgit v1.2.3-70-g09d2 From 007918d168ab70b67acf3fd820ab7ad98b7ab289 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 21:05:15 +0200 Subject: Small Changes --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index d9d4cc8..47de178 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -8,8 +8,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; 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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; @@ -29,6 +27,7 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import java.time.Instant; +import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; -- cgit v1.2.3-70-g09d2 From 93d9c23054e8728606a3460f2a06a32ed6f10c29 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 22:32:42 +0200 Subject: Added test for persistence layer --- .../operation/OperationPersistenceTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java new file mode 100644 index 0000000..ecc0486 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java @@ -0,0 +1,67 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.mock; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.Instant; +import java.util.List; +import org.junit.BeforeClass; +import org.junit.Test; + +public class OperationPersistenceTest { + + private final OperationDAO operationDAO = + new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); + + @BeforeClass + public static void createSchema() throws SQLException { + /*RunScript.execute( + "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", + "", + "", + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false);*/ + } + + @Test + public void addOperation() { + //TODO + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + operationDAO.add(operation); + } catch (PersistenceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From e11f7b4aa80c1db48c445228b9f17654b3c462ce Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 11:46:00 +0200 Subject: Added some test for persistence layer/small changes --- .../service/VehicleServiceImpl.java | 41 ------ .../operation/OperationPersistenceTest.java | 67 --------- .../operation/OperationServiceComponentTest.java | 154 -------------------- .../operation/OperationServiceUnitTest.java | 155 --------------------- 4 files changed, 417 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java deleted file mode 100644 index f21ae9a..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.util.EnumSet; -import java.util.List; - -public class VehicleServiceImpl implements VehicleService { - - // TODO - private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); - - @Override - public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return 0; - } - - @Override - public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return null; - } - - @Override - public List list(EnumSet statuses) throws ServiceException { - // TODO: IMPLEMENT SEARCH WITH STATUS - try { - return vehicleDAO.list(); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - } - - @Override - public void remove(long id) throws InvalidVehicleException, ServiceException {} -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java deleted file mode 100644 index ecc0486..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.mockito.Mockito.mock; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperationPersistenceTest { - - private final OperationDAO operationDAO = - new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - - @BeforeClass - public static void createSchema() throws SQLException { - /*RunScript.execute( - "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", - "", - "", - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false);*/ - } - - @Test - public void addOperation() { - //TODO - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - operationDAO.add(operation); - } catch (PersistenceException e) { - fail(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java deleted file mode 100644 index aeee11f..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceComponentTest { - - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - //TODO: OPERATION DOES NOT WORK - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java deleted file mode 100644 index 866f759..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceUnitTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} -- cgit v1.2.3-70-g09d2 From cbcb6d0122b6c47c4dc2033ff843ac6b672bb025 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 13:09:47 +0200 Subject: Added Operation DAO and -Service for Operation, implemented needed methods. --- .../groupphase/einsatzverwaltung/service/OperationServiceImpl.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 9e4aaaa..669036e 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -1,5 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; @@ -15,6 +16,10 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +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.PersistenceException; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; -- cgit v1.2.3-70-g09d2 From 854f8e0cfdf14b9cbc17f8ec1039604363734c77 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 21:18:20 +0200 Subject: Created first (unfinished) version for operation UI, started implementing Controller --- .../userInterface/CreateOperationController.java | 7 ++ .../fxmlFiles/CreateOperationController.fxml | 94 ++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/main/resources/fxmlFiles/CreateOperationController.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 47de178..3bf50e4 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -6,6 +6,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.service.OperationService; @@ -37,6 +38,12 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; +import java.time.Instant; +import java.util.LinkedList; +import java.util.List; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; diff --git a/src/main/resources/fxmlFiles/CreateOperationController.fxml b/src/main/resources/fxmlFiles/CreateOperationController.fxml new file mode 100644 index 0000000..7b188fd --- /dev/null +++ b/src/main/resources/fxmlFiles/CreateOperationController.fxml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2 From fe9f519deef72b9135626353d0017a7e34b6f3bd Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 2 May 2018 22:08:25 +0200 Subject: Added Vehicle DAO and Vehicle Service Impl, started implementing needed methods --- .../service/OperationServiceImpl.java | 1 + .../service/VehicleServiceImpl.java | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 669036e..36f8d8b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -20,6 +20,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh 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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java new file mode 100644 index 0000000..80d7432 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -0,0 +1,31 @@ +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 class VehicleServiceImpl implements VehicleService { + + @Override + public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return 0; + } + + @Override + public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + return null; + } + + @Override + public List list(EnumSet statuses) throws ServiceException { + return null; + } + + @Override + public void remove(long id) throws InvalidVehicleException, ServiceException { + + } +} -- cgit v1.2.3-70-g09d2 From a24998777f198617819ffef3e7ff5ef7a0bc5dc2 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Fri, 4 May 2018 12:06:52 +0200 Subject: Finished implementing needed methods in Persistence layer, added some validation factors for operation validation; Added methods to ui to add/remove vehicles to operation, created dummy vehicles --- .../einsatzverwaltung/dao/DBOperationDAO.java | 5 +- .../service/OperationServiceImpl.java | 1 + .../service/VehicleServiceImpl.java | 18 ++++- .../userInterface/CreateOperationController.java | 22 ----- .../fxmlFiles/CreateOperationController.fxml | 94 ---------------------- 5 files changed, 19 insertions(+), 121 deletions(-) delete mode 100644 src/main/resources/fxmlFiles/CreateOperationController.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index d332acc..aaf7631 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,6 +5,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -92,7 +93,9 @@ public class DBOperationDAO implements OperationDAO { } pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) return rs.getInt(1); + if (rs.next()) { + return rs.getInt(1); + } else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 36f8d8b..ad16caf 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -21,6 +21,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java index 80d7432..f21ae9a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -1,14 +1,21 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; 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.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; public class VehicleServiceImpl implements VehicleService { + // TODO + private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); + @Override public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { return 0; @@ -21,11 +28,14 @@ public class VehicleServiceImpl implements VehicleService { @Override public List list(EnumSet statuses) throws ServiceException { - return null; + // TODO: IMPLEMENT SEARCH WITH STATUS + try { + return vehicleDAO.list(); + } catch (PersistenceException e) { + throw new ServiceException(e); + } } @Override - public void remove(long id) throws InvalidVehicleException, ServiceException { - - } + public void remove(long id) throws InvalidVehicleException, ServiceException {} } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 3bf50e4..b9b6c6d 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -3,10 +3,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.service.OperationService; @@ -15,7 +11,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; @@ -23,27 +18,10 @@ import java.util.List; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; -import java.time.Instant; -import java.util.EnumSet; -import java.util.LinkedList; -import java.util.List; -import javafx.collections.FXCollections; -import javafx.fxml.FXML; -import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.ListCell; -import java.time.Instant; -import java.util.LinkedList; -import java.util.List; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; diff --git a/src/main/resources/fxmlFiles/CreateOperationController.fxml b/src/main/resources/fxmlFiles/CreateOperationController.fxml deleted file mode 100644 index 7b188fd..0000000 --- a/src/main/resources/fxmlFiles/CreateOperationController.fxml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2 From 690cea4eeb57a49fb0d35046b199a089cafd1a04 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:03:19 +0200 Subject: Small Changes (deleted Comments and TODOs) added an Alert if Operation was saved successfully --- .../assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 5 +---- .../einsatzverwaltung/userInterface/CreateOperationController.java | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index aaf7631..d332acc 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -5,7 +5,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.S import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.beans.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -93,9 +92,7 @@ public class DBOperationDAO implements OperationDAO { } pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) { - return rs.getInt(1); - } + if (rs.next()) return rs.getInt(1); else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); } catch (SQLException e) { throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index b9b6c6d..bff05a2 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -18,6 +18,7 @@ import java.util.List; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; -- cgit v1.2.3-70-g09d2 From b76a739fbab682587ea43afa6652049061a0bdf2 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 16:29:43 +0200 Subject: Added file for unit tests --- .../groupphase/operation/OperationServiceTest.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java new file mode 100644 index 0000000..9b9fc03 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -0,0 +1,49 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.time.LocalDate; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(); + + @Test + public void addOperationTest() { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .build(); + try{ + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From 1e794109035fa88f970ba8df03f4c4f53a030f17 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:10:56 +0200 Subject: Added constructor to create persistence instance --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index bff05a2..6855c8b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -1,5 +1,8 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -- cgit v1.2.3-70-g09d2 From 5e312765f43815a7a2b22d3c5b00f7fceea76a8b Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 17:12:53 +0200 Subject: Added unit tests --- .../groupphase/operation/OperationServiceTest.java | 122 +++++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java index 9b9fc03..aa89a85 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java @@ -7,30 +7,42 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; -import java.time.LocalDate; +import java.util.List; import org.junit.Assert; import org.junit.Test; public class OperationServiceTest { private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(); + private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Operation operation = Operation.builder() .status(Status.ACTIVE) @@ -39,11 +51,105 @@ public class OperationServiceTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) + .vehicles(List.of(vehicle)) .build(); - try{ + try { Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); } } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } } -- cgit v1.2.3-70-g09d2 From 7704a1d04295cad0969a00976c4c552671637e35 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:02:12 +0200 Subject: Small Changes --- .../service/OperationServiceImpl.java | 1 - .../groupphase/operation/OperationServiceTest.java | 155 --------------------- .../operation/OperationServiceUnitTest.java | 155 +++++++++++++++++++++ 3 files changed, 155 insertions(+), 156 deletions(-) delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index ad16caf..5a5108c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -1,6 +1,5 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java deleted file mode 100644 index aa89a85..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java new file mode 100644 index 0000000..866f759 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceUnitTest { + private final OperationDAO operationDAO = mock(OperationDAO.class); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + try { + when(operationDAO.add(any())).thenReturn(1L); + } catch (PersistenceException e) { + fail(); + } + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3-70-g09d2 From 23bd53d2664fc68e6cdbf0e8f317d2354286f5a1 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:07:40 +0200 Subject: Added some component tests, mocking of database still necessary --- .../operation/OperationServiceComponentTest.java | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java new file mode 100644 index 0000000..fc3ea54 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceComponentTest { + + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationService operationService = new OperationServiceImpl(operationDAO); + + @Test + public void addOperationTest() { + //TODO: MOCK H2 + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (InvalidOperationException | ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperationTest() throws InvalidOperationException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + Vehicle vehicle1 = + Vehicle.builder() + .status(Vehicle.Status.ABGEMELDET) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle, vehicle1)) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + fail(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation2Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation3Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + + @Test(expected = InvalidOperationException.class) + public void addFaultyOperation4Test() throws InvalidOperationException { + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("") + .created(Instant.now()) + .destination("Römergasse 7, 2500 Baden") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of()) + .build(); + try { + Assert.assertThat(operationService.add(operation), is(1L)); + } catch (ServiceException e) { + e.printStackTrace(); + } + } + +} -- cgit v1.2.3-70-g09d2 From e385422b562f0614209f4a71f011f7cf85753fe4 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 20:47:39 +0200 Subject: Mocked H2 --- .../groupphase/operation/OperationServiceComponentTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java index fc3ea54..aeee11f 100644 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -17,7 +17,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.time.Instant; @@ -27,12 +26,11 @@ import org.junit.Test; public class OperationServiceComponentTest { - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); + private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); private final OperationService operationService = new OperationServiceImpl(operationDAO); @Test public void addOperationTest() { - //TODO: MOCK H2 Vehicle vehicle = Vehicle.builder() .status(Vehicle.Status.FREI_FUNK) @@ -53,6 +51,7 @@ public class OperationServiceComponentTest { .vehicles(List.of(vehicle)) .build(); try { + //TODO: OPERATION DOES NOT WORK Assert.assertThat(operationService.add(operation), is(1L)); } catch (InvalidOperationException | ServiceException e) { fail(); -- cgit v1.2.3-70-g09d2 From 5456ec86f8eab7669892aed56e5bb800f07f6b2f Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sat, 5 May 2018 22:32:42 +0200 Subject: Added test for persistence layer --- .../operation/OperationPersistenceTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java (limited to 'src') diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java new file mode 100644 index 0000000..ecc0486 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java @@ -0,0 +1,67 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.mock; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.Instant; +import java.util.List; +import org.junit.BeforeClass; +import org.junit.Test; + +public class OperationPersistenceTest { + + private final OperationDAO operationDAO = + new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); + + @BeforeClass + public static void createSchema() throws SQLException { + /*RunScript.execute( + "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", + "", + "", + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false);*/ + } + + @Test + public void addOperation() { + //TODO + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(List.of(vehicle)) + .build(); + try { + operationDAO.add(operation); + } catch (PersistenceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From c1248170fa6432d8ca3bc3212d292a6e761f02b1 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 11:46:00 +0200 Subject: Added some test for persistence layer/small changes --- .../service/VehicleServiceImpl.java | 41 ------ .../operation/OperationPersistenceTest.java | 67 --------- .../operation/OperationServiceComponentTest.java | 154 -------------------- .../operation/OperationServiceUnitTest.java | 155 --------------------- 4 files changed, 417 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java delete mode 100644 src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java deleted file mode 100644 index f21ae9a..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBVehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.util.EnumSet; -import java.util.List; - -public class VehicleServiceImpl implements VehicleService { - - // TODO - private static VehicleDAO vehicleDAO = new DBVehicleDAO(new JDBCConnectionManager()); - - @Override - public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return 0; - } - - @Override - public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - return null; - } - - @Override - public List list(EnumSet statuses) throws ServiceException { - // TODO: IMPLEMENT SEARCH WITH STATUS - try { - return vehicleDAO.list(); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - } - - @Override - public void remove(long id) throws InvalidVehicleException, ServiceException {} -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java deleted file mode 100644 index ecc0486..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.mockito.Mockito.mock; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperationPersistenceTest { - - private final OperationDAO operationDAO = - new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - - @BeforeClass - public static void createSchema() throws SQLException { - /*RunScript.execute( - "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", - "", - "", - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false);*/ - } - - @Test - public void addOperation() { - //TODO - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - operationDAO.add(operation); - } catch (PersistenceException e) { - fail(); - } - } -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java deleted file mode 100644 index aeee11f..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceComponentTest { - - private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - //TODO: OPERATION DOES NOT WORK - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java deleted file mode 100644 index 866f759..0000000 --- a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceUnitTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.operation; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceUnitTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final OperationService operationService = new OperationServiceImpl(operationDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(List.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} -- cgit v1.2.3-70-g09d2 From 7f15b712cdf405ef214b73f0c19b5223555f262e Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 17:45:49 +0200 Subject: small changes --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 6855c8b..b17247e 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -45,7 +45,7 @@ public class CreateOperationController { // TODO: Anders? OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); - VehicleService vehicleService; + VehicleService vehicleService = new VehicleServiceImpl(); public CreateOperationController() {} -- cgit v1.2.3-70-g09d2 From b91e0c9fb50863fab0ce94a2d263425815772c91 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 17:51:13 +0200 Subject: reformated code --- .../einsatzverwaltung/service/OperationServiceImpl.java | 12 ------------ .../userInterface/CreateOperationController.java | 4 ---- 2 files changed, 16 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 5a5108c..74cb7a7 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -9,18 +9,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.util.EnumSet; import java.util.List; import javafx.collections.transformation.SortedList; diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index b17247e..5fefa10 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -1,8 +1,5 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; @@ -25,7 +22,6 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListCell; -import javafx.scene.control.Alert.AlertType; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; -- cgit v1.2.3-70-g09d2 From 1ce1f73533dbf21985259509ae4ef4da1cfeacf0 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Sun, 6 May 2018 18:23:27 +0200 Subject: Fix rebase errors --- .../einsatzverwaltung/dao/OperationDAO.java | 2 + .../einsatzverwaltung/service/VehicleAdd.java | 80 ---------------------- .../service/VehicleServiceImpl.java | 80 ++++++++++++++++++++++ .../userInterface/CreateOperationController.java | 8 ++- .../operation/OperationPersistenceTest.java | 25 +------ .../operation/OperationServiceComponentTest.java | 25 +------ .../groupphase/vehicle/CarAddTestService.java | 4 +- .../vehicle/VehicleServiceTestConfiguration.java | 4 +- 8 files changed, 97 insertions(+), 131 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleAdd.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java (limited to 'src') 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 index 7f28005..dd1a189 100644 --- 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 @@ -45,4 +45,6 @@ public interface OperationDAO { * @throws PersistenceException if loading the stored operations failed */ List list(EnumSet statuses) throws PersistenceException; + + int connectVehicleToOperation(long vehicleID, long operationID) throws PersistenceException; } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleAdd.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleAdd.java deleted file mode 100644 index e78c6b2..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleAdd.java +++ /dev/null @@ -1,80 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.util.EnumSet; -import java.util.List; -import org.springframework.stereotype.Service; - -@Service -public class VehicleAdd implements VehicleService { - private VehicleDAO vehicleDAO; - - public VehicleAdd(VehicleDAO vehicleDAO) { - this.vehicleDAO = vehicleDAO; - } - - public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - - switch (vehicle.type()) { - case RTW: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("RTW darf kein Normales Dach haben"); - } else if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("RTW darf kein Mittelhochdach haben"); - } - break; - case KTW: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("KTW darf kein Normales Dach haben"); - } - break; - case KTW_B: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("KTW-B darf kein Normales Dach haben"); - } - break; - case NEF: - if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); - } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Hochdach haben"); - } - break; - case NAH: - if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); - } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Hochdach haben"); - } - break; - case BKTW: - break; - default: - throw new ServiceException("not a Valid type"); - } - try { - vehicleDAO.add(vehicle); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - return 0; - } - - public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - throw new UnsupportedOperationException(); - } - - public List list(EnumSet statuses) throws ServiceException { - throw new UnsupportedOperationException(); - } - - public void remove(long id) throws InvalidVehicleException, ServiceException { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java new file mode 100644 index 0000000..4a11298 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -0,0 +1,80 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.EnumSet; +import java.util.List; +import org.springframework.stereotype.Service; + +@Service +public class VehicleServiceImpl implements VehicleService { + private VehicleDAO vehicleDAO; + + public VehicleServiceImpl(VehicleDAO vehicleDAO) { + this.vehicleDAO = vehicleDAO; + } + + public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + + switch (vehicle.type()) { + case RTW: + if (vehicle.constructionType() == ConstructionType.NORMAL) { + throw new InvalidVehicleException("RTW darf kein Normales Dach haben"); + } else if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { + throw new InvalidVehicleException("RTW darf kein Mittelhochdach haben"); + } + break; + case KTW: + if (vehicle.constructionType() == ConstructionType.NORMAL) { + throw new InvalidVehicleException("KTW darf kein Normales Dach haben"); + } + break; + case KTW_B: + if (vehicle.constructionType() == ConstructionType.NORMAL) { + throw new InvalidVehicleException("KTW-B darf kein Normales Dach haben"); + } + break; + case NEF: + if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { + throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); + } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { + throw new InvalidVehicleException("NEF darf kein Hochdach haben"); + } + break; + case NAH: + if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { + throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); + } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { + throw new InvalidVehicleException("NEF darf kein Hochdach haben"); + } + break; + case BKTW: + break; + default: + throw new ServiceException("not a Valid type"); + } + try { + vehicleDAO.add(vehicle); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + return 0; + } + + public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + throw new UnsupportedOperationException(); + } + + public List list(EnumSet statuses) throws ServiceException { + throw new UnsupportedOperationException(); + } + + public void remove(long id) throws InvalidVehicleException, ServiceException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 5fefa10..38f6849 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -25,7 +25,9 @@ import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; +import org.springframework.stereotype.Controller; +@Controller public class CreateOperationController { public AnchorPane apCreateOperation; @@ -41,9 +43,11 @@ public class CreateOperationController { // TODO: Anders? OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); - VehicleService vehicleService = new VehicleServiceImpl(); + private final VehicleService vehicleService; - public CreateOperationController() {} + public CreateOperationController(VehicleService vehicleService) { + this.vehicleService = vehicleService; + } @FXML public void initialize() { diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java index 575588e..be612d0 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationPersistenceTest.java @@ -1,28 +1,8 @@ package at.ac.tuwien.sepm.assignment.groupphase.operation; -import static junit.framework.TestCase.fail; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.List; -import org.h2.tools.RunScript; -import org.junit.BeforeClass; -import org.junit.Test; - public class OperationPersistenceTest { - private final OperationDAO operationDAO = + /*private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); @BeforeClass @@ -87,6 +67,7 @@ public class OperationPersistenceTest { .build(); operationDAO.add(operation); }*/ + /* @Test(expected = PersistenceException.class) public void addFaultyOperation1Test() throws PersistenceException { @@ -124,5 +105,5 @@ public class OperationPersistenceTest { } // TODO: ADD CONNECTION TESTS - // KOMMT ID ZURÜCK? + // KOMMT ID ZURÜCK?*/ } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java index 7ffe135..286ee07 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -1,29 +1,8 @@ package at.ac.tuwien.sepm.assignment.groupphase.operation; -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.DBOperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.time.Instant; -import java.util.List; -import org.junit.Assert; -import org.junit.Test; - public class OperationServiceComponentTest { - private final OperationDAO operationDAO = + /*private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); private final OperationService operationService = new OperationServiceImpl(operationDAO); @@ -147,5 +126,5 @@ public class OperationServiceComponentTest { } catch (ServiceException e) { e.printStackTrace(); } - } + }*/ } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java index 3ae2fe6..731da6f 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java @@ -8,8 +8,8 @@ import static org.mockito.Mockito.when; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDBDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleAdd; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; @@ -17,7 +17,7 @@ import org.junit.Test; public class CarAddTestService { private final VehicleDAO vehicleP = mock(VehicleDBDAO.class); - private final VehicleService vehicleService = new VehicleAdd(vehicleP); + private final VehicleService vehicleService = new VehicleServiceImpl(vehicleP); public CarAddTestService() throws PersistenceException { when(vehicleP.add(any())).thenReturn(1L); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehicleServiceTestConfiguration.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehicleServiceTestConfiguration.java index cccd5dc..ccd1e5d 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehicleServiceTestConfiguration.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehicleServiceTestConfiguration.java @@ -2,8 +2,8 @@ package at.ac.tuwien.sepm.assignment.groupphase.vehicle; import static org.mockito.Mockito.mock; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleAdd; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -14,6 +14,6 @@ public class VehicleServiceTestConfiguration { @Bean @Primary public VehicleService vehicleService() { - return mock(VehicleAdd.class); + return mock(VehicleServiceImpl.class); } } -- cgit v1.2.3-70-g09d2 From d3f8c25338c4dfbefc70eb5cb01f2f448ecb9e99 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sun, 6 May 2018 22:03:46 +0200 Subject: Merge 'VehicleDBDAO' and 'DBVehicleDAO' to 'VehicleDatabaseDao' --- .../einsatzverwaltung/dao/DBVehicleDAO.java | 74 ----------- .../einsatzverwaltung/dao/VehicleDBDAO.java | 107 --------------- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 144 +++++++++++++++++++++ .../groupphase/vehicle/CarAddTestService.java | 4 +- 4 files changed, 146 insertions(+), 183 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDBDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java deleted file mode 100644 index d966dc5..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBVehicleDAO.java +++ /dev/null @@ -1,74 +0,0 @@ -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.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.LinkedList; -import java.util.List; - -public class DBVehicleDAO implements VehicleDAO { - - private JDBCConnectionManager jdbcConnectionManager; - - public DBVehicleDAO(JDBCConnectionManager j) { - jdbcConnectionManager = j; - } - - @Override - public long add(Vehicle vehicle) throws PersistenceException { - return 0; - } - - @Override - public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException {} - - @Override - public List list() throws PersistenceException { - PreparedStatement pstmt = null; - List result = new LinkedList<>(); - try { - pstmt = - jdbcConnectionManager - .getConnection() - .prepareStatement( - "Select * from VehicleVersion, " - + "Vehicle where VehicleVersion.id=Vehicle.version"); - pstmt.executeQuery(); - ResultSet rs = pstmt.getResultSet(); - while (rs.next()) { - Vehicle vehicle = - Vehicle.builder() - .name(rs.getString(2)) - .constructionType(ConstructionType.valueOf(rs.getString(3))) - .status(Status.valueOf(rs.getString(8))) - .id(rs.getInt(6)) - .hasNef(rs.getBoolean(5)) - .type(VehicleType.valueOf(rs.getString(4))) - .build(); - result.add(vehicle); - } - } catch (SQLException e) { - throw new PersistenceException("Die Werte konnten nicht geladen werden.", e); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { - throw new PersistenceException( - "Verbindung zur Datenbank konnte nicht geschlossen werden!", e); - } - } - } - return result; - } - - @Override - public void remove(long id) throws ElementNotFoundException, PersistenceException {} -} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDBDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDBDAO.java deleted file mode 100644 index 8a596b3..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDBDAO.java +++ /dev/null @@ -1,107 +0,0 @@ -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.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import org.springframework.stereotype.Repository; - -@Repository -public class VehicleDBDAO implements VehicleDAO { - - private final JDBCConnectionManager jdbcConnectionManager; - - public VehicleDBDAO(JDBCConnectionManager jdbcConnectionManager) { - this.jdbcConnectionManager = jdbcConnectionManager; - } - - public long add(Vehicle vehicle) throws PersistenceException { - String query1 = "INSERT INTO VehicleVersion (name,constructionType,type) VALUES (?,?,?)"; - String query2 = "INSERT INTO Vehicle (version,status) VALUES (?,?)"; - PreparedStatement p1 = null; - PreparedStatement p2 = null; - PreparedStatement p3 = null; - String status = "abgemeldet"; - String name = ""; - int id = -1; - try { - p1 = - jdbcConnectionManager - .getConnection() - .prepareStatement(query1, PreparedStatement.RETURN_GENERATED_KEYS); - p1.setString(1, name); - p1.setString(2, vehicle.constructionType().name()); - if (vehicle.type() == VehicleType.KTW_B) { - p1.setString(3, "KTW-B"); - } else { - p1.setString(3, vehicle.type().name()); - } - p1.executeUpdate(); - - ResultSet keyResultSet = p1.getGeneratedKeys(); - - if (keyResultSet.next()) { - id = keyResultSet.getInt(1); - } - - name = vehicle.type().name() + "-" + id; - - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } finally { - try { - p1.close(); - - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } - } - try { - query1 = "UPDATE VehicleVersion SET name=? WHERE id=?"; - p3 = jdbcConnectionManager.getConnection().prepareStatement(query1); - p3.setString(1, name); - p3.setInt(2, id); - p3.executeUpdate(); - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } finally { - try { - p3.close(); - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } - } - try { - p2 = jdbcConnectionManager.getConnection().prepareStatement(query2); - p2.setInt(1, id); - p2.setString(2, status); - p2.executeUpdate(); - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } finally { - try { - p2.close(); - } catch (SQLException e) { - throw new PersistenceException("SQL Excpetion : " + e.toString()); - } - } - return id; - } - - public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException { - throw new UnsupportedOperationException(); - } - - public List list() throws PersistenceException { - throw new UnsupportedOperationException(); - } - - public void remove(long id) throws ElementNotFoundException, PersistenceException { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java new file mode 100644 index 0000000..5ddb035 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java @@ -0,0 +1,144 @@ +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.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; +import org.springframework.stereotype.Repository; + +@Repository +public class VehicleDatabaseDao implements VehicleDAO { + + private final JDBCConnectionManager jdbcConnectionManager; + + public VehicleDatabaseDao(JDBCConnectionManager j) { + jdbcConnectionManager = j; + } + + public long add(Vehicle vehicle) throws PersistenceException { + String query1 = "INSERT INTO VehicleVersion (name,constructionType,type) VALUES (?,?,?)"; + String query2 = "INSERT INTO Vehicle (version,status) VALUES (?,?)"; + PreparedStatement p1 = null; + PreparedStatement p2 = null; + PreparedStatement p3 = null; + String status = "abgemeldet"; + String name = ""; + int id = -1; + try { + p1 = + jdbcConnectionManager + .getConnection() + .prepareStatement(query1, PreparedStatement.RETURN_GENERATED_KEYS); + p1.setString(1, name); + p1.setString(2, vehicle.constructionType().name()); + if (vehicle.type() == VehicleType.KTW_B) { + p1.setString(3, "KTW-B"); + } else { + p1.setString(3, vehicle.type().name()); + } + p1.executeUpdate(); + + ResultSet keyResultSet = p1.getGeneratedKeys(); + + if (keyResultSet.next()) { + id = keyResultSet.getInt(1); + } + + name = vehicle.type().name() + "-" + id; + + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } finally { + try { + p1.close(); + + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } + } + try { + query1 = "UPDATE VehicleVersion SET name=? WHERE id=?"; + p3 = jdbcConnectionManager.getConnection().prepareStatement(query1); + p3.setString(1, name); + p3.setInt(2, id); + p3.executeUpdate(); + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } finally { + try { + p3.close(); + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } + } + try { + p2 = jdbcConnectionManager.getConnection().prepareStatement(query2); + p2.setInt(1, id); + p2.setString(2, status); + p2.executeUpdate(); + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } finally { + try { + p2.close(); + } catch (SQLException e) { + throw new PersistenceException("SQL Excpetion : " + e.toString()); + } + } + return id; + } + + @Override + public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException {} + + @Override + public List list() throws PersistenceException { + PreparedStatement pstmt = null; + List result = new LinkedList<>(); + try { + pstmt = + jdbcConnectionManager + .getConnection() + .prepareStatement( + "Select * from VehicleVersion, " + + "Vehicle where VehicleVersion.id=Vehicle.version"); + pstmt.executeQuery(); + ResultSet rs = pstmt.getResultSet(); + while (rs.next()) { + Vehicle vehicle = + Vehicle.builder() + .name(rs.getString(2)) + .constructionType(ConstructionType.valueOf(rs.getString(3))) + .status(Status.valueOf(rs.getString(8))) + .id(rs.getInt(6)) + .hasNef(rs.getBoolean(5)) + .type(VehicleType.valueOf(rs.getString(4))) + .build(); + result.add(vehicle); + } + } catch (SQLException e) { + throw new PersistenceException("Die Werte konnten nicht geladen werden.", e); + } finally { + if (pstmt != null) { + try { + pstmt.close(); + } catch (SQLException e) { + throw new PersistenceException( + "Verbindung zur Datenbank konnte nicht geschlossen werden!", e); + } + } + } + return result; + } + + @Override + public void remove(long id) throws ElementNotFoundException, PersistenceException {} +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java index 731da6f..de7a26a 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/CarAddTestService.java @@ -6,7 +6,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDBDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDatabaseDao; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleServiceImpl; @@ -16,7 +16,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import org.junit.Test; public class CarAddTestService { - private final VehicleDAO vehicleP = mock(VehicleDBDAO.class); + private final VehicleDAO vehicleP = mock(VehicleDatabaseDao.class); private final VehicleService vehicleService = new VehicleServiceImpl(vehicleP); public CarAddTestService() throws PersistenceException { -- cgit v1.2.3-70-g09d2 From 40ad8a458a0706ccdcd567965f0275d4dd0aa118 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 12:14:13 +0200 Subject: Add MainApplication which opens Operation window --- .../groupphase/application/MainApplication.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java new file mode 100644 index 0000000..a8a6c62 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java @@ -0,0 +1,51 @@ +package at.ac.tuwien.sepm.assignment.groupphase.application; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.CreateOperationController; +import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; +import javafx.application.Application; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; + +@Component +@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase") +public class MainApplication extends Application { + + private static AnnotationConfigApplicationContext configApplicationContext; + + public static void main(String[] args) { + Application.launch(MainApplication.class, args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + primaryStage.setTitle("Einsatz erstellen"); + primaryStage.centerOnScreen(); + // primaryStage.setOnCloseRequest( event -> ); + + configApplicationContext = new AnnotationConfigApplicationContext(MainApplication.class); + final var fxmlLoader = configApplicationContext.getBean(SpringFXMLLoader.class); + primaryStage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/CreateOperationController.fxml")))); + + /*FXMLLoader fxmlLoader = + new FXMLLoader(getClass().getResource("/fxml/CreateOperationController.fxml")); + Parent node = fxmlLoader.load(); + // TODO:*/ + CreateOperationController controller = + configApplicationContext.getBean( + CreateOperationController.class); // fxmlLoader.getController(); + controller.updateList(); + // primaryStage.setScene(new Scene(node)); + primaryStage.show(); + primaryStage.toFront(); + } +} -- cgit v1.2.3-70-g09d2 From cb1440f1b5fbfe9ce93f3a6256af3f021aa6d484 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 12:32:18 +0200 Subject: Add Platform.exit() on window-close and add stop-method --- .../groupphase/application/MainApplication.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java index a8a6c62..01c04d3 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java @@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.application; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.CreateOperationController; import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; import javafx.application.Application; +import javafx.application.Platform; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; @@ -24,7 +25,7 @@ public class MainApplication extends Application { public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Einsatz erstellen"); primaryStage.centerOnScreen(); - // primaryStage.setOnCloseRequest( event -> ); + primaryStage.setOnCloseRequest(event -> Platform.exit()); configApplicationContext = new AnnotationConfigApplicationContext(MainApplication.class); final var fxmlLoader = configApplicationContext.getBean(SpringFXMLLoader.class); @@ -36,16 +37,16 @@ public class MainApplication extends Application { .getResourceAsStream( "/fxml/CreateOperationController.fxml")))); - /*FXMLLoader fxmlLoader = - new FXMLLoader(getClass().getResource("/fxml/CreateOperationController.fxml")); - Parent node = fxmlLoader.load(); - // TODO:*/ CreateOperationController controller = - configApplicationContext.getBean( - CreateOperationController.class); // fxmlLoader.getController(); + configApplicationContext.getBean(CreateOperationController.class); controller.updateList(); - // primaryStage.setScene(new Scene(node)); primaryStage.show(); primaryStage.toFront(); } + + @Override + public void stop() throws Exception { + super.stop(); + configApplicationContext.close(); + } } -- cgit v1.2.3-70-g09d2 From 3d3f4440238ededefa6bb142106295d6eab4678c Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 12:33:11 +0200 Subject: Change CreateOperationController.fxml labels to hyperlinks with onAction --- src/main/resources/fxml/CreateOperationController.fxml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 949d4ec..1ba6498 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -1,6 +1,7 @@ + @@ -59,21 +60,21 @@ - - - + -- cgit v1.2.3-70-g09d2 From 498b81ada011b0c39dd7db9906db50482586d73b Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 12:35:08 +0200 Subject: Add hyperlink-click-methods in CreateOperationController, implement onEmployeeLinkClicked --- .../userInterface/CreateOperationController.java | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 38f6849..87b9ea7 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -11,12 +11,17 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; +import java.io.IOException; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; +import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; @@ -25,6 +30,7 @@ import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; import org.springframework.stereotype.Controller; @Controller @@ -44,9 +50,11 @@ public class CreateOperationController { OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); private final VehicleService vehicleService; + private final SpringFXMLLoader fxmlLoader; - public CreateOperationController(VehicleService vehicleService) { + public CreateOperationController(VehicleService vehicleService, SpringFXMLLoader fxmlLoader) { this.vehicleService = vehicleService; + this.fxmlLoader = fxmlLoader; } @FXML @@ -174,4 +182,38 @@ public class CreateOperationController { alert.showAndWait(); updateList(); } + + public void onRegistrationLinkClicked(ActionEvent actionEvent) { + throw new UnsupportedOperationException(); + } + + public void onEmployeeLinkClicked(ActionEvent actionEvent) { + openNewWindow("createNewEmployee.fxml"); + } + + public void onVehicleLinkClicked(ActionEvent actionEvent) { + openNewWindow("createCar.fxml"); + } + + private void openNewWindow(String fxmlFileName) { + + Stage stage = new Stage(); + try { + stage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/" + fxmlFileName)))); + } catch (IOException e) { + // TODO: Log error + } + + stage.setTitle("Einsatz erstellen"); + stage.centerOnScreen(); + stage.showAndWait(); // important to call wait so that updateList is executed afterwards + + updateList(); + } } -- cgit v1.2.3-70-g09d2 From f8c893b3a0dc51bde50238ddf3b7d1db318cb743 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 12:37:19 +0200 Subject: Log openNewWindow error --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 87b9ea7..ae99088 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -13,6 +13,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; import java.io.IOException; +import java.lang.invoke.MethodHandles; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; @@ -31,11 +32,15 @@ import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @Controller public class CreateOperationController { + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public AnchorPane apCreateOperation; public TextField txtCode; public TextField txtAddress; @@ -207,7 +212,7 @@ public class CreateOperationController { .getResourceAsStream( "/fxml/" + fxmlFileName)))); } catch (IOException e) { - // TODO: Log error + LOG.error("Could not open new window: {}", e); } stage.setTitle("Einsatz erstellen"); -- cgit v1.2.3-70-g09d2 From 9537613b77696bf3f7b7ecec28b464c17fbe34db Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Fri, 4 May 2018 13:26:46 +0200 Subject: Changed interface to take a whole vehicle, so the combination of vehicle type and employees can be validated --- .../groupphase/einsatzverwaltung/service/RegistrationService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') 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 801148c..c20ed3c 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 @@ -1,6 +1,7 @@ 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.einsatzverwaltung.dto.Vehicle; 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; @@ -11,14 +12,14 @@ public interface RegistrationService { /** * Register employee to a vehicle. * - * @param vehicleId the id of the target vehicle + * @param vehicle the target vehicle * @param registrations that should be added to the vehicle - * @return a list of the ids that were assigned + * @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 */ - List add(long vehicleId, List registrations) + List add(Vehicle vehicle, List registrations) throws InvalidVehicleException, InvalidRegistrationException, ServiceException; /** -- cgit v1.2.3-70-g09d2 From 05c7e29e8d7cd474963b7636f54c3d6f1e4bd390 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Fri, 4 May 2018 15:58:45 +0200 Subject: Implemented RegistrationService using RegistrationValidator --- .../dto/RegistrationValidator.java | 194 +++++++++++++++++++++ .../service/SimpleRegistrationService.java | 45 +++++ 2 files changed, 239 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java new file mode 100644 index 0000000..ac6c1f2 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java @@ -0,0 +1,194 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidRegistrationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistrationValidator { + + private static final Logger LOG = LoggerFactory.getLogger(RegistrationValidator.class); + + private RegistrationValidator() {} + + public static void validate(Vehicle vehicle, List registrations) + throws InvalidVehicleException, InvalidRegistrationException { + /* + Vehicles and Employees are assumed to be valid. + They have been checked at creation, and for them to be checked again, access to + VehicleValidator and EmployeeValidator are needed, which are not available at this time. + */ + /* + The method used here goes as follows: All given employees are inspected in regards to their + qualifications, and added to the appropriate lists of the roles they could fill. + For example, an NFS, who is also a driver, would be added to the lists driverIds, nfsIds + and rsIds (because an NFS can always substitute an RS). + Afterwards, the number of people is checked according to the chosen vehicle type, and if + the number is okay, the program tries to find a valid combination of roles for the vehicle. + For example, for an RTW, first a driver is chosen, their ID marked as found in the aptly + titled HashMap, and then for the second RS, the list of RS is checked, excluding the chosen + driver. If no other valid RS is found, the next possible driver is chosen, and so on. If no + valid combination is found, an InvalidRegistrationException is thrown. + */ + List pilotIds = new LinkedList<>(); + List driverIds = new LinkedList<>(); + List naIds = new LinkedList<>(); + List nfsIds = new LinkedList<>(); + List rsIds = new LinkedList<>(); + HashMap found = + new HashMap<>(); // needed later in DFS, checks that no person is chosen twice + int total = 0; + for (Registration registration : registrations) { + total++; + if (found.put(registration.employee().id(), false) != null) { + LOG.info("Employee with ID {} was added twice", registration.employee().id()); + throw new InvalidRegistrationException( + "Person with the ID: " + + registration.employee().id() + + " was added more than once!"); + } + if (registration.employee().isPilot()) { + pilotIds.add(registration.employee().id()); + } + if (registration.employee().isDriver()) { + driverIds.add(registration.employee().id()); + } + if (registration.employee().educationLevel() == EducationLevel.NA) { + naIds.add(registration.employee().id()); + nfsIds.add(registration.employee().id()); + rsIds.add(registration.employee().id()); + } else if (isNFS(registration.employee())) { + nfsIds.add(registration.employee().id()); + rsIds.add(registration.employee().id()); + } else { // only RS left + rsIds.add(registration.employee().id()); + } + } + if (total <= 0) { + LOG.info("No employees were added"); + throw new InvalidRegistrationException("Kein Personal ausgewählt!"); + } + if (vehicle.type() == VehicleType.NAH) { + /* + NAH + 1 Pilot + 1 NFS + 1 NA + 3-4 Personen + */ + if (total < 3) { + LOG.info("Too few employees for NAH"); + throw new InvalidRegistrationException("Zu wenig Personal für NAH!"); + } else if (total > 4) { + LOG.info("Too many employees for NAH"); + throw new InvalidRegistrationException("Zu viel Personal für NAH!"); + } + for (long pilot_id : pilotIds) { + found.put(pilot_id, true); + for (long na_id : naIds) { + if (found.get(na_id)) continue; + found.put(na_id, true); + for (long nfs_id : nfsIds) { + if (found.get(nfs_id)) continue; + LOG.info("Valid combination found for NAH"); + return; + } + found.put(na_id, false); + } + found.put(pilot_id, false); + } + LOG.info("No valid combination of employees found for NAH"); + throw new InvalidRegistrationException( + "Keine gültige Kombination von Personen für NAH!"); + } else if (vehicle.type() != VehicleType.NEF) { + /* + NEF + 1 Driver (has to be NFS) + 1 NA + */ + if (total < 2) { + LOG.info("Too few employees for NEF"); + throw new InvalidRegistrationException("Zu wenig Personal für NEF!"); + } else if (total > 3) { + LOG.info("Too many employees for NEF"); + throw new InvalidRegistrationException("Zu viel Personal für NEF!"); + } + for (long driver_id : driverIds) { + if (!nfsIds.contains(driver_id)) + continue; // if possible driver is not NFS, skip him + found.put(driver_id, true); + for (long na_id : naIds) { + if (found.get(na_id)) continue; + LOG.info("Valid combinaion found for NEF"); + return; + } + found.put(driver_id, false); + } + LOG.info("No valid combination of employees found for NEF"); + throw new InvalidRegistrationException( + "Keine gültige Kombination von Personen für NEF!"); + } else if (vehicle.type() == VehicleType.BKTW) { + /* + BKTW + 1 Driver + */ + if (total > 3) { + LOG.info("Too many employees for BKTW"); + throw new InvalidRegistrationException("Zu viel Personal für BKTW!"); + } + if (!driverIds.isEmpty()) { + LOG.info("Valid combination found for BKTW"); + return; + } + LOG.info("No driver was found for BKTW"); + throw new InvalidRegistrationException("Kein Fahrer gefunden für BKTW!"); + } else { // KTW or RTW, both have the same requirements + /* + RTW/KTW + 1 Driver + 1 RS + */ + if (total < 2) { + LOG.info("Too few employees for {}", vehicle.type().name()); + throw new InvalidRegistrationException( + "Zu wenig Personal für " + vehicle.type().name() + "!"); + } else if (total > 4) { + LOG.info("Too many employees for {}", vehicle.type().name()); + throw new InvalidRegistrationException( + "Zu viel Persoanl für " + vehicle.type().name() + "!"); + } + for (long driver_id : driverIds) { // driver includes rs + found.put(driver_id, true); + for (long rs_id : rsIds) { + if (found.get(rs_id)) continue; + LOG.info("Valid combination found for {}", vehicle.type().name()); + return; + } + } + LOG.info("No valid combination of employees found for {}", vehicle.type().name()); + throw new InvalidRegistrationException( + "Keine gültige Kombination von Personen für " + vehicle.type().name() + "!"); + } + } + + private static boolean isNFS(Employee employee) { + EducationLevel educationLevel = employee.educationLevel(); + switch (educationLevel) { + case NFS: + return true; + case NKA: + return true; + case NKI: + return true; + case NKV: + return true; + default: + return false; + } + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java new file mode 100644 index 0000000..5b26e39 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java @@ -0,0 +1,45 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.RegistrationValidator; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SimpleRegistrationService implements RegistrationService { + + private static final Logger LOG = LoggerFactory.getLogger(SimpleRegistrationService.class); + + private final RegistrationDAO registrationDAO; + + @Autowired + public SimpleRegistrationService(RegistrationDAO registrationDAO) { + this.registrationDAO = registrationDAO; + } + + @Override + public List add(Vehicle vehicle, List registrations) + throws InvalidVehicleException, InvalidRegistrationException, ServiceException { + RegistrationValidator.validate(vehicle, registrations); + try { + return registrationDAO.add(vehicle.id(), registrations); + } catch (PersistenceException e) { + LOG.warn("PersistenceException caught, throwing matching ServiceException"); + throw new ServiceException(e); + } + } + + @Override + public void remove(long registrationId) throws InvalidRegistrationException, ServiceException { + throw new UnsupportedOperationException(); + } +} -- cgit v1.2.3-70-g09d2 From da1ac259eb6ad8f53bcd884d22ed8de672b0f024 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Fri, 4 May 2018 22:36:00 +0200 Subject: First attempt at implementing RegistrationDAO --- .../einsatzverwaltung/dao/H2RegistrationDAO.java | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java new file mode 100644 index 0000000..825dc80 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java @@ -0,0 +1,96 @@ +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 at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.LinkedList; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class H2RegistrationDAO implements RegistrationDAO { + + private static final Logger LOG = LoggerFactory.getLogger(H2RegistrationDAO.class); + + private static final String ADD_REGISTRATION = + "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; + + private Connection connection; + + @Autowired + public H2RegistrationDAO(JDBCConnectionManager connectionManager) throws PersistenceException { + try { + connection = connectionManager.getConnection(); + } catch (SQLException e) { + LOG.error("Could not get connection!"); + throw new PersistenceException(e); + } + } + + @Override + public List add(long vehicleId, List registrations) + throws PersistenceException { + List returnValues = new LinkedList<>(); + try { + connection.setAutoCommit(false); + for (Registration registration : registrations) { + try (PreparedStatement addRegistration = + connection.prepareStatement( + ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS)) { + addRegistration.setLong(1, vehicleId); + addRegistration.setLong(2, registration.employee().id()); + addRegistration.setObject(3, registration.start()); + addRegistration.setObject(4, registration.end()); + addRegistration.setBoolean( + 5, true); // ASSUMPTION: Registration gets created as active + addRegistration.executeUpdate(); + try (ResultSet rs = addRegistration.getGeneratedKeys()) { + if (rs.next()) { + returnValues.add(rs.getLong(1)); + } else { + LOG.error("No ResultSet was created while adding registration"); + throw new PersistenceException( + "Anmeldung konnte nicht gespeichert werden."); + } + } + } + } + connection.commit(); + return returnValues; + } catch (SQLException e) { + LOG.error( + "An SQLException occurred while trying to save registrations to database. " + + "Attempting a rollback. Error message: {}", + e.getMessage()); + try { + connection.rollback(); + } catch (SQLException e1) { + LOG.error("Rollback failed :("); + } + throw new PersistenceException(e); + } finally { + try { + connection.setAutoCommit(true); + } catch (SQLException e) { + LOG.error( + "Setting back AutoCommit to false failed! Error message: {}", + e.getMessage()); + // SonarLint insists on me not throwing anything here... + } + } + } + + @Override + public void remove(long id) throws ElementNotFoundException, PersistenceException { + throw new UnsupportedOperationException(); + } +} -- cgit v1.2.3-70-g09d2 From 5d8f7e3f27c9ffb1c252a41a339c9d39438b9c45 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Fri, 4 May 2018 23:30:10 +0200 Subject: Add missing update to vehicle table --- .../groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java index 825dc80..c1ea533 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java @@ -23,6 +23,8 @@ public class H2RegistrationDAO implements RegistrationDAO { private static final String ADD_REGISTRATION = "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; + private static final String UPDATE_VEHICLE = + "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; private Connection connection; @@ -64,6 +66,12 @@ public class H2RegistrationDAO implements RegistrationDAO { } } } + + try (PreparedStatement updateVehicle = connection.prepareStatement(UPDATE_VEHICLE)) { + updateVehicle.setLong(1, vehicleId); + updateVehicle.executeUpdate(); + } + connection.commit(); return returnValues; } catch (SQLException e) { -- cgit v1.2.3-70-g09d2 From e7acdd7afb6612ef35265ba706ae968d326495a7 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sat, 5 May 2018 22:17:05 +0200 Subject: First mockup of RegistrationWindow and its controller --- .../controller/RegistrationWindowController.java | 203 +++++++++++++++++++++ src/main/resources/fxml/RegistrationWindow.fxml | 76 ++++++++ 2 files changed, 279 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java create mode 100644 src/main/resources/fxml/RegistrationWindow.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java new file mode 100644 index 0000000..8fea9dc --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -0,0 +1,203 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.controller; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +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.einsatzverwaltung.service.EmployeeService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.RegistrationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +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.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.util.EnumSet; +import java.util.LinkedList; +import java.util.List; +import javafx.beans.property.SimpleStringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.Label; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.input.MouseEvent; +import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +@Controller +public class RegistrationWindowController { + + private static final Logger LOG = LoggerFactory.getLogger(RegistrationWindowController.class); + + private EmployeeService employeeService; + + private VehicleService vehicleService; + + private RegistrationService registrationService; + + @Autowired + public void setEmployeeService(EmployeeService employeeService) { + this.employeeService = employeeService; + } + + @Autowired + public void setVehicleService(VehicleService vehicleService) { + this.vehicleService = vehicleService; + } + + @Autowired + public void setRegistrationService(RegistrationService registrationService) { + this.registrationService = registrationService; + } + + @FXML public ChoiceBox cbStart; + @FXML public ChoiceBox cbEnd; + @FXML public Label lVehicles; + @FXML public Label lEmployees; + @FXML public TextField tfVehicleSearch; + @FXML public TextField tfEmployeeSearch; + @FXML public TableView tvVehicles; + @FXML public TableView tvEmployees; + @FXML public TableColumn tcVehicles; + @FXML public TableColumn tcEmployees; + + private Vehicle chosenVehicle; + private List chosenEmployees = new LinkedList<>(); + + @FXML + public void initialize() { + // will have to be replaced for FlowPane + try { + List vehicles = vehicleService.list(EnumSet.of(Status.ABGEMELDET)); + tcVehicles.setCellValueFactory(x -> new SimpleStringProperty(x.getValue().name())); + tvVehicles.setItems(FXCollections.observableArrayList(vehicles)); + } catch (ServiceException e) { + LOG.warn( + "Caught ServiceException while getting vehicles. Showing it to user. Error message: {}", + e.getMessage()); + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("Fahrzeuge - Fehler!"); + alert.setHeaderText("Beim Auflisten der Fahrzeug ist ein Fehler aufgetreten."); + alert.setContentText(e.getMessage()); + alert.show(); + } + try { + List employees = employeeService.list(); + tcEmployees.setCellValueFactory(x -> new SimpleStringProperty(x.getValue().name())); + tvEmployees.setItems(FXCollections.observableArrayList(employees)); + } catch (ServiceException e) { + LOG.warn( + "Caught ServiceException while getting employees. Showing it to user. Error message: {}", + e.getMessage()); + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("Personal - Fehler!"); + alert.setHeaderText("Beim Auflisten des Personals ist ein Fehler aufgetreten."); + alert.setContentText(e.getMessage()); + alert.show(); + } + tvVehicles.setOnMousePressed( + new EventHandler() { + @Override + public void handle(MouseEvent mouseEvent) { + if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { + chosenVehicle = tvVehicles.getSelectionModel().getSelectedItem(); + lVehicles.setText(chosenVehicle.name()); + } + } + }); + tvEmployees.setOnMousePressed( + new EventHandler() { + @Override + public void handle(MouseEvent mouseEvent) { + if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { + chosenEmployees.add(tvEmployees.getSelectionModel().getSelectedItem()); + StringBuilder text = new StringBuilder(); + for (Employee employee : chosenEmployees) { + text.append(employee.name()).append("\n"); + } + lEmployees.setText(text.toString()); + } + } + }); + ObservableList hours = + FXCollections.observableArrayList( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23); + cbStart.setItems(hours); + cbEnd.setItems(hours); + } + + public void cancel() { + LOG.debug("Cancel Button clicked"); + ((Stage) lVehicles.getScene().getWindow()).close(); + } + + public void create() { + LOG.debug("Create Button clicked"); + + List registrations = new LinkedList<>(); + + for (Employee employee : chosenEmployees) { + registrations.add( + Registration.builder() + .id(chosenVehicle.id()) + .employee(employee) + .start( + LocalDateTime.of( + LocalDate.now(), + LocalTime.of(cbStart.getValue(), 0)) + .toInstant(ZoneOffset.ofHours(0))) + .end( + LocalDateTime.of( + LocalDate.now(), + LocalTime.of(cbEnd.getValue(), 0)) + .toInstant(ZoneOffset.ofHours(0))) + .build()); + } + try { + registrationService.add(chosenVehicle, registrations); + } catch (InvalidVehicleException e) { + // NOT THROWN ANYWHERE RIGHT NOW + LOG.info( + "Caught InvalidVehicleException. Showing it to user. Error message: {}", + e.getClass().toString(), + e.getMessage()); + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("Ungültiges Fahrzeug"); + alert.setHeaderText("Das spezifizierte Fahrzeug ist nicht gültig."); + alert.setContentText(e.getMessage()); + alert.show(); + } catch (ServiceException e) { + LOG.warn( + "Caught ServiceException while getting vehicles. Showing it to user. Error message: {}", + e.getMessage()); + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("Anmeldung - Fehler!"); + alert.setHeaderText("Beim Erstellen der Anmeldung ist ein Fehler aufgetreten."); + alert.setContentText(e.getMessage()); + alert.show(); + } catch (InvalidRegistrationException e) { + LOG.info( + "Caught InvalidRegistrationException. Showing it to user. Error message: {}", + e.getMessage()); + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("Ungültige Eingabe"); + alert.setHeaderText( + "Die gewählte Kombination von Fahrzeug und Personal ist nicht gültig!"); + alert.setContentText(e.getMessage()); + alert.show(); + } + } +} diff --git a/src/main/resources/fxml/RegistrationWindow.fxml b/src/main/resources/fxml/RegistrationWindow.fxml new file mode 100644 index 0000000..0394ca7 --- /dev/null +++ b/src/main/resources/fxml/RegistrationWindow.fxml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2 From 4fc385a3e1be604cce723ace3949ba9f2a9f021b Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 14:45:30 +0200 Subject: Corrected wrong ZoneOffset --- .../einsatzverwaltung/controller/RegistrationWindowController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index 8fea9dc..3f6d806 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -13,7 +13,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.ZoneOffset; +import java.time.OffsetDateTime; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; @@ -158,12 +158,12 @@ public class RegistrationWindowController { LocalDateTime.of( LocalDate.now(), LocalTime.of(cbStart.getValue(), 0)) - .toInstant(ZoneOffset.ofHours(0))) + .toInstant(OffsetDateTime.now().getOffset())) .end( LocalDateTime.of( LocalDate.now(), LocalTime.of(cbEnd.getValue(), 0)) - .toInstant(ZoneOffset.ofHours(0))) + .toInstant(OffsetDateTime.now().getOffset())) .build()); } try { -- cgit v1.2.3-70-g09d2 From 648ad8fa28f9a150e33f26600811d651d0fc81dd Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 14:46:38 +0200 Subject: Replaced EventHandler with lambda --- .../controller/RegistrationWindowController.java | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index 3f6d806..a8d91ad 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -20,7 +20,6 @@ import java.util.List; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; @@ -29,7 +28,6 @@ import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; -import javafx.scene.input.MouseEvent; import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -108,27 +106,21 @@ public class RegistrationWindowController { alert.show(); } tvVehicles.setOnMousePressed( - new EventHandler() { - @Override - public void handle(MouseEvent mouseEvent) { - if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { - chosenVehicle = tvVehicles.getSelectionModel().getSelectedItem(); - lVehicles.setText(chosenVehicle.name()); - } + mouseEvent -> { + if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { + chosenVehicle = tvVehicles.getSelectionModel().getSelectedItem(); + lVehicles.setText(chosenVehicle.name()); } }); tvEmployees.setOnMousePressed( - new EventHandler() { - @Override - public void handle(MouseEvent mouseEvent) { - if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { - chosenEmployees.add(tvEmployees.getSelectionModel().getSelectedItem()); - StringBuilder text = new StringBuilder(); - for (Employee employee : chosenEmployees) { - text.append(employee.name()).append("\n"); - } - lEmployees.setText(text.toString()); + mouseEvent -> { + if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { + chosenEmployees.add(tvEmployees.getSelectionModel().getSelectedItem()); + StringBuilder text = new StringBuilder(); + for (Employee employee : chosenEmployees) { + text.append(employee.name()).append("\n"); } + lEmployees.setText(text.toString()); } }); ObservableList hours = -- cgit v1.2.3-70-g09d2 From f4b5613fd3c6ce8e45fb7b99d10b33bec12ad43c Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 14:50:50 +0200 Subject: Copied changes from branch employee_list to allow for DAO Tests --- .../assignment/groupphase/util/JDBCConnectionManager.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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 index 5494471..6eb15ec 100644 --- 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 @@ -12,12 +12,17 @@ import org.springframework.stereotype.Component; public class JDBCConnectionManager { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static final String CONNECTION_URL = + private static final String DEFAULT_CONNECTION_URL = "jdbc:h2:~/sepm;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; - + private String connectionUrl; private Connection connection; public JDBCConnectionManager() { + this(DEFAULT_CONNECTION_URL); + } + + public JDBCConnectionManager(String connectionUrl) { + this.connectionUrl = connectionUrl; try { Class.forName("org.h2.Driver"); } catch (ClassNotFoundException e) { @@ -27,7 +32,7 @@ public class JDBCConnectionManager { } public Connection getConnection() throws SQLException { - if (connection == null) connection = DriverManager.getConnection(CONNECTION_URL); + if (connection == null) connection = DriverManager.getConnection(connectionUrl); return connection; } -- cgit v1.2.3-70-g09d2 From 5a6c00ebc1583e0505fb795b3483f8937e7b8eb4 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 16:01:10 +0200 Subject: Added groundwork for DAO tests --- pom.xml | 4 +- .../sql/H2RegistrationDAOTest_depopulate.sql | 5 ++ .../sql/H2RegistrationDAOTest_populate.sql | 10 ++++ .../dao/H2RegistrationDAOTest.java | 65 ++++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql create mode 100644 src/main/resources/sql/H2RegistrationDAOTest_populate.sql create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java (limited to 'src') diff --git a/pom.xml b/pom.xml index 42f24e7..95747aa 100644 --- a/pom.xml +++ b/pom.xml @@ -66,13 +66,13 @@ ${auto-value.version} provided - com.h2database h2 ${h2.version} - runtime + compile + ch.qos.logback logback-classic diff --git a/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql b/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql new file mode 100644 index 0000000..f43b641 --- /dev/null +++ b/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql @@ -0,0 +1,5 @@ +DELETE FROM Registration; +DELETE FROM Vehicle; +DELETE FROM VehicleVersion; +DELETE FROM Employee; +DELETE FROM EmployeeVersion; \ No newline at end of file diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql new file mode 100644 index 0000000..8322479 --- /dev/null +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -0,0 +1,10 @@ +INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (1, 'John Doe', '2000-01-01', 'RS', TRUE, TRUE); +INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (2, 'Nick "Kage" Verily', '1990-01-01', 'NKV', TRUE, FALSE); +INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (3, 'Nicht Arzt', '1980-01-01', 'NA', FALSE, FALSE); +INSERT INTO Employee (id, version) VALUES (1, 1); +INSERT INTO Employee (id, version) VALUES (2, 2); +INSERT INTO Employee (id, version) VALUES (3, 3); +INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (1, 'RTW-1', 'Hochdach', 'RTW'); +INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (2, 'NEF-1', 'Normal', 'NEF'); +INSERT INTO Vehicle (id, version, status) VALUES (1, 1, 'abgemeldet'); +INSERT INTO Vehicle (id, version, status) VALUES (2, 2, 'abgemeldet'); \ No newline at end of file diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java new file mode 100644 index 0000000..03b70b1 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java @@ -0,0 +1,65 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import static org.junit.Assert.*; + +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import org.h2.tools.RunScript; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class H2RegistrationDAOTest { + + // Base taken from EmployeePersistenceTest + + private static final String JDBC_DRIVER = org.h2.Driver.class.getName(); + private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; + private static final String USER = ""; + private static final String PASSWORD = ""; + + private RegistrationDAO registrationDAO; + + public H2RegistrationDAOTest() throws PersistenceException { + this.registrationDAO = new H2RegistrationDAO(new JDBCConnectionManager(JDBC_URL)); + } + + @BeforeClass + public static void setupDatabase() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false); + } + + @Before + public void setUp() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/H2RegistrationDAOTest_populate.sql", + Charset.forName("UTF8"), + false); + } + + @After + public void tearDown() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/H2RegistrationDAOTest_depopulate.sql", + Charset.forName("UTF8"), + false); + } + + @Test + public void add() {} +} -- cgit v1.2.3-70-g09d2 From abbf3afda52ef48d1efd7912453d9d71e55fb2d9 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 16:17:34 +0200 Subject: Implemented correct insert test --- .../dao/H2RegistrationDAOTest.java | 72 +++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java index 03b70b1..e89e99a 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java @@ -2,10 +2,17 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; import static org.junit.Assert.*; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.nio.charset.Charset; import java.sql.SQLException; +import java.time.Instant; +import java.time.LocalDate; +import java.util.LinkedList; +import java.util.List; import org.h2.tools.RunScript; import org.junit.After; import org.junit.Before; @@ -61,5 +68,68 @@ public class H2RegistrationDAOTest { } @Test - public void add() {} + public void addRegistrationShouldSucceed() throws PersistenceException { + List registrations = new LinkedList<>(); + /* + Vehicle vehicle = Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + */ + Employee employee1 = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Employee employee2 = + Employee.builder() + .id(2) + .name("Nick \"Kage\" Verily") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NKV) + .isDriver(true) + .isPilot(false) + .build(); + Employee employee3 = + Employee.builder() + .id(3) + .name("Nicht Arzt") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NA) + .isDriver(false) + .isPilot(false) + .build(); + Registration registration1 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee1) + .build(); + Registration registration2 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee2) + .build(); + Registration registration3 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee3) + .build(); + registrations.add(registration1); + registrations.add(registration2); + registrations.add(registration3); + + List returnvalues = registrationDAO.add(1, registrations); + assertFalse(returnvalues.isEmpty()); // can be improved... + } } -- cgit v1.2.3-70-g09d2 From 8c73a66236c9a3c416fdb7d337725ec9d4ab6583 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 17:04:51 +0200 Subject: Implemented incorrect insert test (specified vehicle does not exist in test database) --- .../dao/H2RegistrationDAOTest.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java index e89e99a..1180bfa 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java @@ -17,7 +17,9 @@ import org.h2.tools.RunScript; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class H2RegistrationDAOTest { @@ -67,8 +69,10 @@ public class H2RegistrationDAOTest { false); } + @Rule public ExpectedException thrown = ExpectedException.none(); + @Test - public void addRegistrationShouldSucceed() throws PersistenceException { + public void addRegistrationsShouldSucceed() throws PersistenceException { List registrations = new LinkedList<>(); /* Vehicle vehicle = Vehicle.builder() @@ -132,4 +136,27 @@ public class H2RegistrationDAOTest { List returnvalues = registrationDAO.add(1, registrations); assertFalse(returnvalues.isEmpty()); // can be improved... } + + @Test + public void addRegistrationToInexistentVehicleShouldFail() throws PersistenceException { + thrown.expect(PersistenceException.class); + List registrations = new LinkedList<>(); + Employee employee = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Registration registration = + Registration.builder() + .start(Instant.MIN) + .end(Instant.MAX) + .employee(employee) + .build(); + registrations.add(registration); + registrationDAO.add(200, registrations); + } } -- cgit v1.2.3-70-g09d2 From a2cb1b69f512f18400cb6a048c08074907053648 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 10:27:34 +0200 Subject: Changed behaviour to only prepare statement at construction time --- .../einsatzverwaltung/dao/H2RegistrationDAO.java | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java index c1ea533..fb9bad5 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java @@ -26,14 +26,20 @@ public class H2RegistrationDAO implements RegistrationDAO { private static final String UPDATE_VEHICLE = "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; + private PreparedStatement addRegistration; + private PreparedStatement updateVehicle; + private Connection connection; @Autowired public H2RegistrationDAO(JDBCConnectionManager connectionManager) throws PersistenceException { try { connection = connectionManager.getConnection(); + addRegistration = + connection.prepareStatement(ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS); + updateVehicle = connection.prepareStatement(UPDATE_VEHICLE); } catch (SQLException e) { - LOG.error("Could not get connection!"); + LOG.error("Could not get connection or preparation of statement failed"); throw new PersistenceException(e); } } @@ -45,32 +51,26 @@ public class H2RegistrationDAO implements RegistrationDAO { try { connection.setAutoCommit(false); for (Registration registration : registrations) { - try (PreparedStatement addRegistration = - connection.prepareStatement( - ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS)) { - addRegistration.setLong(1, vehicleId); - addRegistration.setLong(2, registration.employee().id()); - addRegistration.setObject(3, registration.start()); - addRegistration.setObject(4, registration.end()); - addRegistration.setBoolean( - 5, true); // ASSUMPTION: Registration gets created as active - addRegistration.executeUpdate(); - try (ResultSet rs = addRegistration.getGeneratedKeys()) { - if (rs.next()) { - returnValues.add(rs.getLong(1)); - } else { - LOG.error("No ResultSet was created while adding registration"); - throw new PersistenceException( - "Anmeldung konnte nicht gespeichert werden."); - } + addRegistration.setLong(1, vehicleId); + addRegistration.setLong(2, registration.employee().id()); + addRegistration.setObject(3, registration.start()); + addRegistration.setObject(4, registration.end()); + addRegistration.setBoolean( + 5, true); // ASSUMPTION: Registration gets created as active + addRegistration.executeUpdate(); + try (ResultSet rs = addRegistration.getGeneratedKeys()) { + if (rs.next()) { + returnValues.add(rs.getLong(1)); + } else { + LOG.error("No ResultSet was created while adding registration"); + throw new PersistenceException( + "Anmeldung konnte nicht gespeichert werden."); } } } - try (PreparedStatement updateVehicle = connection.prepareStatement(UPDATE_VEHICLE)) { - updateVehicle.setLong(1, vehicleId); - updateVehicle.executeUpdate(); - } + updateVehicle.setLong(1, vehicleId); + updateVehicle.executeUpdate(); connection.commit(); return returnValues; -- cgit v1.2.3-70-g09d2 From daac86e932eeac65078aa0e642e611937004d8d7 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 10:33:35 +0200 Subject: Setting Timestamp instead of Instant Object in SQL Statement --- .../assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java index fb9bad5..f76c706 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java @@ -9,6 +9,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Timestamp; import java.util.LinkedList; import java.util.List; import org.slf4j.Logger; @@ -53,7 +54,7 @@ public class H2RegistrationDAO implements RegistrationDAO { for (Registration registration : registrations) { addRegistration.setLong(1, vehicleId); addRegistration.setLong(2, registration.employee().id()); - addRegistration.setObject(3, registration.start()); + addRegistration.setTimestamp(3, Timestamp.from(registration.start())); addRegistration.setObject(4, registration.end()); addRegistration.setBoolean( 5, true); // ASSUMPTION: Registration gets created as active -- cgit v1.2.3-70-g09d2 From 87c61255822b116552990af221beeff581832778 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 10:59:41 +0200 Subject: Fixed almost all vehicles being wrongly recognized as NEF --- .../groupphase/einsatzverwaltung/dto/RegistrationValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java index ac6c1f2..295b615 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java @@ -105,7 +105,7 @@ public class RegistrationValidator { LOG.info("No valid combination of employees found for NAH"); throw new InvalidRegistrationException( "Keine gültige Kombination von Personen für NAH!"); - } else if (vehicle.type() != VehicleType.NEF) { + } else if (vehicle.type() == VehicleType.NEF) { /* NEF 1 Driver (has to be NFS) -- cgit v1.2.3-70-g09d2 From fcf19c50c2b75b63467a23f8fa16cba2c3a21a14 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 11:01:25 +0200 Subject: Close window after successful adding of reservation --- .../einsatzverwaltung/controller/RegistrationWindowController.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index a8d91ad..152d3f0 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -160,6 +160,7 @@ public class RegistrationWindowController { } try { registrationService.add(chosenVehicle, registrations); + ((Stage) lVehicles.getScene().getWindow()).close(); } catch (InvalidVehicleException e) { // NOT THROWN ANYWHERE RIGHT NOW LOG.info( -- cgit v1.2.3-70-g09d2 From 88ac3a3f65cc854c3f7d0f6ccb27d13de5e9f554 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 11:26:05 +0200 Subject: Add Application for manual tests --- .../controller/RegistrationWindowApplication.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowApplication.java (limited to 'src') diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowApplication.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowApplication.java new file mode 100644 index 0000000..3293ae9 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowApplication.java @@ -0,0 +1,53 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.controller; + +import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; +import java.lang.invoke.MethodHandles; +import javafx.application.Application; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; + +@Component +@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase") +public class RegistrationWindowApplication extends Application { + + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + public static AnnotationConfigApplicationContext context; + + @Override + public void start(Stage primaryStage) throws Exception { + // setup application + primaryStage.setTitle("Person anlegen"); + // primaryStage.setWidth(1366); + // primaryStage.setHeight(768); + primaryStage.centerOnScreen(); + primaryStage.setOnCloseRequest(event -> LOG.debug("Application shutdown initiated")); + + context = new AnnotationConfigApplicationContext(RegistrationWindowApplication.class); + final var fxmlLoader = context.getBean(SpringFXMLLoader.class); + primaryStage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/RegistrationWindow.fxml")))); + + // show application + primaryStage.show(); + primaryStage.toFront(); + LOG.debug("Application startup complete"); + } + + @Override + public void stop() { + LOG.debug("Stopping application"); + context.close(); + } +} -- cgit v1.2.3-70-g09d2 From a1f5ee2623bb2e90b6df80a473eb674f4c200d10 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 13:14:24 +0200 Subject: Added positive and negative tests for RegistrationService --- .../service/SimpleRegistrationServiceTest.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java (limited to 'src') diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java new file mode 100644 index 0000000..b1ef38f --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java @@ -0,0 +1,124 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import static org.junit.Assert.*; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +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.time.Instant; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.LinkedList; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +public class SimpleRegistrationServiceTest { + + @Mock RegistrationDAO daoMock; + + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Rule public ExpectedException thrown = ExpectedException.none(); + + @Test + public void addValidRegistrationsShouldSucceed() + throws InvalidRegistrationException, ServiceException, InvalidVehicleException { + RegistrationService registrationService = new SimpleRegistrationService(daoMock); + List registrations = new LinkedList<>(); + Vehicle vehicle = + Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + Employee employee1 = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Employee employee2 = + Employee.builder() + .id(2) + .name("Nick \"Kage\" Verily") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NKV) + .isDriver(true) + .isPilot(false) + .build(); + Employee employee3 = + Employee.builder() + .id(3) + .name("Nicht Arzt") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NA) + .isDriver(false) + .isPilot(false) + .build(); + Instant start = Instant.now(); + Instant end = start.plus(8, ChronoUnit.HOURS); + Registration registration1 = + Registration.builder().start(start).end(end).employee(employee1).build(); + Registration registration2 = + Registration.builder().start(start).end(end).employee(employee2).build(); + Registration registration3 = + Registration.builder().start(start).end(end).employee(employee3).build(); + registrations.add(registration1); + registrations.add(registration2); + registrations.add(registration3); + registrationService.add(vehicle, registrations); + } + + @Test + public void addOnlyOnePersonToRTWShouldFail() + throws InvalidRegistrationException, ServiceException, InvalidVehicleException { + thrown.expect(InvalidRegistrationException.class); + RegistrationService registrationService = new SimpleRegistrationService(daoMock); + List registrations = new LinkedList<>(); + Vehicle vehicle = + Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + Employee employee = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Registration registration = + Registration.builder() + .start(Instant.MIN) + .end(Instant.MAX) + .employee(employee) + .build(); + registrations.add(registration); + registrationService.add(vehicle, registrations); + } +} -- cgit v1.2.3-70-g09d2 From 12302ff88604440cac2257741b4502b9b173d708 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 14:53:00 +0200 Subject: Changed test data to be in sync with new database schema --- src/main/resources/sql/H2RegistrationDAOTest_populate.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index 8322479..b81eb78 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -4,7 +4,7 @@ INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPil INSERT INTO Employee (id, version) VALUES (1, 1); INSERT INTO Employee (id, version) VALUES (2, 2); INSERT INTO Employee (id, version) VALUES (3, 3); -INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (1, 'RTW-1', 'Hochdach', 'RTW'); -INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (2, 'NEF-1', 'Normal', 'NEF'); +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'Hochdach', 'RTW'); +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, 'Normal', 'NEF'); INSERT INTO Vehicle (id, version, status) VALUES (1, 1, 'abgemeldet'); INSERT INTO Vehicle (id, version, status) VALUES (2, 2, 'abgemeldet'); \ No newline at end of file -- cgit v1.2.3-70-g09d2 From cc362865daee16d234f772d237c020973689e5eb Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 11:26:47 +0200 Subject: Implement EmployeeDatabaseDao.list --- .../einsatzverwaltung/dao/EmployeeDatabaseDao.java | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java index 900fd0e..bd59dd1 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java @@ -1,6 +1,7 @@ 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.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; @@ -10,6 +11,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +25,12 @@ public class EmployeeDatabaseDao implements EmployeeDAO { "INSERT INTO EmployeeVersion(name, birthday, educationLevel, isDriver, isPilot) " + "VALUES(?, ?, ?, ?, ?)"; private static final String INSERT_EMPLOYEE = "INSERT INTO Employee(version) VALUES(?)"; + private static final String LIST_EMPLOYEE = + "SELECT emp.id, v.name, v.birthday, v.educationLevel, v.isDriver, v.isPilot " + + "FROM employee emp " + + "JOIN EmployeeVersion v ON v.id = emp.version"; - private final PreparedStatement insertEmployeeVersion, insertEmployee; + private final PreparedStatement insertEmployeeVersion, insertEmployee, listEmployee; public EmployeeDatabaseDao(JDBCConnectionManager connectionManager) throws PersistenceException { @@ -38,6 +44,8 @@ public class EmployeeDatabaseDao implements EmployeeDAO { insertEmployee = connection.prepareStatement(INSERT_EMPLOYEE, Statement.RETURN_GENERATED_KEYS); + listEmployee = connection.prepareStatement(LIST_EMPLOYEE); + } catch (SQLException e) { throw new PersistenceException(e); } @@ -82,7 +90,31 @@ public class EmployeeDatabaseDao implements EmployeeDAO { @Override public List list() throws PersistenceException { - throw new UnsupportedOperationException(); + + try { + ResultSet rs = listEmployee.executeQuery(); + + List employees = new ArrayList<>(); + while(rs.next()) { + + Employee employee = + Employee.builder() + .id(rs.getLong(1)) + .name(rs.getString(2)) + .birthday(rs.getTimestamp(3).toLocalDateTime().toLocalDate()) + .educationLevel(EducationLevel.valueOf(rs.getString(4))) + .isDriver(rs.getBoolean(5)) + .isPilot(rs.getBoolean(6)) + .build(); + + employees.add(employee); + } + + return employees; + + } catch (SQLException e) { + throw new PersistenceException(e); + } } @Override -- cgit v1.2.3-70-g09d2 From 3d28d350883dce1efebf84f88674b65363b75b80 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 11:27:03 +0200 Subject: Implement EmployeeServiceImpl.list --- .../groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java index 144ccc6..112ddf3 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java @@ -36,7 +36,12 @@ public class EmployeeServiceImpl implements EmployeeService { @Override public List list() throws ServiceException { - return null; + + try { + return employeePersistence.list(); + } catch (PersistenceException e) { + throw new ServiceException(e); + } } @Override -- cgit v1.2.3-70-g09d2 From 81e0e800cc3d07e636d035939cf71b454e981a81 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 15:40:48 +0200 Subject: Change JDBCConnectionManager to allow different connection-url --- .../assignment/groupphase/util/JDBCConnectionManager.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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 index 5494471..6eb15ec 100644 --- 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 @@ -12,12 +12,17 @@ import org.springframework.stereotype.Component; public class JDBCConnectionManager { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static final String CONNECTION_URL = + private static final String DEFAULT_CONNECTION_URL = "jdbc:h2:~/sepm;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; - + private String connectionUrl; private Connection connection; public JDBCConnectionManager() { + this(DEFAULT_CONNECTION_URL); + } + + public JDBCConnectionManager(String connectionUrl) { + this.connectionUrl = connectionUrl; try { Class.forName("org.h2.Driver"); } catch (ClassNotFoundException e) { @@ -27,7 +32,7 @@ public class JDBCConnectionManager { } public Connection getConnection() throws SQLException { - if (connection == null) connection = DriverManager.getConnection(CONNECTION_URL); + if (connection == null) connection = DriverManager.getConnection(connectionUrl); return connection; } -- cgit v1.2.3-70-g09d2 From b029241d53fa17deab6159344d4f2296553ddcb3 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 15:41:26 +0200 Subject: Format EmployeeDatabaseDao and EmployeeServiceImpl --- .../einsatzverwaltung/dao/EmployeeDatabaseDao.java | 22 +++++++++++----------- .../service/EmployeeServiceImpl.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java index bd59dd1..3e4ba12 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java @@ -26,9 +26,9 @@ public class EmployeeDatabaseDao implements EmployeeDAO { + "VALUES(?, ?, ?, ?, ?)"; private static final String INSERT_EMPLOYEE = "INSERT INTO Employee(version) VALUES(?)"; private static final String LIST_EMPLOYEE = - "SELECT emp.id, v.name, v.birthday, v.educationLevel, v.isDriver, v.isPilot " + - "FROM employee emp " + - "JOIN EmployeeVersion v ON v.id = emp.version"; + "SELECT emp.id, v.name, v.birthday, v.educationLevel, v.isDriver, v.isPilot " + + "FROM employee emp " + + "JOIN EmployeeVersion v ON v.id = emp.version"; private final PreparedStatement insertEmployeeVersion, insertEmployee, listEmployee; @@ -95,17 +95,17 @@ public class EmployeeDatabaseDao implements EmployeeDAO { ResultSet rs = listEmployee.executeQuery(); List employees = new ArrayList<>(); - while(rs.next()) { + while (rs.next()) { Employee employee = Employee.builder() - .id(rs.getLong(1)) - .name(rs.getString(2)) - .birthday(rs.getTimestamp(3).toLocalDateTime().toLocalDate()) - .educationLevel(EducationLevel.valueOf(rs.getString(4))) - .isDriver(rs.getBoolean(5)) - .isPilot(rs.getBoolean(6)) - .build(); + .id(rs.getLong(1)) + .name(rs.getString(2)) + .birthday(rs.getTimestamp(3).toLocalDateTime().toLocalDate()) + .educationLevel(EducationLevel.valueOf(rs.getString(4))) + .isDriver(rs.getBoolean(5)) + .isPilot(rs.getBoolean(6)) + .build(); employees.add(employee); } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java index 112ddf3..ed0fb1c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceImpl.java @@ -38,7 +38,7 @@ public class EmployeeServiceImpl implements EmployeeService { public List list() throws ServiceException { try { - return employeePersistence.list(); + return employeePersistence.list(); } catch (PersistenceException e) { throw new ServiceException(e); } -- cgit v1.2.3-70-g09d2 From ad44dc581b063485eede5c2b19b1b5ab0753ce72 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 15:45:15 +0200 Subject: Change enum types to varchar with check constraint to support DBUnit --- src/main/resources/sql/database.sql | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/resources/sql/database.sql b/src/main/resources/sql/database.sql index bb23c91..e775550 100644 --- a/src/main/resources/sql/database.sql +++ b/src/main/resources/sql/database.sql @@ -1,26 +1,30 @@ CREATE TABLE IF NOT EXISTS VehicleVersion ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, - constructionType ENUM('Normal', 'Hochdach', 'Mittelhochdach') NOT NULL, - type ENUM('BKTW', 'KTW-B', 'KTW', 'RTW', 'NEF', 'NAH') NOT NULL, + constructionType VARCHAR NOT NULL, + type VARCHAR NOT NULL, hasNef BOOLEAN NOT NULL, + CHECK constructionType IN ('Normal', 'Hochdach', 'Mittelhochdach'), + CHECK type IN ('BKTW', 'KTW-B', 'KTW', 'RTW', 'NEF', 'NAH') ); CREATE TABLE IF NOT EXISTS Vehicle ( id BIGINT AUTO_INCREMENT PRIMARY KEY, version BIGINT NOT NULL, - status ENUM('abgemeldet', 'frei_wache', 'zum_berufungsort', 'am_berufungsort', 'zum_zielort', - 'am_zielort', 'frei_funk', 'deleted') NOT NULL, + status VARCHAR NOT NULL, FOREIGN KEY (version) REFERENCES VehicleVersion(id), + CHECK status IN ('abgemeldet', 'frei_wache', 'zum_berufungsort', 'am_berufungsort', 'zum_zielort', + 'am_zielort', 'frei_funk', 'deleted') ); CREATE TABLE IF NOT EXISTS EmployeeVersion ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, birthday DATE NOT NULL, - educationLevel ENUM('RS', 'NFS', 'NKV', 'NKA', 'NKI', 'NA') NOT NULL, + educationLevel VARCHAR NOT NULL, isDriver BOOLEAN NOT NULL, isPilot BOOLEAN NOT NULL, + CHECK educationLevel IN ('RS', 'NFS', 'NKV', 'NKA', 'NKI', 'NA') ); CREATE TABLE IF NOT EXISTS Employee ( @@ -43,10 +47,11 @@ CREATE TABLE IF NOT EXISTS Registration ( CREATE TABLE IF NOT EXISTS Operation ( id BIGINT AUTO_INCREMENT PRIMARY KEY, opCode VARCHAR(20) NOT NULL, - severity ENUM('A', 'B', 'C', 'D', 'E', 'O') NOT NULL, + severity VARCHAR NOT NULL, created TIMESTAMP NOT NULL, destination VARCHAR(100) NOT NULL, additionalInfo VARCHAR(100), + CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O') ); CREATE TABLE IF NOT EXISTS VehicleOperation ( -- cgit v1.2.3-70-g09d2 From f14c6eaa7173753cdca8cc44ae798e5700b99de3 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 15:46:09 +0200 Subject: Add test-data in xml format for EmployeePersistenceTest --- src/test/resources/employeeServiceTestData.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/resources/employeeServiceTestData.xml (limited to 'src') diff --git a/src/test/resources/employeeServiceTestData.xml b/src/test/resources/employeeServiceTestData.xml new file mode 100644 index 0000000..c21fde6 --- /dev/null +++ b/src/test/resources/employeeServiceTestData.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 783aad0bd343a0c5a008ed1433d9958ea8e5e7a2 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Sat, 5 May 2018 15:49:41 +0200 Subject: Implement EmployeePersistenceTest with DBUnit --- .../employee/EmployeePersistenceTest.java | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java (limited to 'src') diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java new file mode 100644 index 0000000..f8fe0f3 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/employee/EmployeePersistenceTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.employee; + +import static junit.framework.TestCase.fail; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDatabaseDao; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import org.dbunit.IDatabaseTester; +import org.dbunit.JdbcDatabaseTester; +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; +import org.dbunit.operation.DatabaseOperation; +import org.h2.tools.RunScript; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class EmployeePersistenceTest { + + private static final String JDBC_DRIVER = org.h2.Driver.class.getName(); + private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; + private static final String USER = ""; + private static final String PASSWORD = ""; + + private EmployeeDAO employeePersistence; + + public EmployeePersistenceTest() throws PersistenceException { + employeePersistence = new EmployeeDatabaseDao(new JDBCConnectionManager(JDBC_URL)); + } + + @BeforeClass + public static void createSchema() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false); + } + + @Before + public void importDataSet() throws Exception { + IDataSet dataSet = readDataSet(); + cleanlyInsert(dataSet); + } + + private IDataSet readDataSet() throws DataSetException { + return new FlatXmlDataSetBuilder() + .build( + getClass() + .getClassLoader() + .getResourceAsStream("employeeServiceTestData.xml")); + } + + private void cleanlyInsert(IDataSet dataSet) throws Exception { + IDatabaseTester databaseTester = + new JdbcDatabaseTester(JDBC_DRIVER, JDBC_URL, USER, PASSWORD); + + databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT); + databaseTester.setDataSet(dataSet); + databaseTester.onSetup(); + } + + @Test + public void testListEmployees() { + + try { + List employees = employeePersistence.list(); + + Employee empOne = + Employee.builder() + .id(1) + .name("Adam") + .birthday( + LocalDate.parse( + "10.10.2010", + DateTimeFormatter.ofPattern("dd.MM.yyyy"))) + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(false) + .build(); + + Employee empTwo = + Employee.builder() + .id(2) + .name("Max") + .birthday( + LocalDate.parse( + "11.11.1990", + DateTimeFormatter.ofPattern("dd.MM.yyyy"))) + .educationLevel(EducationLevel.NFS) + .isDriver(false) + .isPilot(false) + .build(); + + Employee empThree = + Employee.builder() + .id(3) + .name("Lisa") + .birthday( + LocalDate.parse( + "16.10.1999", + DateTimeFormatter.ofPattern("dd.MM.yyyy"))) + .educationLevel(EducationLevel.NKI) + .isDriver(true) + .isPilot(false) + .build(); + + Assert.assertTrue(employees.contains(empOne)); + Assert.assertTrue(employees.contains(empTwo)); + Assert.assertTrue(employees.contains(empThree)); + Assert.assertEquals(3, employees.size()); + + } catch (PersistenceException e) { + fail(); + } + } + + @Test + public void testEmployeeListNoElement() { + + try { + List employees = employeePersistence.list(); + + Employee empOne = + Employee.builder() + .id(10) + .name("Adam") + .birthday( + LocalDate.parse( + "10.10.2010", + DateTimeFormatter.ofPattern("dd.MM.yyyy"))) + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(false) + .build(); + + Assert.assertFalse(employees.contains(empOne)); + + } catch (PersistenceException e) { + fail(); + } + } +} -- cgit v1.2.3-70-g09d2 From 8cf177afca4a0da8389ec2f198d10f1513c5d9ca Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Thu, 3 May 2018 23:47:31 +0200 Subject: Implement vehicleService.list --- .../service/VehicleServiceImpl.java | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java index 4a11298..bbe668b 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceImpl.java @@ -9,14 +9,16 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.EnumSet; import java.util.List; +import java.util.stream.Collectors; import org.springframework.stereotype.Service; @Service public class VehicleServiceImpl implements VehicleService { - private VehicleDAO vehicleDAO; - public VehicleServiceImpl(VehicleDAO vehicleDAO) { - this.vehicleDAO = vehicleDAO; + private VehicleDAO vehiclePersistence; + + public VehicleServiceImpl(VehicleDAO vehiclePersistence) { + this.vehiclePersistence = vehiclePersistence; } public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { @@ -59,7 +61,7 @@ public class VehicleServiceImpl implements VehicleService { throw new ServiceException("not a Valid type"); } try { - vehicleDAO.add(vehicle); + vehiclePersistence.add(vehicle); } catch (PersistenceException e) { throw new ServiceException(e); } @@ -70,10 +72,27 @@ public class VehicleServiceImpl implements VehicleService { throw new UnsupportedOperationException(); } + @Override public List list(EnumSet statuses) throws ServiceException { - throw new UnsupportedOperationException(); + + if (statuses == null) { + throw new ServiceException("statuses may not be null"); + } + + List vehicles; + + try { + vehicles = vehiclePersistence.list(); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + + return vehicles.stream() + .filter(vehicle -> statuses.contains(vehicle.status())) + .collect(Collectors.toList()); } + @Override public void remove(long id) throws InvalidVehicleException, ServiceException { throw new UnsupportedOperationException(); } -- cgit v1.2.3-70-g09d2 From 126b9a07facec2916156f74b5f632f161df19f11 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 15:55:23 +0200 Subject: Rename Registration Dao & service to conventional style --- .../einsatzverwaltung/dao/H2RegistrationDAO.java | 105 ------------- .../dao/RegistrationDatabaseDAO.java | 106 ++++++++++++++ .../service/RegistrationServiceImpl.java | 45 ++++++ .../service/SimpleRegistrationService.java | 45 ------ .../dao/H2RegistrationDAOTest.java | 162 --------------------- .../dao/RegistrationDatabaseDAOTest.java | 162 +++++++++++++++++++++ .../service/RegistrationServiceImplTest.java | 122 ++++++++++++++++ .../service/SimpleRegistrationServiceTest.java | 124 ---------------- 8 files changed, 435 insertions(+), 436 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java deleted file mode 100644 index f76c706..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAO.java +++ /dev/null @@ -1,105 +0,0 @@ -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 at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Timestamp; -import java.util.LinkedList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -@Repository -public class H2RegistrationDAO implements RegistrationDAO { - - private static final Logger LOG = LoggerFactory.getLogger(H2RegistrationDAO.class); - - private static final String ADD_REGISTRATION = - "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; - private static final String UPDATE_VEHICLE = - "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; - - private PreparedStatement addRegistration; - private PreparedStatement updateVehicle; - - private Connection connection; - - @Autowired - public H2RegistrationDAO(JDBCConnectionManager connectionManager) throws PersistenceException { - try { - connection = connectionManager.getConnection(); - addRegistration = - connection.prepareStatement(ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS); - updateVehicle = connection.prepareStatement(UPDATE_VEHICLE); - } catch (SQLException e) { - LOG.error("Could not get connection or preparation of statement failed"); - throw new PersistenceException(e); - } - } - - @Override - public List add(long vehicleId, List registrations) - throws PersistenceException { - List returnValues = new LinkedList<>(); - try { - connection.setAutoCommit(false); - for (Registration registration : registrations) { - addRegistration.setLong(1, vehicleId); - addRegistration.setLong(2, registration.employee().id()); - addRegistration.setTimestamp(3, Timestamp.from(registration.start())); - addRegistration.setObject(4, registration.end()); - addRegistration.setBoolean( - 5, true); // ASSUMPTION: Registration gets created as active - addRegistration.executeUpdate(); - try (ResultSet rs = addRegistration.getGeneratedKeys()) { - if (rs.next()) { - returnValues.add(rs.getLong(1)); - } else { - LOG.error("No ResultSet was created while adding registration"); - throw new PersistenceException( - "Anmeldung konnte nicht gespeichert werden."); - } - } - } - - updateVehicle.setLong(1, vehicleId); - updateVehicle.executeUpdate(); - - connection.commit(); - return returnValues; - } catch (SQLException e) { - LOG.error( - "An SQLException occurred while trying to save registrations to database. " - + "Attempting a rollback. Error message: {}", - e.getMessage()); - try { - connection.rollback(); - } catch (SQLException e1) { - LOG.error("Rollback failed :("); - } - throw new PersistenceException(e); - } finally { - try { - connection.setAutoCommit(true); - } catch (SQLException e) { - LOG.error( - "Setting back AutoCommit to false failed! Error message: {}", - e.getMessage()); - // SonarLint insists on me not throwing anything here... - } - } - } - - @Override - public void remove(long id) throws ElementNotFoundException, PersistenceException { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java new file mode 100644 index 0000000..e4bc0ab --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java @@ -0,0 +1,106 @@ +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 at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.LinkedList; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class RegistrationDatabaseDAO implements RegistrationDAO { + + private static final Logger LOG = LoggerFactory.getLogger(RegistrationDatabaseDAO.class); + + private static final String ADD_REGISTRATION = + "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; + private static final String UPDATE_VEHICLE = + "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; + + private PreparedStatement addRegistration; + private PreparedStatement updateVehicle; + + private Connection connection; + + @Autowired + public RegistrationDatabaseDAO(JDBCConnectionManager connectionManager) + throws PersistenceException { + try { + connection = connectionManager.getConnection(); + addRegistration = + connection.prepareStatement(ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS); + updateVehicle = connection.prepareStatement(UPDATE_VEHICLE); + } catch (SQLException e) { + LOG.error("Could not get connection or preparation of statement failed"); + throw new PersistenceException(e); + } + } + + @Override + public List add(long vehicleId, List registrations) + throws PersistenceException { + List returnValues = new LinkedList<>(); + try { + connection.setAutoCommit(false); + for (Registration registration : registrations) { + addRegistration.setLong(1, vehicleId); + addRegistration.setLong(2, registration.employee().id()); + addRegistration.setTimestamp(3, Timestamp.from(registration.start())); + addRegistration.setObject(4, registration.end()); + addRegistration.setBoolean( + 5, true); // ASSUMPTION: Registration gets created as active + addRegistration.executeUpdate(); + try (ResultSet rs = addRegistration.getGeneratedKeys()) { + if (rs.next()) { + returnValues.add(rs.getLong(1)); + } else { + LOG.error("No ResultSet was created while adding registration"); + throw new PersistenceException( + "Anmeldung konnte nicht gespeichert werden."); + } + } + } + + updateVehicle.setLong(1, vehicleId); + updateVehicle.executeUpdate(); + + connection.commit(); + return returnValues; + } catch (SQLException e) { + LOG.error( + "An SQLException occurred while trying to save registrations to database. " + + "Attempting a rollback. Error message: {}", + e.getMessage()); + try { + connection.rollback(); + } catch (SQLException e1) { + LOG.error("Rollback failed :("); + } + throw new PersistenceException(e); + } finally { + try { + connection.setAutoCommit(true); + } catch (SQLException e) { + LOG.error( + "Setting back AutoCommit to false failed! Error message: {}", + e.getMessage()); + // SonarLint insists on me not throwing anything here... + } + } + } + + @Override + public void remove(long id) throws ElementNotFoundException, PersistenceException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java new file mode 100644 index 0000000..b0605f0 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java @@ -0,0 +1,45 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.RegistrationValidator; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +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.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RegistrationServiceImpl implements RegistrationService { + + private static final Logger LOG = LoggerFactory.getLogger(RegistrationServiceImpl.class); + + private final RegistrationDAO registrationDAO; + + @Autowired + public RegistrationServiceImpl(RegistrationDAO registrationDAO) { + this.registrationDAO = registrationDAO; + } + + @Override + public List add(Vehicle vehicle, List registrations) + throws InvalidVehicleException, InvalidRegistrationException, ServiceException { + RegistrationValidator.validate(vehicle, registrations); + try { + return registrationDAO.add(vehicle.id(), registrations); + } catch (PersistenceException e) { + LOG.warn("PersistenceException caught, throwing matching ServiceException"); + throw new ServiceException(e); + } + } + + @Override + public void remove(long registrationId) throws InvalidRegistrationException, ServiceException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java deleted file mode 100644 index 5b26e39..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationService.java +++ /dev/null @@ -1,45 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.RegistrationValidator; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -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.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class SimpleRegistrationService implements RegistrationService { - - private static final Logger LOG = LoggerFactory.getLogger(SimpleRegistrationService.class); - - private final RegistrationDAO registrationDAO; - - @Autowired - public SimpleRegistrationService(RegistrationDAO registrationDAO) { - this.registrationDAO = registrationDAO; - } - - @Override - public List add(Vehicle vehicle, List registrations) - throws InvalidVehicleException, InvalidRegistrationException, ServiceException { - RegistrationValidator.validate(vehicle, registrations); - try { - return registrationDAO.add(vehicle.id(), registrations); - } catch (PersistenceException e) { - LOG.warn("PersistenceException caught, throwing matching ServiceException"); - throw new ServiceException(e); - } - } - - @Override - public void remove(long registrationId) throws InvalidRegistrationException, ServiceException { - throw new UnsupportedOperationException(); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java deleted file mode 100644 index 1180bfa..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; - -import static org.junit.Assert.*; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.time.LocalDate; -import java.util.LinkedList; -import java.util.List; -import org.h2.tools.RunScript; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class H2RegistrationDAOTest { - - // Base taken from EmployeePersistenceTest - - private static final String JDBC_DRIVER = org.h2.Driver.class.getName(); - private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; - private static final String USER = ""; - private static final String PASSWORD = ""; - - private RegistrationDAO registrationDAO; - - public H2RegistrationDAOTest() throws PersistenceException { - this.registrationDAO = new H2RegistrationDAO(new JDBCConnectionManager(JDBC_URL)); - } - - @BeforeClass - public static void setupDatabase() throws SQLException { - RunScript.execute( - JDBC_URL, - USER, - PASSWORD, - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false); - } - - @Before - public void setUp() throws SQLException { - RunScript.execute( - JDBC_URL, - USER, - PASSWORD, - "classpath:sql/H2RegistrationDAOTest_populate.sql", - Charset.forName("UTF8"), - false); - } - - @After - public void tearDown() throws SQLException { - RunScript.execute( - JDBC_URL, - USER, - PASSWORD, - "classpath:sql/H2RegistrationDAOTest_depopulate.sql", - Charset.forName("UTF8"), - false); - } - - @Rule public ExpectedException thrown = ExpectedException.none(); - - @Test - public void addRegistrationsShouldSucceed() throws PersistenceException { - List registrations = new LinkedList<>(); - /* - Vehicle vehicle = Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .status(Status.ABGEMELDET) - .hasNef(true) - .build(); - */ - Employee employee1 = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Employee employee2 = - Employee.builder() - .id(2) - .name("Nick \"Kage\" Verily") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NKV) - .isDriver(true) - .isPilot(false) - .build(); - Employee employee3 = - Employee.builder() - .id(3) - .name("Nicht Arzt") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NA) - .isDriver(false) - .isPilot(false) - .build(); - Registration registration1 = - Registration.builder() - .start(Instant.now()) // incorrect, but should be irrelevant to outcome - .end(Instant.now()) // same - .employee(employee1) - .build(); - Registration registration2 = - Registration.builder() - .start(Instant.now()) // incorrect, but should be irrelevant to outcome - .end(Instant.now()) // same - .employee(employee2) - .build(); - Registration registration3 = - Registration.builder() - .start(Instant.now()) // incorrect, but should be irrelevant to outcome - .end(Instant.now()) // same - .employee(employee3) - .build(); - registrations.add(registration1); - registrations.add(registration2); - registrations.add(registration3); - - List returnvalues = registrationDAO.add(1, registrations); - assertFalse(returnvalues.isEmpty()); // can be improved... - } - - @Test - public void addRegistrationToInexistentVehicleShouldFail() throws PersistenceException { - thrown.expect(PersistenceException.class); - List registrations = new LinkedList<>(); - Employee employee = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Registration registration = - Registration.builder() - .start(Instant.MIN) - .end(Instant.MAX) - .employee(employee) - .build(); - registrations.add(registration); - registrationDAO.add(200, registrations); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java new file mode 100644 index 0000000..980c429 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java @@ -0,0 +1,162 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import static org.junit.Assert.*; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.nio.charset.Charset; +import java.sql.SQLException; +import java.time.Instant; +import java.time.LocalDate; +import java.util.LinkedList; +import java.util.List; +import org.h2.tools.RunScript; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class RegistrationDatabaseDAOTest { + + // Base taken from EmployeePersistenceTest + + private static final String JDBC_DRIVER = org.h2.Driver.class.getName(); + private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; + private static final String USER = ""; + private static final String PASSWORD = ""; + + private RegistrationDAO registrationDAO; + + public RegistrationDatabaseDAOTest() throws PersistenceException { + this.registrationDAO = new RegistrationDatabaseDAO(new JDBCConnectionManager(JDBC_URL)); + } + + @BeforeClass + public static void setupDatabase() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/database.sql", + Charset.forName("UTF8"), + false); + } + + @Before + public void setUp() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/H2RegistrationDAOTest_populate.sql", + Charset.forName("UTF8"), + false); + } + + @After + public void tearDown() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/H2RegistrationDAOTest_depopulate.sql", + Charset.forName("UTF8"), + false); + } + + @Rule public ExpectedException thrown = ExpectedException.none(); + + @Test + public void addRegistrationsShouldSucceed() throws PersistenceException { + List registrations = new LinkedList<>(); + /* + Vehicle vehicle = Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + */ + Employee employee1 = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Employee employee2 = + Employee.builder() + .id(2) + .name("Nick \"Kage\" Verily") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NKV) + .isDriver(true) + .isPilot(false) + .build(); + Employee employee3 = + Employee.builder() + .id(3) + .name("Nicht Arzt") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NA) + .isDriver(false) + .isPilot(false) + .build(); + Registration registration1 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee1) + .build(); + Registration registration2 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee2) + .build(); + Registration registration3 = + Registration.builder() + .start(Instant.now()) // incorrect, but should be irrelevant to outcome + .end(Instant.now()) // same + .employee(employee3) + .build(); + registrations.add(registration1); + registrations.add(registration2); + registrations.add(registration3); + + List returnvalues = registrationDAO.add(1, registrations); + assertFalse(returnvalues.isEmpty()); // can be improved... + } + + @Test + public void addRegistrationToInexistentVehicleShouldFail() throws PersistenceException { + thrown.expect(PersistenceException.class); + List registrations = new LinkedList<>(); + Employee employee = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Registration registration = + Registration.builder() + .start(Instant.MIN) + .end(Instant.MAX) + .employee(employee) + .build(); + registrations.add(registration); + registrationDAO.add(200, registrations); + } +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java new file mode 100644 index 0000000..7171f83 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java @@ -0,0 +1,122 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +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.time.Instant; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.LinkedList; +import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +public class RegistrationServiceImplTest { + + @Mock RegistrationDAO daoMock; + + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Rule public ExpectedException thrown = ExpectedException.none(); + + @Test + public void addValidRegistrationsShouldSucceed() + throws InvalidRegistrationException, ServiceException, InvalidVehicleException { + RegistrationService registrationService = new RegistrationServiceImpl(daoMock); + List registrations = new LinkedList<>(); + Vehicle vehicle = + Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + Employee employee1 = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Employee employee2 = + Employee.builder() + .id(2) + .name("Nick \"Kage\" Verily") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NKV) + .isDriver(true) + .isPilot(false) + .build(); + Employee employee3 = + Employee.builder() + .id(3) + .name("Nicht Arzt") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.NA) + .isDriver(false) + .isPilot(false) + .build(); + Instant start = Instant.now(); + Instant end = start.plus(8, ChronoUnit.HOURS); + Registration registration1 = + Registration.builder().start(start).end(end).employee(employee1).build(); + Registration registration2 = + Registration.builder().start(start).end(end).employee(employee2).build(); + Registration registration3 = + Registration.builder().start(start).end(end).employee(employee3).build(); + registrations.add(registration1); + registrations.add(registration2); + registrations.add(registration3); + registrationService.add(vehicle, registrations); + } + + @Test + public void addOnlyOnePersonToRTWShouldFail() + throws InvalidRegistrationException, ServiceException, InvalidVehicleException { + thrown.expect(InvalidRegistrationException.class); + RegistrationService registrationService = new RegistrationServiceImpl(daoMock); + List registrations = new LinkedList<>(); + Vehicle vehicle = + Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .status(Status.ABGEMELDET) + .hasNef(true) + .build(); + Employee employee = + Employee.builder() + .id(1) + .name("John Doe") + .birthday(LocalDate.now()) // incorrect, but should be irrelevant + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(true) + .build(); + Registration registration = + Registration.builder() + .start(Instant.MIN) + .end(Instant.MAX) + .employee(employee) + .build(); + registrations.add(registration); + registrationService.add(vehicle, registrations); + } +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java deleted file mode 100644 index b1ef38f..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/SimpleRegistrationServiceTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.junit.Assert.*; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -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.time.Instant; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; -import java.util.LinkedList; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -public class SimpleRegistrationServiceTest { - - @Mock RegistrationDAO daoMock; - - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Rule public ExpectedException thrown = ExpectedException.none(); - - @Test - public void addValidRegistrationsShouldSucceed() - throws InvalidRegistrationException, ServiceException, InvalidVehicleException { - RegistrationService registrationService = new SimpleRegistrationService(daoMock); - List registrations = new LinkedList<>(); - Vehicle vehicle = - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .status(Status.ABGEMELDET) - .hasNef(true) - .build(); - Employee employee1 = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Employee employee2 = - Employee.builder() - .id(2) - .name("Nick \"Kage\" Verily") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NKV) - .isDriver(true) - .isPilot(false) - .build(); - Employee employee3 = - Employee.builder() - .id(3) - .name("Nicht Arzt") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NA) - .isDriver(false) - .isPilot(false) - .build(); - Instant start = Instant.now(); - Instant end = start.plus(8, ChronoUnit.HOURS); - Registration registration1 = - Registration.builder().start(start).end(end).employee(employee1).build(); - Registration registration2 = - Registration.builder().start(start).end(end).employee(employee2).build(); - Registration registration3 = - Registration.builder().start(start).end(end).employee(employee3).build(); - registrations.add(registration1); - registrations.add(registration2); - registrations.add(registration3); - registrationService.add(vehicle, registrations); - } - - @Test - public void addOnlyOnePersonToRTWShouldFail() - throws InvalidRegistrationException, ServiceException, InvalidVehicleException { - thrown.expect(InvalidRegistrationException.class); - RegistrationService registrationService = new SimpleRegistrationService(daoMock); - List registrations = new LinkedList<>(); - Vehicle vehicle = - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .status(Status.ABGEMELDET) - .hasNef(true) - .build(); - Employee employee = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Registration registration = - Registration.builder() - .start(Instant.MIN) - .end(Instant.MAX) - .employee(employee) - .build(); - registrations.add(registration); - registrationService.add(vehicle, registrations); - } -} -- cgit v1.2.3-70-g09d2 From 1243cb27f0239d4dc17fa519a0b0c51881723644 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 15:56:33 +0200 Subject: Fix NullPointerException occurring when empty area clicked in table --- .../einsatzverwaltung/controller/RegistrationWindowController.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index 152d3f0..0683c77 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -109,6 +109,9 @@ public class RegistrationWindowController { mouseEvent -> { if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { chosenVehicle = tvVehicles.getSelectionModel().getSelectedItem(); + if (chosenVehicle == null) { + return; + } lVehicles.setText(chosenVehicle.name()); } }); @@ -116,6 +119,9 @@ public class RegistrationWindowController { mouseEvent -> { if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { chosenEmployees.add(tvEmployees.getSelectionModel().getSelectedItem()); + if (chosenEmployees == null) { + return; + } StringBuilder text = new StringBuilder(); for (Employee employee : chosenEmployees) { text.append(employee.name()).append("\n"); -- cgit v1.2.3-70-g09d2 From 35a0979bf30241f5dea833ac1297d9ff54c0fbc0 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 16:15:43 +0200 Subject: Implement onRegistrationClicked --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index ae99088..19f24e3 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -189,7 +189,7 @@ public class CreateOperationController { } public void onRegistrationLinkClicked(ActionEvent actionEvent) { - throw new UnsupportedOperationException(); + openNewWindow("RegistrationWindow.fxml"); } public void onEmployeeLinkClicked(ActionEvent actionEvent) { -- cgit v1.2.3-70-g09d2 From 55f3fd7c0decca6cfc82791e77cbae549d9d9b8b Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 17:16:24 +0200 Subject: Add hasNef property to VehicleDatabaseDao.add --- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java index 5ddb035..6beb994 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java @@ -24,12 +24,13 @@ public class VehicleDatabaseDao implements VehicleDAO { } public long add(Vehicle vehicle) throws PersistenceException { - String query1 = "INSERT INTO VehicleVersion (name,constructionType,type) VALUES (?,?,?)"; + String query1 = + "INSERT INTO VehicleVersion (name,hasNef,constructionType,type) VALUES (?,?,?,?)"; String query2 = "INSERT INTO Vehicle (version,status) VALUES (?,?)"; PreparedStatement p1 = null; PreparedStatement p2 = null; PreparedStatement p3 = null; - String status = "abgemeldet"; + String status = "ABGEMELDET"; String name = ""; int id = -1; try { @@ -38,11 +39,12 @@ public class VehicleDatabaseDao implements VehicleDAO { .getConnection() .prepareStatement(query1, PreparedStatement.RETURN_GENERATED_KEYS); p1.setString(1, name); - p1.setString(2, vehicle.constructionType().name()); + p1.setBoolean(2, vehicle.hasNef()); + p1.setString(3, vehicle.constructionType().name()); if (vehicle.type() == VehicleType.KTW_B) { - p1.setString(3, "KTW-B"); + p1.setString(4, "KTW-B"); } else { - p1.setString(3, vehicle.type().name()); + p1.setString(4, vehicle.type().name()); } p1.executeUpdate(); @@ -115,12 +117,13 @@ public class VehicleDatabaseDao implements VehicleDAO { while (rs.next()) { Vehicle vehicle = Vehicle.builder() - .name(rs.getString(2)) - .constructionType(ConstructionType.valueOf(rs.getString(3))) - .status(Status.valueOf(rs.getString(8))) - .id(rs.getInt(6)) - .hasNef(rs.getBoolean(5)) - .type(VehicleType.valueOf(rs.getString(4))) + .name(rs.getString("name")) + .constructionType( + ConstructionType.valueOf(rs.getString("constructionType"))) + .status(Status.valueOf(rs.getString("status"))) + .id(rs.getInt("id")) + .hasNef(rs.getBoolean("hasNef")) + .type(VehicleType.valueOf(rs.getString("type"))) .build(); result.add(vehicle); } -- cgit v1.2.3-70-g09d2 From eb76fb14b43bd3a1493632f5514eca9a1496bbca Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:17:20 +0200 Subject: Set default values for time-ChoiceBoxes --- .../einsatzverwaltung/controller/RegistrationWindowController.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index 0683c77..f375fe9 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -134,7 +134,9 @@ public class RegistrationWindowController { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23); cbStart.setItems(hours); + cbStart.setValue(0); cbEnd.setItems(hours); + cbEnd.setValue(12); } public void cancel() { -- cgit v1.2.3-70-g09d2 From d4d8ba884a80d0f7483efe2fb2c981023f983022 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:23:31 +0200 Subject: Changed enums (and similar fields) to match enum names of Java --- .../einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 2 +- src/main/resources/sql/H2RegistrationDAOTest_populate.sql | 8 ++++---- src/main/resources/sql/database.sql | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java index e4bc0ab..8fbcd18 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java @@ -25,7 +25,7 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { private static final String ADD_REGISTRATION = "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; private static final String UPDATE_VEHICLE = - "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; + "UPDATE Vehicle SET status = 'FREI_WACHE' WHERE id = ?;"; private PreparedStatement addRegistration; private PreparedStatement updateVehicle; diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index b81eb78..3c268a0 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -4,7 +4,7 @@ INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPil INSERT INTO Employee (id, version) VALUES (1, 1); INSERT INTO Employee (id, version) VALUES (2, 2); INSERT INTO Employee (id, version) VALUES (3, 3); -INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'Hochdach', 'RTW'); -INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, 'Normal', 'NEF'); -INSERT INTO Vehicle (id, version, status) VALUES (1, 1, 'abgemeldet'); -INSERT INTO Vehicle (id, version, status) VALUES (2, 2, 'abgemeldet'); \ No newline at end of file +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'HOCHDACH', 'RTW'); +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, 'NORMAL', 'NEF'); +INSERT INTO Vehicle (id, version, status) VALUES (1, 1, 'ABGEMELDET'); +INSERT INTO Vehicle (id, version, status) VALUES (2, 2, 'ABGEMELDET'); \ No newline at end of file diff --git a/src/main/resources/sql/database.sql b/src/main/resources/sql/database.sql index e775550..4f3adf7 100644 --- a/src/main/resources/sql/database.sql +++ b/src/main/resources/sql/database.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS VehicleVersion ( constructionType VARCHAR NOT NULL, type VARCHAR NOT NULL, hasNef BOOLEAN NOT NULL, - CHECK constructionType IN ('Normal', 'Hochdach', 'Mittelhochdach'), + CHECK constructionType IN ('NORMAL', 'HOCHDACH', 'MITTELHOCHDACH'), CHECK type IN ('BKTW', 'KTW-B', 'KTW', 'RTW', 'NEF', 'NAH') ); @@ -13,8 +13,8 @@ CREATE TABLE IF NOT EXISTS Vehicle ( version BIGINT NOT NULL, status VARCHAR NOT NULL, FOREIGN KEY (version) REFERENCES VehicleVersion(id), - CHECK status IN ('abgemeldet', 'frei_wache', 'zum_berufungsort', 'am_berufungsort', 'zum_zielort', - 'am_zielort', 'frei_funk', 'deleted') + CHECK status IN ('ABGEMELDET', 'FREI_WACHE', 'ZUM_BERUFUNGSORT', 'AM_BERUFUNGSORT', 'ZUM_ZIELORT', + 'AM_ZIELORT', 'FREI_FUNK', 'DELETED') ); CREATE TABLE IF NOT EXISTS EmployeeVersion ( @@ -51,7 +51,9 @@ CREATE TABLE IF NOT EXISTS Operation ( created TIMESTAMP NOT NULL, destination VARCHAR(100) NOT NULL, additionalInfo VARCHAR(100), - CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O') + status VARCHAR NOT NULL, + CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O'), + CHECK status IN ('ACTIVE', 'COMPLETED', 'CANCELLED') ); CREATE TABLE IF NOT EXISTS VehicleOperation ( -- cgit v1.2.3-70-g09d2 From f9559106ee3492087f4a33f8df790a250d7ad0cf Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:30:01 +0200 Subject: Set severity as a letter, not a number --- .../groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index d332acc..4071d3a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -41,7 +41,7 @@ public class DBOperationDAO implements OperationDAO { throw new PersistenceException( "Länge des OP-Codes überschreitet erlaubte Länge von 100 Zeichen!"); else pstmt.setString(1, operation.opCode()); - switch (operation.severity()) { + /*switch (operation.severity()) { case A: pstmt.setInt(2, 0); break; @@ -63,7 +63,8 @@ public class DBOperationDAO implements OperationDAO { default: throw new PersistenceException( "Schwere des Einsatzes konnte nicht validiert werden!"); - } + }*/ + pstmt.setString(2, operation.severity().name()); if (operation.created() != null) { pstmt.setTimestamp(3, Timestamp.from(operation.created())); } else { @@ -152,5 +153,7 @@ public class DBOperationDAO implements OperationDAO { } } } + + return 1; } } -- cgit v1.2.3-70-g09d2 From 781954cb0637fa4d166ce8d1e839c184d021df1b Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:31:48 +0200 Subject: Remove nonexistent return value --- .../assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index 4071d3a..672424a 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -135,12 +135,14 @@ public class DBOperationDAO implements OperationDAO { + "values (?,?)"); pstmt.setLong(1, vehicleID); pstmt.setLong(2, operationID); - pstmt.execute(); + pstmt.executeUpdate(); + + /* ResultSet rs = pstmt.getGeneratedKeys(); if (rs.next()) return rs.getInt(1); else throw new PersistenceException( - "Fahrzeug für die Operation konnte nicht abgespeichert werden!"); + "Fahrzeug für die Operation konnte nicht abgespeichert werden!");*/ } catch (SQLException e) { throw new PersistenceException("Die Werte konnten nicht gespeichert werden!"); } finally { -- cgit v1.2.3-70-g09d2 From 42b98ee0673f94949413c6b690bc8a7ac6fb0f78 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 17:33:13 +0200 Subject: Swap add and connectVehicleToOperation --- .../einsatzverwaltung/service/OperationServiceImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 74cb7a7..05a548c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -82,18 +82,23 @@ public class OperationServiceImpl implements OperationService { "Der Schweregrad des Einsatzes konnte nicht ausgelesen werden!"); } operation = operation.toBuilder().status(Status.ACTIVE).build(); + + long operationId = -1; + try { + operationId = operationDAO.add(operation); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + for (Vehicle vehicle : vehicles) { try { - operationDAO.connectVehicleToOperation(vehicle.id(), operation.id()); + operationDAO.connectVehicleToOperation(vehicle.id(), operationId); } catch (PersistenceException e) { throw new ServiceException(e); } } - try { - return operationDAO.add(operation); - } catch (PersistenceException e) { - throw new ServiceException(e); - } + + return operationId; } private boolean faultyInput(String name) { -- cgit v1.2.3-70-g09d2 From dab91fac74c2c51ad823dc53b68acf5aea5b3111 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:43:55 +0200 Subject: Change database location to ./ --- .../tuwien/sepm/assignment/groupphase/util/JDBCConnectionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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 index 6eb15ec..0ee3319 100644 --- 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 @@ -13,7 +13,7 @@ public class JDBCConnectionManager { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String DEFAULT_CONNECTION_URL = - "jdbc:h2:~/sepm;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; + "jdbc:h2:./sepm;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; private String connectionUrl; private Connection connection; -- cgit v1.2.3-70-g09d2 From 834f9b4fff11c778dbb09dc74a88d658fc094a54 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 18:06:00 +0200 Subject: Changed test behaviour to leave "clean" database for other tests --- .../sql/H2RegistrationDAOTest_populate.sql | 5 +++++ .../dao/RegistrationDatabaseDAOTest.java | 24 ++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index 3c268a0..7e7b428 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -1,3 +1,8 @@ +DELETE FROM Registration; +DELETE FROM Vehicle; +DELETE FROM VehicleVersion; +DELETE FROM Employee; +DELETE FROM EmployeeVersion; INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (1, 'John Doe', '2000-01-01', 'RS', TRUE, TRUE); INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (2, 'Nick "Kage" Verily', '1990-01-01', 'NKV', TRUE, FALSE); INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (3, 'Nicht Arzt', '1980-01-01', 'NA', FALSE, FALSE); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java index 980c429..03059ff 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java @@ -14,8 +14,7 @@ import java.time.LocalDate; import java.util.LinkedList; import java.util.List; import org.h2.tools.RunScript; -import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -45,10 +44,6 @@ public class RegistrationDatabaseDAOTest { "classpath:sql/database.sql", Charset.forName("UTF8"), false); - } - - @Before - public void setUp() throws SQLException { RunScript.execute( JDBC_URL, USER, @@ -57,9 +52,20 @@ public class RegistrationDatabaseDAOTest { Charset.forName("UTF8"), false); } - - @After - public void tearDown() throws SQLException { + /* + @Before + public void setUp() throws SQLException { + RunScript.execute( + JDBC_URL, + USER, + PASSWORD, + "classpath:sql/H2RegistrationDAOTest_populate.sql", + Charset.forName("UTF8"), + false); + } + */ + @AfterClass + public static void tearDown() throws SQLException { RunScript.execute( JDBC_URL, USER, -- cgit v1.2.3-70-g09d2 From d26af6246ba85c7e163838f7a48eb31d4369cfcb Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Mon, 7 May 2018 18:22:35 +0200 Subject: Fixed a bug where nullpointer was thrown when element in vehicle list was null --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 19f24e3..5b645f3 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -84,6 +84,9 @@ public class CreateOperationController { event -> { if (event.getClickCount() == 2) { boolean remove = false; + if (lvVehicles.getSelectionModel().getSelectedItem() == null) { + return; + } for (Vehicle vehicle : chosenVehicles) { if (lvVehicles.getSelectionModel().getSelectedItem().equals(vehicle)) { remove = true; -- cgit v1.2.3-70-g09d2 From be80ff84430b5f28613ec5b99cbc6b5e5d3ee45b Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 18:53:28 +0200 Subject: Changed interface back to how it was before --- .../controller/RegistrationWindowController.java | 2 +- .../service/RegistrationService.java | 7 ++--- .../service/RegistrationServiceImpl.java | 21 +++++++++++-- .../service/RegistrationServiceImplTest.java | 34 +++++++++++++++++++--- 4 files changed, 53 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index f375fe9..bf413bb 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -167,7 +167,7 @@ public class RegistrationWindowController { .build()); } try { - registrationService.add(chosenVehicle, registrations); + registrationService.add(chosenVehicle.id(), registrations); ((Stage) lVehicles.getScene().getWindow()).close(); } catch (InvalidVehicleException e) { // NOT THROWN ANYWHERE RIGHT NOW 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 c20ed3c..c345a2b 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 @@ -1,7 +1,6 @@ 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.einsatzverwaltung.dto.Vehicle; 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; @@ -12,14 +11,14 @@ public interface RegistrationService { /** * Register employee to a vehicle. * - * @param vehicle the target vehicle + * @param vehicleId the id of the target vehicle * @param registrations that should be added to the vehicle - * @return the id that was assigned + * @return the list of 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 */ - List add(Vehicle vehicle, List registrations) + List add(long vehicleId, List registrations) throws InvalidVehicleException, InvalidRegistrationException, ServiceException; /** diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java index b0605f0..a267b6f 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImpl.java @@ -4,10 +4,12 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.Registratio import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.RegistrationValidator; 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.InvalidRegistrationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.EnumSet; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,15 +22,30 @@ public class RegistrationServiceImpl implements RegistrationService { private static final Logger LOG = LoggerFactory.getLogger(RegistrationServiceImpl.class); private final RegistrationDAO registrationDAO; + private final VehicleService vehicleService; @Autowired - public RegistrationServiceImpl(RegistrationDAO registrationDAO) { + public RegistrationServiceImpl(RegistrationDAO registrationDAO, VehicleService vehicleService) { this.registrationDAO = registrationDAO; + this.vehicleService = vehicleService; } @Override - public List add(Vehicle vehicle, List registrations) + public List add(long vehicleId, List registrations) throws InvalidVehicleException, InvalidRegistrationException, ServiceException { + + Vehicle vehicle = + vehicleService + .list(EnumSet.of(Status.ABGEMELDET)) + .stream() + .filter(v -> v.id() == vehicleId) + .findFirst() + .orElse(null); + + if (vehicle == null) { + throw new ServiceException("no vehicle with this id"); + } + RegistrationValidator.validate(vehicle, registrations); try { return registrationDAO.add(vehicle.id(), registrations); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java index 7171f83..f3efbef 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java @@ -1,5 +1,8 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; @@ -14,12 +17,15 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.time.Instant; import java.time.LocalDate; import java.time.temporal.ChronoUnit; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -27,14 +33,33 @@ public class RegistrationServiceImplTest { @Mock RegistrationDAO daoMock; + @Mock VehicleService vehicleService; + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Rule public ExpectedException thrown = ExpectedException.none(); + @Before + public void setUp() throws ServiceException { + MockitoAnnotations.initMocks(this); + when(vehicleService.list(any())) + .thenReturn( + Arrays.asList( + Vehicle.builder() + .id(1) + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .status(Status.ABGEMELDET) + .type(VehicleType.RTW) + .hasNef(true) + .build())); + } + @Test public void addValidRegistrationsShouldSucceed() throws InvalidRegistrationException, ServiceException, InvalidVehicleException { - RegistrationService registrationService = new RegistrationServiceImpl(daoMock); + RegistrationService registrationService = + new RegistrationServiceImpl(daoMock, vehicleService); List registrations = new LinkedList<>(); Vehicle vehicle = Vehicle.builder() @@ -83,14 +108,15 @@ public class RegistrationServiceImplTest { registrations.add(registration1); registrations.add(registration2); registrations.add(registration3); - registrationService.add(vehicle, registrations); + registrationService.add(vehicle.id(), registrations); } @Test public void addOnlyOnePersonToRTWShouldFail() throws InvalidRegistrationException, ServiceException, InvalidVehicleException { thrown.expect(InvalidRegistrationException.class); - RegistrationService registrationService = new RegistrationServiceImpl(daoMock); + RegistrationService registrationService = + new RegistrationServiceImpl(daoMock, vehicleService); List registrations = new LinkedList<>(); Vehicle vehicle = Vehicle.builder() @@ -117,6 +143,6 @@ public class RegistrationServiceImplTest { .employee(employee) .build(); registrations.add(registration); - registrationService.add(vehicle, registrations); + registrationService.add(vehicle.id(), registrations); } } -- cgit v1.2.3-70-g09d2 From 3cff15bba35a762992a579decb84555d6638876b Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 21:00:00 +0200 Subject: Fix 'KTW-B' vs 'KTW_B' parsing problem --- .../assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java index 6beb994..ca1d45c 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java @@ -123,7 +123,7 @@ public class VehicleDatabaseDao implements VehicleDAO { .status(Status.valueOf(rs.getString("status"))) .id(rs.getInt("id")) .hasNef(rs.getBoolean("hasNef")) - .type(VehicleType.valueOf(rs.getString("type"))) + .type(VehicleType.valueOf(rs.getString("type").replace("-", "_"))) .build(); result.add(vehicle); } -- cgit v1.2.3-70-g09d2 From e8aff26f9855c9106defd23c78d37c0907a0d97e Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Mon, 7 May 2018 21:29:38 +0200 Subject: Change header-background-color and add drop-shadows to main elements --- src/main/resources/fxml/CreateOperationController.fxml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 1ba6498..086a5d1 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -10,8 +10,8 @@ - - + + - - + @@ -75,7 +75,7 @@ - + - + -- cgit v1.2.3-70-g09d2 From d1be1e7dc30f11084f4d7054612d02a230271514 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Thu, 3 May 2018 20:25:01 +0200 Subject: Empty skeleton for VehiclePane. --- .../ui/vehiclePane/VehiclePaneController.java | 33 ++++++++++++++++++++++ src/main/resources/fxml/vehiclePane.fxml | 14 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java create mode 100644 src/main/resources/fxml/vehiclePane.fxml (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java new file mode 100644 index 0000000..ee9e29f --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java @@ -0,0 +1,33 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.ui.vehiclePane; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import java.io.IOException; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; + +public class VehiclePaneController { + public static VehiclePaneController createVehiclePane() throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); + Node root = fxmlLoader.load(); + VehiclePaneController result = fxmlLoader.getController(); + result.rootElement = root; + + return result; + } + + private Node rootElement; + + public Node getRootElement() { + return rootElement; + } + + /*** + * Set the displayed data of this VehiclePane. + * @param vehicle The data to display. + * @param showQualification If true, the most recent registration of vehicle will be searched for the highest qualification. + */ + public void setData(Vehicle vehicle, boolean showQualification) + { + + } +} diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml new file mode 100644 index 0000000..f6824dc --- /dev/null +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + -- cgit v1.2.3-70-g09d2 From 4e9bbe5134b2efd9e3eab277a92366fe0ba38d4e Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Sat, 5 May 2018 16:28:09 +0200 Subject: VehiclePane FXML --- .../ui/vehiclePane/VehiclePaneController.java | 11 +++ src/main/resources/fxml/vehiclePane.fxml | 78 ++++++++++++++++++--- src/main/resources/images/NEF.png | Bin 0 -> 327 bytes src/main/resources/images/Not.png | Bin 0 -> 872 bytes src/main/resources/images/NotNEF.png | Bin 0 -> 1042 bytes src/main/resources/images/Qualification.png | Bin 0 -> 1029 bytes src/main/resources/images/Vehicle.png | Bin 0 -> 964 bytes 7 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/images/NEF.png create mode 100644 src/main/resources/images/Not.png create mode 100644 src/main/resources/images/NotNEF.png create mode 100644 src/main/resources/images/Qualification.png create mode 100644 src/main/resources/images/Vehicle.png (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java index ee9e29f..903028e 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java @@ -4,8 +4,19 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; import java.io.IOException; import javafx.fxml.FXMLLoader; import javafx.scene.Node; +import javafx.scene.image.ImageView; +import javafx.scene.text.Text; public class VehiclePaneController { + + private Text txtType; + private Text txtNumber; + private ImageView ivNEF; + private Text txtNEF; + private ImageView ivQualification; + private Text txtQualification; + private Text txtRooftype; + public static VehiclePaneController createVehiclePane() throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); Node root = fxmlLoader.load(); diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml index f6824dc..6014c72 100644 --- a/src/main/resources/fxml/vehiclePane.fxml +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -1,14 +1,70 @@ - - - - - + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/images/NEF.png b/src/main/resources/images/NEF.png new file mode 100644 index 0000000..687f914 Binary files /dev/null and b/src/main/resources/images/NEF.png differ diff --git a/src/main/resources/images/Not.png b/src/main/resources/images/Not.png new file mode 100644 index 0000000..03063af Binary files /dev/null and b/src/main/resources/images/Not.png differ diff --git a/src/main/resources/images/NotNEF.png b/src/main/resources/images/NotNEF.png new file mode 100644 index 0000000..0c17d53 Binary files /dev/null and b/src/main/resources/images/NotNEF.png differ diff --git a/src/main/resources/images/Qualification.png b/src/main/resources/images/Qualification.png new file mode 100644 index 0000000..c58a640 Binary files /dev/null and b/src/main/resources/images/Qualification.png differ diff --git a/src/main/resources/images/Vehicle.png b/src/main/resources/images/Vehicle.png new file mode 100644 index 0000000..2fe992d Binary files /dev/null and b/src/main/resources/images/Vehicle.png differ -- cgit v1.2.3-70-g09d2 From f0a06739827a2efbf81e20449d92c8312e8832c9 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Sat, 5 May 2018 16:55:31 +0200 Subject: VehiclePane Controller --- .../ui/vehiclePane/VehiclePaneController.java | 55 ++++++++++++++++------ 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java index 903028e..2b0df13 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java @@ -2,23 +2,25 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.ui.vehiclePane import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; import java.io.IOException; +import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.text.Text; public class VehiclePaneController { - - private Text txtType; - private Text txtNumber; - private ImageView ivNEF; - private Text txtNEF; - private ImageView ivQualification; - private Text txtQualification; - private Text txtRooftype; + @FXML private Text txtType; + @FXML private Text txtNumber; + @FXML private ImageView ivNEF; + @FXML private Text txtNEF; + @FXML private ImageView ivQualification; + @FXML private Text txtQualification; + @FXML private Text txtRooftype; public static VehiclePaneController createVehiclePane() throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); + FXMLLoader fxmlLoader = + new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); Node root = fxmlLoader.load(); VehiclePaneController result = fxmlLoader.getController(); result.rootElement = root; @@ -32,13 +34,36 @@ public class VehiclePaneController { return rootElement; } - /*** - * Set the displayed data of this VehiclePane. + /** + * * Set the displayed data of this VehiclePane. + * * @param vehicle The data to display. - * @param showQualification If true, the most recent registration of vehicle will be searched for the highest qualification. + * @param showQualification If true, the most recent registration of vehicle will be searched + * for the highest qualification. */ - public void setData(Vehicle vehicle, boolean showQualification) - { - + public void setData(Vehicle vehicle, boolean showQualification) { + txtType.setText(vehicle.type().name()); + String constrType = vehicle.constructionType().name(); + txtRooftype.setText( + constrType.substring(0, 1).toUpperCase() + constrType.substring(1).toLowerCase()); + txtNumber.setText("" + vehicle.id()); + if (vehicle.hasNef()) { + ivNEF.setImage(new Image("../images/NEF.png")); + txtNEF.setText("hat NEF-Halterung"); + } else { + ivNEF.setImage(new Image("../images/NotNEF.png")); + txtNEF.setText("keine NEF-Halterung"); + } + if (showQualification) + { + //TODO + } + else + { + txtQualification.setVisible(false); + txtQualification.setManaged(false); + ivQualification.setVisible(false); + ivQualification.setManaged(false); + } } } -- cgit v1.2.3-70-g09d2 From b9aadec691affd632c8d83e30293964cc1bb05bb Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Mon, 7 May 2018 17:53:59 +0200 Subject: Reformat. Implemented find maximum education in VehiclePaneController; relies on EducationLevel.Compare. --- .../ui/vehiclePane/VehiclePaneController.java | 69 ----------------- .../ui/vehiclepane/VehiclePaneController.java | 84 ++++++++++++++++++++ src/main/resources/fxml/vehiclePane.fxml | 90 +++++++++++----------- 3 files changed, 129 insertions(+), 114 deletions(-) delete mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclepane/VehiclePaneController.java (limited to 'src') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java deleted file mode 100644 index 2b0df13..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclePane/VehiclePaneController.java +++ /dev/null @@ -1,69 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.ui.vehiclePane; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import java.io.IOException; -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Node; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.text.Text; - -public class VehiclePaneController { - @FXML private Text txtType; - @FXML private Text txtNumber; - @FXML private ImageView ivNEF; - @FXML private Text txtNEF; - @FXML private ImageView ivQualification; - @FXML private Text txtQualification; - @FXML private Text txtRooftype; - - public static VehiclePaneController createVehiclePane() throws IOException { - FXMLLoader fxmlLoader = - new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); - Node root = fxmlLoader.load(); - VehiclePaneController result = fxmlLoader.getController(); - result.rootElement = root; - - return result; - } - - private Node rootElement; - - public Node getRootElement() { - return rootElement; - } - - /** - * * Set the displayed data of this VehiclePane. - * - * @param vehicle The data to display. - * @param showQualification If true, the most recent registration of vehicle will be searched - * for the highest qualification. - */ - public void setData(Vehicle vehicle, boolean showQualification) { - txtType.setText(vehicle.type().name()); - String constrType = vehicle.constructionType().name(); - txtRooftype.setText( - constrType.substring(0, 1).toUpperCase() + constrType.substring(1).toLowerCase()); - txtNumber.setText("" + vehicle.id()); - if (vehicle.hasNef()) { - ivNEF.setImage(new Image("../images/NEF.png")); - txtNEF.setText("hat NEF-Halterung"); - } else { - ivNEF.setImage(new Image("../images/NotNEF.png")); - txtNEF.setText("keine NEF-Halterung"); - } - if (showQualification) - { - //TODO - } - else - { - txtQualification.setVisible(false); - txtQualification.setManaged(false); - ivQualification.setVisible(false); - ivQualification.setManaged(false); - } - } -} diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclepane/VehiclePaneController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclepane/VehiclePaneController.java new file mode 100644 index 0000000..2db6f37 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/ui/vehiclepane/VehiclePaneController.java @@ -0,0 +1,84 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.ui.vehiclepane; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import java.io.IOException; +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.text.Text; + +public class VehiclePaneController { + @FXML private Text txtType; + @FXML private Text txtNumber; + @FXML private ImageView ivNEF; + @FXML private Text txtNEF; + @FXML private ImageView ivQualification; + @FXML private Text txtQualification; + @FXML private Text txtRooftype; + + public static VehiclePaneController createVehiclePane() throws IOException { + FXMLLoader fxmlLoader = + new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml")); + Node root = fxmlLoader.load(); + VehiclePaneController result = fxmlLoader.getController(); + result.rootElement = root; + + return result; + } + + private Node rootElement; + + public Node getRootElement() { + return rootElement; + } + + /** + * * Set the displayed data of this VehiclePane. + * + * @param vehicle The data to display. + * @param showQualification If true, the most recent registration of vehicle will be searched + * for the highest qualification. + */ + public void setData(Vehicle vehicle, boolean showQualification) { + txtType.setText(vehicle.type().name()); + String constrType = vehicle.constructionType().name(); + txtRooftype.setText( + constrType.substring(0, 1).toUpperCase() + constrType.substring(1).toLowerCase()); + txtNumber.setText("" + vehicle.id()); + if (vehicle.hasNef()) { + ivNEF.setImage(new Image("../images/NEF.png")); + txtNEF.setText("hat NEF-Halterung"); + } else { + ivNEF.setImage(new Image("../images/NotNEF.png")); + txtNEF.setText("keine NEF-Halterung"); + } + if (showQualification) { + + Instant now = (new Date()).toInstant(); + List regs = vehicle.registrations(); + + assert regs != null; + Optional edu = + regs.stream() + .filter(reg -> reg.start().isBefore(now) && reg.end().isAfter(now)) + .map(reg -> reg.employee().educationLevel()) + .max(EducationLevel::compareTo); + + assert edu.isPresent(); + txtQualification.setText(edu.get().name()); + } else { + txtQualification.setVisible(false); + txtQualification.setManaged(false); + ivQualification.setVisible(false); + ivQualification.setManaged(false); + } + } +} diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml index 6014c72..8b1d194 100644 --- a/src/main/resources/fxml/vehiclePane.fxml +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -10,61 +10,61 @@ - + - - - - + + + + - - - - + + + + - + - - - - - - - - - - - - - - - - - + + - + - - - - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2