private Leg toLeg(TransitEdge edge)
 {
     return(Leg.DeriveLeg(
                voyageRepository.find(new VoyageNumber(edge.getVoyageNumber())),
                locationRepository.find(new UnLocode(edge.getFromUnLocode())),
                locationRepository.find(new UnLocode(edge.getToUnLocode()))
                ));
 }
Beispiel #2
0
        public void testSave()
        {
            TrackingId trackingId  = new TrackingId("AAA");
            Location   origin      = locationRepository.find(SampleLocations.STOCKHOLM.UnLocode);
            Location   destination = locationRepository.find(SampleLocations.MELBOURNE.UnLocode);

            Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, DateTime.Now));

            cargoRepository.store(cargo);

            getSession().Flush();
            getSession().Clear();

            cargo = cargoRepository.find(trackingId);
            Assert.IsNull(cargo.Itinerary);

            cargo.AssignToRoute(
                new Itinerary(Leg.DeriveLeg(voyageRepository.find(new VoyageNumber("0101")),
                                            locationRepository.find(SampleLocations.STOCKHOLM.UnLocode),
                                            locationRepository.find(SampleLocations.MELBOURNE.UnLocode))));

            flush();

            var map = GenericTemplate.QueryForObjectDelegate(CommandType.Text,
                                                             String.Format("select * from Cargo where tracking_id = '{0}'", trackingId.Value),
                                                             (r, i) => new { TRACKING_ID = r["TRACKING_ID"] });

            Assert.AreEqual("AAA", map.TRACKING_ID);

            long originId = (long)getSession().GetIdentifier(cargo);
            //Assert.AreEqual(originId, map.get("SPEC_ORIGIN_ID"));

            long destinationId = (long)getSession().GetIdentifier(cargo);

            //Assert.AreEqual(destinationId, map.get("SPEC_DESTINATION_ID"));

            getSession().Clear();

            Cargo loadedCargo = cargoRepository.find(trackingId);

            Assert.AreEqual(1, loadedCargo.Itinerary.Legs.Count());
        }
        public void updateItineraries(VoyageNumber voyageNumber)
        {
            var voyage         = voyageRepository.find(voyageNumber);
            var affectedCargos = cargoRepository.findCargosOnVoyage(voyage);

            foreach (Cargo cargo in affectedCargos)
            {
                var newItinerary = cargo.Itinerary.WithRescheduledVoyage(voyage);
                cargo.AssignToRoute(newItinerary);
                LOG.Info("Updated itinerary of cargo " + cargo);
            }
        }
Beispiel #4
0
 internal static Itinerary fromDTO(RouteCandidateDTO routeCandidateDTO,
                          VoyageRepository voyageRepository,
                          LocationRepository locationRepository)
 {
     var legs = new List<Leg>(routeCandidateDTO.getLegs().Count());
     foreach(LegDTO legDTO in routeCandidateDTO.getLegs())
     {
         var voyageNumber = new VoyageNumber(legDTO.getVoyageNumber());
         var voyage = voyageRepository.find(voyageNumber);
         var from = locationRepository.find(new UnLocode(legDTO.getFrom()));
         var to = locationRepository.find(new UnLocode(legDTO.getTo()));
         legs.Add(Leg.DeriveLeg(voyage, from, to));
     }
     return new Itinerary(legs);
 }
Beispiel #5
0
        internal static Itinerary fromDTO(RouteCandidateDTO routeCandidateDTO,
                                          VoyageRepository voyageRepository,
                                          LocationRepository locationRepository)
        {
            var legs = new List <Leg>(routeCandidateDTO.getLegs().Count());

            foreach (LegDTO legDTO in routeCandidateDTO.getLegs())
            {
                var voyageNumber = new VoyageNumber(legDTO.getVoyageNumber());
                var voyage       = voyageRepository.find(voyageNumber);
                var from         = locationRepository.find(new UnLocode(legDTO.getFrom()));
                var to           = locationRepository.find(new UnLocode(legDTO.getTo()));
                legs.Add(Leg.DeriveLeg(voyage, from, to));
            }
            return(new Itinerary(legs));
        }
Beispiel #6
0
        private Voyage findVoyage(VoyageNumber voyageNumber)
        {
            if (voyageNumber == null)
            {
                return(null);
            }

            var voyage = voyageRepository.find(voyageNumber);

            if (voyage == null)
            {
                throw new UnknownVoyageException(voyageNumber);
            }

            return(voyage);
        }