blob: a6a1dfec30163dc5f9f18dfe236d23365e268229 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;
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 at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDAO;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDAO;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Registration;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.RegistrationValidator;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RegistrationServiceImpl implements RegistrationService {
private final RegistrationDAO registrationDAO;
private final VehicleDAO vehicleDAO;
@Autowired
public RegistrationServiceImpl(RegistrationDAO registrationDAO, VehicleDAO vehicleDAO) {
this.registrationDAO = registrationDAO;
this.vehicleDAO = vehicleDAO;
}
@Override
public Set<Long> add(long vehicleId, Set<Registration> registrations)
throws InvalidVehicleException, InvalidRegistrationException, ServiceException {
if (vehicleId <= 0) throw new InvalidVehicleException("VehicleId invalid");
try {
Vehicle vehicle = vehicleDAO.get(vehicleId);
RegistrationValidator.validate(vehicle, registrations);
return registrationDAO.add(vehicle.id(), registrations);
} catch (PersistenceException e) {
throw new ServiceException(e);
} catch (ElementNotFoundException e) {
throw new InvalidVehicleException(e);
}
}
@Override
public void remove(long registrationId) throws InvalidRegistrationException, ServiceException {
if (registrationId <= 0) throw new InvalidRegistrationException("RegistrationId invalid");
try {
registrationDAO.remove(registrationId);
} catch (PersistenceException e) {
throw new ServiceException(e);
} catch (ElementNotFoundException e) {
throw new InvalidRegistrationException(e);
}
}
}
|