Exemple #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cargo">cargo</param>
        /// <param name="completionTime">completion time, the reported time that the event actually happened (e.g. the receive took place).</param>
        /// <param name="registrationTime">registration time, the time the message is received</param>
        /// <param name="type">type of event</param>
        /// <param name="location">where the event took place</param>
        /// <param name="voyage">the voyage</param>
        /// <param name="operatorCode">operator code for port operator</param>
        internal HandlingEvent(Cargo cargo,
                               DateTime completionTime,
                               DateTime registrationTime,
                               HandlingActivityType type,
                               Location location,
                               Voyage voyage,
                               OperatorCode operatorCode)
        {
            Validate.notNull(cargo, "Cargo is required");
            Validate.notNull(location, "Location is required");
            Validate.notNull(voyage, "Voyage is required");
            Validate.notNull(operatorCode, "Operator code is required");

            if (!type.isVoyageRelated())
            {
                throw new ArgumentException("Voyage is not allowed with event type " + type);
            }

            SequenceNumber   = EventSequenceNumber.Next();
            Cargo            = cargo;
            CompletionTime   = completionTime;
            RegistrationTime = registrationTime;
            Activity         = new HandlingActivity(type, location, voyage);
            OperatorCode     = operatorCode;
        }
Exemple #2
0
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo    = findCargo(trackingId);
            var voyage   = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if (voyage == null)
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location));
                }
                else
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode));
                }
            }
            catch (Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo = findCargo(trackingId);
            var voyage = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if(voyage == null)
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
                }
                else
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode);
                }
            }
            catch(Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
Exemple #4
0
        public HandlingActivity(HandlingActivityType type, Location location)
        {
            Validate.notNull(location, "Location is required");

            Type     = type;
            Location = location;
            Voyage   = null;
        }
Exemple #5
0
        public HandlingActivity(HandlingActivityType type, Location location, Voyage voyage)
        {
            Validate.notNull(location, "Location is required");
            Validate.notNull(voyage, "Voyage is required");

            Type     = type;
            Location = location;
            Voyage   = voyage;
        }
Exemple #6
0
        public void registerHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                          VoyageNumber voyageNumber, UnLocode unLocode,
                                          HandlingActivityType type, OperatorCode operatorCode)
        {
            // Using a factory to create a HandlingEvent (aggregate). This is where
            // it is determined wether the incoming data, the attempt, actually is capable
            // of representing a real handling handlingEvent.
            var handlingEvent = handlingEventFactory.createHandlingEvent(
                completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
                );

            // Store the new handling handlingEvent, which updates the persistent
            // state of the handling handlingEvent aggregate (but not the cargo aggregate -
            // that happens asynchronously!)
            handlingEventRepository.store(handlingEvent);

            // Publish a system event
            systemEvents.notifyOfHandlingEvent(handlingEvent);

            LOG.Info("Registered handling event: " + handlingEvent);
        }
Exemple #7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cargo">cargo</param>
        /// <param name="completionTime">completion time, the reported time that the event actually happened (e.g. the receive took place).</param>
        /// <param name="registrationTime">registration time, the time the message is received</param>
        /// <param name="type">type of event</param>
        /// <param name="location">where the event took place</param>
        public HandlingEvent(Cargo cargo,
                             DateTime completionTime,
                             DateTime registrationTime,
                             HandlingActivityType type,
                             Location location)
        {
            // TODO: make internal
            Validate.notNull(cargo, "Cargo is required");
            Validate.notNull(location, "Location is required");

            if (type.isVoyageRelated())
            {
                throw new ArgumentException("Voyage is required for event type " + type);
            }

            SequenceNumber   = EventSequenceNumber.Next();
            CompletionTime   = completionTime;
            RegistrationTime = registrationTime;
            Cargo            = cargo;
            Activity         = new HandlingActivity(type, location);
        }
        public void registerHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                          VoyageNumber voyageNumber, UnLocode unLocode,
                                          HandlingActivityType type, OperatorCode operatorCode)
        {
            // Using a factory to create a HandlingEvent (aggregate). This is where
            // it is determined wether the incoming data, the attempt, actually is capable
            // of representing a real handling handlingEvent.
            var handlingEvent = handlingEventFactory.createHandlingEvent(
              completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
            );

            // Store the new handling handlingEvent, which updates the persistent
            // state of the handling handlingEvent aggregate (but not the cargo aggregate -
            // that happens asynchronously!)
            handlingEventRepository.store(handlingEvent);

            // Publish a system event
            systemEvents.notifyOfHandlingEvent(handlingEvent);

            LOG.Info("Registered handling event: " + handlingEvent);
        }
Exemple #9
0
        private void assertHandlingEvent(Cargo cargo,
                                         HandlingEvent @event,
                                         HandlingActivityType expectedEventType,
                                         Location expectedLocation,
                                         int completionTimeMs,
                                         int registrationTimeMs,
                                         Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, @event.Type);
            Assert.AreEqual(expectedLocation, @event.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.offset(completionTimeMs);

            Assert.AreEqual(expectedCompletionTime, @event.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);

            Assert.AreEqual(expectedRegistrationTime, @event.RegistrationTime);

            Assert.AreEqual(voyage, @event.Voyage);
            Assert.AreEqual(cargo, @event.Cargo);
        }
Exemple #10
0
 /// <summary>
 /// True if this is a physical handling.
 /// </summary>
 /// <returns>True if this is a physical handling.</returns>
 public static bool isPhysical(this HandlingActivityType type)
 {
     return(Map[type].isPhysical());
 }
Exemple #11
0
 /// <summary>
 /// True if a voyage association is required for this event type.
 /// </summary>
 /// <returns>True if a voyage association is required for this event type.</returns>
 public static bool isVoyageRelated(this HandlingActivityType type)
 {
     return(Map[type].isVoyageRelated());
 }
Exemple #12
0
 public InLocation(HandlingActivityType type, Voyage voyage)
 {
     _type   = type;
     _voyage = voyage;
 }
        private void assertHandlingEvent(Cargo cargo,
            HandlingEvent @event,
            HandlingActivityType expectedEventType,
            Location expectedLocation,
            int completionTimeMs,
            int registrationTimeMs,
            Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, @event.Type);
            Assert.AreEqual(expectedLocation, @event.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.offset(completionTimeMs);
            Assert.AreEqual(expectedCompletionTime, @event.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);
            Assert.AreEqual(expectedRegistrationTime, @event.RegistrationTime);

            Assert.AreEqual(voyage, @event.Voyage);
            Assert.AreEqual(cargo, @event.Cargo);
        }