From 813e658bc5a69fc5caecf7d93c88df1d942e1057 Mon Sep 17 00:00:00 2001 From: TudorOrban <130213626+TudorOrban@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:27:13 +0300 Subject: [PATCH] Add Compartment service and Warehouse Storage tab --- .../org/chainoptim/desktop/AppModule.java | 1 + .../controller/WarehouseController.java | 7 ++ .../WarehouseStorageController.java | 82 +++++++++++++++++++ .../features/warehouse/model/Compartment.java | 17 ++++ .../warehouse/model/CompartmentData.java | 16 ++++ .../features/warehouse/model/Crate.java | 20 +++++ .../features/warehouse/model/CrateData.java | 14 ++++ .../features/warehouse/model/CrateSpec.java | 15 ++++ .../warehouse/service/CompartmentService.java | 12 +++ .../service/CompartmentServiceImpl.java | 40 +++++++++ .../model/SearchOptionsConfiguration.java | 21 +++++ .../warehouse/WarehouseStorageView.fxml | 10 +++ .../features/warehouse/WarehouseView.fxml | 1 + 13 files changed, 256 insertions(+) create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseStorageController.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/model/Compartment.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/model/CompartmentData.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/model/Crate.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateData.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateSpec.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentService.java create mode 100644 src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentServiceImpl.java create mode 100644 src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml diff --git a/src/main/java/org/chainoptim/desktop/AppModule.java b/src/main/java/org/chainoptim/desktop/AppModule.java index a495871d..ad343461 100644 --- a/src/main/java/org/chainoptim/desktop/AppModule.java +++ b/src/main/java/org/chainoptim/desktop/AppModule.java @@ -148,6 +148,7 @@ protected void configure() { bind(WarehouseWriteService.class).to(WarehouseWriteServiceImpl.class); bind(WarehouseInventoryItemService.class).to(WarehouseInventoryItemServiceImpl.class); bind(WarehouseInventoryItemWriteService.class).to(WarehouseInventoryItemWriteServiceImpl.class); + bind(CompartmentService.class).to(CompartmentServiceImpl.class); // - Supplier bind(SupplierService.class).to(SupplierServiceImpl.class); diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseController.java b/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseController.java index 25dc5cca..35f26c01 100644 --- a/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseController.java +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseController.java @@ -39,6 +39,8 @@ public class WarehouseController implements Initializable { @FXML private Tab inventoryTab; @FXML + private Tab storageTab; + @FXML private Label warehouseName; @FXML private Label warehouseLocation; @@ -81,6 +83,11 @@ private void setupListeners() { commonViewsLoader.loadTabContent(inventoryTab, "/org/chainoptim/desktop/features/warehouse/WarehouseInventoryView.fxml", this.warehouse); } }); + storageTab.selectedProperty().addListener((observable, wasSelected, isNowSelected) -> { + if (Boolean.TRUE.equals(isNowSelected) && storageTab.getContent() == null) { + commonViewsLoader.loadTabContent(storageTab, "/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml", this.warehouse); + } + }); fallbackManager.isEmptyProperty().addListener((observable, oldValue, newValue) -> { tabPane.setVisible(newValue); diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseStorageController.java b/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseStorageController.java new file mode 100644 index 00000000..6662dc99 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/controller/WarehouseStorageController.java @@ -0,0 +1,82 @@ +package org.chainoptim.desktop.features.warehouse.controller; + +import org.chainoptim.desktop.features.warehouse.model.Compartment; +import org.chainoptim.desktop.features.warehouse.model.Warehouse; +import org.chainoptim.desktop.features.warehouse.service.CompartmentService; +import org.chainoptim.desktop.shared.fallback.FallbackManager; +import org.chainoptim.desktop.shared.httphandling.Result; +import org.chainoptim.desktop.shared.util.DataReceiver; +import com.google.inject.Inject; +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; + +import java.util.List; + +public class WarehouseStorageController implements DataReceiver { + + // Services + private final CompartmentService compartmentService; + + // State + private final FallbackManager fallbackManager; + + // FXML + @FXML + private VBox compartmentsVBox; + + @Inject + public WarehouseStorageController(CompartmentService compartmentService, + FallbackManager fallbackManager) { + this.compartmentService = compartmentService; + this.fallbackManager = fallbackManager; + } + + public void setData(Warehouse warehouse) { + loadCompartments(warehouse.getId()); + } + + private void loadCompartments(Integer warehouseId) { + fallbackManager.reset(); + fallbackManager.setLoading(true); + + compartmentService.getCompartmentsByWarehouseId(warehouseId) + .thenApply(this::handleCompartmentsResponse) + .exceptionally(this::handleCompartmentsError); + } + + private Result> handleCompartmentsResponse(Result> result) { + Platform.runLater(() -> { + if (result.getError() != null) { + fallbackManager.setErrorMessage(result.getError().getMessage()); + return; + } + + fallbackManager.setLoading(false); + + renderCompartments(result.getData()); + }); + + return result; + } + + private Result> handleCompartmentsError(Throwable throwable) { + fallbackManager.setErrorMessage("Failed to load compartments"); + + return new Result<>(); + } + + private void renderCompartments(List compartments) { + compartmentsVBox.getChildren().clear(); + + for (Compartment compartment : compartments) { + Label compartmentName = new Label(compartment.getName()); + compartmentName.getStyleClass().add("entity-name-label"); + + compartmentsVBox.getChildren().add(compartmentName); + } + + fallbackManager.setNoResults(false); + } +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/model/Compartment.java b/src/main/java/org/chainoptim/desktop/features/warehouse/model/Compartment.java new file mode 100644 index 00000000..67ee0a12 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/model/Compartment.java @@ -0,0 +1,17 @@ +package org.chainoptim.desktop.features.warehouse.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Compartment { + + private Integer id; + private String name; + private Integer warehouseId; + private Integer organizationId; + private CompartmentData data; +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/model/CompartmentData.java b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CompartmentData.java new file mode 100644 index 00000000..b5264f0c --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CompartmentData.java @@ -0,0 +1,16 @@ +package org.chainoptim.desktop.features.warehouse.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CompartmentData { + + private List crateSpecs; + private List currentCrates; +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/model/Crate.java b/src/main/java/org/chainoptim/desktop/features/warehouse/model/Crate.java new file mode 100644 index 00000000..a93865f4 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/model/Crate.java @@ -0,0 +1,20 @@ +package org.chainoptim.desktop.features.warehouse.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Crate { + + private Integer id; + private String name; + private Integer organizationId; + private Integer componentId; + private Float quantity; + private Float volumeM3; + private Boolean stackable; + private Float heightM; +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateData.java b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateData.java new file mode 100644 index 00000000..b9118629 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateData.java @@ -0,0 +1,14 @@ +package org.chainoptim.desktop.features.warehouse.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CrateData { + + private Integer crateId; + private Integer numberOfCrates; +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateSpec.java b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateSpec.java new file mode 100644 index 00000000..584fdc69 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateSpec.java @@ -0,0 +1,15 @@ +package org.chainoptim.desktop.features.warehouse.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CrateSpec { + + private Integer crateId; + private Integer componentId; + private Float maxCrates; +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentService.java b/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentService.java new file mode 100644 index 00000000..17f67933 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentService.java @@ -0,0 +1,12 @@ +package org.chainoptim.desktop.features.warehouse.service; + +import org.chainoptim.desktop.features.warehouse.model.Compartment; +import org.chainoptim.desktop.shared.httphandling.Result; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public interface CompartmentService { + + CompletableFuture>> getCompartmentsByWarehouseId(Integer warehouseId); +} diff --git a/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentServiceImpl.java b/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentServiceImpl.java new file mode 100644 index 00000000..b486fea0 --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentServiceImpl.java @@ -0,0 +1,40 @@ +package org.chainoptim.desktop.features.warehouse.service; + +import org.chainoptim.desktop.core.user.service.TokenManager; +import org.chainoptim.desktop.features.warehouse.model.Compartment; +import org.chainoptim.desktop.features.warehouse.model.Warehouse; +import org.chainoptim.desktop.shared.caching.CachingService; +import org.chainoptim.desktop.shared.httphandling.RequestBuilder; +import org.chainoptim.desktop.shared.httphandling.RequestHandler; +import org.chainoptim.desktop.shared.httphandling.Result; +import org.chainoptim.desktop.shared.search.model.PaginatedResults; +import com.fasterxml.jackson.core.type.TypeReference; +import com.google.inject.Inject; + +import java.net.http.HttpRequest; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class CompartmentServiceImpl implements CompartmentService { + + private final RequestBuilder requestBuilder; + private final RequestHandler requestHandler; + private final TokenManager tokenManager; + + @Inject + public CompartmentServiceImpl(RequestBuilder requestBuilder, + RequestHandler requestHandler, + TokenManager tokenManager) { + this.requestBuilder = requestBuilder; + this.requestHandler = requestHandler; + this.tokenManager = tokenManager; + } + + public CompletableFuture>> getCompartmentsByWarehouseId(Integer warehouseId) { + String routeAddress = "http://localhost:8080/api/v1/compartments/warehouse/" + warehouseId.toString(); + + HttpRequest request = requestBuilder.buildReadRequest(routeAddress, tokenManager.getToken()); + + return requestHandler.sendRequest(request, new TypeReference>() {}); + } +} diff --git a/src/main/java/org/chainoptim/desktop/shared/search/model/SearchOptionsConfiguration.java b/src/main/java/org/chainoptim/desktop/shared/search/model/SearchOptionsConfiguration.java index 9de2d8a2..cd25e249 100644 --- a/src/main/java/org/chainoptim/desktop/shared/search/model/SearchOptionsConfiguration.java +++ b/src/main/java/org/chainoptim/desktop/shared/search/model/SearchOptionsConfiguration.java @@ -130,10 +130,31 @@ private SearchOptionsConfiguration() { ) ); + private static final SearchOptions WAREHOUSE_INVENTORY_OPTIONS = new SearchOptions( + List.of( + new FilterOption( + new UIItem("Created At Start", "createdAtStart"), + new ArrayList<>(), + FilterType.DATE + ), + new FilterOption( + new UIItem("Quantity", "greaterThanQuantity"), + new ArrayList<>(), + FilterType.NUMBER + ) + ), + Map.of( + "createdAt", "Created At", + "updatedAt", "Updated At", + "quantity", "Quantity" + ) + ); + private static final Map SEARCH_OPTIONS_MAP = Map.of( Feature.SUPPLIER_ORDER, SUPPLIER_ORDER_OPTIONS, Feature.SUPPLIER_SHIPMENT, SUPPLIER_SHIPMENT_OPTIONS, Feature.FACTORY_INVENTORY, FACTORY_INVENTORY_OPTIONS, + Feature.WAREHOUSE_INVENTORY, WAREHOUSE_INVENTORY_OPTIONS, Feature.CLIENT_ORDER, CLIENT_ORDER_OPTIONS, Feature.CLIENT_SHIPMENT, CLIENT_SHIPMENT_OPTIONS ); diff --git a/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml b/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml new file mode 100644 index 00000000..43faf69e --- /dev/null +++ b/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseView.fxml b/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseView.fxml index 7f1ecc46..fddda891 100644 --- a/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseView.fxml +++ b/src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseView.fxml @@ -22,6 +22,7 @@ +