use of it.unibo.dronesecurity.userapplication.shipping.courier.entities.DeliveringOrder in project DroneSecurity by mirko-felice.
the class CourierShippingService method performDelivery.
private void performDelivery(@NotNull final RoutingContext routingContext) {
final RequestParameters params = routingContext.get(ValidationHandler.REQUEST_CONTEXT_KEY);
final JsonObject body = params.body().getJsonObject();
final PlacedOrder order = body.getJsonObject(OrderConstants.ORDER_KEY).mapTo(PlacedOrder.class);
if (order == null)
routingContext.response().setStatusCode(CLIENT_ERROR_CODE).end();
else {
final DeliveringOrder deliveringOrder = order.deliver();
OrderRepository.getInstance().delivering(deliveringOrder);
final JsonNode messageJson = new ObjectMapper().createObjectNode().put(MqttMessageParameterConstants.SYNC_PARAMETER, MqttMessageValueConstants.PERFORM_DELIVERY_MESSAGE).put(MqttMessageParameterConstants.ORDER_ID_PARAMETER, order.getId()).put(MqttMessageParameterConstants.COURIER_PARAMETER, body.getString(OrderConstants.COURIER_KEY));
final Connection connection = Connection.getInstance();
connection.publish(MqttTopicConstants.ORDER_TOPIC, messageJson);
connection.subscribe(MqttTopicConstants.LIFECYCLE_TOPIC, this::callback);
routingContext.response().end(CORRECT_RESPONSE_TO_PERFORM_DELIVERY);
}
}
Aggregations