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 ++++++------- .../service/RegistrationServiceImplTest.java | 36 ++++++++-------- 4 files changed, 77 insertions(+), 48 deletions(-) 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); } } 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 f3efbef..88642ee 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceImplTest.java @@ -1,23 +1,26 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; -import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; 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.Employee; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Builder; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.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.time.Instant; import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; import org.junit.Before; @@ -31,35 +34,32 @@ import org.mockito.junit.MockitoRule; public class RegistrationServiceImplTest { - @Mock RegistrationDAO daoMock; + @Mock private RegistrationDAO registrationDAO; - @Mock VehicleService vehicleService; + @Mock private VehicleDAO vehicleDAO; @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Rule public ExpectedException thrown = ExpectedException.none(); @Before - public void setUp() throws ServiceException { + public void setUp() throws ElementNotFoundException, PersistenceException { MockitoAnnotations.initMocks(this); - when(vehicleService.list(any())) - .thenReturn( - Arrays.asList( - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .status(Status.ABGEMELDET) - .type(VehicleType.RTW) - .hasNef(true) - .build())); + Builder b = + Vehicle.builder() + .name("RTW-1") + .constructionType(ConstructionType.HOCHDACH) + .status(Status.ABGEMELDET) + .type(VehicleType.RTW) + .hasNef(true); + when(vehicleDAO.get(anyLong())).thenAnswer(ans -> b.id(ans.getArgument(0)).build()); } @Test public void addValidRegistrationsShouldSucceed() throws InvalidRegistrationException, ServiceException, InvalidVehicleException { RegistrationService registrationService = - new RegistrationServiceImpl(daoMock, vehicleService); + new RegistrationServiceImpl(registrationDAO, vehicleDAO); List registrations = new LinkedList<>(); Vehicle vehicle = Vehicle.builder() @@ -116,7 +116,7 @@ public class RegistrationServiceImplTest { throws InvalidRegistrationException, ServiceException, InvalidVehicleException { thrown.expect(InvalidRegistrationException.class); RegistrationService registrationService = - new RegistrationServiceImpl(daoMock, vehicleService); + new RegistrationServiceImpl(registrationDAO, vehicleDAO); List registrations = new LinkedList<>(); Vehicle vehicle = Vehicle.builder() -- cgit v1.2.3-70-g09d2 From d9b90441bc0723abb23f85f54d5b8d64a285d982 Mon Sep 17 00:00:00 2001 From: Tharre Date: Fri, 11 May 2018 22:58:31 +0200 Subject: Change Intellij db location to the new ./sepm one --- .idea/dataSources.xml | 4 ++-- .idea/sqldialects.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index f8c1056..9b90d71 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,11 +1,11 @@ - + h2.unified true org.h2.Driver - jdbc:h2:~/bev + jdbc:h2:$PROJECT_DIR$/sepm \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 7562c0f..1605aa7 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file -- 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(-) 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(-) 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 605cbd804d558de5085f4c3889c70fc56c1953c8 Mon Sep 17 00:00:00 2001 From: Tharre Date: Sun, 13 May 2018 23:53:30 +0200 Subject: Extract dbunit JDBC modifications to JdbcTestCase --- .../employee/EmployeePersistenceTest.java | 45 ++----------------- .../assignment/groupphase/util/JdbcTestCase.java | 50 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java 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 5099976..d4f5646 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 @@ -5,35 +5,21 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDat 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 at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; import java.io.InputStream; -import java.sql.Types; import java.time.LocalDate; import java.util.Set; -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.ext.postgresql.PostgresqlDataTypeFactory; import org.junit.Assert; -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;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; +public class EmployeePersistenceTest extends JdbcTestCase { private EmployeeDAO employeePersistence; public EmployeePersistenceTest() throws PersistenceException { - employeePersistence = new EmployeeDatabaseDao(new JDBCConnectionManager(JDBC_URL)); - - System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); - System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, JDBC_URL); + employeePersistence = new EmployeeDatabaseDao(jdbcConnectionManager); } @Override @@ -43,31 +29,6 @@ public class EmployeePersistenceTest extends DBTestCase { return new FlatXmlDataSetBuilder().build(res); } - @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); - } - public void testListEmployees() throws PersistenceException { Set employees = employeePersistence.list(); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java new file mode 100644 index 0000000..5390841 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java @@ -0,0 +1,50 @@ +package at.ac.tuwien.sepm.assignment.groupphase.util; + +import java.sql.Types; +import org.dbunit.DBTestCase; +import org.dbunit.PropertiesBasedJdbcDatabaseTester; +import org.dbunit.database.DatabaseConfig; +import org.dbunit.dataset.datatype.DataType; +import org.dbunit.dataset.datatype.DataTypeException; +import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; + +public abstract class JdbcTestCase extends DBTestCase { + + private static final String JDBC_DRIVER = "org.h2.Driver"; + private static final String JDBC_URL = + "jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; + + protected final JDBCConnectionManager jdbcConnectionManager; + + protected JdbcTestCase() { + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, JDBC_URL); + + jdbcConnectionManager = new JDBCConnectionManager(JDBC_URL); + } + + @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); + } +} -- cgit v1.2.3-70-g09d2 From 8e0abdfcbc798c8ed0f85af1f641d58d341fe83a Mon Sep 17 00:00:00 2001 From: Tharre Date: Mon, 21 May 2018 15:21:43 +0200 Subject: JdbcTestCase changed to work with Junit 4 --- .../employee/EmployeePersistenceTest.java | 2 +- .../assignment/groupphase/util/JdbcTestCase.java | 101 +++++++++++++++++++-- 2 files changed, 92 insertions(+), 11 deletions(-) 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 d4f5646..71af3bd 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 @@ -19,7 +19,7 @@ public class EmployeePersistenceTest extends JdbcTestCase { private EmployeeDAO employeePersistence; public EmployeePersistenceTest() throws PersistenceException { - employeePersistence = new EmployeeDatabaseDao(jdbcConnectionManager); + employeePersistence = new EmployeeDatabaseDao(getJdbcConnectionManager()); } @Override diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java index 5390841..dae93ff 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java @@ -1,30 +1,87 @@ package at.ac.tuwien.sepm.assignment.groupphase.util; +import java.lang.invoke.MethodHandles; +import java.sql.SQLException; import java.sql.Types; -import org.dbunit.DBTestCase; -import org.dbunit.PropertiesBasedJdbcDatabaseTester; +import org.dbunit.DefaultDatabaseTester; +import org.dbunit.IDatabaseTester; +import org.dbunit.IOperationListener; import org.dbunit.database.DatabaseConfig; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.datatype.DataType; import org.dbunit.dataset.datatype.DataTypeException; import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; +import org.dbunit.operation.DatabaseOperation; +import org.junit.After; +import org.junit.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; -public abstract class JdbcTestCase extends DBTestCase { +@Component +public abstract class JdbcTestCase { - private static final String JDBC_DRIVER = "org.h2.Driver"; + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String JDBC_URL = "jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; - protected final JDBCConnectionManager jdbcConnectionManager; + private IDatabaseTester dbTester; + private IDatabaseConnection connection; + private IOperationListener operationListener; + private JDBCConnectionManager jdbcConnectionManager; protected JdbcTestCase() { - System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); - System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, JDBC_URL); - jdbcConnectionManager = new JDBCConnectionManager(JDBC_URL); } - @Override - protected void setUpDatabaseConfig(DatabaseConfig config) { + protected abstract IDataSet getDataSet() throws Exception; + + protected JDBCConnectionManager getJdbcConnectionManager() { + return jdbcConnectionManager; + } + + protected IDatabaseConnection getConnection() throws Exception { + if (connection == null) + connection = new DatabaseConnection(jdbcConnectionManager.getConnection(), null, true); + + return connection; + } + + private IOperationListener getOperationListener() { + if (operationListener == null) { + operationListener = + new IOperationListener() { + @Override + public void connectionRetrieved(IDatabaseConnection connection) { + setUpDatabaseConfig(connection.getConfig()); + } + + @Override + public void operationSetUpFinished(IDatabaseConnection connection) { + LOG.debug("operationSetUpFinished(connection={}) - start", connection); + } + + @Override + public void operationTearDownFinished(IDatabaseConnection connection) { + LOG.debug( + "operationTearDownFinished(connection={}) - start", connection); + try { + connection.close(); + } catch (SQLException e) { + LOG.error("Failed to close connection:" + e); + e.printStackTrace(); + } + } + }; + } + + return operationListener; + } + + // override DBUnit's enum handling + private void setUpDatabaseConfig(DatabaseConfig config) { PostgresqlDataTypeFactory factory = new PostgresqlDataTypeFactory() { @Override @@ -47,4 +104,28 @@ public abstract class JdbcTestCase extends DBTestCase { config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory); } + + @Before + public void setUp() throws Exception { + IDataSet dataSet = getDataSet(); + + dbTester = new DefaultDatabaseTester(getConnection()); + getOperationListener().connectionRetrieved(getConnection()); + + dbTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT); + dbTester.setTearDownOperation(DatabaseOperation.NONE); + dbTester.setDataSet(dataSet); + dbTester.setOperationListener(getOperationListener()); + dbTester.onSetup(); + } + + @After + public void tearDown() throws Exception { + try { + dbTester.onTearDown(); + getConnection().close(); + } finally { + dbTester = null; + } + } } -- 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 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(-) 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 fa6ac1c592c22ac688123fabed062879881dc843 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Fri, 18 May 2018 11:15:50 +0200 Subject: Updated Visuals in MainWindow. --- .../resources/fxml/CreateOperationController.fxml | 30 +++++++++++++++------- src/main/resources/styles/main.css | 4 +++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 88fe26a..54e08b0 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -10,19 +10,31 @@ + + - + + + + + + + + - + - + - - + + - + - - + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + 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 689d8f9b2092473c7c10c8a39744c8a2c8765ce4 Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Mon, 14 May 2018 16:31:12 +0200 Subject: Reworking MainWindow UI. --- .../resources/fxml/CreateOperationController.fxml | 153 ++++++++------------- src/main/resources/fxml/vehiclePane.fxml | 2 +- 2 files changed, 58 insertions(+), 97 deletions(-) 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 @@ - + -- 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 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(-) 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"/> + + + + -- cgit v1.2.3-70-g09d2 From 3f45e04f289edf24de1b7254138a882cb9226156 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Tue, 22 May 2018 21:10:04 +0200 Subject: Fixed some errors, added listener for mouse input on active-operation list --- .../einsatzverwaltung/dao/DBOperationDAO.java | 17 ++++++++++++- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 9 +++---- .../userInterface/CreateOperationController.java | 28 +++++++++++++++++++--- .../userInterface/OperationDetailsController.java | 13 ++++------ 4 files changed, 51 insertions(+), 16 deletions(-) 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 773ccb6..bb6fb27 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 @@ -201,7 +201,22 @@ public class DBOperationDAO implements OperationDAO { @Override public Operation get(long operationId) throws ElementNotFoundException, PersistenceException { - return null; + if (operationId <= 0) + throw new ElementNotFoundException("Es wurde eine falsche ID übergeben!"); + + String sql = "Select * from operation where id = ?"; + + try (PreparedStatement pstmt = + jdbcConnectionManager.getConnection().prepareStatement(sql)) { + pstmt.setLong(1, operationId); + pstmt.execute(); + ResultSet rs = pstmt.getResultSet(); + if (rs.next()) { + return operationFromRS(rs); + } else throw new ElementNotFoundException("No element could be found!"); + } catch (SQLException e) { + throw new PersistenceException(e); + } } @Override 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 796dd7b..7e0f494 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 @@ -180,13 +180,14 @@ public class VehicleDatabaseDao implements VehicleDAO { try { Connection con = jdbcConnectionManager.getConnection(); - try (PreparedStatement pstmt = con.prepareStatement(sql); - ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = con.prepareStatement(sql)) { pstmt.setLong(1, id); - if (!rs.first()) throw new ElementNotFoundException("No such vehicle exists"); + try (ResultSet rs = pstmt.executeQuery()) { + if (!rs.first()) throw new ElementNotFoundException("No such vehicle exists"); - return vehicleFromRS(rs); + return vehicleFromRS(rs); + } } } catch (SQLException e) { throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 44e28d8..2744fcd 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 @@ -21,6 +21,7 @@ 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; import javafx.fxml.FXMLLoader; @@ -31,6 +32,7 @@ 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.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.MenuItem; import javafx.scene.control.TextField; @@ -56,7 +58,6 @@ public class CreateOperationController { public ListView lvVehicles; public ListView lvActiveOperations; public Label lblChosenVehicles; - public LinkedList chosenVehicles = new LinkedList<>(); public AnchorPane apInvisible; @FXML private OperationDetailsController operationDetailsController; public FlowPane fpVehicles; @@ -75,7 +76,29 @@ public class CreateOperationController { @FXML public void initialize() { lblChosenVehicles.setText("keine ausgewählt"); - + lvActiveOperations.setCellFactory( + param -> + new ListCell<>() { + @Override + protected void updateItem(Operation item, boolean empty) { + super.updateItem(item, empty); + + if (empty || item == null || item.opCode() == null) { + setText(null); + } else { + setText(item.opCode()); + } + } + }); + lvActiveOperations.setOnMouseClicked( + event -> { + if (event.getClickCount() == 2) { + if (lvActiveOperations.getSelectionModel().getSelectedItem() == null) { + return; + } + openDetailsWindow(lvActiveOperations.getSelectionModel().getSelectedItem()); + } + }); } public void updateList() { @@ -147,7 +170,6 @@ public class CreateOperationController { } } - private static ContextMenu createContextMenu(Vehicle data, VehicleService vehicleService) { ContextMenu menu = new ContextMenu(); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java index cacaa29..3809760 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java @@ -8,7 +8,9 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.Collection; import java.util.EnumSet; +import java.util.stream.Collectors; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -91,14 +93,9 @@ public class OperationDetailsController { fillActiveList(); this.operation = operation; lblCode.setText(operation.opCode()); - StringBuilder result = new StringBuilder(); - for (int i = 0; i < operation.vehicles().size(); i++) { - if (i != operation.vehicles().size() - 1) { - result.append(operation.vehicles().get(i).name()).append(","); - } else { - result.append(operation.vehicles().get(i).name()); - } - } + Collection vehicleNames = + operation.vehicles().stream().map(Vehicle::name).collect(Collectors.toList()); + String result = String.join(", ", vehicleNames); lblChosenVehicles.setText(result.toString()); lblAdditionalInfo.setText(operation.additionalInfo()); lblAddress.setText(operation.destination()); -- cgit v1.2.3-70-g09d2 From b67a8ecb3919961e9d6fbc6956d50740af94b394 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Tue, 22 May 2018 21:58:34 +0200 Subject: Replace assert statements by if-null early-returns [#25874] --- .../ui/vehiclepane/VehiclePaneController.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 405eee3..dfebb00 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 @@ -74,14 +74,20 @@ public class VehiclePaneController { Instant now = Instant.now(); List regs = vehicle.registrations(); - assert regs != null; + if (regs == null) { + return; + } + Optional edu = regs.stream() .filter(reg -> reg.start().isBefore(now) && reg.end().isAfter(now)) .map(reg -> reg.employee().educationLevel()) .max(EducationLevel::compareTo); - assert edu.isPresent(); + if (!edu.isPresent()) { + return; + } + txtQualification.setText(edu.get().name()); } else { txtQualification.setVisible(false); -- cgit v1.2.3-70-g09d2 From 3af783d5de0137a52e3d8944aa650df12ec8e29f Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Tue, 22 May 2018 22:18:43 +0200 Subject: Show only registered vehicles in main window [#25874] --- .../einsatzverwaltung/userInterface/CreateOperationController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 2744fcd..e1d01cb 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 @@ -104,7 +104,9 @@ public class CreateOperationController { public void updateList() { try { fpVehicles.getChildren().clear(); - Set vehicles = vehicleService.list(EnumSet.allOf(Vehicle.Status.class)); + EnumSet stati = EnumSet.allOf(Vehicle.Status.class); + stati.remove(Vehicle.Status.ABGEMELDET); + Set vehicles = vehicleService.list(stati); for (Vehicle vehicle : vehicles) { VehiclePaneController controller = VehiclePaneController.createVehiclePane(); -- cgit v1.2.3-70-g09d2 From 694c5f3e6b5b260298af91a6d9d1b63dbc9e6231 Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Tue, 22 May 2018 22:27:25 +0200 Subject: fixing registration Employee list #25874 --- .../einsatzverwaltung/controller/RegistrationWindowController.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 9ed6147..fa79e27 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 @@ -143,6 +143,7 @@ public class RegistrationWindowController { public void cancel() { LOG.debug("Cancel Button clicked"); + chosenEmployees.clear(); ((Stage) lVehicles.getScene().getWindow()).close(); } @@ -170,7 +171,9 @@ public class RegistrationWindowController { } try { registrationService.add(chosenVehicle.id(), registrations); + chosenEmployees.clear(); ((Stage) lVehicles.getScene().getWindow()).close(); + } catch (InvalidVehicleException e) { // NOT THROWN ANYWHERE RIGHT NOW LOG.info( @@ -182,6 +185,7 @@ public class RegistrationWindowController { alert.setHeaderText("Das spezifizierte Fahrzeug ist nicht gültig."); alert.setContentText(e.getMessage()); alert.show(); + chosenEmployees.clear(); } catch (ServiceException e) { LOG.warn( "Caught ServiceException while getting vehicles. Showing it to user. Error message: {}", @@ -191,6 +195,7 @@ public class RegistrationWindowController { alert.setHeaderText("Beim Erstellen der Anmeldung ist ein Fehler aufgetreten."); alert.setContentText(e.getMessage()); alert.show(); + chosenEmployees.clear(); } catch (InvalidRegistrationException e) { LOG.info( "Caught InvalidRegistrationException. Showing it to user. Error message: {}", @@ -201,6 +206,7 @@ public class RegistrationWindowController { "Die gewählte Kombination von Fahrzeug und Personal ist nicht gültig!"); alert.setContentText(e.getMessage()); alert.show(); + chosenEmployees.clear(); } } } -- cgit v1.2.3-70-g09d2 From d13cee465d399895668a88edc34a30a4d0a380c5 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Wed, 23 May 2018 12:25:51 +0200 Subject: Fix problem where listing operations would throw exception, downgrading h2 to 1.4.196 because of bug in .197 #24993 --- pom.xml | 2 +- .../einsatzverwaltung/dao/DBOperationDAO.java | 18 ++++++++++++------ .../einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 78dbb4c..5f30fff 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 1.8.0-beta2 1.6 - 1.4.197 + 1.4.196 1.3.0-alpha4 4.12 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 bb6fb27..1fcdc2e 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 @@ -221,16 +221,22 @@ public class DBOperationDAO implements OperationDAO { @Override public Set list(EnumSet statuses) throws PersistenceException { - String sql = "SELECT * FROM Operation WHERE status IN (?)"; + StringBuilder listString = new StringBuilder("SELECT * FROM Operation WHERE status IN ("); + boolean first = true; + for (Status status : statuses) { + if (first) { + first = false; + } else { + listString.append(", "); + } + listString.append("\'" + status.name() + "\'"); + } + listString.append(") ;"); Set operations = new HashSet<>(); try { Connection con = jdbcConnectionManager.getConnection(); - - try (PreparedStatement pstmt = con.prepareStatement(sql)) { - Object[] arr = statuses.stream().map(Enum::ordinal).toArray(); - pstmt.setArray(1, con.createArrayOf("INTEGER", arr)); - + try (PreparedStatement pstmt = con.prepareStatement(listString.toString())) { try (ResultSet rs = pstmt.executeQuery()) { while (rs.next()) operations.add(operationFromRS(rs)); } 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 13aeffc..5c00447 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 @@ -56,7 +56,7 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { addRegistration.setLong(1, vehicleId); addRegistration.setLong(2, registration.employee().id()); addRegistration.setTimestamp(3, Timestamp.from(registration.start())); - addRegistration.setObject(4, registration.end()); + addRegistration.setTimestamp(4, Timestamp.from(registration.end())); addRegistration.setBoolean( 5, true); // ASSUMPTION: Registration gets created as active addRegistration.executeUpdate(); -- cgit v1.2.3-70-g09d2 From 37f18628822e9c2281c4627e71981b2131f8c33c Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 23 May 2018 12:31:19 +0200 Subject: Fixed an error which would duplicate vehicles [#24981] --- .../userInterface/OperationDetailsController.java | 27 ---------------------- 1 file changed, 27 deletions(-) diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java index 3809760..b844117 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java @@ -6,7 +6,6 @@ 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.VehicleService; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.util.Collection; import java.util.EnumSet; @@ -129,19 +128,6 @@ public class OperationDetailsController { alert.showAndWait(); return; } - for (Vehicle v : operation.vehicles()) { - v = v.toBuilder().status(Vehicle.Status.FREI_FUNK).build(); - try { - vehicleService.update(v); - } catch (InvalidVehicleException | ServiceException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Fehler"); - alert.setHeaderText("Fehler!"); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } - } Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Erfolg"); alert.setHeaderText("Erfolgreich aktualisiert"); @@ -162,19 +148,6 @@ public class OperationDetailsController { alert.showAndWait(); return; } - for (Vehicle v : operation.vehicles()) { - v = v.toBuilder().status(Vehicle.Status.FREI_FUNK).build(); - try { - vehicleService.update(v); - } catch (InvalidVehicleException | ServiceException e) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Fehler"); - alert.setHeaderText("Fehler!"); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } - } Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Erfolg"); alert.setHeaderText("Erfolgreich aktualisiert"); -- cgit v1.2.3-70-g09d2 From b7fb4e11afc3dbc622652f54d96470da102436ea Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Wed, 23 May 2018 12:33:55 +0200 Subject: Fix employees being added twice instead of removed #25963 --- .../controller/RegistrationWindowController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 fa79e27..7e533de 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 @@ -120,10 +120,15 @@ public class RegistrationWindowController { tvEmployees.setOnMousePressed( mouseEvent -> { if (mouseEvent.isPrimaryButtonDown() && mouseEvent.getClickCount() == 2) { - chosenEmployees.add(tvEmployees.getSelectionModel().getSelectedItem()); - if (chosenEmployees == null) { + Employee selection = tvEmployees.getSelectionModel().getSelectedItem(); + if (selection == null) { return; + } else if (chosenEmployees.contains(selection)) { + chosenEmployees.remove(selection); + } else { + chosenEmployees.add(selection); } + StringBuilder text = new StringBuilder(); for (Employee employee : chosenEmployees) { text.append(employee.name()).append("\n"); -- cgit v1.2.3-70-g09d2 From 505c7dbdd8d2de827eefba8007463fb314a0f1a0 Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Wed, 23 May 2018 12:45:35 +0200 Subject: Fix VehicleVersion Id #25963 --- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) 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 7e0f494..808e7e7 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 @@ -33,6 +33,7 @@ public class VehicleDatabaseDao implements VehicleDAO { String status = "ABGEMELDET"; String name = ""; int id = -1; + int version = -1; try { Connection connection = jdbcConnectionManager.getConnection(); connection.setAutoCommit(false); @@ -46,9 +47,21 @@ public class VehicleDatabaseDao implements VehicleDAO { p1.setString(4, vehicle.type().name()); p1.executeUpdate(); - try (ResultSet keyResultSet = p1.getGeneratedKeys()) { + if (keyResultSet.next()) { + version = keyResultSet.getInt(1); + } + } + } + try (PreparedStatement p2 = + connection.prepareStatement(query2, Statement.RETURN_GENERATED_KEYS)) { + + p2.setInt(1, version); + p2.setString(2, status); + p2.executeUpdate(); + try (ResultSet keyResultSet = p2.getGeneratedKeys()) { + if (keyResultSet.next()) { id = keyResultSet.getInt(1); } @@ -56,20 +69,13 @@ public class VehicleDatabaseDao implements VehicleDAO { name = vehicle.type().name() + "-" + id; } - query1 = "UPDATE VehicleVersion SET name=? WHERE id=?"; try (PreparedStatement p3 = connection.prepareStatement(query1)) { p3.setString(1, name); - p3.setInt(2, id); + p3.setInt(2, version); p3.executeUpdate(); } - try (PreparedStatement p2 = connection.prepareStatement(query2)) { - - p2.setInt(1, id); - p2.setString(2, status); - p2.executeUpdate(); - } connection.commit(); connection.setAutoCommit(true); } catch (SQLException e) { @@ -125,7 +131,7 @@ public class VehicleDatabaseDao implements VehicleDAO { throw new ElementNotFoundException("Vehicle don´t found"); } } - name = vehicle.type().name() + "-" + vehicleVersion; + name = vehicle.type().name() + "-" + vehicleID; query = "UPDATE VehicleVersion SET name=? WHERE id=?"; try (PreparedStatement p = connection.prepareStatement(query)) { -- cgit v1.2.3-70-g09d2 From d980f26121360ab7dacf7f482c9e85fb5ef43b0b Mon Sep 17 00:00:00 2001 From: Tharre Date: Wed, 23 May 2018 12:55:24 +0200 Subject: Revert "Fix problem where listing operations would throw exception, downgrading h2 to 1.4.196 because of bug in .197 #24993" This reverts commit d13cee465d399895668a88edc34a30a4d0a380c5. --- pom.xml | 2 +- .../einsatzverwaltung/dao/DBOperationDAO.java | 18 ++++++------------ .../einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 5f30fff..78dbb4c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 1.8.0-beta2 1.6 - 1.4.196 + 1.4.197 1.3.0-alpha4 4.12 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 1fcdc2e..bb6fb27 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 @@ -221,22 +221,16 @@ public class DBOperationDAO implements OperationDAO { @Override public Set list(EnumSet statuses) throws PersistenceException { - StringBuilder listString = new StringBuilder("SELECT * FROM Operation WHERE status IN ("); - boolean first = true; - for (Status status : statuses) { - if (first) { - first = false; - } else { - listString.append(", "); - } - listString.append("\'" + status.name() + "\'"); - } - listString.append(") ;"); + String sql = "SELECT * FROM Operation WHERE status IN (?)"; Set operations = new HashSet<>(); try { Connection con = jdbcConnectionManager.getConnection(); - try (PreparedStatement pstmt = con.prepareStatement(listString.toString())) { + + try (PreparedStatement pstmt = con.prepareStatement(sql)) { + Object[] arr = statuses.stream().map(Enum::ordinal).toArray(); + pstmt.setArray(1, con.createArrayOf("INTEGER", arr)); + try (ResultSet rs = pstmt.executeQuery()) { while (rs.next()) operations.add(operationFromRS(rs)); } 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 5c00447..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 @@ -56,7 +56,7 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { addRegistration.setLong(1, vehicleId); addRegistration.setLong(2, registration.employee().id()); addRegistration.setTimestamp(3, Timestamp.from(registration.start())); - addRegistration.setTimestamp(4, Timestamp.from(registration.end())); + addRegistration.setObject(4, registration.end()); addRegistration.setBoolean( 5, true); // ASSUMPTION: Registration gets created as active addRegistration.executeUpdate(); -- cgit v1.2.3-70-g09d2 From a6b6eb25425a103ba49ea4ef16265aaf38181935 Mon Sep 17 00:00:00 2001 From: Tharre Date: Wed, 23 May 2018 13:18:21 +0200 Subject: Work around H2 bug in operation.list() --- pom.xml | 2 +- .../groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 16 +++++++++++++--- .../einsatzverwaltung/dao/OperationDAOTest.java | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 78dbb4c..5f30fff 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 1.8.0-beta2 1.6 - 1.4.197 + 1.4.196 1.3.0-alpha4 4.12 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 bb6fb27..143fdd6 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 @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; @@ -221,16 +222,25 @@ public class DBOperationDAO implements OperationDAO { @Override public Set list(EnumSet statuses) throws PersistenceException { - String sql = "SELECT * FROM Operation WHERE status IN (?)"; + // This hack exists because H2 currently has a bug that prevents IN (?) with an array of + // ids, i.e. pstmt.setArray(1, con.createArrayOf("INT", intarray) from working. See + // commented code below. + String str = + statuses.stream() + .map(Enum::name) + .map(s -> "'" + s + "'") + .collect(Collectors.joining(",")); + String sql = "SELECT * FROM Operation WHERE status IN (" + str + ")"; Set operations = new HashSet<>(); try { Connection con = jdbcConnectionManager.getConnection(); try (PreparedStatement pstmt = con.prepareStatement(sql)) { - Object[] arr = statuses.stream().map(Enum::ordinal).toArray(); - pstmt.setArray(1, con.createArrayOf("INTEGER", arr)); + // Object[] arr = statuses.stream().map(Enum::ordinal).toArray(); + // pstmt.setArray(1, con.createArrayOf("INT", arr)); + // TODO: this should set the vehicles as well try (ResultSet rs = pstmt.executeQuery()) { while (rs.next()) operations.add(operationFromRS(rs)); } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java index 726735d..e62554c 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java @@ -8,6 +8,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundExceptio import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; import java.time.Instant; import java.util.Collections; +import java.util.EnumSet; import java.util.Set; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; @@ -78,4 +79,12 @@ public class OperationDAOTest extends JdbcTestCase { compareWith("operationDAOUpdateRemoveVehicles.xml", COMPARE_TABLES); } + + @Test + public void testListOperations() throws Exception { + Set operationSet = operationDAO.list(EnumSet.allOf(Status.class)); + + // TODO: operations.list() currently doesn't set the vehicles set + // assertEquals(Set.of(o), operationSet); + } } -- cgit v1.2.3-70-g09d2 From 13bcb3768dd9b1cf1577ddacdc61d75a14267e4a Mon Sep 17 00:00:00 2001 From: Tharre Date: Wed, 23 May 2018 13:22:12 +0200 Subject: Fix insert bug in RegistrationDAO.add() --- .../groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 13aeffc..5c00447 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 @@ -56,7 +56,7 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { addRegistration.setLong(1, vehicleId); addRegistration.setLong(2, registration.employee().id()); addRegistration.setTimestamp(3, Timestamp.from(registration.start())); - addRegistration.setObject(4, registration.end()); + addRegistration.setTimestamp(4, Timestamp.from(registration.end())); addRegistration.setBoolean( 5, true); // ASSUMPTION: Registration gets created as active addRegistration.executeUpdate(); -- cgit v1.2.3-70-g09d2 From 3765c79ce8ff4d673c427ca5af1114cb21e3d661 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 16:26:35 +0200 Subject: JF: Remove duplicate code by extracting validation-method [#27241] --- .../service/VehicleServiceImpl.java | 58 +++++----------------- 1 file changed, 13 insertions(+), 45 deletions(-) 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 47a2520..da995c4 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 @@ -24,43 +24,7 @@ public class VehicleServiceImpl implements VehicleService { public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - switch (vehicle.type()) { - case RTW: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("RTW darf kein Normales Dach haben"); - } else if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("RTW darf kein Mittelhochdach haben"); - } - break; - case KTW: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("KTW darf kein Normales Dach haben"); - } - break; - case KTW_B: - if (vehicle.constructionType() == ConstructionType.NORMAL) { - throw new InvalidVehicleException("KTW-B darf kein Normales Dach haben"); - } - break; - case NEF: - if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); - } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Hochdach haben"); - } - break; - case NAH: - if (vehicle.constructionType() == ConstructionType.MITTELHOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Mittelhochdach haben"); - } else if (vehicle.constructionType() == ConstructionType.HOCHDACH) { - throw new InvalidVehicleException("NEF darf kein Hochdach haben"); - } - break; - case BKTW: - break; - default: - throw new ServiceException("not a Valid type"); - } + validateVehicle(vehicle); try { vehiclePersistence.add(vehicle); } catch (PersistenceException e) { @@ -70,6 +34,18 @@ public class VehicleServiceImpl implements VehicleService { } public Vehicle update(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + validateVehicle(vehicle); + try { + vehiclePersistence.update(vehicle); + } catch (ElementNotFoundException e) { + throw new ServiceException("Element not found"); + } catch (PersistenceException e) { + throw new ServiceException(e); + } + return vehicle; + } + + private void validateVehicle(Vehicle vehicle) throws InvalidVehicleException, ServiceException { switch (vehicle.type()) { case RTW: if (vehicle.constructionType() == ConstructionType.NORMAL) { @@ -107,14 +83,6 @@ public class VehicleServiceImpl implements VehicleService { default: throw new ServiceException("not a Valid type"); } - try { - vehiclePersistence.update(vehicle); - } catch (ElementNotFoundException e) { - throw new ServiceException("Element not found"); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - return vehicle; } @Override -- cgit v1.2.3-70-g09d2 From 5ee4e894eb9bf4f72d68bd8e3db4dd32db218c0b Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 16:27:03 +0200 Subject: JF: Move VehiclePersistenceTest to correct package [#27241] --- .../dao/VehiclePersistenceTest.java | 151 ++++++++++++++++++++ .../groupphase/vehicle/VehiclePersistenceTest.java | 153 --------------------- 2 files changed, 151 insertions(+), 153 deletions(-) create mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehiclePersistenceTest.java diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java new file mode 100644 index 0000000..9909385 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java @@ -0,0 +1,151 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; +import at.ac.tuwien.sepm.assignment.groupphase.util.Helper; +import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; +import java.io.InputStream; +import java.util.Set; +import org.dbunit.Assertion; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.ITable; +import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; +import org.junit.Assert; +import org.junit.Test; + +public class VehiclePersistenceTest extends JdbcTestCase { + + private VehicleDAO vehicleDAO; + + private Vehicle validUpdateVehicle = + Vehicle.builder() + .hasNef(true) + .constructionType(ConstructionType.HOCHDACH) + .type(VehicleType.RTW) + .id(2) + .name("RTW-2") + .status(Status.ABGEMELDET) + .build(); + + public VehiclePersistenceTest() { + vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); + } + + @Override + protected IDataSet getDataSet() throws Exception { + InputStream res = getClass().getClassLoader().getResourceAsStream("vehicleTestData.xml"); + return new FlatXmlDataSetBuilder().build(res); + } + + @Test + public void testListVehicle() throws PersistenceException { + Set vehicles = vehicleDAO.list(); + + Vehicle v1 = + Vehicle.builder() + .id(1) + .constructionType(ConstructionType.HOCHDACH) + .name("RTW-1") + .hasNef(true) + .status(Status.ABGEMELDET) + .type(VehicleType.RTW) + .build(); + Vehicle v2 = + Vehicle.builder() + .id(2) + .constructionType(ConstructionType.MITTELHOCHDACH) + .name("KTW-2") + .hasNef(false) + .status(Status.FREI_WACHE) + .type(VehicleType.KTW) + .build(); + Vehicle v3 = + Vehicle.builder() + .id(3) + .constructionType(ConstructionType.NORMAL) + .name("NEF-3") + .hasNef(false) + .status(Status.FREI_FUNK) + .type(VehicleType.NEF) + .build(); + + Assert.assertTrue(vehicles.contains(v1)); + Assert.assertTrue(vehicles.contains(v2)); + Assert.assertTrue(vehicles.contains(v3)); + Assert.assertEquals(3, vehicles.size()); + } + + @Test + public void testVehicleListNoElement() throws PersistenceException { + Set vehicles = vehicleDAO.list(); + + Vehicle v1 = + Vehicle.builder() + .id(30) + .constructionType(ConstructionType.NORMAL) + .name("NEF-3") + .hasNef(false) + .status(Status.FREI_FUNK) + .type(VehicleType.NEF) + .build(); + + Assert.assertFalse(vehicles.contains(v1)); + } + + @Test + public void testUpdateValid_VehicleVersion() throws Exception { + vehicleDAO.update(validUpdateVehicle); + + String[] excludedColumnsVehicleVersion = new String[] {"ID", "NAME"}; + String tableVehicleVersion = "VEHICLEVERSION"; + + ITable actualTableData = + Helper.getActualFilteredTableData( + getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion); + + ITable expectedTableData = + Helper.getExpectedFilteredTableData( + tableVehicleVersion, + excludedColumnsVehicleVersion, + "vehicleTestUpdateExpectedData.xml"); + Assertion.assertEquals(expectedTableData, actualTableData); + } + + @Test + public void testUpdateValid_Vehicle() throws Exception { + vehicleDAO.update(validUpdateVehicle); + + String[] excludedColumnsVehicleVersion = new String[] {"VERSION", "STATUS"}; + String tableVehicleVersion = "VEHICLE"; + + ITable actualTableData = + Helper.getActualFilteredTableData( + getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion); + + ITable expectedTableData = + Helper.getExpectedFilteredTableData( + tableVehicleVersion, + excludedColumnsVehicleVersion, + "vehicleTestUpdateExpectedData.xml"); + Assertion.assertEquals(expectedTableData, actualTableData); + } + + @Test(expected = ElementNotFoundException.class) + public void testUpdateNonExistingVehicle() + throws PersistenceException, ElementNotFoundException { + Vehicle nonExistentVehicle = + Vehicle.builder() + .id(35) + .constructionType(ConstructionType.NORMAL) + .name("NEF-3") + .hasNef(false) + .status(Status.FREI_FUNK) + .type(VehicleType.NEF) + .build(); + vehicleDAO.update(nonExistentVehicle); + } +} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehiclePersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehiclePersistenceTest.java deleted file mode 100644 index 81ebf63..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/vehicle/VehiclePersistenceTest.java +++ /dev/null @@ -1,153 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.vehicle; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDatabaseDao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.Helper; -import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; -import java.io.InputStream; -import java.util.Set; -import org.dbunit.Assertion; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.ITable; -import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; -import org.junit.Assert; -import org.junit.Test; - -public class VehiclePersistenceTest extends JdbcTestCase { - - private VehicleDAO vehicleDAO; - - private Vehicle validUpdateVehicle = - Vehicle.builder() - .hasNef(true) - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .id(2) - .name("RTW-2") - .status(Status.ABGEMELDET) - .build(); - - public VehiclePersistenceTest() { - vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); - } - - @Override - protected IDataSet getDataSet() throws Exception { - InputStream res = getClass().getClassLoader().getResourceAsStream("vehicleTestData.xml"); - return new FlatXmlDataSetBuilder().build(res); - } - - @Test - public void testListVehicle() throws PersistenceException { - Set vehicles = vehicleDAO.list(); - - Vehicle v1 = - Vehicle.builder() - .id(1) - .constructionType(ConstructionType.HOCHDACH) - .name("RTW-1") - .hasNef(true) - .status(Status.ABGEMELDET) - .type(VehicleType.RTW) - .build(); - Vehicle v2 = - Vehicle.builder() - .id(2) - .constructionType(ConstructionType.MITTELHOCHDACH) - .name("KTW-2") - .hasNef(false) - .status(Status.FREI_WACHE) - .type(VehicleType.KTW) - .build(); - Vehicle v3 = - Vehicle.builder() - .id(3) - .constructionType(ConstructionType.NORMAL) - .name("NEF-3") - .hasNef(false) - .status(Status.FREI_FUNK) - .type(VehicleType.NEF) - .build(); - - Assert.assertTrue(vehicles.contains(v1)); - Assert.assertTrue(vehicles.contains(v2)); - Assert.assertTrue(vehicles.contains(v3)); - Assert.assertEquals(3, vehicles.size()); - } - - @Test - public void testVehicleListNoElement() throws PersistenceException { - Set vehicles = vehicleDAO.list(); - - Vehicle v1 = - Vehicle.builder() - .id(30) - .constructionType(ConstructionType.NORMAL) - .name("NEF-3") - .hasNef(false) - .status(Status.FREI_FUNK) - .type(VehicleType.NEF) - .build(); - - Assert.assertFalse(vehicles.contains(v1)); - } - - @Test - public void testUpdateValid_VehicleVersion() throws Exception { - vehicleDAO.update(validUpdateVehicle); - - String[] excludedColumnsVehicleVersion = new String[] {"ID", "NAME"}; - String tableVehicleVersion = "VEHICLEVERSION"; - - ITable actualTableData = - Helper.getActualFilteredTableData( - getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion); - - ITable expectedTableData = - Helper.getExpectedFilteredTableData( - tableVehicleVersion, - excludedColumnsVehicleVersion, - "vehicleTestUpdateExpectedData.xml"); - Assertion.assertEquals(expectedTableData, actualTableData); - } - - @Test - public void testUpdateValid_Vehicle() throws Exception { - vehicleDAO.update(validUpdateVehicle); - - String[] excludedColumnsVehicleVersion = new String[] {"VERSION", "STATUS"}; - String tableVehicleVersion = "VEHICLE"; - - ITable actualTableData = - Helper.getActualFilteredTableData( - getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion); - - ITable expectedTableData = - Helper.getExpectedFilteredTableData( - tableVehicleVersion, - excludedColumnsVehicleVersion, - "vehicleTestUpdateExpectedData.xml"); - Assertion.assertEquals(expectedTableData, actualTableData); - } - - @Test(expected = ElementNotFoundException.class) - public void testUpdateNonExistingVehicle() - throws PersistenceException, ElementNotFoundException { - Vehicle nonExistentVehicle = - Vehicle.builder() - .id(35) - .constructionType(ConstructionType.NORMAL) - .name("NEF-3") - .hasNef(false) - .status(Status.FREI_FUNK) - .type(VehicleType.NEF) - .build(); - vehicleDAO.update(nonExistentVehicle); - } -} -- cgit v1.2.3-70-g09d2 From bd24d413b47e833c1ea28c43a20d3d51696f6027 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 17:05:53 +0200 Subject: JF: Change SQL-string to final [#27241] --- .../assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 143fdd6..070b3fb 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 @@ -265,7 +265,7 @@ public class DBOperationDAO implements OperationDAO { .build(); } - private static String GET_VEHICLE_ID = + private static final String GET_VEHICLE_ID = "SELECT vehicleId FROM VehicleOperation WHERE operationId = ? ;"; private final PreparedStatement getVehicleId; -- cgit v1.2.3-70-g09d2 From 3bd1d99f0223311a36abd0ee0d5cb6cc1d9047d5 Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 23 May 2018 20:48:48 +0200 Subject: Adjusted methods in Controllers [#25963] Changed modifier for FXML-annotated methods and variables from public to private, added implementation of services/controllers through constructors (dependency injection), changed fxmlloader to spring-fxmlloader for archive window --- .../controller/CreateCarController.java | 6 +-- .../controller/CreateNewEmployeeController.java | 6 +-- .../controller/FilterEmployeesController.java | 4 +- .../controller/ListEmployeesController.java | 2 +- .../controller/RegistrationWindowController.java | 43 ++++++++----------- .../userInterface/ArchiveOperationController.java | 30 +++++++------- .../userInterface/CreateOperationController.java | 48 +++++++++++----------- .../userInterface/OperationDetailsController.java | 40 +++++++++--------- 8 files changed, 86 insertions(+), 93 deletions(-) diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateCarController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateCarController.java index e88e640..ce795da 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateCarController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateCarController.java @@ -49,7 +49,7 @@ public class CreateCarController { } @FXML - public void initialize() { + private void initialize() { cmb_Ctyp.setItems( FXCollections.observableArrayList( Stream.of( @@ -75,12 +75,12 @@ public class CreateCarController { } @FXML - public void onCancelClicked() { + private void onCancelClicked() { ((Stage) btn_cancel.getScene().getWindow()).close(); } @FXML - public void createCar(ActionEvent actionEvent) { + private void createCar(ActionEvent actionEvent) { if (!update) { Vehicle vehicle = diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java index 99614d0..15282cc 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/CreateNewEmployeeController.java @@ -54,7 +54,7 @@ public class CreateNewEmployeeController { } @FXML - public void initialize() { + private void initialize() { inputQualification.setItems( FXCollections.observableArrayList( Stream.of( @@ -79,14 +79,14 @@ public class CreateNewEmployeeController { } @FXML - public void onCancelClicked() { + private void onCancelClicked() { if (consumerCancelClicked != null) { consumerCancelClicked.run(); } } @FXML - public void onCreateClicked() { + private void onCreateClicked() { employee = employee.toBuilder() diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/FilterEmployeesController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/FilterEmployeesController.java index 0d2f894..6d6214d 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/FilterEmployeesController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/FilterEmployeesController.java @@ -22,14 +22,14 @@ public class FilterEmployeesController { private Node rootElement; @FXML - public void onAddEmployeeClicked() { + private void onAddEmployeeClicked() { if (consumerAddEmployeeClicked != null) { consumerAddEmployeeClicked.run(); } } @FXML - public void onFilterTextChanged() { + private void onFilterTextChanged() { if (consumerFilterTextChanged != null) { consumerFilterTextChanged.accept(inputFilterString.getText()); } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/ListEmployeesController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/ListEmployeesController.java index 038b14c..25f1263 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/ListEmployeesController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/ListEmployeesController.java @@ -32,7 +32,7 @@ public class ListEmployeesController { } @FXML - public void initialize() { + private void initialize() { openFilter(); } 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 7e533de..ac6470e 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 @@ -33,7 +33,6 @@ import javafx.scene.control.TextField; 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 @@ -41,43 +40,37 @@ public class RegistrationWindowController { private static final Logger LOG = LoggerFactory.getLogger(RegistrationWindowController.class); - private EmployeeService employeeService; + private final EmployeeService employeeService; - private VehicleService vehicleService; + private final VehicleService vehicleService; - private RegistrationService registrationService; + private final RegistrationService registrationService; - @Autowired - public void setEmployeeService(EmployeeService employeeService) { + public RegistrationWindowController( + EmployeeService employeeService, + VehicleService vehicleService, + RegistrationService registrationService) { this.employeeService = employeeService; - } - - @Autowired - public void setVehicleService(VehicleService vehicleService) { this.vehicleService = vehicleService; - } - - @Autowired - public void setRegistrationService(RegistrationService registrationService) { this.registrationService = registrationService; } - @FXML public ChoiceBox cbStart; - @FXML public ChoiceBox cbEnd; - @FXML public Label lVehicles; - @FXML public Label lEmployees; - @FXML public TextField tfVehicleSearch; - @FXML public TextField tfEmployeeSearch; - @FXML public TableView tvVehicles; - @FXML public TableView tvEmployees; - @FXML public TableColumn tcVehicles; - @FXML public TableColumn tcEmployees; + @FXML private ChoiceBox cbStart; + @FXML private ChoiceBox cbEnd; + @FXML private Label lVehicles; + @FXML private Label lEmployees; + @FXML private TextField tfVehicleSearch; + @FXML private TextField tfEmployeeSearch; + @FXML private TableView tvVehicles; + @FXML private TableView tvEmployees; + @FXML private TableColumn tcVehicles; + @FXML private TableColumn tcEmployees; private Vehicle chosenVehicle; private List chosenEmployees = new LinkedList<>(); @FXML - public void initialize() { + private void initialize() { // will have to be replaced for FlowPane try { Set vehicles = vehicleService.list(EnumSet.of(Status.ABGEMELDET)); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/ArchiveOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/ArchiveOperationController.java index 7b69402..53e7067 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/ArchiveOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/ArchiveOperationController.java @@ -12,6 +12,7 @@ import java.util.EnumSet; import java.util.LinkedList; import java.util.Objects; import java.util.stream.Collectors; +import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; @@ -23,26 +24,24 @@ import org.springframework.stereotype.Controller; @Controller public class ArchiveOperationController { - - public AnchorPane apDetails; - public Label lblCodeHeader; - public Hyperlink hypBack; - public Label lblOpCode; - public Label lblVehicles; - public Label lblDate; - public Label lblAddress; - public FlowPane fpVehicles; - private OperationService operationService; - public FlowPane archiveOperationFlowPane; + @FXML private AnchorPane apDetails; + @FXML private Label lblCodeHeader; + @FXML private Hyperlink hypBack; + @FXML private Label lblOpCode; + @FXML private Label lblVehicles; + @FXML private Label lblDate; + @FXML private Label lblAddress; + @FXML private FlowPane fpVehicles; + private final OperationService operationService; + @FXML private FlowPane archiveOperationFlowPane; private LinkedList list = new LinkedList<>(); - public ArchiveOperationController() {} - - void setServices(OperationService operationService) { + public ArchiveOperationController(OperationService operationService) { this.operationService = operationService; } - void fillList() { + @FXML + private void initialize() { try { list.addAll(operationService.list(EnumSet.of(Status.CANCELLED, Status.COMPLETED))); } catch (ServiceException e) { @@ -122,6 +121,7 @@ public class ArchiveOperationController { } public void backClicked() { + fpVehicles.getChildren().clear(); setDetailsVisible(false); } } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index e1d01cb..60a085c 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 @@ -24,7 +24,7 @@ import java.util.Set; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; @@ -42,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 @@ -51,30 +50,34 @@ public class CreateOperationController { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public AnchorPane apCreateOperation; - public TextField txtCode; - public TextField txtAddress; - public TextField txtNote; - public Button btnCreateOperation; - public ListView lvVehicles; - public ListView lvActiveOperations; - public Label lblChosenVehicles; - public AnchorPane apInvisible; + @FXML private TextField txtCode; + @FXML private TextField txtAddress; + @FXML private TextField txtNote; + @FXML private Button btnCreateOperation; + @FXML private ListView lvVehicles; + @FXML private ListView lvActiveOperations; + @FXML private Label lblChosenVehicles; + @FXML private AnchorPane apInvisible; @FXML private OperationDetailsController operationDetailsController; - public FlowPane fpVehicles; + @FXML private FlowPane fpVehicles; private LinkedList chosenVehicles = new LinkedList<>(); - @Autowired private OperationService operationService; + private final OperationService operationService; private final VehicleService vehicleService; private final SpringFXMLLoader fxmlLoader; - public CreateOperationController(VehicleService vehicleService, SpringFXMLLoader fxmlLoader) { + public CreateOperationController( + OperationService operationService, + VehicleService vehicleService, + SpringFXMLLoader fxmlLoader) { + this.operationService = operationService; this.vehicleService = vehicleService; this.fxmlLoader = fxmlLoader; } @FXML - public void initialize() { + private void initialize() { lblChosenVehicles.setText("keine ausgewählt"); lvActiveOperations.setCellFactory( param -> @@ -291,13 +294,13 @@ public class CreateOperationController { private void openNewArchivWindow() { Stage stage = new Stage(); try { - FXMLLoader fxmlLoader = - new FXMLLoader(getClass().getResource("/fxml/ArchiveOperation.fxml")); - Parent node = fxmlLoader.load(); - ArchiveOperationController archiveOperationController = fxmlLoader.getController(); - archiveOperationController.setServices(operationService); - archiveOperationController.fillList(); - stage.setScene(new Scene(node)); + stage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/ArchiveOperation.fxml")))); } catch (IOException e) { LOG.error("Could not open new window: {}", e); } @@ -334,8 +337,7 @@ public class CreateOperationController { } private void openDetailsWindow(Operation operation) { - operationDetailsController.setControllers(this, operationService, vehicleService); - apInvisible.setVisible(true); operationDetailsController.initOperation(operation); + apInvisible.setVisible(true); } } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java index b844117..9c9eb28 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java @@ -25,21 +25,28 @@ import org.springframework.stereotype.Controller; public class OperationDetailsController { public Operation operation; - private OperationService operationService; - private VehicleService vehicleService; - private CreateOperationController createOperationController; - public ListView lvVehicles; - public ListView lvActiveOperations; - public Label lblChosenVehicles; - public Button btnCloseOperation; - public Button btnCancelOperation; - public Label lblCode, lblAdditionalInfo, lblAddress; - public AnchorPane operationDetailsAP; + private final OperationService operationService; + private final VehicleService vehicleService; + private final CreateOperationController createOperationController; + @FXML private ListView lvVehicles; + @FXML private ListView lvActiveOperations; + @FXML private Label lblChosenVehicles; + @FXML private Button btnCloseOperation; + @FXML private Button btnCancelOperation; + @FXML private Label lblCode, lblAdditionalInfo, lblAddress; + @FXML private AnchorPane operationDetailsAP; - public OperationDetailsController() {} + public OperationDetailsController( + OperationService operationService, + VehicleService vehicleService, + CreateOperationController createOperationController) { + this.operationService = operationService; + this.vehicleService = vehicleService; + this.createOperationController = createOperationController; + } @FXML - public void initialize() { + private void initialize() { lvVehicles.setCellFactory( param -> new ListCell<>() { @@ -79,15 +86,6 @@ public class OperationDetailsController { }); } - void setControllers( - CreateOperationController createOperationController, - OperationService operationService, - VehicleService vehicleService) { - this.operationService = operationService; - this.createOperationController = createOperationController; - this.vehicleService = vehicleService; - } - void initOperation(Operation operation) { fillActiveList(); this.operation = operation; -- cgit v1.2.3-70-g09d2 From 78c894e25e907d6d1cab710b148e306aa4e4202d Mon Sep 17 00:00:00 2001 From: Viktoria Pundy Date: Wed, 23 May 2018 21:04:08 +0200 Subject: Fields in create-operation mechanism are cleared after successful creation [#25963] --- .../userInterface/CreateOperationController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 60a085c..ef890e0 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 @@ -24,7 +24,6 @@ import java.util.Set; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; @@ -273,6 +272,11 @@ public class CreateOperationController { alert.setContentText("Der Einsatz wurde erfolgreich gespeichert."); alert.showAndWait(); updateList(); + lblChosenVehicles.setText("keine ausgewählt"); + txtAddress.setText(""); + txtCode.setText(""); + txtNote.setText(""); + chosenVehicles = new LinkedList<>(); } public void onRegistrationLinkClicked(ActionEvent actionEvent) { @@ -338,6 +342,6 @@ public class CreateOperationController { private void openDetailsWindow(Operation operation) { operationDetailsController.initOperation(operation); - apInvisible.setVisible(true); + this.setVisible(false); } } -- cgit v1.2.3-70-g09d2 From c16fd1d735698f2fbab7ffaf2557058107e5997f Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 03:28:17 +0200 Subject: Fix DBUnit warnings --- .../at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java index daf4ec4..c509a1f 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java @@ -6,6 +6,8 @@ import java.io.InputStream; import java.lang.invoke.MethodHandles; import java.sql.SQLException; import java.sql.Types; +import java.util.Collection; +import java.util.Collections; import org.dbunit.DefaultDatabaseTester; import org.dbunit.IDatabaseTester; import org.dbunit.IOperationListener; @@ -112,6 +114,11 @@ public abstract class JdbcTestCase { return super.createDataType(sqlType, sqlTypeName); } + + @Override + public Collection getValidDbProducts() { + return Collections.singletonList("H2"); + } }; config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory); -- cgit v1.2.3-70-g09d2 From 5f74bbf608b2a2159841f892e0334fd238216600 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 02:43:44 +0200 Subject: Fix and cleanup Operation dao+service #25963 --- .../einsatzverwaltung/dao/DBOperationDAO.java | 371 ++++----------------- .../einsatzverwaltung/dao/OperationDAO.java | 2 - .../service/OperationServiceImpl.java | 219 +++++------- .../service/VehicleServiceImpl.java | 7 +- .../einsatzverwaltung/dao/OperationDAOTest.java | 66 +++- .../dao/OperationPersistenceTest.java | 127 ------- .../service/CarAddTestService.java | 281 ---------------- .../service/OperationServiceTest.java | 56 +++- .../service/OperationServiceUnitTest.java | 156 --------- 9 files changed, 272 insertions(+), 1013 deletions(-) delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java delete mode 100644 src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.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 070b3fb..0bb25b8 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 @@ -1,18 +1,12 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; import at.ac.tuwien.sepm.assignment.groupphase.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.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.lang.invoke.MethodHandles; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -20,143 +14,71 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.EnumSet; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository; @Repository public class DBOperationDAO implements OperationDAO { private JDBCConnectionManager jdbcConnectionManager; - private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private VehicleDAO vehicleDAO; - public DBOperationDAO(JDBCConnectionManager j) { - jdbcConnectionManager = j; - try { - - getVehicleId = jdbcConnectionManager.getConnection().prepareStatement(GET_VEHICLE_ID); - - getVehicle = jdbcConnectionManager.getConnection().prepareStatement(GET_VEHICLE); - - getVehicleVersion = - jdbcConnectionManager.getConnection().prepareStatement(GET_VEHICLE_VERSION); - - getRegistrations = - jdbcConnectionManager.getConnection().prepareStatement(GET_REGISTRATIONS); + public DBOperationDAO(JDBCConnectionManager jdbcConnectionManager, VehicleDAO vehicleDAO) { + this.jdbcConnectionManager = jdbcConnectionManager; + this.vehicleDAO = vehicleDAO; + } - getEmployee = jdbcConnectionManager.getConnection().prepareStatement(GET_EMPLOYEE); + @Override + public long add(@NonNull Operation o) throws PersistenceException { + String sql = + "INSERT INTO Operation(opCode, severity, created, destination, additionalInfo," + + " status) VALUES (?, ?, ?, ?, ?, ?)"; + String sql2 = "INSERT INTO VehicleOperation(vehicleId, operationId) VALUES (?, ?)"; + long operationId; - getEmployeeVersion = - jdbcConnectionManager.getConnection().prepareStatement(GET_EMPLOYEE_VERSION); + try { + Connection con = jdbcConnectionManager.getConnection(); + con.setAutoCommit(false); + try (PreparedStatement pstmt = con.prepareStatement(sql)) { + pstmt.setString(1, o.opCode()); + pstmt.setInt(2, o.severity().ordinal()); + pstmt.setTimestamp(3, Timestamp.from(Objects.requireNonNull(o.created()))); + pstmt.setString(4, o.destination()); + pstmt.setString(5, o.additionalInfo()); + pstmt.setInt(6, o.status().ordinal()); + pstmt.executeUpdate(); - } catch (SQLException e) { + try (ResultSet rs = pstmt.getGeneratedKeys()) { + if (!rs.next()) throw new PersistenceException("Failed to persist operation"); - LOG.error( - "SQLException occurred while preparing Statements. Error message: {} ", - e.getMessage()); + operationId = rs.getLong(1); + } + } - // TODO: nothing should be thrown here - throw new IllegalStateException("TODO: fix me"); - // throw new PersistenceException(e); - } - } + try (PreparedStatement pstmt = con.prepareStatement(sql2)) { + pstmt.setLong(2, operationId); - @Override - public long add(Operation operation) throws PersistenceException { - if (operation == null) { - throw new PersistenceException("Das der Datenbank übergebene Objekt ist fehlerhaft!"); - } - PreparedStatement pstmt = null; - try { - pstmt = - jdbcConnectionManager - .getConnection() - .prepareStatement( - "INSERT INTO operation(opCode, severity, " - + "created, destination, additionalInfo, status) values (?,?,?,?,?,?)", - java.sql.Statement.RETURN_GENERATED_KEYS); - - if (operation.opCode() == null) { - throw new PersistenceException("Code darf nicht null sein!"); - } else if (operation.opCode().length() > 20) - throw new PersistenceException( - "Länge des OP-Codes überschreitet erlaubte Länge von 100 Zeichen!"); - else pstmt.setString(1, operation.opCode()); - /*switch (operation.severity()) { - case A: - pstmt.setInt(2, 0); - break; - case B: - pstmt.setInt(2, 1); - break; - case C: - pstmt.setInt(2, 2); - break; - case D: - pstmt.setInt(2, 3); - break; - case E: - pstmt.setInt(2, 4); - break; - case O: - pstmt.setInt(2, 5); - break; - default: - throw new PersistenceException( - "Schwere des Einsatzes konnte nicht validiert werden!"); - }*/ - pstmt.setString(2, operation.severity().name()); - if (operation.created() != null) { - pstmt.setTimestamp(3, Timestamp.from(Objects.requireNonNull(operation.created()))); - } else { - throw new PersistenceException("Zeitpunkt der Erstellung darf nicht null sein!"); - } + for (long id : (Iterable) o.vehicles().stream().map(Vehicle::id)::iterator) { + pstmt.setLong(1, id); + pstmt.addBatch(); + } - if (operation.destination() == null) { - throw new PersistenceException("Einsatzort darf nicht null sein!"); - } else if (operation.destination().length() > 100) { - throw new PersistenceException( - "Länge der Adresse überschreitet erlaubte Länge von 100 Zeichen!"); - } else { - pstmt.setString(4, operation.destination()); - } - if (operation.additionalInfo().length() > 100) - throw new PersistenceException( - "Länge der zusätzlichen Information überschreitet erlaubte Länge von 100 Zeichen!"); - else pstmt.setString(5, operation.additionalInfo()); - if (operation.status() == null) { - throw new PersistenceException("Status darf nicht null sein!"); - } else if (operation.status().toString().length() > 100) { - throw new PersistenceException( - "Länge des Status überschreitet erlaubte Länge von 100 Zeichen!"); - } else { - pstmt.setString(6, operation.status().toString()); + pstmt.executeBatch(); } - pstmt.executeUpdate(); - ResultSet rs = pstmt.getGeneratedKeys(); - if (rs.next()) return rs.getInt(1); - else throw new PersistenceException("Einsatz konnte nicht gespeichert werden"); + con.commit(); + con.setAutoCommit(true); + return operationId; } catch (SQLException e) { throw new PersistenceException(e); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { - throw new PersistenceException( - "Verbindung zur Datenbank konnte nicht geschlossen werden!", e); - } - } } } @Override - public void update(Operation o) throws ElementNotFoundException, PersistenceException { + public void update(@NonNull Operation o) throws ElementNotFoundException, PersistenceException { + // Note this will, by design, not update created String sql = "UPDATE Operation SET opCode = ?, severity = ?, destination = ?," + " additionalInfo = ?, status = ? WHERE id = ?"; @@ -175,7 +97,7 @@ public class DBOperationDAO implements OperationDAO { pstmt.setLong(6, o.id()); if (pstmt.executeUpdate() != 1) - throw new ElementNotFoundException("No such operationId exists: " + pstmt); + throw new ElementNotFoundException("No such operationId exists"); } try (PreparedStatement pstmt = con.prepareStatement(sql2)) { @@ -202,19 +124,21 @@ public class DBOperationDAO implements OperationDAO { @Override public Operation get(long operationId) throws ElementNotFoundException, PersistenceException { - if (operationId <= 0) - throw new ElementNotFoundException("Es wurde eine falsche ID übergeben!"); - String sql = "Select * from operation where id = ?"; - try (PreparedStatement pstmt = - jdbcConnectionManager.getConnection().prepareStatement(sql)) { - pstmt.setLong(1, operationId); - pstmt.execute(); - ResultSet rs = pstmt.getResultSet(); - if (rs.next()) { - return operationFromRS(rs); - } else throw new ElementNotFoundException("No element could be found!"); + try { + Connection con = jdbcConnectionManager.getConnection(); + try (PreparedStatement pstmt = con.prepareStatement(sql)) { + pstmt.setLong(1, operationId); + pstmt.execute(); + + try (ResultSet rs = pstmt.getResultSet()) { + if (!rs.next()) + throw new ElementNotFoundException("No such element could be found"); + + return operationFromRS(rs); + } + } } catch (SQLException e) { throw new PersistenceException(e); } @@ -240,7 +164,6 @@ public class DBOperationDAO implements OperationDAO { // Object[] arr = statuses.stream().map(Enum::ordinal).toArray(); // pstmt.setArray(1, con.createArrayOf("INT", arr)); - // TODO: this should set the vehicles as well try (ResultSet rs = pstmt.executeQuery()) { while (rs.next()) operations.add(operationFromRS(rs)); } @@ -253,194 +176,42 @@ public class DBOperationDAO implements OperationDAO { } private Operation operationFromRS(ResultSet rs) throws PersistenceException, SQLException { + Long operationId = rs.getLong("id"); + return Operation.builder() - .id(rs.getLong("id")) + .id(operationId) .opCode(rs.getString("opCode")) .severity(Severity.valueOf(rs.getString("severity"))) .status(Status.valueOf(rs.getString("status"))) - .vehicles(getVehiclesFromOperationId(rs.getLong("id"))) + .vehicles(getVehiclesFromOperationId(operationId)) .created(rs.getTimestamp("created").toInstant()) .destination(rs.getString("destination")) .additionalInfo(rs.getString("additionalInfo")) .build(); } - private static final String GET_VEHICLE_ID = - "SELECT vehicleId FROM VehicleOperation WHERE operationId = ? ;"; - - private final PreparedStatement getVehicleId; - private Set getVehiclesFromOperationId(long operationId) throws PersistenceException { + String sql = "SELECT vehicleId FROM VehicleOperation WHERE operationId = ?"; Set vehicles = new HashSet<>(); - try { - getVehicleId.setLong(1, operationId); - try (ResultSet resultSet = getVehicleId.executeQuery()) { - while (resultSet.next()) { - vehicles.add(getVehicle(resultSet.getLong("vehicleId"))); - } - } - } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting VehicleId from OperationId. Error message: {}", - e.getMessage()); - throw new PersistenceException(e); - } - return vehicles; - } - - private static String GET_VEHICLE = "SELECT * FROM Vehicle WHERE id = ? ;"; - private final PreparedStatement getVehicle; - - private Vehicle getVehicle(long vehicleId) throws PersistenceException { try { - getVehicle.setLong(1, vehicleId); - try (ResultSet resultSet = getVehicle.executeQuery()) { - resultSet.next(); - return getVehicleVersion( - resultSet.getLong("id"), - resultSet.getLong("version"), - resultSet.getString("status")); - } - } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting Vehicle by id. Error message: {}", - e.getMessage()); - throw new PersistenceException(e); - } - } - - private static String GET_VEHICLE_VERSION = "SELECT * FROM VehicleVersion WHERE id = ? ;"; - - private final PreparedStatement getVehicleVersion; - - private Vehicle getVehicleVersion(long vehicleId, long versionId, String status) - throws PersistenceException { - try { - getVehicleVersion.setLong(1, versionId); - try (ResultSet resultSet = getVehicleVersion.executeQuery()) { - resultSet.next(); - return Vehicle.builder() - .id(vehicleId) - .name(resultSet.getString("name")) - .constructionType( - ConstructionType.valueOf(resultSet.getString("constructionType"))) - .type(VehicleType.valueOf(resultSet.getString("type"))) - .status(Vehicle.Status.valueOf(status)) - .hasNef(resultSet.getBoolean("hasNef")) - .registrations(getRegistrations(vehicleId)) - .build(); - } - } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting VehicleVersion. Error message: {}", - e.getMessage()); - throw new PersistenceException(e); - } - } - - private static String GET_REGISTRATIONS = "SELECT * FROM Registration WHERE id = ? ;"; - - private final PreparedStatement getRegistrations; + Connection con = jdbcConnectionManager.getConnection(); + try (PreparedStatement pstmt = con.prepareStatement(sql)) { + pstmt.setLong(1, operationId); + pstmt.execute(); - private List getRegistrations(long vehicleId) throws PersistenceException { - List registrations = new LinkedList<>(); - try { - getRegistrations.setLong(1, vehicleId); - try (ResultSet resultSet = getRegistrations.executeQuery()) { - while (resultSet.next()) { - long registrationId = resultSet.getLong("id"); - registrations.add( - Registration.builder() - .id(registrationId) - .start(resultSet.getTimestamp("start").toInstant()) - .end(resultSet.getTimestamp("end").toInstant()) - .employee(getEmployee(resultSet.getLong("employeeId"))) - .build()); + try (ResultSet rs = pstmt.getResultSet()) { + while (rs.next()) { + vehicles.add(vehicleDAO.get(rs.getLong("vehicleId"))); + } } } } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting Registration. Error message: {}", - e.getMessage()); - throw new PersistenceException(e); - } - return registrations; - } - - private static String GET_EMPLOYEE = "SELECT version FROM Employee WHERE id = ? ;"; - - private final PreparedStatement getEmployee; - - private Employee getEmployee(long employeeId) throws PersistenceException { - try { - getEmployee.setLong(1, employeeId); - try (ResultSet resultSet = getEmployee.executeQuery()) { - resultSet.next(); - return getEmployeeVersion(employeeId, resultSet.getLong("version")); - } - } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting Employee. Error message: {}", - e.getMessage()); throw new PersistenceException(e); + } catch (ElementNotFoundException e) { + throw new PersistenceException("VehicleOperation contained nonexistent vehicle", e); } - } - - private static String GET_EMPLOYEE_VERSION = "SELECT * FROM EmployeeVersion WHERE id = ? ;"; - private final PreparedStatement getEmployeeVersion; - - private Employee getEmployeeVersion(long employeeId, long versionId) - throws PersistenceException { - try { - getEmployeeVersion.setLong(1, versionId); - try (ResultSet resultSet = getEmployeeVersion.executeQuery()) { - resultSet.next(); - return Employee.builder() - .id(employeeId) - .name(resultSet.getString("name")) - .birthday(resultSet.getDate("birthday").toLocalDate()) - .educationLevel( - EducationLevel.valueOf(resultSet.getString("educationLevel"))) - .isDriver(resultSet.getBoolean("isDriver")) - .isPilot(resultSet.getBoolean("isPilot")) - .build(); - } - } catch (SQLException e) { - LOG.error( - "SQLException occurred while getting EmployeeVersion. Error message: {}", - e.getMessage()); - throw new PersistenceException(e); - } - } - - @Override - public int connectVehicleToOperation(long vehicleID, long operationID) - throws PersistenceException { - PreparedStatement pstmt = null; - try { - pstmt = - jdbcConnectionManager - .getConnection() - .prepareStatement( - "insert into VehicleOperation(vehicleId, operationId)" - + "values (?,?)"); - pstmt.setLong(1, vehicleID); - pstmt.setLong(2, operationID); - pstmt.executeUpdate(); - } catch (SQLException e) { - throw new PersistenceException("Die Werte konnten nicht gespeichert werden!"); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { - throw new PersistenceException( - "Verbindung zur Datenbank konnte nicht geschlossen werden!", e); - } - } - } - return 1; + return vehicles; } } 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 da90cc8..d82f768 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAO.java @@ -45,6 +45,4 @@ public interface OperationDAO { * @throws PersistenceException if loading the stored operations failed */ 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/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 74d6457..4663d76 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 @@ -26,10 +26,9 @@ import org.springframework.stereotype.Service; @Service public class OperationServiceImpl implements OperationService { - // TODO: anders? - private OperationDAO operationDAO; private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private final OperationDAO operationDAO; private final VehicleDAO vehicleDAO; public OperationServiceImpl(OperationDAO operationDAO, VehicleDAO vehicleDAO) { @@ -38,91 +37,30 @@ public class OperationServiceImpl implements OperationService { } @Override - public long add(Operation operation) throws InvalidOperationException, ServiceException { - Set vehicles = operation.vehicles(); - boolean rtw = false; - if (faultyInput(operation.opCode())) { - throw new InvalidOperationException("Code ist ungültig!"); - } - if (faultyInput(operation.destination())) { - throw new InvalidOperationException("Adresse ist ungültig!"); - } - if (operation.vehicles().size() == 0) { - throw new InvalidOperationException( - "Es muss mindestens ein Fahrzeug ausgewählt werden!"); - } - for (Vehicle vehicle : vehicles) { - if (vehicle.status() == Vehicle.Status.ABGEMELDET - || (vehicle.status() != Vehicle.Status.FREI_FUNK - && vehicle.status() != Vehicle.Status.FREI_WACHE)) - throw new InvalidOperationException( - "Abgemeldete Fahrzeuge dürfen nicht zu einem Einsatz geschickt werden!"); - /*if (vehicle.type() == VehicleType.NEF && !rtw) { - for (Vehicle vehicleA : vehicles) { - if (vehicleA.type() == VehicleType.RTW && vehicleA.hasNef()) { - rtw = true; - break; - } - } - if (!rtw) - throw new InvalidOperationException( - "Zu einem Fahrzeug des Typs NEF muss auch ein Fahrzeug des Typs RTW mit NEF-Halterung geschickt werden!"); - }*/ - /* if (vehicle.type() == VehicleType.NAH && !rtw) { - for (Vehicle vehicleA : vehicles) { - if (vehicleA.type() == VehicleType.RTW) { - rtw = true; - break; - } - } - if (!rtw) - throw new InvalidOperationException( - "Zu einem Fahrzeug des Typs NAH muss auch ein Fahrzeug des Typs RTW geschickt werden!"); - }*/ - } - String[] codeParts = operation.opCode().split("-"); - String severity = ""; - for (int i = 0; i < codeParts[1].length(); i++) { - if (((int) (codeParts[1].charAt(i)) >= 65 && (int) (codeParts[1].charAt(i)) <= 79) - || ((int) (codeParts[1].charAt(i)) >= 97 - && (int) (codeParts[1].charAt(i)) <= 111)) { - severity = "" + codeParts[1].charAt(i); - break; - } - } - try { - operation = operation.toBuilder().severity(Severity.valueOf(severity)).build(); - } catch (IllegalArgumentException e) { - throw new InvalidOperationException( - "Der Schweregrad des Einsatzes konnte nicht ausgelesen werden!"); - } - operation = operation.toBuilder().status(Status.ACTIVE).build(); + public long add(Operation o) throws InvalidOperationException, ServiceException { + if (o.created() != null) throw new InvalidOperationException("Created must not be set"); - long operationId; - try { - operationId = operationDAO.add(operation); - } catch (PersistenceException e) { - throw new ServiceException(e); - } + if (o.status() != Status.ACTIVE) + LOG.warn("Status was set but will be overridden"); // TODO: nullable instead?? - for (Vehicle vehicle : vehicles) { - try { - operationDAO.connectVehicleToOperation(vehicle.id(), operationId); - } catch (PersistenceException e) { - throw new ServiceException(e); + try { + for (long id : (Iterable) o.vehicles().stream().map(Vehicle::id)::iterator) { + Vehicle v = vehicleDAO.get(id); + VehicleServiceImpl.validateVehicle(v); } - } - return operationId; - } + validateOperation(o); - private boolean faultyInput(String name) { - if (name == null) return true; - else if (name.isEmpty()) return true; - for (int i = 0; i < name.length(); i++) { - if (name.charAt(i) != ' ') return false; + return operationDAO.add( + o.toBuilder().created(Instant.now()).status(Status.ACTIVE).build()); + } catch (PersistenceException e) { + LOG.error("PersistenceException while adding operation: {}", e); + throw new ServiceException(e); + } catch (InvalidVehicleException e) { + throw new InvalidOperationException("Enthaltenes Fahrzeug ist invalid", e); + } catch (ElementNotFoundException e) { + throw new InvalidOperationException("Enthaltenes Fahrzeug existiert nicht", e); } - return true; } @Override @@ -131,28 +69,29 @@ public class OperationServiceImpl implements OperationService { Set vs = new HashSet<>(); try { - if (operationId <= 0) throw new InvalidOperationException("OperationId is invalid"); + if (operationId <= 0) throw new InvalidOperationException("OperationId ist invalid"); Operation o = operationDAO.get(operationId); validateOperation(o); if (o.status() != Status.ACTIVE) - throw new InvalidOperationException( - "Can't request vehicles for a nonactive operation"); + throw new InvalidOperationException("Einsatz ist inaktiv"); - if (!o.status().equals(Status.ACTIVE)) - throw new InvalidOperationException("Can't add vehicles to a nonactive operation"); + if (o.created() == null) + throw new InvalidOperationException("Created darf nicht leer sein"); for (Long id : vehicleIds) { - if (id <= 0) throw new InvalidVehicleException("VehicleId is invalid"); + if (id <= 0) throw new InvalidVehicleException("VehicleId ist invalid"); try { Vehicle v = vehicleDAO.get(id); + VehicleServiceImpl.validateVehicle(v); if (v.status() == Vehicle.Status.ABGEMELDET) - throw new InvalidVehicleException("Can't request nonactive vehicles"); + throw new InvalidVehicleException( + "Kann keine inaktiven Fahrzeuge anfordern"); vs.add(v); } catch (ElementNotFoundException e) { - throw new InvalidVehicleException("VehicleId does not exist"); + throw new InvalidVehicleException("VehicleId ist invalid"); } } @@ -161,55 +100,23 @@ public class OperationServiceImpl implements OperationService { operationDAO.update(o.toBuilder().vehicles(vs).build()); } catch (ElementNotFoundException e) { - throw new InvalidOperationException("No such operationId exists"); + throw new InvalidOperationException("Kein Einsatz mit dieser id existiert"); } catch (PersistenceException e) { + LOG.error("PersistenceException while requesting vehicles: {}", e); throw new ServiceException(e); } } - private static final Pattern opCodePattern = Pattern.compile("(?:\\w{1,3}-\\d{0,2})(.)(?:.*)"); - - private void validateOperation(Operation o) throws InvalidOperationException { - if (o.id() <= 0) throw new InvalidOperationException("Id is invalid"); - - if (o.opCode().trim().isEmpty()) throw new InvalidOperationException("opCode is invalid"); - - Matcher m = opCodePattern.matcher(o.opCode()); - if (!m.matches()) throw new InvalidOperationException("opCode is invalid"); - - if (!m.group(1).equals(o.severity().toString())) - throw new InvalidOperationException("Severity is invalid"); - - if (o.vehicles().isEmpty()) - throw new InvalidOperationException("No vehicles assigned to operation"); - - Instant created = o.created(); - if (created == null) throw new InvalidOperationException("Created can't be empty"); - - if (created.isAfter(Instant.now())) - throw new InvalidOperationException("Vehicle was created in the future"); - - if (o.destination().trim().isEmpty()) - throw new InvalidOperationException("Destination can't be empty"); - } - @Override public void complete(long operationId, Status status) throws InvalidOperationException, ServiceException { - Operation operation; - try { - operation = operationDAO.get(operationId); - } catch (ElementNotFoundException e) { - throw new InvalidOperationException(e); - } catch (PersistenceException e) { - throw new ServiceException(e); - } - operation = operation.toBuilder().status(status).build(); try { - operationDAO.update(operation); + Operation o = operationDAO.get(operationId); + operationDAO.update(o.toBuilder().status(status).build()); } catch (ElementNotFoundException e) { throw new InvalidOperationException(e); } catch (PersistenceException e) { + LOG.error("PersistenceException while completing operation: {}", e); throw new ServiceException(e); } } @@ -217,18 +124,68 @@ public class OperationServiceImpl implements OperationService { @Override public SortedSet rankVehicles(long operationId) throws InvalidOperationException, ServiceException { - return null; + throw new UnsupportedOperationException(); } @Override public Set list(EnumSet statuses) throws ServiceException { try { - return operationDAO.list(statuses); + Set operations = operationDAO.list(statuses); + for (Operation o : operations) validateOperation(o); + + return operations; } catch (PersistenceException e) { - LOG.debug( - "Caught PersistenceException. Throwing ServiceException. Message: {}", - e.getMessage()); + LOG.error("PersistenceException while listing operations", e); throw new ServiceException(e); + } catch (InvalidOperationException e) { + // database returned invalid values + LOG.error("DB returned invalid operation: {}", e); + throw new ServiceException("DB returned invalid operation", e); } } + + private static void validateOperation(Operation o) throws InvalidOperationException { + if (o.id() <= 0) throw new InvalidOperationException("Id is invalid"); + + if (o.opCode().trim().isEmpty()) throw new InvalidOperationException("opCode is invalid"); + + if (extractSeverityFromOpCode(o.opCode()) != o.severity()) + throw new InvalidOperationException("Einsatzcode ist invalid"); + + if (o.vehicles().isEmpty()) + throw new InvalidOperationException( + "Es muss mindestens ein Fahrzeug ausgewählt werden!"); + + for (Vehicle v : o.vehicles()) { + try { + VehicleServiceImpl.validateVehicle(v); + } catch (InvalidVehicleException e) { + throw new InvalidOperationException("Fahrzeug " + v.name() + " ist invalid" + e); + } + + if (v.status() != Vehicle.Status.FREI_FUNK && v.status() != Vehicle.Status.FREI_WACHE) + throw new InvalidOperationException( + "Fahrzeug nicht verfügbar (" + v.status() + ")"); + + // TODO: validate if NEF/RTW/NAH conditions? + } + + Instant created = o.created(); + if (created != null && created.isAfter(Instant.now())) + throw new InvalidOperationException("Fahrzeug wurde in der Zukunft erstellt"); + + if (o.destination().trim().isEmpty()) + throw new InvalidOperationException("Adresse darf nicht leer sein"); + } + + private static final Pattern opCodePattern = Pattern.compile("(?:\\w{1,3}-\\d{0,2})(.)(?:.*)"); + + private static Severity extractSeverityFromOpCode(String opCode) + throws InvalidOperationException { + Matcher m = opCodePattern.matcher(opCode); + + if (!m.matches()) throw new InvalidOperationException("Einsatzcode ist invalid"); + + return Severity.valueOf(m.group(1)); + } } 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 da995c4..8b317ce 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 @@ -12,6 +12,7 @@ import java.util.EnumSet; import java.util.Set; import java.util.stream.Collectors; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; @Service public class VehicleServiceImpl implements VehicleService { @@ -23,6 +24,8 @@ public class VehicleServiceImpl implements VehicleService { } public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + if (CollectionUtils.isEmpty(vehicle.registrations())) + throw new InvalidVehicleException("Vehicle can't be created with registrations"); validateVehicle(vehicle); try { @@ -45,7 +48,7 @@ public class VehicleServiceImpl implements VehicleService { return vehicle; } - private void validateVehicle(Vehicle vehicle) throws InvalidVehicleException, ServiceException { + protected static void validateVehicle(Vehicle vehicle) throws InvalidVehicleException { switch (vehicle.type()) { case RTW: if (vehicle.constructionType() == ConstructionType.NORMAL) { @@ -81,7 +84,7 @@ public class VehicleServiceImpl implements VehicleService { case BKTW: break; default: - throw new ServiceException("not a Valid type"); + throw new IllegalStateException("BUG: invalid vehicle type" + vehicle.type()); } } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java index e62554c..da20030 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java @@ -4,9 +4,13 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; import java.time.Instant; +import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.Set; @@ -19,12 +23,13 @@ public class OperationDAOTest extends JdbcTestCase { private static final String[] COMPARE_TABLES = new String[] {"VehicleOperation", "Operation", "Vehicle", "VehicleVersion"}; - private OperationDAO operationDAO; + private final OperationDAO operationDAO; private final Operation o; public OperationDAOTest() { - this.operationDAO = new DBOperationDAO(getJdbcConnectionManager()); + VehicleDAO vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); + this.operationDAO = new DBOperationDAO(getJdbcConnectionManager(), vehicleDAO); Vehicle v1 = Vehicle.builder() @@ -87,4 +92,61 @@ public class OperationDAOTest extends JdbcTestCase { // TODO: operations.list() currently doesn't set the vehicles set // assertEquals(Set.of(o), operationSet); } + + @Test + public void testAddOperation() throws Exception { + operationDAO.add(o); + + // TODO: won't work because id won't match + // compareWith("operationDAOUpdateNormal.xml", COMPARE_TABLES); + } + + @Test(expected = PersistenceException.class) + public void testAddFaultyOperation() throws PersistenceException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode(String.valueOf(Arrays.stream(new int[200]).map(i -> 'a'))) + .created(Instant.now()) + .destination("Wiedner Hauptstraße 35, Wien") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(Set.of(vehicle)) + .build(); + operationDAO.add(operation); + } + + @Test(expected = PersistenceException.class) + public void testAddFaultyOperation2() throws PersistenceException { + Vehicle vehicle = + Vehicle.builder() + .status(Vehicle.Status.FREI_FUNK) + .constructionType(ConstructionType.HOCHDACH) + .name("BKTW_123") + .hasNef(true) + .type(VehicleType.BKTW) + .build(); + + Operation operation = + Operation.builder() + .status(Status.ACTIVE) + .opCode("ALP-95E7") + .created(Instant.now()) + .destination( + "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ") + .additionalInfo("HTU Wien") + .severity(Severity.B) + .vehicles(Set.of(vehicle)) + .build(); + operationDAO.add(operation); + } } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java deleted file mode 100644 index a5e4993..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; - -import static junit.framework.TestCase.fail; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.Arrays; -import java.util.Set; -import org.h2.tools.RunScript; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperationPersistenceTest { - - private final OperationDAO operationDAO = - new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - - @BeforeClass - public static void createSchema() throws SQLException { - RunScript.execute( - "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", - "", - "", - "classpath:sql/database.sql", - Charset.forName("UTF8"), - false); - } - - @Test - public void addOperationTest() { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of(vehicle)) - .build(); - try { - operationDAO.add(operation); - } catch (PersistenceException e) { - fail(); - } - } - - @Test(expected = PersistenceException.class) - public void addFaultyOperationTest() throws PersistenceException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode(String.valueOf(Arrays.stream(new int[200]).map(i -> 'a'))) - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of(vehicle)) - .build(); - operationDAO.add(operation); - } - - @Test(expected = PersistenceException.class) - public void addFaultyOperation1Test() throws PersistenceException { - operationDAO.add(null); - } - - @Test(expected = PersistenceException.class) - public void addFaultyOperation2Test() throws PersistenceException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination( - "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of(vehicle)) - .build(); - operationDAO.add(operation); - } - - @Test(expected = PersistenceException.class) - public void addConnectionTest() throws PersistenceException { - operationDAO.connectVehicleToOperation(-1, 0); - } - - // TODO: ADD CONNECTION TESTS - // KOMMT ID ZURÜCK?*/ -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java deleted file mode 100644 index fd8b43f..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java +++ /dev/null @@ -1,281 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static junit.framework.TestCase.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDatabaseDao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import org.junit.Test; - -public class CarAddTestService { - private final VehicleDAO vehicleP = mock(VehicleDatabaseDao.class); - private final VehicleService vehicleService = new VehicleServiceImpl(vehicleP); - - public CarAddTestService() throws PersistenceException { - when(vehicleP.add(any())).thenReturn(1L); - } - - @Test - public void testValidVehicleH() { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.RTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.KTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.KTW_B) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.BKTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - } - - @Test - public void testValidVehicleM() { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.KTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.KTW_B) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.BKTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - } - - @Test - public void testValidVehicleN() { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.BKTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.NEF) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.NAH) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (InvalidVehicleException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidVehicleException.class) - public void testInvalidVehicleH() throws InvalidVehicleException { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.NEF) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.NAH) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidVehicleException.class) - public void testInvalidVehicleM() throws InvalidVehicleException { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.NEF) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.NAH) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.RTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidVehicleException.class) - public void testInvalidVehicleN() throws InvalidVehicleException { - Vehicle vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.RTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.KTW_B) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - vehicle = - Vehicle.builder() - .constructionType(Vehicle.ConstructionType.NORMAL) - .type(Vehicle.VehicleType.KTW) - .hasNef(true) - .status(Vehicle.Status.ABGEMELDET) - .name("") - .build(); - try { - vehicleService.add(vehicle); - } catch (ServiceException e) { - fail(); - } - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java index 70185d3..f9ec287 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java @@ -1,5 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -11,10 +12,10 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import java.time.Instant; import java.util.Collections; import java.util.Set; @@ -36,14 +37,15 @@ public class OperationServiceTest { private Set vehicles; private Vehicle v1, v2, v3, v4, v5; + private Operation baseOp, o1, o2; @Before - public void setUp() throws ElementNotFoundException, PersistenceException { + public void setUp() throws Exception { v1 = Vehicle.builder() .id(1) .name("RTW-1") - .constructionType(Vehicle.ConstructionType.HOCHDACH) + .constructionType(ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.RTW) .status(Vehicle.Status.FREI_FUNK) .hasNef(true) @@ -53,7 +55,7 @@ public class OperationServiceTest { Vehicle.builder() .id(2) .name("KTW-1") - .constructionType(Vehicle.ConstructionType.HOCHDACH) + .constructionType(ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.KTW) .status(Vehicle.Status.FREI_WACHE) .hasNef(true) @@ -63,7 +65,7 @@ public class OperationServiceTest { Vehicle.builder() .id(3) .name("KTW-2") - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) + .constructionType(ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.KTW_B) .status(Vehicle.Status.FREI_FUNK) .hasNef(false) @@ -73,7 +75,7 @@ public class OperationServiceTest { Vehicle.builder() .id(4) .name("BKTW-2") - .constructionType(Vehicle.ConstructionType.HOCHDACH) + .constructionType(ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.BKTW) .status(Vehicle.Status.FREI_FUNK) .hasNef(false) @@ -83,7 +85,7 @@ public class OperationServiceTest { Vehicle.builder() .id(5) .name("NEF-1") - .constructionType(Vehicle.ConstructionType.NORMAL) + .constructionType(ConstructionType.NORMAL) .type(Vehicle.VehicleType.NEF) .status(Vehicle.Status.FREI_WACHE) .hasNef(true) @@ -93,7 +95,7 @@ public class OperationServiceTest { Vehicle.builder() .id(6) .name("NAH-1") - .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) + .constructionType(ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.NAH) .status(Vehicle.Status.ABGEMELDET) .hasNef(true) @@ -101,24 +103,24 @@ public class OperationServiceTest { vehicles = Set.of(v1, v2, v3, v4, v5, v6); - Operation o = + baseOp = Operation.builder() .id(1) .opCode("ALP-95E7") .severity(Severity.E) .status(Status.ACTIVE) .vehicles(Collections.singleton(v1)) - .created(Instant.now()) .destination("Wiedner Hauptstraße 35, Wien") .build(); - Operation o2 = o.toBuilder().status(Status.CANCELLED).build(); + o1 = baseOp.toBuilder().created(Instant.now()).build(); + o2 = o1.toBuilder().id(5).status(Status.CANCELLED).build(); when(operationDAO.get(anyLong())) .thenAnswer( ans -> { long arg = ans.getArgument(0); - if (arg == 1L) return o; + if (arg == 1L) return o1; else if (arg == 5L) return o2; else throw new ElementNotFoundException(""); }); @@ -172,4 +174,34 @@ public class OperationServiceTest { public void requestInactiveOperation() throws Exception { operationService.requestVehicles(5, Set.of(1L)); } + + @Test + public void addOperation() throws Exception { + operationService.add(baseOp); + + // Operation result = + verify(operationDAO, times(1)) + .add(baseOp.toBuilder().created(any()).status(Status.ACTIVE).build()); + verify(vehicleDAO, times(1)).get(v1.id()); + } + + @Test(expected = InvalidOperationException.class) + public void addInvalidSeverity() throws Exception { + operationService.add(baseOp.toBuilder().severity(Severity.B).build()); + } + + @Test(expected = InvalidOperationException.class) + public void addWithoutVehicles() throws Exception { + operationService.add(baseOp.toBuilder().vehicles(Set.of()).build()); + } + + @Test(expected = InvalidOperationException.class) + public void addInvalidOpcode() throws Exception { + operationService.add(baseOp.toBuilder().opCode("ABC").build()); + } + + @Test(expected = InvalidOperationException.class) + public void addWithSetCreated() throws Exception { + operationService.add(baseOp.toBuilder().created(Instant.now()).build()); + } } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java deleted file mode 100644 index 7b574a1..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.Set; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceUnitTest { - private final OperationDAO operationDAO = mock(OperationDAO.class); - private final VehicleDAO vehicleDAO = mock(VehicleDAO.class); - private final OperationService operationService = - new OperationServiceImpl(operationDAO, vehicleDAO); - - @Test - public void addOperationTest() { - try { - when(operationDAO.add(any())).thenReturn(1L); - } catch (PersistenceException e) { - fail(); - } - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of(vehicle)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (InvalidOperationException | ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperationTest() throws InvalidOperationException { - Vehicle vehicle = - Vehicle.builder() - .status(Vehicle.Status.FREI_FUNK) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - Vehicle vehicle1 = - Vehicle.builder() - .status(Vehicle.Status.ABGEMELDET) - .constructionType(ConstructionType.HOCHDACH) - .name("BKTW_123") - .hasNef(true) - .type(VehicleType.BKTW) - .build(); - - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of(vehicle, vehicle1)) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - fail(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation2Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("Wiedner Hauptstraße 35, Wien") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation3Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("ALP-95E7") - .created(Instant.now()) - .destination("") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } - - @Test(expected = InvalidOperationException.class) - public void addFaultyOperation4Test() throws InvalidOperationException { - Operation operation = - Operation.builder() - .status(Status.ACTIVE) - .opCode("") - .created(Instant.now()) - .destination("Römergasse 7, 2500 Baden") - .additionalInfo("HTU Wien") - .severity(Severity.B) - .vehicles(Set.of()) - .build(); - try { - Assert.assertThat(operationService.add(operation), is(1L)); - } catch (ServiceException e) { - e.printStackTrace(); - } - } -} -- cgit v1.2.3-70-g09d2 From aa170291e9da8b943828d3ec4e71b914d55319ba Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 23:36:05 +0200 Subject: Prepare vehicle-dao fix by adding RegistrationDatabaseDAO.list [#25963] --- .../dao/RegistrationDatabaseDAO.java | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 5c00447..13f2c0f 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 @@ -1,5 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; @@ -10,7 +11,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,20 +29,27 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; private static final String UPDATE_VEHICLE = "UPDATE Vehicle SET status = 'FREI_WACHE' WHERE id = ?;"; + private static final String FETCH_REGISTRATIONS = + "SELECT * FROM Registration WHERE vehicleId = ?"; private PreparedStatement addRegistration; private PreparedStatement updateVehicle; + private PreparedStatement fetchRegistrations; private Connection connection; + private EmployeeDAO employeePersistence; @Autowired - public RegistrationDatabaseDAO(JDBCConnectionManager connectionManager) + public RegistrationDatabaseDAO( + JDBCConnectionManager connectionManager, EmployeeDAO employeePersistence) throws PersistenceException { + this.employeePersistence = employeePersistence; try { connection = connectionManager.getConnection(); addRegistration = connection.prepareStatement(ADD_REGISTRATION, Statement.RETURN_GENERATED_KEYS); updateVehicle = connection.prepareStatement(UPDATE_VEHICLE); + fetchRegistrations = connection.prepareStatement(FETCH_REGISTRATIONS); } catch (SQLException e) { LOG.error("Could not get connection or preparation of statement failed"); throw new PersistenceException(e); @@ -103,4 +113,35 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { public void remove(long id) throws ElementNotFoundException, PersistenceException { throw new UnsupportedOperationException(); } + + public List list(long vehicleId) throws PersistenceException { + List registrationList = new ArrayList<>(); + try { + fetchRegistrations.setLong(1, vehicleId); + ResultSet rs = fetchRegistrations.executeQuery(); + while (rs.next()) { + long employeeId = rs.getLong("employeeId"); + // TODO: replace the following with employeePersistence.get once implemented + Employee emp = + employeePersistence + .list() + .stream() + .filter(employee -> employee.id() == employeeId) + .findAny() + .orElse(null); + Registration registration = + Registration.builder() + .id(rs.getLong("id")) + .start(rs.getTimestamp("start").toInstant()) + .end(rs.getTimestamp("end").toInstant()) + .employee(emp) + .build(); + registrationList.add(registration); + } + } catch (SQLException e) { + throw new PersistenceException(e); + } + + return registrationList; + } } -- cgit v1.2.3-70-g09d2 From 68d85ab02777e30d74637291de7a2e9d8e861306 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 23:42:28 +0200 Subject: Fix vehicle-dao [#25963] 1) set registrations in vehicleFromRS 2) side-fix: change 'version' to 'id' in update method as they were previously swapped. Same fix was done today in add method, but not in update --- .../einsatzverwaltung/dao/VehicleDatabaseDao.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 808e7e7..89a3aca 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 @@ -20,9 +20,12 @@ import org.springframework.stereotype.Repository; public class VehicleDatabaseDao implements VehicleDAO { private final JDBCConnectionManager jdbcConnectionManager; + private RegistrationDatabaseDAO registrationDatabaseDao; - public VehicleDatabaseDao(JDBCConnectionManager j) { + public VehicleDatabaseDao( + JDBCConnectionManager j, RegistrationDatabaseDAO registrationDatabaseDao) { jdbcConnectionManager = j; + this.registrationDatabaseDao = registrationDatabaseDao; } public long add(Vehicle vehicle) throws PersistenceException { @@ -86,7 +89,7 @@ public class VehicleDatabaseDao implements VehicleDAO { @Override public void update(Vehicle vehicle) throws ElementNotFoundException, PersistenceException { - String query = "SELECT id FROM vehicle WHERE version=?"; + String query = "SELECT * FROM vehicle WHERE id=?"; long vehicleID = -1; long vehicleVersion = -1; @@ -100,7 +103,7 @@ public class VehicleDatabaseDao implements VehicleDAO { p.executeQuery(); try (ResultSet rs = p.getResultSet()) { while (rs.next()) { - vehicleID = rs.getLong(1); + vehicleID = rs.getLong("id"); } } } @@ -203,14 +206,15 @@ public class VehicleDatabaseDao implements VehicleDAO { @Override public void remove(long id) throws ElementNotFoundException, PersistenceException {} - private Vehicle vehicleFromRS(ResultSet rs) throws SQLException { + private Vehicle vehicleFromRS(ResultSet rs) throws SQLException, PersistenceException { return Vehicle.builder() - .id(rs.getLong("id")) + .id(rs.getLong("Vehicle.id")) .name(rs.getString("name")) .constructionType(ConstructionType.values()[rs.getInt("constructionType")]) .type(VehicleType.valueOf(rs.getString("type"))) .status(Status.values()[rs.getInt("status")]) .hasNef(rs.getBoolean("hasNef")) + .registrations(registrationDatabaseDao.list(rs.getLong("id"))) .build(); } } -- cgit v1.2.3-70-g09d2 From 7e81a28260bb6aa40cfdc3a2c50fcb0b2a93b637 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 23:49:25 +0200 Subject: Add missing constructor parameters in RegistrationDAOTest [#25963] Additional parameters were added in 19419f8 --- .../einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 09699c5..bdc16fb 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 @@ -32,7 +32,11 @@ public class RegistrationDatabaseDAOTest { private RegistrationDAO registrationDAO; public RegistrationDatabaseDAOTest() throws PersistenceException { - this.registrationDAO = new RegistrationDatabaseDAO(new JDBCConnectionManager(JDBC_URL)); + JDBCConnectionManager jdbcConnectionManager = new JDBCConnectionManager(JDBC_URL); + this.registrationDAO = + new RegistrationDatabaseDAO( + jdbcConnectionManager, new EmployeeDatabaseDao(jdbcConnectionManager)); + // TODO: Use Spring Dependency Injection here! } @BeforeClass -- cgit v1.2.3-70-g09d2 From 7ea55a0450c562b4e3a2a23acd3a1ee73f04c876 Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 23:50:52 +0200 Subject: Add missing constructor parameters in VehiclePersistenceTest [#25963] Additional parameters for VehicleDatabaseDao were added in previous commit f43bb72 --- .../einsatzverwaltung/dao/VehiclePersistenceTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java index 9909385..0beb5c1 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehiclePersistenceTest.java @@ -9,6 +9,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.util.Helper; import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase; import java.io.InputStream; +import java.util.ArrayList; import java.util.Set; import org.dbunit.Assertion; import org.dbunit.dataset.IDataSet; @@ -31,8 +32,14 @@ public class VehiclePersistenceTest extends JdbcTestCase { .status(Status.ABGEMELDET) .build(); - public VehiclePersistenceTest() { - vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); + public VehiclePersistenceTest() throws PersistenceException { + vehicleDAO = + new VehicleDatabaseDao( + getJdbcConnectionManager(), + new RegistrationDatabaseDAO( + getJdbcConnectionManager(), + new EmployeeDatabaseDao(getJdbcConnectionManager()))); + // TODO: use Spring Dependency Injection! } @Override @@ -53,6 +60,7 @@ public class VehiclePersistenceTest extends JdbcTestCase { .hasNef(true) .status(Status.ABGEMELDET) .type(VehicleType.RTW) + .registrations(new ArrayList<>()) .build(); Vehicle v2 = Vehicle.builder() @@ -62,6 +70,7 @@ public class VehiclePersistenceTest extends JdbcTestCase { .hasNef(false) .status(Status.FREI_WACHE) .type(VehicleType.KTW) + .registrations(new ArrayList<>()) .build(); Vehicle v3 = Vehicle.builder() @@ -71,6 +80,7 @@ public class VehiclePersistenceTest extends JdbcTestCase { .hasNef(false) .status(Status.FREI_FUNK) .type(VehicleType.NEF) + .registrations(new ArrayList<>()) .build(); Assert.assertTrue(vehicles.contains(v1)); -- cgit v1.2.3-70-g09d2 From 80a8d2dc7df2f6760bf2c499d50e9dee4432eb8b Mon Sep 17 00:00:00 2001 From: Dominic Rogetzer Date: Wed, 23 May 2018 23:53:37 +0200 Subject: Fix vehicleTestData, vehicleTestUpdateExpectedData (id swap) [#25963] Changes relate to 'side-fix' addressed in f43bb72 --- src/test/resources/vehicleTestData.xml | 12 ++++++------ src/test/resources/vehicleTestUpdateExpectedData.xml | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/resources/vehicleTestData.xml b/src/test/resources/vehicleTestData.xml index 19d25ad..c3f2e79 100644 --- a/src/test/resources/vehicleTestData.xml +++ b/src/test/resources/vehicleTestData.xml @@ -1,10 +1,10 @@ - - - + + + - - - + + + \ No newline at end of file diff --git a/src/test/resources/vehicleTestUpdateExpectedData.xml b/src/test/resources/vehicleTestUpdateExpectedData.xml index 159ccaa..861880b 100644 --- a/src/test/resources/vehicleTestUpdateExpectedData.xml +++ b/src/test/resources/vehicleTestUpdateExpectedData.xml @@ -1,10 +1,10 @@ - - - - + + + + - - - + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 351ea799e6c757c7a3c3ea960175976f4bfa627e Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 03:45:53 +0200 Subject: Fix conflict with OperationDAOTest #25963 --- .../groupphase/einsatzverwaltung/dao/OperationDAOTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java index da20030..d2a6b7e 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java @@ -27,8 +27,13 @@ public class OperationDAOTest extends JdbcTestCase { private final Operation o; - public OperationDAOTest() { - VehicleDAO vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); + public OperationDAOTest() throws PersistenceException { + // TODO: fix once everything properly uses dependency injection + EmployeeDAO employeeDAO = new EmployeeDatabaseDao(getJdbcConnectionManager()); + RegistrationDatabaseDAO registrationDatabaseDAO = + new RegistrationDatabaseDAO(getJdbcConnectionManager(), employeeDAO); + VehicleDAO vehicleDAO = + new VehicleDatabaseDao(getJdbcConnectionManager(), registrationDatabaseDAO); this.operationDAO = new DBOperationDAO(getJdbcConnectionManager(), vehicleDAO); Vehicle v1 = -- cgit v1.2.3-70-g09d2 From 2f9b23f0a2504fc754e3630872c9747404a2bdfe Mon Sep 17 00:00:00 2001 From: Andreas Weninger Date: Thu, 24 May 2018 09:52:11 +0200 Subject: Hotfix: Correctly apply styles. --- .../einsatzverwaltung/ui/vehiclepane/VehiclePaneController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 dfebb00..e7a1cc0 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 @@ -102,7 +102,12 @@ public class VehiclePaneController { public void setSelected(boolean selected) { rootElement.getStyleClass().clear(); - if (selected) rootElement.getStyleClass().add("bg-yellow, shadowed"); - else rootElement.getStyleClass().add("bg-white, shadowed"); + if (selected) { + rootElement.getStyleClass().add("bg-yellow"); + rootElement.getStyleClass().add("shadowed"); + } else { + rootElement.getStyleClass().add("bg-white"); + rootElement.getStyleClass().add("shadowed"); + } } } -- cgit v1.2.3-70-g09d2 From cbc9019c96f2412ce3c6ec941726a4051e8d842a Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Thu, 24 May 2018 11:58:03 +0200 Subject: Fix VehicleServiceImpl von empty to !empty Id #25963 --- .../groupphase/einsatzverwaltung/service/VehicleServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8b317ce..61a24e5 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 @@ -24,7 +24,7 @@ public class VehicleServiceImpl implements VehicleService { } public long add(Vehicle vehicle) throws InvalidVehicleException, ServiceException { - if (CollectionUtils.isEmpty(vehicle.registrations())) + if (!CollectionUtils.isEmpty(vehicle.registrations())) throw new InvalidVehicleException("Vehicle can't be created with registrations"); validateVehicle(vehicle); -- cgit v1.2.3-70-g09d2 From e594ae7ee261bd3359d8cce55deda989bcb33206 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 14:26:01 +0200 Subject: Change OperationService rankVehicle() #25963 Taken an opCode instead of a operationId, since we need the ranking before the operation is created. --- .../groupphase/einsatzverwaltung/service/OperationService.java | 8 ++++---- .../einsatzverwaltung/service/OperationServiceImpl.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 98a2068..4b7e630 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 @@ -48,15 +48,15 @@ public interface OperationService { throws InvalidOperationException, ServiceException; /** - * Get all available vehicles, sorted by how well they fit to the given operation, starting with + * Get all available vehicles, sorted by how well they fit to the given opCode, starting with * the best fitting. * - * @param operationId id of the operation that is used to determine the ranking + * @param opCode the operation code that is used to determine the ranking * @return a sorted list containing all available vehicles - * @throws InvalidOperationException if the operationId is invalid or does not exist + * @throws InvalidOperationException if the opCode is invalid * @throws ServiceException if loading the stored vehicles failed */ - SortedSet rankVehicles(long operationId) + SortedSet rankVehicles(String opCode) throws InvalidOperationException, 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 4663d76..e1d6f29 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 @@ -122,7 +122,7 @@ public class OperationServiceImpl implements OperationService { } @Override - public SortedSet rankVehicles(long operationId) + public SortedSet rankVehicles(String opCode) throws InvalidOperationException, ServiceException { throw new UnsupportedOperationException(); } -- cgit v1.2.3-70-g09d2 From 81ce4fe6d5cebff6054b70620b7b8130e9b8ad10 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 14:44:57 +0200 Subject: Implement rankVehicles from Andi #25963 --- .../service/OperationServiceImpl.java | 67 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) 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 e1d6f29..a89e3b1 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -6,6 +6,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; @@ -13,12 +14,17 @@ import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import java.lang.invoke.MethodHandles; import java.time.Instant; +import java.util.ArrayList; import java.util.EnumSet; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -30,10 +36,13 @@ public class OperationServiceImpl implements OperationService { private final OperationDAO operationDAO; private final VehicleDAO vehicleDAO; + private final VehicleService vehicleService; - public OperationServiceImpl(OperationDAO operationDAO, VehicleDAO vehicleDAO) { + public OperationServiceImpl( + OperationDAO operationDAO, VehicleDAO vehicleDAO, VehicleService vehicleService) { this.operationDAO = operationDAO; this.vehicleDAO = vehicleDAO; + this.vehicleService = vehicleService; } @Override @@ -124,7 +133,61 @@ public class OperationServiceImpl implements OperationService { @Override public SortedSet rankVehicles(String opCode) throws InvalidOperationException, ServiceException { - throw new UnsupportedOperationException(); + Set vehicles = + vehicleService.list(EnumSet.complementOf(EnumSet.of(Vehicle.Status.ABGEMELDET))); + + List> priorities = new ArrayList<>(); + Predicate ktw = v -> v.type() == VehicleType.KTW; + Predicate rtwNoNEF = v -> v.type() == VehicleType.RTW && !v.hasNef(); + Predicate rtwNEF = v -> v.type() == VehicleType.RTW && v.hasNef(); + Predicate nef = v -> v.type() == VehicleType.NEF; + Predicate nah = v -> v.type() == VehicleType.NAH; + + switch (extractSeverityFromOpCode(opCode)) { + case A: + // fallthrough + case B: + // fallthrough + case O: + priorities.add(ktw); + priorities.add(rtwNoNEF); + priorities.add(rtwNEF); + break; + case C: + priorities.add(rtwNEF); + priorities.add(rtwNoNEF); + priorities.add(ktw); + break; + case D: + priorities.add(rtwNEF); + priorities.add(nef); + priorities.add(nah); + priorities.add(rtwNoNEF); + priorities.add(ktw); + break; + case E: + priorities.add(nah); + priorities.add(nef); + priorities.add(rtwNEF); + priorities.add(rtwNoNEF); + priorities.add(ktw); + break; + } + + return vehicles.stream() + .sorted( + (v1, v2) -> { + for (Predicate priority : priorities) { + if (priority.test(v1)) { + return -1; + } + if (priority.test(v2)) { + return +1; + } + } + return 0; + }) + .collect(Collectors.toCollection(TreeSet::new)); } @Override -- cgit v1.2.3-70-g09d2 From 9c60ec80f47fa87d4f339d97c21eb1724b66d5c7 Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 14:58:26 +0200 Subject: Use rankVehicles() in ui instead of list #25963 --- .../userInterface/CreateOperationController.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 ef890e0..5222712 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 @@ -35,6 +35,8 @@ import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.MenuItem; import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseButton; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; @@ -106,9 +108,16 @@ public class CreateOperationController { public void updateList() { try { fpVehicles.getChildren().clear(); - EnumSet stati = EnumSet.allOf(Vehicle.Status.class); - stati.remove(Vehicle.Status.ABGEMELDET); - Set vehicles = vehicleService.list(stati); + + // TODO: this should probably be handled differently + Set vehicles; + if (txtCode.getText().isEmpty()) { + vehicles = + vehicleService.list( + EnumSet.complementOf(EnumSet.of(Vehicle.Status.ABGEMELDET))); + } else { + vehicles = operationService.rankVehicles(txtCode.getText()); + } for (Vehicle vehicle : vehicles) { VehiclePaneController controller = VehiclePaneController.createVehiclePane(); @@ -152,7 +161,7 @@ public class CreateOperationController { fpVehicles.getChildren().add(controller.getRootElement()); } - } catch (ServiceException | IOException e) { + } catch (ServiceException | IOException | InvalidOperationException e) { LOG.error("Error while updating list.", e); Alert alert = new Alert(Alert.AlertType.ERROR); @@ -344,4 +353,11 @@ public class CreateOperationController { operationDetailsController.initOperation(operation); this.setVisible(false); } + + @FXML + public void onOperationCodeChanged(KeyEvent keyEvent) { + if (keyEvent.getCode() == KeyCode.ENTER) { + updateList(); + } + } } -- cgit v1.2.3-70-g09d2 From 2cb71544b5306b3ad0bde74509000ede208f6faf Mon Sep 17 00:00:00 2001 From: Tharre Date: Thu, 24 May 2018 15:14:33 +0200 Subject: Set severity inside OperationService.add() #25963 This avoids duplicate parsing in the UI or adding a getSeverityFromOpcode() method to the interface. --- .../groupphase/einsatzverwaltung/dto/Operation.java | 1 + .../einsatzverwaltung/service/OperationServiceImpl.java | 17 +++++++++++------ .../userInterface/CreateOperationController.java | 3 --- .../einsatzverwaltung/service/OperationServiceTest.java | 7 +++---- 4 files changed, 15 insertions(+), 13 deletions(-) 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 7d91c88..3a97dc7 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 @@ -26,6 +26,7 @@ public abstract class Operation { public abstract String opCode(); + @Nullable public abstract Severity severity(); public abstract Status status(); 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 a89e3b1..3e811d4 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 @@ -49,6 +49,8 @@ public class OperationServiceImpl implements OperationService { public long add(Operation o) throws InvalidOperationException, ServiceException { if (o.created() != null) throw new InvalidOperationException("Created must not be set"); + if (o.severity() != null) throw new InvalidOperationException("Severity must not be set"); + if (o.status() != Status.ACTIVE) LOG.warn("Status was set but will be overridden"); // TODO: nullable instead?? @@ -61,7 +63,11 @@ public class OperationServiceImpl implements OperationService { validateOperation(o); return operationDAO.add( - o.toBuilder().created(Instant.now()).status(Status.ACTIVE).build()); + o.toBuilder() + .created(Instant.now()) + .severity(extractSeverityFromOpCode(o.opCode())) + .status(Status.ACTIVE) + .build()); } catch (PersistenceException e) { LOG.error("PersistenceException while adding operation: {}", e); throw new ServiceException(e); @@ -82,6 +88,10 @@ public class OperationServiceImpl implements OperationService { Operation o = operationDAO.get(operationId); validateOperation(o); + if (o.opCode().trim().isEmpty() + || extractSeverityFromOpCode(o.opCode()) != o.severity()) + throw new InvalidOperationException("Einsatzcode ist invalid"); + if (o.status() != Status.ACTIVE) throw new InvalidOperationException("Einsatz ist inaktiv"); @@ -210,11 +220,6 @@ public class OperationServiceImpl implements OperationService { private static void validateOperation(Operation o) throws InvalidOperationException { if (o.id() <= 0) throw new InvalidOperationException("Id is invalid"); - if (o.opCode().trim().isEmpty()) throw new InvalidOperationException("opCode is invalid"); - - if (extractSeverityFromOpCode(o.opCode()) != o.severity()) - throw new InvalidOperationException("Einsatzcode ist invalid"); - if (o.vehicles().isEmpty()) throw new InvalidOperationException( "Es muss mindestens ein Fahrzeug ausgewählt werden!"); 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 5222712..9debddf 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,7 +1,6 @@ package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; @@ -259,11 +258,9 @@ public class CreateOperationController { Operation.builder() .additionalInfo(txtNote.getText()) .destination(txtAddress.getText()) - .created(Instant.now()) .opCode(txtCode.getText()) .status(Status.ACTIVE) .vehicles(Set.of(vehicles)) - .severity(Severity.A) .build(); try { operationService.add(operation); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java index f9ec287..ac53555 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java @@ -177,17 +177,16 @@ public class OperationServiceTest { @Test public void addOperation() throws Exception { - operationService.add(baseOp); + operationService.add(baseOp.toBuilder().severity(null).build()); - // Operation result = verify(operationDAO, times(1)) .add(baseOp.toBuilder().created(any()).status(Status.ACTIVE).build()); verify(vehicleDAO, times(1)).get(v1.id()); } @Test(expected = InvalidOperationException.class) - public void addInvalidSeverity() throws Exception { - operationService.add(baseOp.toBuilder().severity(Severity.B).build()); + public void addWithSeverity() throws Exception { + operationService.add(baseOp.toBuilder().severity(Severity.E).build()); } @Test(expected = InvalidOperationException.class) -- cgit v1.2.3-70-g09d2 From 3921e1bb05b7fa449bc72f136b3ede62984614af Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Thu, 24 May 2018 14:00:04 +0200 Subject: Add onOperationCodeChanged method + format in fxml --- .../resources/fxml/CreateOperationController.fxml | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index dbdb4ef..9b063e3 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -13,15 +13,19 @@ xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.CreateOperationController" stylesheets="@/styles/main.css"> - + -