From d01fe53ec94935379215e025c985bd27109af9ec Mon Sep 17 00:00:00 2001 From: Tharre Date: Fri, 11 May 2018 22:54:45 +0200 Subject: Implement VehicleDAO.get() and fix list() misuse --- .../einsatzverwaltung/dao/VehicleDAO.java | 10 +++++ .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 50 ++++++++++++++++------ .../service/RegistrationServiceImpl.java | 29 ++++++------- 3 files changed, 59 insertions(+), 30 deletions(-) (limited to 'src/main/java') 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 index fe12952..2f0df44 100644 --- 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 @@ -33,6 +33,16 @@ public interface VehicleDAO { */ List list() throws PersistenceException; + /** + * Returns the vehicle with the given id. + * + * @param vehicleId id of the vehicle that should be returned + * @return vehicle with the given id + * @throws ElementNotFoundException if no vehicle with the given id exists + * @throws PersistenceException if the vehicle could not be loaded + */ + Vehicle get(long vehicleId) throws ElementNotFoundException, PersistenceException; + /** * Remove vehicle with the given id from the store. * 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 ca1d45c..8f0d28b 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 @@ -7,6 +7,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Veh 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; @@ -114,19 +115,8 @@ public class VehicleDatabaseDao implements VehicleDAO { + "Vehicle where VehicleVersion.id=Vehicle.version"); pstmt.executeQuery(); ResultSet rs = pstmt.getResultSet(); - while (rs.next()) { - Vehicle vehicle = - Vehicle.builder() - .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").replace("-", "_"))) - .build(); - result.add(vehicle); - } + while (rs.next()) result.add(vehicleFromRS(rs)); + } catch (SQLException e) { throw new PersistenceException("Die Werte konnten nicht geladen werden.", e); } finally { @@ -142,6 +132,40 @@ public class VehicleDatabaseDao implements VehicleDAO { return result; } + @Override + public Vehicle get(long id) throws ElementNotFoundException, PersistenceException { + String sql = + "SELECT a.id, b.name, b.constructionType, b.type, a.status, b.hasNef" + + " FROM Vehicle a" + + " INNER JOIN VehicleVersion b" + + " ON version = b.id" + + " WHERE a.id = ?"; + + try { + Connection con = jdbcConnectionManager.getConnection(); + try (PreparedStatement pstmt = con.prepareStatement(sql); + ResultSet rs = pstmt.executeQuery()) { + + if (!rs.first()) throw new ElementNotFoundException("No such vehicle exists"); + + return vehicleFromRS(rs); + } + } catch (SQLException e) { + throw new PersistenceException(e); + } + } + @Override public void remove(long id) throws ElementNotFoundException, PersistenceException {} + + private Vehicle vehicleFromRS(ResultSet rs) throws SQLException { + return Vehicle.builder() + .id(rs.getLong("id")) + .name(rs.getString("name")) + .constructionType(ConstructionType.valueOf(rs.getString("constructionType"))) + .type(VehicleType.valueOf(rs.getString("type"))) + .status(Status.valueOf(rs.getString("constructionType"))) + .hasNef(rs.getBoolean("hasNef")) + .build(); + } } 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 a267b6f..8203ef3 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 @@ -1,15 +1,15 @@ 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.dao.VehicleDAO; 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.ElementNotFoundException; 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; @@ -22,36 +22,31 @@ public class RegistrationServiceImpl implements RegistrationService { private static final Logger LOG = LoggerFactory.getLogger(RegistrationServiceImpl.class); private final RegistrationDAO registrationDAO; - private final VehicleService vehicleService; + private final VehicleDAO vehicleDAO; @Autowired - public RegistrationServiceImpl(RegistrationDAO registrationDAO, VehicleService vehicleService) { + public RegistrationServiceImpl(RegistrationDAO registrationDAO, VehicleDAO vehicleDAO) { this.registrationDAO = registrationDAO; - this.vehicleService = vehicleService; + this.vehicleDAO = vehicleDAO; } @Override 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 (vehicleId <= 0) throw new InvalidVehicleException("VehicleId invalid"); - if (vehicle == null) { - throw new ServiceException("no vehicle with this id"); - } - - RegistrationValidator.validate(vehicle, registrations); try { + Vehicle vehicle = vehicleDAO.get(vehicleId); + + RegistrationValidator.validate(vehicle, registrations); + return registrationDAO.add(vehicle.id(), registrations); } catch (PersistenceException e) { LOG.warn("PersistenceException caught, throwing matching ServiceException"); throw new ServiceException(e); + } catch (ElementNotFoundException e) { + throw new InvalidVehicleException(e); } } -- cgit v1.2.3-70-g09d2 From 41f094201aaeb573968d2b96b9dc6760e0c5aedc Mon Sep 17 00:00:00 2001 From: Tharre Date: Sat, 12 May 2018 01:58:06 +0200 Subject: Fix DBUnit's enums and revert database changes --- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 4 +- src/main/resources/sql/database.sql | 20 +- .../employee/EmployeePersistenceTest.java | 213 +++++++++------------ 3 files changed, 101 insertions(+), 136 deletions(-) (limited to 'src/main/java') 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 8f0d28b..3e8c0fc 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 @@ -162,9 +162,9 @@ public class VehicleDatabaseDao implements VehicleDAO { return Vehicle.builder() .id(rs.getLong("id")) .name(rs.getString("name")) - .constructionType(ConstructionType.valueOf(rs.getString("constructionType"))) + .constructionType(ConstructionType.values()[rs.getInt("constructionType")]) .type(VehicleType.valueOf(rs.getString("type"))) - .status(Status.valueOf(rs.getString("constructionType"))) + .status(Status.values()[rs.getInt("status")]) .hasNef(rs.getBoolean("hasNef")) .build(); } diff --git a/src/main/resources/sql/database.sql b/src/main/resources/sql/database.sql index 4f3adf7..ddedeac 100644 --- a/src/main/resources/sql/database.sql +++ b/src/main/resources/sql/database.sql @@ -1,30 +1,26 @@ CREATE TABLE IF NOT EXISTS VehicleVersion ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, - constructionType VARCHAR NOT NULL, - type VARCHAR NOT NULL, + constructionType ENUM('NORMAL', 'HOCHDACH', 'MITTELHOCHDACH') NOT NULL, + type ENUM('BKTW', 'KTW_B', 'KTW', 'RTW', 'NEF', 'NAH') 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 VARCHAR 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), - 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 VARCHAR NOT NULL, + educationLevel ENUM('RS', 'NFS', 'NKV', 'NKA', 'NKI', 'NA') 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 ( @@ -47,13 +43,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 VARCHAR NOT NULL, + severity ENUM('A', 'B', 'C', 'D', 'E', 'O') NOT NULL, created TIMESTAMP NOT NULL, destination VARCHAR(100) NOT NULL, additionalInfo VARCHAR(100), - status VARCHAR NOT NULL, - CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O'), - CHECK status IN ('ACTIVE', 'COMPLETED', 'CANCELLED') + status ENUM('ACTIVE', 'COMPLETED', 'CANCELLED'), ); CREATE TABLE IF NOT EXISTS VehicleOperation ( 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 index f8fe0f3..e8d0d4d 100644 --- 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 @@ -1,155 +1,126 @@ 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.io.InputStream; +import java.sql.Types; import java.time.LocalDate; -import java.time.format.DateTimeFormatter; import java.util.List; -import org.dbunit.IDatabaseTester; -import org.dbunit.JdbcDatabaseTester; +import org.dbunit.DBTestCase; +import org.dbunit.PropertiesBasedJdbcDatabaseTester; +import org.dbunit.database.DatabaseConfig; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.datatype.DataType; +import org.dbunit.dataset.datatype.DataTypeException; import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; -import org.dbunit.operation.DatabaseOperation; -import org.h2.tools.RunScript; +import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -public class EmployeePersistenceTest { +public class EmployeePersistenceTest extends DBTestCase { 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 static final String JDBC_URL = + "jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; 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); + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, JDBC_URL); } - @Before - public void importDataSet() throws Exception { - IDataSet dataSet = readDataSet(); - cleanlyInsert(dataSet); + @Override + protected IDataSet getDataSet() throws DataSetException { + InputStream res = + getClass().getClassLoader().getResourceAsStream("employeeServiceTestData.xml"); + return new FlatXmlDataSetBuilder().build(res); } - private IDataSet readDataSet() throws DataSetException { - return new FlatXmlDataSetBuilder() - .build( - getClass() - .getClassLoader() - .getResourceAsStream("employeeServiceTestData.xml")); + @Override + protected void setUpDatabaseConfig(DatabaseConfig config) { + PostgresqlDataTypeFactory factory = + new PostgresqlDataTypeFactory() { + @Override + public boolean isEnumType(String sqlTypeName) { + if (sqlTypeName.equalsIgnoreCase("enum")) return true; + + return super.isEnumType(sqlTypeName); + } + + @Override + public DataType createDataType(int sqlType, String sqlTypeName) + throws DataTypeException { + if (isEnumType(sqlTypeName)) { + sqlType = Types.VARCHAR; + } + + return super.createDataType(sqlType, sqlTypeName); + } + }; + + config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory); } - 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(); + public void testListEmployees() throws PersistenceException { + List employees = employeePersistence.list(); + + System.out.println(LocalDate.parse("2010-10-10")); + Employee empOne = + Employee.builder() + .id(1) + .name("Adam") + .birthday(LocalDate.parse("2010-10-10")) + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(false) + .build(); + + Employee empTwo = + Employee.builder() + .id(2) + .name("Max") + .birthday(LocalDate.parse("1990-11-11")) + .educationLevel(EducationLevel.NFS) + .isDriver(false) + .isPilot(false) + .build(); + + Employee empThree = + Employee.builder() + .id(3) + .name("Lisa") + .birthday(LocalDate.parse("1999-10-16")) + .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()); } - @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(); - } - } + public void testEmployeeListNoElement() throws PersistenceException { + List employees = employeePersistence.list(); + + Employee empOne = + Employee.builder() + .id(10) + .name("Adam") + .birthday(LocalDate.parse("2010-10-10")) + .educationLevel(EducationLevel.RS) + .isDriver(true) + .isPilot(false) + .build(); - @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(); - } + Assert.assertFalse(employees.contains(empOne)); } } -- cgit v1.2.3-70-g09d2 From c6f72ff5d177e7ab61015408b64cfa2bf6c8e25c Mon Sep 17 00:00:00 2001 From: Tharre Date: Sat, 12 May 2018 18:55:51 +0200 Subject: Change interfaces to use Set instead of List --- .../controller/RegistrationWindowController.java | 8 +++++--- .../groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 4 ++-- .../groupphase/einsatzverwaltung/dao/EmployeeDAO.java | 4 ++-- .../einsatzverwaltung/dao/EmployeeDatabaseDao.java | 8 ++++---- .../groupphase/einsatzverwaltung/dao/OperationDAO.java | 4 ++-- .../groupphase/einsatzverwaltung/dao/RegistrationDAO.java | 4 ++-- .../einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 8 ++++---- .../groupphase/einsatzverwaltung/dao/VehicleDAO.java | 4 ++-- .../groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java | 8 ++++---- .../groupphase/einsatzverwaltung/dto/Operation.java | 6 +++--- .../einsatzverwaltung/dto/RegistrationValidator.java | 3 ++- .../einsatzverwaltung/service/EmployeeService.java | 4 ++-- .../einsatzverwaltung/service/EmployeeServiceImpl.java | 4 ++-- .../einsatzverwaltung/service/OperationService.java | 10 +++++----- .../einsatzverwaltung/service/OperationServiceImpl.java | 12 ++++++------ .../einsatzverwaltung/service/RegistrationService.java | 4 ++-- .../einsatzverwaltung/service/RegistrationServiceImpl.java | 4 ++-- .../groupphase/einsatzverwaltung/service/VehicleService.java | 4 ++-- .../einsatzverwaltung/service/VehicleServiceImpl.java | 8 ++++---- .../userInterface/CreateOperationController.java | 4 ++-- .../einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java | 10 +++++----- .../service/RegistrationServiceImplTest.java | 8 ++++---- .../groupphase/employee/EmployeePersistenceTest.java | 6 +++--- .../groupphase/operation/OperationServiceUnitTest.java | 12 ++++++------ 24 files changed, 77 insertions(+), 74 deletions(-) (limited to 'src/main/java') 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 bf413bb..9ed6147 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 @@ -15,8 +15,10 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; import java.util.EnumSet; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -78,7 +80,7 @@ public class RegistrationWindowController { public void initialize() { // will have to be replaced for FlowPane try { - List vehicles = vehicleService.list(EnumSet.of(Status.ABGEMELDET)); + Set vehicles = vehicleService.list(EnumSet.of(Status.ABGEMELDET)); tcVehicles.setCellValueFactory(x -> new SimpleStringProperty(x.getValue().name())); tvVehicles.setItems(FXCollections.observableArrayList(vehicles)); } catch (ServiceException e) { @@ -92,7 +94,7 @@ public class RegistrationWindowController { alert.show(); } try { - List employees = employeeService.list(); + Set employees = employeeService.list(); tcEmployees.setCellValueFactory(x -> new SimpleStringProperty(x.getValue().name())); tvEmployees.setItems(FXCollections.observableArrayList(employees)); } catch (ServiceException e) { @@ -147,7 +149,7 @@ public class RegistrationWindowController { public void create() { LOG.debug("Create Button clicked"); - List registrations = new LinkedList<>(); + Set registrations = new HashSet<>(); for (Employee employee : chosenEmployees) { registrations.add( 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 672424a..1423240 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 @@ -10,7 +10,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.EnumSet; -import java.util.List; +import java.util.Set; public class DBOperationDAO implements OperationDAO { @@ -118,7 +118,7 @@ public class DBOperationDAO implements OperationDAO { } @Override - public List list(EnumSet statuses) throws PersistenceException { + public Set list(EnumSet statuses) throws PersistenceException { return null; } 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 index 564ce7c..539a8e5 100644 --- 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 @@ -3,7 +3,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.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import java.util.List; +import java.util.Set; public interface EmployeeDAO { @@ -31,7 +31,7 @@ public interface EmployeeDAO { * @return list containing all stored employees * @throws PersistenceException if loading the stored employees failed */ - List list() throws PersistenceException; + Set list() throws PersistenceException; /** * Remove employee with the given id from the store. 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 3e4ba12..8da79e7 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 @@ -11,8 +11,8 @@ 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 java.util.HashSet; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; @@ -89,12 +89,12 @@ public class EmployeeDatabaseDao implements EmployeeDAO { } @Override - public List list() throws PersistenceException { + public Set list() throws PersistenceException { try { ResultSet rs = listEmployee.executeQuery(); - List employees = new ArrayList<>(); + Set employees = new HashSet<>(); while (rs.next()) { Employee employee = 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 dd1a189..da90cc8 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 @@ -5,7 +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 java.util.EnumSet; -import java.util.List; +import java.util.Set; public interface OperationDAO { @@ -44,7 +44,7 @@ public interface OperationDAO { * @return list containing all matched operations * @throws PersistenceException if loading the stored operations failed */ - List list(EnumSet statuses) throws PersistenceException; + Set 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/dao/RegistrationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAO.java index ba8f909..36b6f1b 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,7 +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; +import java.util.Set; public interface RegistrationDAO { @@ -15,7 +15,7 @@ public interface RegistrationDAO { * @return a list of the ids that were assigned * @throws PersistenceException if the registration could not be persisted */ - List add(long vehicleId, List registrations) throws PersistenceException; + Set add(long vehicleId, Set registrations) throws PersistenceException; /** * Make registration with the given id inactive. 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 8fbcd18..13aeffc 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 @@ -10,8 +10,8 @@ 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 java.util.HashSet; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -47,9 +47,9 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { } @Override - public List add(long vehicleId, List registrations) + public Set add(long vehicleId, Set registrations) throws PersistenceException { - List returnValues = new LinkedList<>(); + Set returnValues = new HashSet<>(); try { connection.setAutoCommit(false); for (Registration registration : registrations) { 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 index 2f0df44..5782fd9 100644 --- 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 @@ -3,7 +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.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import java.util.List; +import java.util.Set; public interface VehicleDAO { @@ -31,7 +31,7 @@ public interface VehicleDAO { * @return list containing all stored vehicles * @throws PersistenceException if loading the stored vehicles failed */ - List list() throws PersistenceException; + Set list() throws PersistenceException; /** * Returns the vehicle with the given id. 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 3e8c0fc..dfdc04c 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 @@ -11,8 +11,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.LinkedList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import org.springframework.stereotype.Repository; @Repository @@ -103,9 +103,9 @@ public class VehicleDatabaseDao implements VehicleDAO { public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException {} @Override - public List list() throws PersistenceException { + public Set list() throws PersistenceException { PreparedStatement pstmt = null; - List result = new LinkedList<>(); + Set result = new HashSet<>(); try { pstmt = jdbcConnectionManager 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 6641437..d33995f 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 @@ -2,7 +2,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; import com.google.auto.value.AutoValue; import java.time.Instant; -import java.util.List; +import java.util.Set; import javax.annotation.Nullable; @AutoValue @@ -30,7 +30,7 @@ public abstract class Operation { public abstract Status status(); - public abstract List vehicles(); + public abstract Set vehicles(); @Nullable public abstract Instant created(); @@ -53,7 +53,7 @@ public abstract class Operation { public abstract Builder status(Status status); - public abstract Builder vehicles(List vehicles); + public abstract Builder vehicles(Set vehicles); public abstract Builder created(Instant created); 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 295b615..610426c 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 @@ -7,6 +7,7 @@ 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; @@ -16,7 +17,7 @@ public class RegistrationValidator { private RegistrationValidator() {} - public static void validate(Vehicle vehicle, List registrations) + public static void validate(Vehicle vehicle, Set registrations) throws InvalidVehicleException, InvalidRegistrationException { /* Vehicles and Employees are assumed to be valid. 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 index 8753504..f7f8e71 100644 --- 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 @@ -3,7 +3,7 @@ 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; +import java.util.Set; public interface EmployeeService { @@ -33,7 +33,7 @@ public interface EmployeeService { * @return list containing all stored employees * @throws ServiceException if loading the stored employees failed */ - List list() throws ServiceException; + Set list() throws ServiceException; /** * Remove employee with the given id from the store. 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 ed0fb1c..b4119b0 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 @@ -6,7 +6,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.EmployeeVal import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.util.List; +import java.util.Set; import org.springframework.stereotype.Service; @Service @@ -35,7 +35,7 @@ public class EmployeeServiceImpl implements EmployeeService { } @Override - public List list() throws ServiceException { + public Set list() throws ServiceException { try { return employeePersistence.list(); 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 index e21c10b..98a2068 100644 --- 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 @@ -7,8 +7,8 @@ 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.ServiceException; import java.util.EnumSet; -import java.util.List; -import javafx.collections.transformation.SortedList; +import java.util.Set; +import java.util.SortedSet; public interface OperationService { @@ -32,7 +32,7 @@ public interface OperationService { * @throws ServiceException if the vehicles could not be loaded or the operation could not be * persisted */ - void requestVehicles(long operationId, List vehicleIds) + void requestVehicles(long operationId, Set vehicleIds) throws InvalidOperationException, InvalidVehicleException, ServiceException; /** @@ -56,7 +56,7 @@ public interface OperationService { * @throws InvalidOperationException if the operationId is invalid or does not exist * @throws ServiceException if loading the stored vehicles failed */ - SortedList rankVehicles(long operationId) + SortedSet rankVehicles(long operationId) throws InvalidOperationException, ServiceException; /** @@ -66,5 +66,5 @@ public interface OperationService { * @return list containing all matched operations * @throws ServiceException if loading the stored operations failed */ - List list(EnumSet statuses) throws ServiceException; + Set list(EnumSet statuses) throws ServiceException; } 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 05a548c..7b69886 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,8 +10,8 @@ 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; +import java.util.Set; +import java.util.SortedSet; public class OperationServiceImpl implements OperationService { @@ -24,7 +24,7 @@ public class OperationServiceImpl implements OperationService { @Override public long add(Operation operation) throws InvalidOperationException, ServiceException { - List vehicles = operation.vehicles(); + Set vehicles = operation.vehicles(); boolean rtw = false; if (faultyInput(operation.opCode())) { throw new InvalidOperationException("Code ist ungültig!"); @@ -111,7 +111,7 @@ public class OperationServiceImpl implements OperationService { } @Override - public void requestVehicles(long operationId, List vehicleIds) + public void requestVehicles(long operationId, Set vehicleIds) throws InvalidOperationException, InvalidVehicleException, ServiceException {} @Override @@ -119,13 +119,13 @@ public class OperationServiceImpl implements OperationService { throws InvalidOperationException, ServiceException {} @Override - public SortedList rankVehicles(long operationId) + public SortedSet rankVehicles(long operationId) throws InvalidOperationException, ServiceException { return null; } @Override - public List list(EnumSet statuses) throws ServiceException { + public Set list(EnumSet statuses) throws ServiceException { return null; } } 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 c345a2b..b7d8eef 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,7 +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; +import java.util.Set; public interface RegistrationService { @@ -18,7 +18,7 @@ public interface RegistrationService { * @throws InvalidRegistrationException if the registration is invalid * @throws ServiceException if the registration could not be persisted */ - List add(long vehicleId, List registrations) + Set add(long vehicleId, Set 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 8203ef3..54d46e7 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 @@ -10,7 +10,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidRegistrationExce 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 java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +31,7 @@ public class RegistrationServiceImpl implements RegistrationService { } @Override - public List add(long vehicleId, List registrations) + public Set add(long vehicleId, Set registrations) throws InvalidVehicleException, InvalidRegistrationException, ServiceException { if (vehicleId <= 0) throw new InvalidVehicleException("VehicleId invalid"); 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 index 6a96bc5..fe09ca1 100644 --- 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 @@ -5,7 +5,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Sta 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 java.util.Set; public interface VehicleService { @@ -36,7 +36,7 @@ public interface VehicleService { * @return list containing all stored vehicles * @throws ServiceException if loading the stored vehicles failed */ - List list(EnumSet statuses) throws ServiceException; + Set list(EnumSet statuses) throws ServiceException; /** * Remove vehicle with the given id from the store. 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 bbe668b..92386e1 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 @@ -8,7 +8,7 @@ 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 java.util.Set; import java.util.stream.Collectors; import org.springframework.stereotype.Service; @@ -73,13 +73,13 @@ public class VehicleServiceImpl implements VehicleService { } @Override - public List list(EnumSet statuses) throws ServiceException { + public Set list(EnumSet statuses) throws ServiceException { if (statuses == null) { throw new ServiceException("statuses may not be null"); } - List vehicles; + Set vehicles; try { vehicles = vehiclePersistence.list(); @@ -89,7 +89,7 @@ public class VehicleServiceImpl implements VehicleService { return vehicles.stream() .filter(vehicle -> statuses.contains(vehicle.status())) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); } @Override 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 5b645f3..7b04efe 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 @@ -17,7 +17,7 @@ import java.lang.invoke.MethodHandles; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; -import java.util.List; +import java.util.Set; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -170,7 +170,7 @@ public class CreateOperationController { .created(Instant.now()) .opCode(txtCode.getText()) .status(Status.ACTIVE) - .vehicles(List.of(vehicles)) + .vehicles(Set.of(vehicles)) .severity(Severity.A) .build(); try { 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 03059ff..09699c5 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 @@ -11,8 +11,8 @@ 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 java.util.HashSet; +import java.util.Set; import org.h2.tools.RunScript; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -79,7 +79,7 @@ public class RegistrationDatabaseDAOTest { @Test public void addRegistrationsShouldSucceed() throws PersistenceException { - List registrations = new LinkedList<>(); + Set registrations = new HashSet<>(); /* Vehicle vehicle = Vehicle.builder() .id(1) @@ -139,14 +139,14 @@ public class RegistrationDatabaseDAOTest { registrations.add(registration2); registrations.add(registration3); - List returnvalues = registrationDAO.add(1, registrations); + Set 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<>(); + Set registrations = new HashSet<>(); Employee employee = Employee.builder() .id(1) 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 88642ee..95d8d77 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 @@ -21,8 +21,8 @@ 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 java.util.HashSet; +import java.util.Set; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -60,7 +60,7 @@ public class RegistrationServiceImplTest { throws InvalidRegistrationException, ServiceException, InvalidVehicleException { RegistrationService registrationService = new RegistrationServiceImpl(registrationDAO, vehicleDAO); - List registrations = new LinkedList<>(); + Set registrations = new HashSet<>(); Vehicle vehicle = Vehicle.builder() .id(1) @@ -117,7 +117,7 @@ public class RegistrationServiceImplTest { thrown.expect(InvalidRegistrationException.class); RegistrationService registrationService = new RegistrationServiceImpl(registrationDAO, vehicleDAO); - List registrations = new LinkedList<>(); + Set registrations = new HashSet<>(); Vehicle vehicle = Vehicle.builder() .id(1) 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 index e8d0d4d..5099976 100644 --- 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 @@ -9,7 +9,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; import java.io.InputStream; import java.sql.Types; import java.time.LocalDate; -import java.util.List; +import java.util.Set; import org.dbunit.DBTestCase; import org.dbunit.PropertiesBasedJdbcDatabaseTester; import org.dbunit.database.DatabaseConfig; @@ -69,7 +69,7 @@ public class EmployeePersistenceTest extends DBTestCase { } public void testListEmployees() throws PersistenceException { - List employees = employeePersistence.list(); + Set employees = employeePersistence.list(); System.out.println(LocalDate.parse("2010-10-10")); Employee empOne = @@ -109,7 +109,7 @@ public class EmployeePersistenceTest extends DBTestCase { } public void testEmployeeListNoElement() throws PersistenceException { - List employees = employeePersistence.list(); + Set employees = employeePersistence.list(); Employee empOne = Employee.builder() 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 index fc10553..2b1e2f0 100644 --- 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 @@ -19,7 +19,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationExcepti 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 java.util.Set; import org.junit.Assert; import org.junit.Test; @@ -51,7 +51,7 @@ public class OperationServiceUnitTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) - .vehicles(List.of(vehicle)) + .vehicles(Set.of(vehicle)) .build(); try { Assert.assertThat(operationService.add(operation), is(1L)); @@ -87,7 +87,7 @@ public class OperationServiceUnitTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) - .vehicles(List.of(vehicle, vehicle1)) + .vehicles(Set.of(vehicle, vehicle1)) .build(); try { Assert.assertThat(operationService.add(operation), is(1L)); @@ -106,7 +106,7 @@ public class OperationServiceUnitTest { .destination("Wiedner Hauptstraße 35, Wien") .additionalInfo("HTU Wien") .severity(Severity.B) - .vehicles(List.of()) + .vehicles(Set.of()) .build(); try { Assert.assertThat(operationService.add(operation), is(1L)); @@ -125,7 +125,7 @@ public class OperationServiceUnitTest { .destination("") .additionalInfo("HTU Wien") .severity(Severity.B) - .vehicles(List.of()) + .vehicles(Set.of()) .build(); try { Assert.assertThat(operationService.add(operation), is(1L)); @@ -144,7 +144,7 @@ public class OperationServiceUnitTest { .destination("Römergasse 7, 2500 Baden") .additionalInfo("HTU Wien") .severity(Severity.B) - .vehicles(List.of()) + .vehicles(Set.of()) .build(); try { Assert.assertThat(operationService.add(operation), is(1L)); -- cgit v1.2.3-70-g09d2 From 166ff610e62f0671f65a6fd27d4760f0881eb6f4 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Fri, 11 May 2018 16:17:42 +0200 Subject: UI Changes Main Window --- .../einsatzverwaltung/dto/Registration.java | 7 + .../ui/vehiclepane/VehiclePaneController.java | 23 ++- .../userInterface/CreateOperationController.java | 143 ++++++++-------- .../resources/fxml/CreateOperationController.fxml | 179 ++++++++++++--------- src/main/resources/fxml/vehiclePane.fxml | 51 +++--- src/main/resources/styles/main.css | 0 6 files changed, 226 insertions(+), 177 deletions(-) create mode 100644 src/main/resources/styles/main.css (limited to 'src/main/java') 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 8551266..93530bc 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 @@ -2,6 +2,7 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto; import com.google.auto.value.AutoValue; import java.time.Instant; +import java.util.Date; @AutoValue public abstract class Registration { @@ -17,6 +18,12 @@ public abstract class Registration { return new AutoValue_Registration.Builder().id(0); } + public boolean isActive() { + Instant now = (new Date()).toInstant(); + + return start().isBefore(now) && end().isAfter(now); + } + @AutoValue.Builder public abstract static class Builder { public abstract Builder id(long id); 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 2db6f37..29230f3 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,6 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.Ed 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; @@ -16,6 +14,7 @@ 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; @@ -35,11 +34,16 @@ public class VehiclePaneController { } private Node rootElement; + private Vehicle data; public Node getRootElement() { return rootElement; } + public Vehicle getData() { + return data; + } + /** * * Set the displayed data of this VehiclePane. * @@ -52,23 +56,22 @@ public class VehiclePaneController { String constrType = vehicle.constructionType().name(); txtRooftype.setText( constrType.substring(0, 1).toUpperCase() + constrType.substring(1).toLowerCase()); - txtNumber.setText("" + vehicle.id()); + txtNumber.setText("-" + vehicle.id()); if (vehicle.hasNef()) { - ivNEF.setImage(new Image("../images/NEF.png")); + ivNEF.setImage(new Image("images/NEF.png")); txtNEF.setText("hat NEF-Halterung"); } else { - ivNEF.setImage(new Image("../images/NotNEF.png")); + 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)) + .filter(Registration::isActive) .map(reg -> reg.employee().educationLevel()) .max(EducationLevel::compareTo); @@ -80,5 +83,11 @@ public class VehiclePaneController { ivQualification.setVisible(false); ivQualification.setManaged(false); } + + this.data = vehicle; + } + + public void setSelected(boolean selected) { + // TODO } } 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 7b04efe..58874da 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,13 +1,19 @@ 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.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.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.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.ui.vehiclepane.VehiclePaneController; 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; @@ -15,10 +21,11 @@ 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.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; import java.util.LinkedList; import java.util.Set; -import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -27,10 +34,10 @@ 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 javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.FlowPane; import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,13 +53,14 @@ public class CreateOperationController { public TextField txtAddress; public TextField txtNote; public Button btnCreateOperation; - public ListView lvVehicles; public ListView lvActiveOperations; public Label lblChosenVehicles; - public LinkedList chosenVehicles = new LinkedList<>(); + public FlowPane fpVehicles; + + private LinkedList chosenVehicles = new LinkedList<>(); // TODO: Anders? - OperationService operationService = + private OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); private final VehicleService vehicleService; private final SpringFXMLLoader fxmlLoader; @@ -65,65 +73,55 @@ 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) { - boolean remove = false; - if (lvVehicles.getSelectionModel().getSelectedItem() == null) { - return; - } - for (Vehicle vehicle : chosenVehicles) { - if (lvVehicles.getSelectionModel().getSelectedItem().equals(vehicle)) { - remove = true; - break; - } - } - if (!remove) { - chosenVehicles.add(lvVehicles.getSelectionModel().getSelectedItem()); - - } else { - chosenVehicles.remove(lvVehicles.getSelectionModel().getSelectedItem()); - } - StringBuilder result = new StringBuilder(); - for (int i = 0; i < chosenVehicles.size(); i++) { - if (i == chosenVehicles.size() - 1) { - result.append(chosenVehicles.get(i).name()); - } else { - result.append(chosenVehicles.get(i).name()).append(", "); - } - } - if (result.toString().equals("")) { - lblChosenVehicles.setText("keine ausgewählt"); - } else { - lblChosenVehicles.setText(result.toString()); - } - } - }); } public void updateList() { try { - this.lvVehicles.setItems( - FXCollections.observableArrayList( - vehicleService.list( - EnumSet.of( - Vehicle.Status.FREI_FUNK, Vehicle.Status.FREI_WACHE)))); - } catch (ServiceException e) { + fpVehicles.getChildren().clear(); + List vehicles = vehicleService.list(); + + // TODO Remove debug + vehicles = testData(); + + for (Vehicle vehicle : vehicles) { + VehiclePaneController controller = VehiclePaneController.createVehiclePane(); + + controller.setData(vehicle, true); + controller + .getRootElement() + .setOnMouseClicked( + event -> { + if (event.getClickCount() == 2) { + if (chosenVehicles.contains(vehicle)) { + chosenVehicles.remove(vehicle); + controller.setSelected(false); + } else { + chosenVehicles.add(vehicle); + controller.setSelected(true); + } + + StringBuilder result = new StringBuilder(); + for (int i = 0; i < chosenVehicles.size(); i++) { + if (i == chosenVehicles.size() - 1) { + result.append(chosenVehicles.get(i).name()); + } else { + result.append(chosenVehicles.get(i).name()) + .append(", "); + } + } + if (result.toString().equals("")) { + lblChosenVehicles.setText("keine ausgewählt"); + } else { + lblChosenVehicles.setText(result.toString()); + } + } + }); + + fpVehicles.getChildren().add(controller.getRootElement()); + } + } catch (ServiceException | IOException e) { + LOG.error("Error while updating list.", e); + Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Fehler"); alert.setHeaderText("Fehler!"); @@ -132,14 +130,30 @@ public class CreateOperationController { } } - /*private LinkedList mylist() { + private LinkedList testData() { + Employee empl = + Employee.builder() + .birthday(LocalDate.MIN) + .isDriver(true) + .isPilot(true) + .educationLevel(EducationLevel.NKV) + .name("Hans Test") + .build(); + Registration reg = + Registration.builder() + .employee(empl) + .start(Instant.now().minus(1, ChronoUnit.HOURS)) + .end(Instant.now().plus(1, ChronoUnit.HOURS)) + .build(); + Vehicle vehicle = Vehicle.builder() .name("Test-KTW") .constructionType(ConstructionType.HOCHDACH) .type(VehicleType.KTW) .status(Vehicle.Status.FREI_WACHE) - .hasNef(true) + .hasNef(false) + .registrations(Arrays.asList(reg)) .build(); Vehicle vehicle1 = @@ -149,13 +163,14 @@ public class CreateOperationController { .type(VehicleType.NEF) .status(Vehicle.Status.FREI_FUNK) .hasNef(true) + .registrations(Arrays.asList(reg)) .build(); LinkedList list = new LinkedList<>(); list.add(vehicle); list.add(vehicle1); // this.lvVehicles.setItems(FXCollections.observableArrayList(list)); return list; - }*/ + } @FXML protected void createOperationClicked() { diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 086a5d1..18a1508 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -5,91 +5,114 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml index 8b1d194..38be664 100644 --- a/src/main/resources/fxml/vehiclePane.fxml +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -10,61 +10,56 @@ - + - - - - + + + + - - - - + + + + - + - + - + - + - + - - + + - + - - + + - + - - + + - + diff --git a/src/main/resources/styles/main.css b/src/main/resources/styles/main.css new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-70-g09d2 From 3990268905e3223276160e2a32c74d4f05d0796e Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Mon, 14 May 2018 16:31:12 +0200 Subject: Reworking MainWindow UI. --- .../ui/vehiclepane/VehiclePaneController.java | 5 +- .../resources/fxml/CreateOperationController.fxml | 153 ++++++++------------- src/main/resources/fxml/vehiclePane.fxml | 2 +- src/main/resources/styles/main.css | 28 ++++ 4 files changed, 90 insertions(+), 98 deletions(-) (limited to 'src/main/java') 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 29230f3..d0dcbae 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 @@ -88,6 +88,9 @@ public class VehiclePaneController { } public void setSelected(boolean selected) { - // TODO + rootElement.getStyleClass().clear(); + + if (selected) rootElement.getStyleClass().add("shadowed-yellow"); + else rootElement.getStyleClass().add("shadowed-white"); } } diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 18a1508..88fe26a 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -13,106 +13,67 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + fx:controller="at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.CreateOperationController" + stylesheets="@/styles/main.css"> + + + - + + - + - - + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml index 38be664..79cfaf9 100644 --- a/src/main/resources/fxml/vehiclePane.fxml +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -10,7 +10,7 @@ - + diff --git a/src/main/resources/styles/main.css b/src/main/resources/styles/main.css index e69de29..11a069e 100644 --- a/src/main/resources/styles/main.css +++ b/src/main/resources/styles/main.css @@ -0,0 +1,28 @@ +.shadowed-white { + -fx-background-color: white; + -fx-effect: dropshadow(gaussian, rgba(100,100,100,0.8), 5, 0, 0, 3); +} + +.shadowed-yellow { + -fx-background-color: #FFE699; + -fx-effect: dropshadow(gaussian, rgba(100,100,100,0.8), 5, 0, 0, 3); +} + +.text-big { + -fx-font-size: 18px; +} + +.text-medium { + -fx-font-size: 14px; +} + +.text-small { + -fx-font-size: 14px; +} + +.button { + -fx-background-radius: 0em; + -fx-background-color: darkgreen; + -fx-text-fill: white; + -fx-font-weight: bold; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From b01c84cc72fa21ba5c5e59ec65faa09c828139ba Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Wed, 16 May 2018 14:51:31 +0200 Subject: [#25958] Apply code formatting. Context Menu Label now bold and black while highlighted. Annotate stuff. --- .../einsatzverwaltung/dao/DBOperationDAO.java | 2 + .../service/OperationServiceImpl.java | 2 + .../userInterface/CreateOperationController.java | 132 ++++++++++++--------- src/main/resources/styles/main.css | 21 +++- 4 files changed, 100 insertions(+), 57 deletions(-) (limited to 'src/main/java') 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 1423240..476f968 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 @@ -11,7 +11,9 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.EnumSet; import java.util.Set; +import org.springframework.stereotype.Repository; +@Repository public class DBOperationDAO implements OperationDAO { private JDBCConnectionManager jdbcConnectionManager; 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 7b69886..a6be111 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 @@ -12,7 +12,9 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.EnumSet; import java.util.Set; import java.util.SortedSet; +import org.springframework.stereotype.Service; +@Service public class OperationServiceImpl implements OperationService { // TODO: anders? 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 58874da..446ca50 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,30 +1,25 @@ 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.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.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.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.ui.vehiclepane.VehiclePaneController; 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 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.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.EnumSet; import java.util.LinkedList; +import java.util.List; import java.util.Set; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -33,14 +28,18 @@ import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; import javafx.scene.control.ListView; +import javafx.scene.control.MenuItem; import javafx.scene.control.TextField; +import javafx.scene.input.MouseButton; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; 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 @@ -59,9 +58,7 @@ public class CreateOperationController { private LinkedList chosenVehicles = new LinkedList<>(); - // TODO: Anders? - private OperationService operationService = - new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); + @Autowired private OperationService operationService; private final VehicleService vehicleService; private final SpringFXMLLoader fxmlLoader; @@ -78,10 +75,7 @@ public class CreateOperationController { public void updateList() { try { fpVehicles.getChildren().clear(); - List vehicles = vehicleService.list(); - - // TODO Remove debug - vehicles = testData(); + Set vehicles = vehicleService.list(EnumSet.allOf(Vehicle.Status.class)); for (Vehicle vehicle : vehicles) { VehiclePaneController controller = VehiclePaneController.createVehiclePane(); @@ -91,7 +85,13 @@ public class CreateOperationController { .getRootElement() .setOnMouseClicked( event -> { - if (event.getClickCount() == 2) { + if (event.getButton().equals(MouseButton.SECONDARY)) { + createContextMenu(vehicle, vehicleService) + .show( + controller.getRootElement(), + event.getScreenX(), + event.getScreenY()); + } else { if (chosenVehicles.contains(vehicle)) { chosenVehicles.remove(vehicle); controller.setSelected(false); @@ -130,46 +130,68 @@ public class CreateOperationController { } } - private LinkedList testData() { - Employee empl = - Employee.builder() - .birthday(LocalDate.MIN) - .isDriver(true) - .isPilot(true) - .educationLevel(EducationLevel.NKV) - .name("Hans Test") - .build(); - Registration reg = - Registration.builder() - .employee(empl) - .start(Instant.now().minus(1, ChronoUnit.HOURS)) - .end(Instant.now().plus(1, ChronoUnit.HOURS)) - .build(); + private static ContextMenu createContextMenu(Vehicle data, VehicleService vehicleService) { + ContextMenu menu = new ContextMenu(); - Vehicle vehicle = - Vehicle.builder() - .name("Test-KTW") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.KTW) - .status(Vehicle.Status.FREI_WACHE) - .hasNef(false) - .registrations(Arrays.asList(reg)) - .build(); + for (Vehicle.Status status : Vehicle.Status.values()) { + if (status == Vehicle.Status.ABGEMELDET) { + continue; + } - Vehicle vehicle1 = - Vehicle.builder() - .name("Test-NEF") - .constructionType(ConstructionType.NORMAL) - .type(VehicleType.NEF) - .status(Vehicle.Status.FREI_FUNK) - .hasNef(true) - .registrations(Arrays.asList(reg)) - .build(); - LinkedList list = new LinkedList<>(); - list.add(vehicle); - list.add(vehicle1); - // this.lvVehicles.setItems(FXCollections.observableArrayList(list)); - return list; + MenuItem mi = new MenuItem(status.name()); + + if (status == Vehicle.Status.FREI_FUNK || status == Vehicle.Status.FREI_WACHE) { + mi.getStyleClass().add("mi-free"); + } else { + mi.getStyleClass().add("mi-other"); + } + + mi.setOnAction( + event -> { + try { + vehicleService.update(data.toBuilder().status(status).build()); + } catch (InvalidVehicleException | ServiceException e) { + LOG.error("Error while setting status.", e); + Alert a = new Alert(AlertType.ERROR, e.getMessage()); + a.show(); + } + }); + + menu.getItems().add(mi); + } + + MenuItem abmelden = new MenuItem("abmelden"); + + abmelden.setOnAction( + event -> { + try { + List registrations = data.registrations(); + assert registrations + != null; // Otherwise the element shouldn't be in the list. + + List newRegistrations = new ArrayList<>(); + + for (Registration registration : registrations) { + if (registration.isActive()) { + newRegistrations.add( + registration + .toBuilder() + .end(Instant.now().minus(1, ChronoUnit.SECONDS)) + .build()); + } else newRegistrations.add(registration); + } + + vehicleService.update( + data.toBuilder().registrations(newRegistrations).build()); + } catch (InvalidVehicleException | ServiceException e) { + LOG.error("Error while unregistering.", e); + Alert a = new Alert(AlertType.ERROR, e.getMessage()); + a.show(); + } + }); + + menu.getItems().add(abmelden); + return menu; } @FXML diff --git a/src/main/resources/styles/main.css b/src/main/resources/styles/main.css index c4af039..61634b6 100644 --- a/src/main/resources/styles/main.css +++ b/src/main/resources/styles/main.css @@ -27,6 +27,23 @@ -fx-font-weight: bold; } -.scroll-pane { - -fx-background-color:transparent; +.button-free-status { + -fx-background-color: #C5E0B4; +} + +.button-other-status { + -fx-background-color: #F8CBAD; +} + +.mi-free { + -fx-background-color: #C5E0B4; +} + +.mi-other { + -fx-background-color: #F8CBAD; +} + +.menu-item:focused .label { + -fx-text-fill: black; + -fx-font-weight: bold; } \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 4d28a72048d208cf2dfd3e34b5fb23a194975314 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Fri, 11 May 2018 16:17:42 +0200 Subject: UI Changes Main Window --- .../userInterface/CreateOperationController.java | 8 +- .../resources/fxml/CreateOperationController.fxml | 165 ++++++++++++--------- src/main/resources/fxml/vehiclePane.fxml | 2 +- 3 files changed, 103 insertions(+), 72 deletions(-) (limited to 'src/main/java') 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 446ca50..512087f 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,16 +1,19 @@ 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; 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.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.ui.vehiclepane.VehiclePaneController; 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 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; @@ -39,7 +42,6 @@ import javafx.scene.layout.FlowPane; 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 @@ -58,7 +60,9 @@ public class CreateOperationController { private LinkedList chosenVehicles = new LinkedList<>(); - @Autowired private OperationService operationService; + // TODO: Anders? + private OperationService operationService = + new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); private final VehicleService vehicleService; private final SpringFXMLLoader fxmlLoader; diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 54e08b0..18a1508 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -10,82 +10,109 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/vehiclePane.fxml b/src/main/resources/fxml/vehiclePane.fxml index 79cfaf9..38be664 100644 --- a/src/main/resources/fxml/vehiclePane.fxml +++ b/src/main/resources/fxml/vehiclePane.fxml @@ -10,7 +10,7 @@ - + -- cgit v1.2.3-70-g09d2 From 07c485c63e94e7508bad2ec2c7b385f5a102f720 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Mon, 14 May 2018 19:21:54 +0200 Subject: StatusMenu --- .../einsatzverwaltung/controller/StatusMenuController.java | 13 +++++++++++++ src/main/resources/fxml/statusMenu.fxml | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java create mode 100644 src/main/resources/fxml/statusMenu.fxml (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java new file mode 100644 index 0000000..50f4359 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java @@ -0,0 +1,13 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.controller; + +import java.net.URL; +import java.util.ResourceBundle; +import javafx.fxml.Initializable; + +public class StatusMenuController implements Initializable { + + @Override + public void initialize(URL location, ResourceBundle resources) { + + } +} diff --git a/src/main/resources/fxml/statusMenu.fxml b/src/main/resources/fxml/statusMenu.fxml new file mode 100644 index 0000000..57b152a --- /dev/null +++ b/src/main/resources/fxml/statusMenu.fxml @@ -0,0 +1,9 @@ + + + + + + -- cgit v1.2.3-70-g09d2 From 3f84016b6f9136f8d877e15ace1b214ea67c75b2 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Tue, 15 May 2018 12:10:59 +0200 Subject: Status menu FXML & Controller --- .../controller/StatusMenuController.java | 32 ++++++++++++++++++++++ .../groupphase/einsatzverwaltung/dto/Vehicle.java | 2 +- .../resources/fxml/CreateOperationController.fxml | 3 +- src/main/resources/fxml/statusMenu.fxml | 20 +++++++++++--- src/main/resources/styles/main.css | 17 ++++++++++++ 5 files changed, 68 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java index 50f4359..d4e5b04 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/StatusMenuController.java @@ -1,13 +1,45 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.controller; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; import java.net.URL; import java.util.ResourceBundle; +import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.geometry.Insets; +import javafx.scene.control.Button; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.VBox; +import org.springframework.stereotype.Controller; +@Controller public class StatusMenuController implements Initializable { + @FXML + private VBox vboxMain; + @Override public void initialize(URL location, ResourceBundle resources) { + for (Status status : Status.values()) { + if (status == Status.ABGEMELDET) { + continue; + } + + Button btn = new Button(status.name()); + + btn.setPrefWidth(Double.MAX_VALUE); + btn.setPadding(new Insets(6)); + if (status == Status.FREI_FUNK || status == Status.FREI_WACHE) { + btn.getStyleClass().add("button-free-status"); + } else { + btn.getStyleClass().add("button-other-status"); + } + btn.getStyleClass().add("text-medium"); + + vboxMain.getChildren().add(vboxMain.getChildren().size() - 1, btn); + } + } + public void unregister(MouseEvent mouseEvent) { + //TODO } } 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 84d9c92..e81db0b 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 @@ -24,11 +24,11 @@ public abstract class Vehicle { public enum Status { ABGEMELDET, FREI_WACHE, + FREI_FUNK, ZUM_BERUFUNGSORT, AM_BERUFUNGSORT, ZUM_ZIELORT, AM_ZIELORT, - FREI_FUNK, } public abstract long id(); diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 88fe26a..cb8239d 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -45,7 +45,7 @@ text="Fahrzeuge:" styleClass="text-medium"/>