http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectReceivedCargo.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectReceivedCargo.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectReceivedCargo.java deleted file mode 100644 index ad18b66..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectReceivedCargo.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event; - -import java.time.Instant; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisdirectedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.Cargo; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.RouteSpecification; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.Delivery; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.NextHandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Leg; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.location.Location; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.voyage.Voyage; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.Context; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.RoleMixin; - -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE; - -/** - * Inspect Received Cargo (subfunction use case) - * - * This is one the variations of the {@link org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.InspectCargoDeliveryStatus} use case. - * - * Note that we consider the cargo still on track if it's received in cargo origin regardless of routing status! - */ -public class InspectReceivedCargo extends Context -{ - private DeliveryInspectorRole deliveryInspector; - - private HandlingEvent previousEvent; - - private HandlingEvent receiveEvent; - private Location receiveLocation; - private Voyage voyage; - - private RouteSpecification routeSpecification; - private Itinerary itinerary; - private Integer itineraryProgressIndex; - - public InspectReceivedCargo( Cargo cargo, HandlingEvent handlingEvent ) - { - deliveryInspector = rolePlayer( DeliveryInspectorRole.class, cargo ); - previousEvent = cargo.delivery().get().lastHandlingEvent().get(); - - receiveEvent = handlingEvent; - receiveLocation = receiveEvent.location().get(); - voyage = receiveEvent.voyage().get(); - - routeSpecification = cargo.routeSpecification().get(); - itinerary = cargo.itinerary().get(); - - // Before handling - itineraryProgressIndex = cargo.delivery().get().itineraryProgressIndex().get(); - } - - public void inspect() - throws InspectionException - { - // Pre-conditions - - // Cargo has already been received before - if( previousEvent != null && !previousEvent.equals( receiveEvent ) ) - { - throw new InspectionFailedException( "Can't receive cargo again." ); - } - - if( receiveEvent == null || !receiveEvent.handlingEventType().get().equals( RECEIVE ) ) - { - throw new InspectionFailedException( "Can only inspect received cargo." ); - } - - deliveryInspector.inspectReceivedCargo(); - } - - @Mixins( DeliveryInspectorRole.Mixin.class ) - public interface DeliveryInspectorRole - { - void setContext( InspectReceivedCargo context ); - - void inspectReceivedCargo() - throws InspectionException; - - class Mixin - extends RoleMixin<InspectReceivedCargo> - implements DeliveryInspectorRole - { - @This - Cargo cargo; - - Delivery newDelivery; - - public void inspectReceivedCargo() - throws InspectionException - { - // Step 1 - Collect known delivery data - - ValueBuilder<Delivery> newDeliveryBuilder = vbf.newValueBuilder( Delivery.class ); - newDelivery = newDeliveryBuilder.prototype(); - newDelivery.timestamp().set( Instant.now() ); - newDelivery.lastHandlingEvent().set( c.receiveEvent ); - newDelivery.transportStatus().set( IN_PORT ); - newDelivery.isUnloadedAtDestination().set( false ); - newDelivery.itineraryProgressIndex().set( 0 ); - - // Step 2 - Verify cargo is routed - - if( c.itinerary == null ) - { - newDelivery.routingStatus().set( NOT_ROUTED ); - } - else if( !c.routeSpecification.isSatisfiedBy( c.itinerary ) ) - { - newDelivery.routingStatus().set( MISROUTED ); - } - else - { - newDelivery.routingStatus().set( ROUTED ); - } - - if( newDelivery.routingStatus().get().equals( ROUTED ) ) - { - // Step 3 - Verify cargo is received in origin - - Leg firstLeg = c.itinerary.firstLeg(); - if( !firstLeg.loadLocation().get().equals( c.receiveEvent.location().get() ) ) - { - newDelivery.isMisdirected().set( true ); - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - throw new CargoMisdirectedException( c.receiveEvent, "Itinerary expected receipt in " - + firstLeg.loadLocation() - .get() - .getString() ); - } - - newDelivery.isMisdirected().set( false ); - newDelivery.eta().set( c.itinerary.eta() ); - - // Step 4 - Determine next expected handling event - - ValueBuilder<NextHandlingEvent> nextHandlingEvent = vbf.newValueBuilder( NextHandlingEvent.class ); - nextHandlingEvent.prototype().handlingEventType().set( LOAD ); - nextHandlingEvent.prototype().location().set( firstLeg.loadLocation().get() ); - nextHandlingEvent.prototype().date().set( firstLeg.loadDate().get() ); - nextHandlingEvent.prototype().voyage().set( firstLeg.voyage().get() ); - newDelivery.nextHandlingEvent().set( nextHandlingEvent.newInstance() ); - } - - // Step 5 - Save cargo delivery snapshot - - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - } - } - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnhandledCargo.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnhandledCargo.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnhandledCargo.java deleted file mode 100644 index 2694e55..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnhandledCargo.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event; - -import java.time.Instant; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.Cargo; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.RouteSpecification; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.Delivery; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.NextHandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.Context; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.RoleMixin; - -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE; - -/** - * Inspect Unhandled Cargo (subfunction use case) - * - * This is one the variations of the {@link org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.InspectCargoDeliveryStatus} use case. - * - * Here we can check a cargo that hasn't been received in origin yet. - */ -public class InspectUnhandledCargo extends Context -{ - private DeliveryInspectorRole deliveryInspector; - - private HandlingEvent noEvent; - - private RouteSpecification routeSpecification; - - private Itinerary itinerary; - - public InspectUnhandledCargo( Cargo cargo ) - { - deliveryInspector = rolePlayer( DeliveryInspectorRole.class, cargo ); - - noEvent = cargo.delivery().get().lastHandlingEvent().get(); - - routeSpecification = cargo.routeSpecification().get(); - itinerary = cargo.itinerary().get(); - } - - public void inspect() - throws InspectionException - { - // Pre-conditions - if( noEvent != null ) - { - throw new InspectionFailedException( "Can only inspect unhandled cargo." ); - } - - deliveryInspector.inspectUnhandledCargo(); - } - - @Mixins( DeliveryInspectorRole.Mixin.class ) - public interface DeliveryInspectorRole - { - void setContext( InspectUnhandledCargo context ); - - void inspectUnhandledCargo() - throws InspectionException; - - class Mixin - extends RoleMixin<InspectUnhandledCargo> - implements DeliveryInspectorRole - { - @This - Cargo cargo; - - Delivery newDelivery; - - public void inspectUnhandledCargo() - throws InspectionException - { - // Step 1 - Collect known delivery data - - ValueBuilder<Delivery> newDeliveryBuilder = vbf.newValueBuilder( Delivery.class ); - newDelivery = newDeliveryBuilder.prototype(); - newDelivery.timestamp().set( Instant.now() ); - newDelivery.lastHandlingEvent().set( null ); - newDelivery.transportStatus().set( NOT_RECEIVED ); - newDelivery.isUnloadedAtDestination().set( false ); - newDelivery.itineraryProgressIndex().set( 0 ); - - // Can't be misdirected before being handled - newDelivery.isMisdirected().set( false ); - - // Step 2 - Determine if cargo is routed - - if( c.itinerary == null ) - { - newDelivery.routingStatus().set( NOT_ROUTED ); - newDelivery.eta().set( null ); - } - else if( !c.routeSpecification.isSatisfiedBy( c.itinerary ) ) - { - newDelivery.routingStatus().set( MISROUTED ); - newDelivery.eta().set( null ); - } - else - { - newDelivery.routingStatus().set( ROUTED ); - newDelivery.eta().set( c.itinerary.eta() ); - } - - // Step 3 - Expect receipt in origin location - - ValueBuilder<NextHandlingEvent> nextHandlingEvent = vbf.newValueBuilder( NextHandlingEvent.class ); - nextHandlingEvent.prototype().handlingEventType().set( RECEIVE ); - nextHandlingEvent.prototype().location().set( cargo.origin().get() ); - nextHandlingEvent.prototype().date().set( null ); - nextHandlingEvent.prototype().voyage().set( null ); - newDelivery.nextHandlingEvent().set( nextHandlingEvent.newInstance() ); - - // Step 4 - Save cargo delivery snapshot - - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnloadedCargo.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnloadedCargo.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnloadedCargo.java deleted file mode 100644 index 22f9311..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/event/InspectUnloadedCargo.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event; - -import java.time.Instant; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisdirectedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisroutedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoNotRoutedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.Cargo; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.RouteSpecification; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.Delivery; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.NextHandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Leg; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.location.Location; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.voyage.Voyage; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.Context; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.RoleMixin; - -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD; - -/** - * Inspect Unloaded Cargo (subfunction use case) - * - * This is one the variations of the {@link org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.InspectCargoDeliveryStatus} use case. - */ -public class InspectUnloadedCargo extends Context -{ - private DeliveryInspectorRole deliveryInspector; - - private HandlingEvent unloadEvent; - private Location unloadLocation; - private Voyage voyage; - - private RouteSpecification routeSpecification; - private Location destination; - private Itinerary itinerary; - private Integer itineraryProgressIndex; - private boolean wasMisdirected; - - public InspectUnloadedCargo( Cargo cargo, HandlingEvent handlingEvent ) - { - deliveryInspector = rolePlayer( DeliveryInspectorRole.class, cargo ); - - unloadEvent = handlingEvent; - unloadLocation = unloadEvent.location().get(); - voyage = unloadEvent.voyage().get(); - - routeSpecification = cargo.routeSpecification().get(); - destination = routeSpecification.destination().get(); - itinerary = cargo.itinerary().get(); - wasMisdirected = cargo.delivery().get().isMisdirected().get(); - - // Before inspection - itineraryProgressIndex = cargo.delivery().get().itineraryProgressIndex().get(); - } - - public void inspect() - throws InspectionException - { - // Pre-conditions - if( unloadEvent == null || !unloadEvent.handlingEventType() - .get() - .equals( UNLOAD ) || unloadLocation.equals( destination ) ) - { - throw new InspectionFailedException( "Can only inspect unloaded cargo that hasn't arrived at destination." ); - } - - deliveryInspector.inspectUnloadedCargo(); - } - - @Mixins( DeliveryInspectorRole.Mixin.class ) - public interface DeliveryInspectorRole - { - void setContext( InspectUnloadedCargo context ); - - void inspectUnloadedCargo() - throws InspectionException; - - class Mixin - extends RoleMixin<InspectUnloadedCargo> - implements DeliveryInspectorRole - { - @This - Cargo cargo; - - Delivery newDelivery; - - public void inspectUnloadedCargo() - throws InspectionException - { - // Step 1 - Collect known delivery data - - ValueBuilder<Delivery> newDeliveryBuilder = vbf.newValueBuilder( Delivery.class ); - newDelivery = newDeliveryBuilder.prototype(); - newDelivery.timestamp().set( Instant.now() ); - newDelivery.lastHandlingEvent().set( c.unloadEvent ); - newDelivery.transportStatus().set( IN_PORT ); - newDelivery.isUnloadedAtDestination().set( false ); - - // Step 2 - Verify cargo is routed - - if( c.itinerary == null ) - { - newDelivery.routingStatus().set( NOT_ROUTED ); - newDelivery.itineraryProgressIndex().set( 0 ); - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - throw new CargoNotRoutedException( c.unloadEvent ); - } - if( !c.routeSpecification.isSatisfiedBy( c.itinerary ) ) - { - newDelivery.routingStatus().set( MISROUTED ); - newDelivery.itineraryProgressIndex().set( 0 ); - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - throw new CargoMisroutedException( c.unloadEvent, c.routeSpecification, c.itinerary ); - } - newDelivery.routingStatus().set( ROUTED ); - newDelivery.eta().set( c.itinerary.eta() ); - - // Current itinerary progress - newDelivery.itineraryProgressIndex().set( c.itineraryProgressIndex ); - - // Step 3 - Verify cargo is on track - - Leg plannedCarrierMovement = c.itinerary.leg( c.itineraryProgressIndex ); - if( plannedCarrierMovement == null ) - { - throw new InspectionFailedException( "Itinerary progress index '" + c.itineraryProgressIndex + "' is invalid!" ); - } - - Integer itineraryProgressIndex; -// if (c.wasMisdirected && c.unloadLocation.equals( c.routeSpecification.origin().get() )) - if( c.unloadLocation.equals( c.routeSpecification.origin().get() ) ) -// if (c.itineraryProgressIndex == -1) - { - /** - * Unloading in the origin of a route specification of a misdirected cargo - * tells us that the cargo has been re-routed (re-routing while on board a - * carrier sets new origin of route specification to arrival location of - * current carrier movement). - * - * Since the current unload was related to the old itinerary, we don't verify - * the misdirection status against the new itinerary. - * - * The itinerary index starts over from the first leg of the new itinerary - * */ - itineraryProgressIndex = 0; - } - else if( !plannedCarrierMovement.unloadLocation().get().equals( c.unloadLocation ) ) - { - newDelivery.isMisdirected().set( true ); - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - throw new CargoMisdirectedException( c.unloadEvent, "Itinerary expected unload in " - + plannedCarrierMovement.unloadLocation() - .get() ); - } - else if( !plannedCarrierMovement.voyage().get().equals( c.voyage ) ) - { - // Do we care if cargo unloads from an unexpected carrier? - itineraryProgressIndex = c.itineraryProgressIndex + 1; - } - else - { - // Cargo delivery has progressed and we expect a load in next itinerary leg load location - itineraryProgressIndex = c.itineraryProgressIndex + 1; - } - - newDelivery.isMisdirected().set( false ); - - // Modify itinerary progress index according to misdirection status - newDelivery.itineraryProgressIndex().set( itineraryProgressIndex ); - - // Step 4 - Determine next expected handling event - - Leg nextCarrierMovement = c.itinerary.leg( itineraryProgressIndex ); - - ValueBuilder<NextHandlingEvent> nextHandlingEvent = vbf.newValueBuilder( NextHandlingEvent.class ); - nextHandlingEvent.prototype().handlingEventType().set( LOAD ); - nextHandlingEvent.prototype().location().set( nextCarrierMovement.loadLocation().get() ); - nextHandlingEvent.prototype().date().set( nextCarrierMovement.loadDate().get() ); - nextHandlingEvent.prototype().voyage().set( nextCarrierMovement.voyage().get() ); - newDelivery.nextHandlingEvent().set( nextHandlingEvent.newInstance() ); - - // Step 5 - Save cargo delivery snapshot - - cargo.delivery().set( newDeliveryBuilder.newInstance() ); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoArrivedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoArrivedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoArrivedException.java deleted file mode 100644 index 6af1e96..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoArrivedException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; - -public class CargoArrivedException extends InspectionException -{ - public CargoArrivedException( HandlingEvent handlingEvent ) - { - super( createMessage( handlingEvent) ); - } - - public static String createMessage(HandlingEvent handlingEvent ) - { - String id = handlingEvent.trackingId().get().id().get(); - String city = handlingEvent.location().get().name().get(); - String location = handlingEvent.location().get().getString(); - String msg = "Cargo '" + id + "' has arrived in destination " + location + "."; - msg += "\nMOCKUP REQUEST TO CARGO OWNER: Please claim cargo '" + id + "' in " + city + "."; - return msg; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoHijackedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoHijackedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoHijackedException.java deleted file mode 100644 index 53fe4ec..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoHijackedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; - -/** - * The easter egg. - */ -public class CargoHijackedException extends InspectionException -{ - public CargoHijackedException( HandlingEvent handlingEvent ) - { - super( createMessage( handlingEvent ) ); - } - - public static String createMessage( HandlingEvent handlingEvent ) - { - String id = handlingEvent.trackingId().get().id().get(); - StringBuilder msg = new StringBuilder().append( "Cargo '" ).append( id ).append( "' was hijacked." ); - msg.append( msg ); - msg.append( "\nMOCKUP MESSAGE TO CARGO OWNER: We're sorry to inform you that your cargo '" ); - msg.append( id ); - msg.append( "' was hijacked. Please contact your insurance company." ); - return msg.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisdirectedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisdirectedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisdirectedException.java deleted file mode 100644 index 53702d5..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisdirectedException.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary; - -/** - * CargoMisdirectedException - * - * This would have to set off notifying the cargo owner and request a re-route. - */ -public class CargoMisdirectedException extends InspectionException -{ - private Itinerary itinerary; - - public CargoMisdirectedException( HandlingEvent handlingEvent, String msg ) - { - super( createMessage(msg, handlingEvent, null) ); - } - - public CargoMisdirectedException( HandlingEvent handlingEvent, Itinerary itinerary, String msg ) - { - super( msg ); - this.itinerary = itinerary; - } - - private static String createMessage( String msg, HandlingEvent handlingEvent, Itinerary itinerary ) - { - String id = handlingEvent.trackingId().get().id().get(); - String city = handlingEvent.location().get().name().get(); - - String itineraryString = ""; - if( itinerary != null ) - { - itineraryString = itinerary.print(); - } - - return "\nCargo is MISDIRECTED! " + msg + "\n" + handlingEvent.print() + itineraryString - + "MOCKUP REQUEST TO CARGO OWNER: Please re-route misdirected cargo '" + id + "' (now in " + city + ")."; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisroutedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisroutedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisroutedException.java deleted file mode 100644 index 1fc70ab..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoMisroutedException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.RouteSpecification; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary; - -/** - * CargoMisroutedException - * - * This would have to set off notifying the cargo owner and request a re-route. - */ -public class CargoMisroutedException extends InspectionException -{ - public CargoMisroutedException( HandlingEvent handlingEvent, - RouteSpecification routeSpecification, - Itinerary itinerary - ) - { - super( createMessage( handlingEvent, routeSpecification, itinerary ) ); - } - - private static String createMessage( HandlingEvent handlingEvent, - RouteSpecification routeSpecification, - Itinerary itinerary ) - { - String id = handlingEvent.trackingId().get().id().get(); - String city = handlingEvent.location().get().name().get(); - return "\nCargo is MISROUTED! Route specification is not satisfied with itinerary:\n" - + routeSpecification.print() + itinerary.print() - + "MOCKUP REQUEST TO CARGO OWNER: Please re-route misrouted cargo '" + id + "' (now in " + city + ")." - ; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoNotRoutedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoNotRoutedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoNotRoutedException.java deleted file mode 100644 index 2d5bcbc..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/CargoNotRoutedException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; - -public class CargoNotRoutedException extends InspectionException -{ - public CargoNotRoutedException( HandlingEvent handlingEvent ) - { - super( createMessage(handlingEvent) ); - } - - private static String createMessage( HandlingEvent handlingEvent ) - { - String id = handlingEvent.trackingId().get().id().get(); - String city = handlingEvent.location().get().name().get(); - return "\nCargo is NOT ROUTED while being handled!" + handlingEvent.print() - + "MOCKUP REQUEST TO CARGO OWNER: Please re-route cargo '" + id + "' (now in " + city + ")."; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionException.java deleted file mode 100644 index 3e0a99b..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -/** - * Base exception for all variations of inspection. - */ -public class InspectionException extends Exception -{ - public InspectionException( String message ) - { - super( message ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionFailedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionFailedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionFailedException.java deleted file mode 100644 index 0b2ef76..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/InspectionFailedException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -/** - * Truly unexpected errors. - */ -public class InspectionFailedException extends InspectionException -{ - public InspectionFailedException( String s ) - { - super( s ); - } - - @Override - public String getMessage() - { - return "INTERNAL ERROR: " + super.getMessage(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/UnexpectedCarrierException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/UnexpectedCarrierException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/UnexpectedCarrierException.java deleted file mode 100644 index 277e5c5..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/inspection/exception/UnexpectedCarrierException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception; - -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; - -public class UnexpectedCarrierException extends InspectionException -{ - public UnexpectedCarrierException( HandlingEvent handlingEvent ) - { - super( createMessage(handlingEvent) ); - } - - private static String createMessage( HandlingEvent handlingEvent ) - { - String voyage = handlingEvent.voyage().get().voyageNumber().get().number().get(); - String city = handlingEvent.location().get().name().get(); - String location = handlingEvent.location().get().getString(); - return "\nCarrier of voyage " + voyage + " didn't expect a load in " + location; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/ParseHandlingEventData.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/ParseHandlingEventData.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/ParseHandlingEventData.java deleted file mode 100644 index 5274dfd..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/ParseHandlingEventData.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; -import org.apache.zest.api.common.Optional; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.api.value.ValueBuilderFactory; -import org.apache.zest.library.constraints.annotation.NotEmpty; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.exception.InvalidHandlingEventDataException; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType; - -/** - * Parse Handling Event Data (subfunction use case) - * - * First step in the ProcessHandlingEvent use case. - * - * Since no Data objects are playing a Role in a Context, it's implemented as a Service - * instead of a Context. In that respect it doesn't have much to do with DCI, but it shares - * the intend to implement a use case and we therefore have it in the context package that - * is then given the broader semantics of the English word "context". - * - * Could be implemented as a web service endpoint like HandlingReportServiceImpl, - * a file upload solution like UploadDirectoryScanner in the DDD sample - or some other - * technical solution. - */ -@Mixins( ParseHandlingEventData.Mixin.class ) -public interface ParseHandlingEventData - extends ServiceComposite -{ - // Step 1 - Receive handling event data for a handled cargo - // Step 2 - Verify that data is complete (with annotated constraints) - - public ParsedHandlingEventData parse( @NotEmpty String completionStr, - @NotEmpty String trackingIdStr, - @NotEmpty String handlingEventTypeStr, - @NotEmpty String unLocodeStr, - @Optional String voyageNumberStr - ) - throws InvalidHandlingEventDataException; - - abstract class Mixin - implements ParseHandlingEventData - { - @Structure - ValueBuilderFactory vbf; - - static final String ISO_8601_FORMAT = "yyyy-MM-dd HH:mm"; - - LocalDate completionDate; - HandlingEventType handlingEventType; - - public ParsedHandlingEventData parse( String completionStr, - String trackingIdStr, - String handlingEventTypeStr, - String unLocodeStr, - String voyageNumberStr - ) - throws InvalidHandlingEventDataException - { - // Step 3 - Perform basic type conversion - - try - { - completionDate = LocalDate.parse( completionStr.trim(), DateTimeFormatter.ISO_LOCAL_DATE ); - } - catch( DateTimeParseException e ) - { - throw new InvalidHandlingEventDataException( - "Invalid date format: '" + completionStr + "' must be on ISO 8601 format " + ISO_8601_FORMAT ); - } - - try - { - handlingEventType = HandlingEventType.valueOf( handlingEventTypeStr.trim() ); - } - catch( Exception e ) - { - throw new InvalidHandlingEventDataException( e.getMessage() ); - } - - // Step 4 - Collect parsed handling event data - - ValueBuilder<ParsedHandlingEventData> parsedData = vbf.newValueBuilder( ParsedHandlingEventData.class ); - parsedData.prototype().registrationDate().set( LocalDate.now() ); - parsedData.prototype().completionDate().set( completionDate ); - parsedData.prototype().trackingIdString().set( trackingIdStr ); - parsedData.prototype().handlingEventType().set( handlingEventType ); - parsedData.prototype().unLocodeString().set( unLocodeStr ); - parsedData.prototype().voyageNumberString().set( voyageNumberStr ); - - // Step 5 - Return parsed handling event data - - return parsedData.newInstance(); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/dto/ParsedHandlingEventData.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/dto/ParsedHandlingEventData.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/dto/ParsedHandlingEventData.java deleted file mode 100644 index d1909d9..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/dto/ParsedHandlingEventData.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto; - -import java.time.LocalDate; -import org.apache.zest.api.common.Optional; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Immutable; -import org.apache.zest.api.property.Property; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.conversion.DTO; - -/** - * The ParsedHandlingEventData simply helps move submitted event registration data around. - */ -@Immutable -@Mixins( ParsedHandlingEventData.Mixin.class ) -public interface ParsedHandlingEventData -{ - Property<LocalDate> registrationDate(); - - Property<LocalDate> completionDate(); - - Property<String> trackingIdString(); - - Property<HandlingEventType> handlingEventType(); - - Property<String> unLocodeString(); - - @Optional - Property<String> voyageNumberString(); - - public String print(); - - abstract class Mixin - implements ParsedHandlingEventData - { - public String print() - { - String voyage = ""; - if( voyageNumberString().get() != null ) - { - voyage = voyageNumberString().get(); - } - - return "\nPARSED HANDLING EVENT DATA -----------------" + - "\n Tracking id string " + trackingIdString().get() + - "\n Handling Event Type string " + handlingEventType().get().name() + - "\n UnLocode string " + unLocodeString().get() + - "\n Completed string " + completionDate().get() + - "\n Registered string " + registrationDate().get() + - "\n Voyage string " + voyage + - "\n--------------------------------------------\n"; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/exception/InvalidHandlingEventDataException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/exception/InvalidHandlingEventDataException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/exception/InvalidHandlingEventDataException.java deleted file mode 100644 index 8236457..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/parsing/exception/InvalidHandlingEventDataException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.exception; - -public class InvalidHandlingEventDataException extends Exception -{ - public InvalidHandlingEventDataException( String msg ) - { - super( msg ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/RegisterHandlingEvent.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/RegisterHandlingEvent.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/RegisterHandlingEvent.java deleted file mode 100644 index 17e159b..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/RegisterHandlingEvent.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration; - -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.query.Query; -import org.apache.zest.api.query.QueryBuilder; -import org.apache.zest.api.unitofwork.NoSuchEntityException; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.ProcessHandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.AlreadyClaimedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.CannotRegisterHandlingEventException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.DuplicateEventException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.MissingVoyageNumberException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownCargoException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownLocationException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownVoyageException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.factory.HandlingEventFactory; -import org.apache.zest.sample.dcicargo.sample_b.data.factory.exception.CannotCreateHandlingEventException; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.Cargo; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.location.Location; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.tracking.TrackingId; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.voyage.Voyage; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.Context; -import org.apache.zest.sample.dcicargo.sample_b.infrastructure.dci.RoleMixin; - -import static org.apache.zest.api.query.QueryExpressions.*; -import static org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot.HANDLING_EVENTS_ID; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.*; - -/** - * Register Handling Event (subfunction use case) - * - * Second step in the ProcessHandlingEvent use case. - * - * Verifies handling event data received from ParseHandlingEventData against the database in - * order to create a valid HandlingEvent. - * - * If only the enclosing {@link ProcessHandlingEvent} summary use case is allowed to call this - * subfunction use case, we could draw an interesting parallel to the responsibilities of the - * DDD aggregate of enforcing invariants between its member objects. Whereas here it would be - * {@link ProcessHandlingEvent} enforcing its subfunction use cases to process correctly and - * ultimately abort the interactions chain when any of the subfunction interactions fail... - * - * As an example of "process integrity enforcement" we here validate that a cargo with the - * given TrackingId exists in our system. When we then inspect the cargo in the third and last - * step of the ProcessHandlingEvent summary use case, we presume having a valid cargo. - * - * How can we ensure that RegisterHandlingEvent is not mistakenly called directly out of the - * larger context of ProcessHandlingEvent? - * - * IMPORTANT: - * Compared to the DDD sample, we don't save a Cargo object with the HandlingEvent, but only - * the TrackingId! HandlingEvent never needs the full Cargo graph (not in the DDD sample either), - * so by saving only the TrackingId we get a much slimmer HandlingEvent object. - */ -public class RegisterHandlingEvent extends Context -{ - private EventRegistrarRole eventRegistrar; - - private ParsedHandlingEventData eventData; - private HandlingEventType eventType; - private String trackingIdString; - private String unLocodeString; - private String voyageNumberString; - - public RegisterHandlingEvent( ParsedHandlingEventData parsedEventData ) - { - eventRegistrar = rolePlayer( EventRegistrarRole.class, HandlingEventAggregateRoot.class, HANDLING_EVENTS_ID ); - - this.eventData = parsedEventData; - eventType = parsedEventData.handlingEventType().get(); - trackingIdString = parsedEventData.trackingIdString().get(); - unLocodeString = parsedEventData.unLocodeString().get(); - voyageNumberString = parsedEventData.voyageNumberString().get(); - } - - public HandlingEvent getEvent() - throws CannotRegisterHandlingEventException - { - return eventRegistrar.registerAndGetHandlingEvent(); - } - - @Mixins( EventRegistrarRole.Mixin.class ) - public interface EventRegistrarRole - { - void setContext( RegisterHandlingEvent context ); - - HandlingEvent registerAndGetHandlingEvent() - throws CannotRegisterHandlingEventException; - - class Mixin - extends RoleMixin<RegisterHandlingEvent> - implements EventRegistrarRole - { - @This - HandlingEventFactory eventFactory; - - public HandlingEvent registerAndGetHandlingEvent() - throws CannotRegisterHandlingEventException - { - UnitOfWork uow = uowf.currentUnitOfWork(); - TrackingId trackingId; - Location location; - Voyage voyage = null; - - // Step 1 - Find Cargo from tracking id string - try - { - trackingId = uow.get( Cargo.class, c.trackingIdString ).trackingId().get(); - } - catch( NoSuchEntityException e ) - { - throw new UnknownCargoException( c.eventData ); - } - - // Step 2 - Find Location from UnLocode string - - try - { - location = uow.get( Location.class, c.unLocodeString ); - } - catch( NoSuchEntityException e ) - { - throw new UnknownLocationException( c.eventData ); - } - - // Step 3 - Find Voyage from voyage number string - - if( c.eventType.requiresVoyage() ) - { - if( c.voyageNumberString == null ) - { - throw new MissingVoyageNumberException( c.eventData ); - } - - try - { - voyage = uow.get( Voyage.class, c.voyageNumberString ); - } - catch( NoSuchEntityException e ) - { - throw new UnknownVoyageException( c.eventData ); - } - } - - // Step 4 - Verify that cargo is not received, in customs or claimed more than once - - if( c.eventType.equals( RECEIVE ) || c.eventType.equals( CUSTOMS ) || c.eventType.equals( CLAIM ) ) - { - QueryBuilder<HandlingEvent> qb = qbf.newQueryBuilder( HandlingEvent.class ) - .where( - and( - eq( templateFor( HandlingEvent.class ).trackingId().get().id(), c.trackingIdString ), - eq( templateFor( HandlingEvent.class ).handlingEventType(), c.eventType ) - ) - ); - Query<HandlingEvent> duplicates = uowf.currentUnitOfWork().newQuery( qb ); - if( duplicates.count() > 0 ) - { - throw new DuplicateEventException( c.eventData ); - } - } - - // Step 5 - Verify that cargo is not handled after being claimed - - if( !c.eventType.equals( CLAIM ) ) - { - HandlingEvent eventTemplate = templateFor( HandlingEvent.class ); - QueryBuilder<HandlingEvent> qb = qbf.newQueryBuilder( HandlingEvent.class ) - .where( - and( - eq( eventTemplate.trackingId().get().id(), c.trackingIdString ), - eq( eventTemplate.handlingEventType(), CLAIM ) - ) - ); - Query<HandlingEvent> alreadyClaimed = uowf.currentUnitOfWork().newQuery( qb ); - if( alreadyClaimed.count() > 0 ) - { - throw new AlreadyClaimedException( c.eventData ); - } - } - - // Step 6 - Create Handling Event in the system - - try - { - return eventFactory.createHandlingEvent( c.eventData.registrationDate().get(), - c.eventData.completionDate().get(), - trackingId, - c.eventData.handlingEventType().get(), - location, - voyage ); - } - catch( CannotCreateHandlingEventException e ) - { - throw new CannotRegisterHandlingEventException( c.eventData ); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/AlreadyClaimedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/AlreadyClaimedException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/AlreadyClaimedException.java deleted file mode 100644 index 11514bb..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/AlreadyClaimedException.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception; - -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; - -/** - * Thrown when trying to register a handling event after cargo has been claimed. - */ -public final class AlreadyClaimedException extends CannotRegisterHandlingEventException -{ - public AlreadyClaimedException( ParsedHandlingEventData parsedHandlingEventData ) - { - super( parsedHandlingEventData ); - } - - @Override - public String getMessage() - { - return type + " handling event can't be registered after cargo has been claimed."; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/CannotRegisterHandlingEventException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/CannotRegisterHandlingEventException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/CannotRegisterHandlingEventException.java deleted file mode 100644 index 4a3d905..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/CannotRegisterHandlingEventException.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; - -/** - * If a {@link HandlingEvent} can't be created from a given set of parameters. - * - * It is a checked exception because it's not a programming error, but rather a - * special case that the application is built to handle. It can occur during normal - * program execution. - */ -public class CannotRegisterHandlingEventException extends Exception -{ - private ParsedHandlingEventData parsedHandlingEventData; - - protected String msg, id, time, type, unloc; - protected String voy = ""; - - public CannotRegisterHandlingEventException( ParsedHandlingEventData parsedHandlingEventData ) - { - super(); - this.parsedHandlingEventData = parsedHandlingEventData; - - time = parseDate( parsedHandlingEventData.completionDate().get() ); - id = parse( parsedHandlingEventData.trackingIdString().get() ); - type = parse( parsedHandlingEventData.handlingEventType().get().name() ); - unloc = parse( parsedHandlingEventData.unLocodeString().get() ); - voy = parse( parsedHandlingEventData.voyageNumberString().get() ); - } - - public ParsedHandlingEventData getParsedHandlingEventData() - { - return parsedHandlingEventData; - } - - private String parse( String str ) - { - return str == null ? "null" : str; - } - - private String parseDate( LocalDate date ) - { - return date == null ? "null" : date.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/ChronologicalException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/ChronologicalException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/ChronologicalException.java deleted file mode 100644 index 7aaaf2d..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/ChronologicalException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception; - -import java.time.LocalDate; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; - -/** - * Thrown when trying to register a handling event with an unknown tracking id. - */ -public final class ChronologicalException extends CannotRegisterHandlingEventException -{ - private LocalDate lastCompletionTime; - - public ChronologicalException( ParsedHandlingEventData parsedHandlingEventData, LocalDate lastCompletionTime ) - { - super( parsedHandlingEventData ); - this.lastCompletionTime = lastCompletionTime; - } - - @Override - public String getMessage() - { - return "Completion time " + time + " is unexpectedly before last handling event completion."; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/DuplicateEventException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/DuplicateEventException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/DuplicateEventException.java deleted file mode 100644 index 2c68e58..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/DuplicateEventException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception; - -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; - -/** - * Thrown when trying to register a receive/in customs/claim handling event twice. - */ -public final class DuplicateEventException extends CannotRegisterHandlingEventException -{ - public DuplicateEventException( ParsedHandlingEventData parsedHandlingEventData ) - { - super( parsedHandlingEventData ); - } - - @Override - public String getMessage() - { - if( type.equals( "RECEIVE" ) ) - { - return "Cargo can't be received more than once."; - } - else if( type.equals( "CUSTOMS" ) ) - { - return "Cargo can't be in customs more than once."; - } - else if( type.equals( "CLAIM" ) ) - { - return "Cargo can't be claimed more than once."; - } - else - { - return "INTERNAL ERROR: Unexpected handling event type for this exception"; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/MissingVoyageNumberException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/MissingVoyageNumberException.java b/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/MissingVoyageNumberException.java deleted file mode 100644 index 05b0d52..0000000 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/apache/zest/sample/dcicargo/sample_b/context/interaction/handling/registration/exception/MissingVoyageNumberException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception; - -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; - -/** - * Thrown when trying to register a handling event without a required voyage - */ -public final class MissingVoyageNumberException extends CannotRegisterHandlingEventException -{ - public MissingVoyageNumberException( ParsedHandlingEventData parsedHandlingEventData ) - { - super( parsedHandlingEventData ); - } - - @Override - public String getMessage() - { - msg = "Unsuccessful handling event registration for cargo '" + id + "' (handling event '" + type + "' in '" + unloc + "')." + - "\nMissing voyage number. Handling event " + type + " requires a voyage."; - - msg += "\nMOCKUP NOTIFICATION TO HANDLING AUTHORITY: Please check submitted invalid handling event data:"; - msg += getParsedHandlingEventData(); - - return msg; - } -}
