use of it.unibo.dronesecurity.userapplication.shipping.courier.repo.OrderRepository in project DroneSecurity by mirko-felice.
the class CourierShippingService method callback.
private void callback(@NotNull final MqttMessage msg) {
final JsonObject json = new JsonObject(new String(msg.getPayload(), StandardCharsets.UTF_8));
final String orderId = json.getString(MqttMessageParameterConstants.ORDER_ID_PARAMETER);
final String statusValue = json.getString(MqttMessageParameterConstants.STATUS_PARAMETER);
final OrderRepository orderRepository = OrderRepository.getInstance();
CastHelper.safeCast(orderRepository.getOrderById(orderId), DeliveringOrder.class).ifPresent(order -> {
final Connection connection = Connection.getInstance();
if (MqttMessageValueConstants.DELIVERY_SUCCESSFUL_MESSAGE.equals(statusValue))
orderRepository.confirmedDelivery(order.confirmDelivery());
else if (MqttMessageValueConstants.DELIVERY_FAILED_MESSAGE.equals(statusValue))
orderRepository.failedDelivery(order.failDelivery());
// TODO maybe catch else branch that does NOT send this message
final JsonNode message = new ObjectMapper().createObjectNode().put(MqttMessageParameterConstants.SYNC_PARAMETER, MqttMessageValueConstants.DRONE_CALLBACK_MESSAGE);
connection.publish(MqttTopicConstants.ORDER_TOPIC, message);
});
}
Aggregations