|
|
|
|
|
|
1
|
package se.citerus.dddsample.interfaces.booking.facade;
|
1
|
package se.citerus.dddsample.interfaces.booking.facade;
|
|
2
|
|
2
|
|
|
3
|
import org.apache.log4j.Logger;
|
3
|
import org.apache.log4j.Logger;
|
|
4
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
5
|
import se.citerus.dddsample.application.BookingService;
|
4
|
import se.citerus.dddsample.application.BookingService;
|
|
6
|
import se.citerus.dddsample.domain.model.cargo.Cargo;
|
5
|
import se.citerus.dddsample.domain.model.cargo.Cargo;
|
|
7
|
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
|
6
|
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
|
|
|
|
|
|
|
20
|
|
19
|
|
|
21
|
import java.rmi.RemoteException;
|
20
|
import java.rmi.RemoteException;
|
|
22
|
import java.util.ArrayList;
|
21
|
import java.util.ArrayList;
|
|
|
|
22
|
+import java.util.Date;
|
|
23
|
import java.util.List;
|
23
|
import java.util.List;
|
|
24
|
|
24
|
|
|
25
|
|
25
|
|
|
|
|
|
|
|
38
|
private VoyageRepository voyageRepository;
|
38
|
private VoyageRepository voyageRepository;
|
|
39
|
private final Logger logger = Logger.getLogger(BookingServiceFacadeImpl.class);
|
39
|
private final Logger logger = Logger.getLogger(BookingServiceFacadeImpl.class);
|
|
40
|
|
40
|
|
|
41
|
- @Transactional(readOnly = true)
|
|
|
|
42
|
public List<LocationDTO> listShippingLocations() {
|
41
|
public List<LocationDTO> listShippingLocations() {
|
|
43
|
final List<Location> allLocations = locationRepository.findAll();
|
42
|
final List<Location> allLocations = locationRepository.findAll();
|
|
44
|
final LocationDTOAssembler assembler = new LocationDTOAssembler();
|
43
|
final LocationDTOAssembler assembler = new LocationDTOAssembler();
|
|
45
|
return assembler.toDTOList(allLocations);
|
44
|
return assembler.toDTOList(allLocations);
|
|
46
|
}
|
45
|
}
|
|
47
|
|
46
|
|
|
48
|
- @Transactional(readOnly = false)
|
|
|
|
49
|
public String bookNewCargo(String origin, String destination) {
|
47
|
public String bookNewCargo(String origin, String destination) {
|
|
50
|
- TrackingId trackingId = bookingService.bookNewCargo(new UnLocode(origin), new UnLocode(destination));
|
|
|
|
|
|
48
|
+ // TODO push date to parameter
|
|
|
|
49
|
+ Date arrivalDeadline = new Date();
|
|
|
|
50
|
+ TrackingId trackingId = bookingService.bookNewCargo(new UnLocode(origin), new UnLocode(destination), arrivalDeadline);
|
|
51
|
return trackingId.idString();
|
51
|
return trackingId.idString();
|
|
52
|
}
|
52
|
}
|
|
53
|
|
53
|
|
|
54
|
- @Transactional(readOnly = true)
|
|
|
|
55
|
public CargoRoutingDTO loadCargoForRouting(String trackingId) {
|
54
|
public CargoRoutingDTO loadCargoForRouting(String trackingId) {
|
|
56
|
final Cargo cargo = cargoRepository.find(new TrackingId(trackingId));
|
55
|
final Cargo cargo = cargoRepository.find(new TrackingId(trackingId));
|
|
57
|
final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
|
56
|
final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
|
|
58
|
return assembler.toDTO(cargo);
|
57
|
return assembler.toDTO(cargo);
|
|
59
|
}
|
58
|
}
|
|
60
|
|
59
|
|
|
61
|
- @Transactional(readOnly = false)
|
|
|
|
62
|
public void assignCargoToRoute(String trackingId, ItineraryCandidateDTO itineraryCandidateDTO) {
|
60
|
public void assignCargoToRoute(String trackingId, ItineraryCandidateDTO itineraryCandidateDTO) {
|
|
63
|
final Itinerary itinerary = new ItineraryCandidateDTOAssembler().fromDTO(itineraryCandidateDTO, voyageRepository, locationRepository);
|
61
|
final Itinerary itinerary = new ItineraryCandidateDTOAssembler().fromDTO(itineraryCandidateDTO, voyageRepository, locationRepository);
|
|
64
|
|
62
|
|
|
|
|
|
|
|
73
|
logger.info("Assigned cargo " + trackingId + " to new route");
|
71
|
logger.info("Assigned cargo " + trackingId + " to new route");
|
|
74
|
}
|
72
|
}
|
|
75
|
|
73
|
|
|
76
|
- @Transactional(readOnly = true)
|
|
|
|
77
|
public List<CargoRoutingDTO> listAllCargos() {
|
74
|
public List<CargoRoutingDTO> listAllCargos() {
|
|
78
|
final List<Cargo> cargoList = cargoRepository.findAll();
|
75
|
final List<Cargo> cargoList = cargoRepository.findAll();
|
|
79
|
final List<CargoRoutingDTO> dtoList = new ArrayList<CargoRoutingDTO>(cargoList.size());
|
76
|
final List<CargoRoutingDTO> dtoList = new ArrayList<CargoRoutingDTO>(cargoList.size());
|
|
|
|
|
|
|
84
|
return dtoList;
|
81
|
return dtoList;
|
|
85
|
}
|
82
|
}
|
|
86
|
|
83
|
|
|
87
|
- @Transactional(readOnly = true)
|
|
|
|
88
|
public List<ItineraryCandidateDTO> requestPossibleRoutesForCargo(String trackingId) throws RemoteException {
|
84
|
public List<ItineraryCandidateDTO> requestPossibleRoutesForCargo(String trackingId) throws RemoteException {
|
|
89
|
final List<Itinerary> itineraries = bookingService.requestPossibleRoutesForCargo(new TrackingId(trackingId));
|
85
|
final List<Itinerary> itineraries = bookingService.requestPossibleRoutesForCargo(new TrackingId(trackingId));
|
|
90
|
|
86
|
|