|
|
@@ -3,9 +3,9 @@ package se.citerus.dddsample.tracking.core.application.booking;
|
|
3
|
3
|
import org.apache.commons.lang.Validate;
|
|
4
|
4
|
import org.apache.commons.logging.Log;
|
|
5
|
5
|
import org.apache.commons.logging.LogFactory;
|
|
6
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
7
|
|
-import org.springframework.stereotype.Service;
|
|
8
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
7
|
+import org.springframework.stereotype.Service;
|
|
|
8
|
+import org.springframework.transaction.annotation.Transactional;
|
|
9
|
9
|
import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
|
|
10
|
10
|
import se.citerus.dddsample.tracking.core.domain.model.location.Location;
|
|
11
|
11
|
import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
|
|
|
@@ -20,18 +20,18 @@ import java.util.List;
|
|
20
|
20
|
public final class BookingServiceImpl implements BookingService {
|
|
21
|
21
|
|
|
22
|
22
|
private final RoutingService routingService;
|
|
23
|
|
- private final CargoFactory cargoFactory;
|
|
24
|
23
|
private final CargoRepository cargoRepository;
|
|
25
|
24
|
private final LocationRepository locationRepository;
|
|
26
|
25
|
private final Log logger = LogFactory.getLog(getClass());
|
|
|
26
|
+ private final TrackingIdFactory trackingIdFactory;
|
|
27
|
27
|
|
|
28
|
28
|
@Autowired
|
|
29
|
29
|
public BookingServiceImpl(final RoutingService routingService,
|
|
30
|
|
- final CargoFactory cargoFactory,
|
|
|
30
|
+ final TrackingIdFactory trackingIdFactory,
|
|
31
|
31
|
final CargoRepository cargoRepository,
|
|
32
|
32
|
final LocationRepository locationRepository) {
|
|
33
|
33
|
this.routingService = routingService;
|
|
34
|
|
- this.cargoFactory = cargoFactory;
|
|
|
34
|
+ this.trackingIdFactory = trackingIdFactory;
|
|
35
|
35
|
this.cargoRepository = cargoRepository;
|
|
36
|
36
|
this.locationRepository = locationRepository;
|
|
37
|
37
|
}
|
|
|
@@ -41,8 +41,14 @@ public final class BookingServiceImpl implements BookingService {
|
|
41
|
41
|
public TrackingId bookNewCargo(final UnLocode originUnLocode,
|
|
42
|
42
|
final UnLocode destinationUnLocode,
|
|
43
|
43
|
final Date arrivalDeadline) {
|
|
44
|
|
- final Cargo cargo = cargoFactory.newCargo(originUnLocode, destinationUnLocode, arrivalDeadline);
|
|
|
44
|
+ final TrackingId trackingId = trackingIdFactory.nextTrackingId();
|
|
|
45
|
+ final Location origin = locationRepository.find(originUnLocode);
|
|
|
46
|
+ final Location destination = locationRepository.find(destinationUnLocode);
|
|
|
47
|
+ final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
|
|
|
48
|
+
|
|
|
49
|
+ final Cargo cargo = new Cargo(trackingId, routeSpecification);
|
|
45
|
50
|
cargoRepository.store(cargo);
|
|
|
51
|
+
|
|
46
|
52
|
logger.info("Booked new cargo with tracking id " + cargo.trackingId().stringValue());
|
|
47
|
53
|
|
|
48
|
54
|
return cargo.trackingId();
|