How to use the eventsourcing.contrib.cargo_shipping_example.HandlingActivity function in eventsourcing

To help you get started, we’ve selected a few eventsourcing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
for leg in obj.route.legs:
                    if leg.origin == self.location.value:
                        if leg.voyage_number == self.voyage_number:
                            obj._next_expected_activity = (
                                HandlingActivity.UNLOAD,
                                Location[leg.destination],
                                self.voyage_number,
                            )
                            break
                else:
                    raise Exception(
                        "Can't find leg with origin={} and "
                        "voyage_number={}".format(self.location, self.voyage_number)
                    )

            elif self.handling_activity == HandlingActivity.UNLOAD:
                obj._current_voyage_number = None
                obj._last_known_location = self.location
                obj._transport_status = "IN_PORT"
                if self.location == obj.destination:
                    obj._next_expected_activity = (
                        HandlingActivity.CLAIM,
                        self.location,
                    )
                elif self.location.value in [leg.destination for leg in obj.route.legs]:
                    for i, leg in enumerate(obj.route.legs):
                        if leg.voyage_number == self.voyage_number:
                            next_leg: Leg = obj.route.legs[i + 1]
                            assert Location[next_leg.origin] == self.location
                            obj._next_expected_activity = (
                                HandlingActivity.LOAD,
                                self.location,
github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
def mutate(self, obj: "Cargo") -> None:
            assert obj.route is not None
            if self.handling_activity == HandlingActivity.RECEIVE:
                obj._transport_status = "IN_PORT"
                obj._last_known_location = self.location
                obj._next_expected_activity = (
                    HandlingActivity.LOAD,
                    self.location,
                    obj.route.legs[0].voyage_number,
                )
            elif self.handling_activity == HandlingActivity.LOAD:
                obj._transport_status = "ONBOARD_CARRIER"
                obj._current_voyage_number = self.voyage_number
                for leg in obj.route.legs:
                    if leg.origin == self.location.value:
                        if leg.voyage_number == self.voyage_number:
                            obj._next_expected_activity = (
                                HandlingActivity.UNLOAD,
                                Location[leg.destination],
                                self.voyage_number,
                            )
                            break
                else:
                    raise Exception(
                        "Can't find leg with origin={} and "
                        "voyage_number={}".format(self.location, self.voyage_number)
                    )
github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
elif self.location.value in [leg.destination for leg in obj.route.legs]:
                    for i, leg in enumerate(obj.route.legs):
                        if leg.voyage_number == self.voyage_number:
                            next_leg: Leg = obj.route.legs[i + 1]
                            assert Location[next_leg.origin] == self.location
                            obj._next_expected_activity = (
                                HandlingActivity.LOAD,
                                self.location,
                                next_leg.voyage_number,
                            )
                            break
                else:
                    obj._is_misdirected = True
                    obj._next_expected_activity = None

            elif self.handling_activity == HandlingActivity.CLAIM:
                obj._next_expected_activity = None
                obj._transport_status = "CLAIMED"

            else:
                raise Exception(
                    "Unsupported handling event: {}".format(self.handling_activity)
                )
github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
def mutate(self, obj: "Cargo") -> None:
            assert obj.route is not None
            if self.handling_activity == HandlingActivity.RECEIVE:
                obj._transport_status = "IN_PORT"
                obj._last_known_location = self.location
                obj._next_expected_activity = (
                    HandlingActivity.LOAD,
                    self.location,
                    obj.route.legs[0].voyage_number,
                )
            elif self.handling_activity == HandlingActivity.LOAD:
                obj._transport_status = "ONBOARD_CARRIER"
                obj._current_voyage_number = self.voyage_number
                for leg in obj.route.legs:
                    if leg.origin == self.location.value:
                        if leg.voyage_number == self.voyage_number:
                            obj._next_expected_activity = (
                                HandlingActivity.UNLOAD,
                                Location[leg.destination],
github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
)
    ],
}


# Handling activities.
class HandlingActivity(Enum):
    RECEIVE = "RECEIVE"
    LOAD = "LOAD"
    UNLOAD = "UNLOAD"
    CLAIM = "CLAIM"


# Custom static types.
NextExpectedActivity = Optional[
    Union[Tuple[HandlingActivity, Location], Tuple[HandlingActivity, Location, str]]
]
CargoDetails = Dict[str, Optional[Union[str, bool, datetime, Tuple]]]
LegDetails = Dict[str, str]
ItineraryDetails = Dict[str, Union[str, List[LegDetails]]]

# Type variable for Cargo aggregate class.
T_cargo = TypeVar("T_cargo", bound="Cargo")


# Custom aggregate root class.
class Aggregate(AggregateRoot):
    __subclassevents__ = True


# The Cargo aggregate is an event sourced domain model aggregate that
# specifies the routing from origin to destination, and can track what
github johnbywater / eventsourcing / eventsourcing / contrib / cargo_shipping_example.py View on Github external
def register_handling_event(
        self,
        tracking_id: str,
        voyage_number: Optional[str],
        location: str,
        handling_activity: str,
    ) -> None:
        self.booking_application.register_handling_event(
            UUID(tracking_id),
            voyage_number,
            Location[location],
            HandlingActivity[handling_activity],
        )