diff options
author | Tharre <tharre3@gmail.com> | 2018-06-20 22:07:36 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-06-20 22:07:36 +0200 |
commit | 0c995a05985da749d93aa56eba976c7fc621a4fa (patch) | |
tree | 5b80394920705aae5e2b6004c3dfbd839c8b8fa3 /src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto | |
parent | f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa (diff) | |
parent | e21feb3ac772a5394dc5381b58142c3c061de716 (diff) | |
download | sepm-groupproject-master.tar.gz sepm-groupproject-master.tar.xz sepm-groupproject-master.zip |
Diffstat (limited to 'src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto')
6 files changed, 0 insertions, 446 deletions
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 deleted file mode 100644 index 583bf5b..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Employee.java +++ /dev/null @@ -1,51 +0,0 @@ -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 - } - - public abstract long id(); - - public abstract String name(); - - public abstract LocalDate birthday(); - - public abstract EducationLevel educationLevel(); - - public abstract boolean isDriver(); - - public 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/EmployeeValidator.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/EmployeeValidator.java deleted file mode 100644 index d7fa9aa..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/EmployeeValidator.java +++ /dev/null @@ -1,23 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; - -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; - -public class EmployeeValidator { - - public static boolean validate(Employee employee) throws InvalidEmployeeException { - - if (employee.name() == null || employee.name().trim().length() == 0) { - throw new InvalidEmployeeException("name not set"); - } - - if (employee.birthday() == null) { - throw new InvalidEmployeeException("birthday not set"); - } - - if (employee.educationLevel() == null) { - throw new InvalidEmployeeException("educationLevel not set"); - } - - return true; - } -} 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 deleted file mode 100644 index 3a97dc7..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Operation.java +++ /dev/null @@ -1,70 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; - -import com.google.auto.value.AutoValue; -import java.time.Instant; -import java.util.Set; -import javax.annotation.Nullable; - -@AutoValue -public abstract class Operation { - public enum Severity { - A, - B, - C, - D, - E, - O, - } - - public enum Status { - ACTIVE, - COMPLETED, - CANCELLED, - } - - public abstract long id(); - - public abstract String opCode(); - - @Nullable - public abstract Severity severity(); - - public abstract Status status(); - - public abstract Set<Vehicle> vehicles(); - - @Nullable - public abstract Instant created(); - - public abstract String destination(); - - @Nullable - public 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(Set<Vehicle> 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 deleted file mode 100644 index 8551266..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Registration.java +++ /dev/null @@ -1,34 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; - -import com.google.auto.value.AutoValue; -import java.time.Instant; - -@AutoValue -public abstract class Registration { - public abstract long id(); - - public abstract Instant start(); - - public abstract Instant end(); - - public 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/RegistrationValidator.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java deleted file mode 100644 index 610426c..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/RegistrationValidator.java +++ /dev/null @@ -1,195 +0,0 @@ -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 java.util.Set; -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, Set<Registration> 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<Long> pilotIds = new LinkedList<>(); - List<Long> driverIds = new LinkedList<>(); - List<Long> naIds = new LinkedList<>(); - List<Long> nfsIds = new LinkedList<>(); - List<Long> rsIds = new LinkedList<>(); - HashMap<Long, Boolean> 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/dto/Vehicle.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java deleted file mode 100644 index e81db0b..0000000 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dto/Vehicle.java +++ /dev/null @@ -1,73 +0,0 @@ -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, - FREI_FUNK, - ZUM_BERUFUNGSORT, - AM_BERUFUNGSORT, - ZUM_ZIELORT, - AM_ZIELORT, - } - - public abstract long id(); - - public abstract String name(); - - public abstract ConstructionType constructionType(); - - public abstract VehicleType type(); - - public abstract Status status(); - - public abstract boolean hasNef(); - - @Nullable - public abstract List<Registration> 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<Registration> registrations); - - public abstract Vehicle build(); - } - - public abstract Builder toBuilder(); -} |