Search in sources :

Example 1 with Order

use of it.unibo.dronesecurity.userapplication.shipping.courier.entities.Order in project DroneSecurity by mirko-felice.

the class OrdersController method performDelivery.

@FXML
private void performDelivery() {
    final Optional<Order> selectedOrder = this.getSelectedOrder();
    selectedOrder.ifPresentOrElse(order -> {
        // TODO how to check ???
        if (order instanceof PlacedOrder) {
            final JsonObject body = new JsonObject().put(OrderConstants.ORDER_KEY, order).put(OrderConstants.COURIER_KEY, UserHelper.getLoggedUser().getUsername());
            VertxHelper.WEB_CLIENT.post(PORT, HOST, PERFORM_DELIVERY_URI).putHeader("Content-Type", "application/json").sendBuffer(body.toBuffer()).onSuccess(h -> Platform.runLater(() -> {
                ((Stage) this.performDeliveryButton.getScene().getWindow()).close();
                final URL fileUrl = getClass().getResource(MONITORING_FILENAME);
                final FXMLLoader fxmlLoader = new FXMLLoader(fileUrl);
                FXHelper.initializeWindow(Modality.NONE, "Monitoring...", fxmlLoader).ifPresent(Stage::show);
            }));
        } else
            AlertUtils.showErrorAlert("You can NOT deliver an order that isn't placed.");
    }, NOT_SELECTED_RUNNABLE);
}
Also used : Order(it.unibo.dronesecurity.userapplication.shipping.courier.entities.Order) PlacedOrder(it.unibo.dronesecurity.userapplication.shipping.courier.entities.PlacedOrder) JsonObject(io.vertx.core.json.JsonObject) FXMLLoader(javafx.fxml.FXMLLoader) URL(java.net.URL) PlacedOrder(it.unibo.dronesecurity.userapplication.shipping.courier.entities.PlacedOrder) FXML(javafx.fxml.FXML)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 Order (it.unibo.dronesecurity.userapplication.shipping.courier.entities.Order)1 PlacedOrder (it.unibo.dronesecurity.userapplication.shipping.courier.entities.PlacedOrder)1 URL (java.net.URL)1 FXML (javafx.fxml.FXML)1 FXMLLoader (javafx.fxml.FXMLLoader)1