Skip to content

Commit

Permalink
Add Compartment service and Warehouse Storage tab
Browse files Browse the repository at this point in the history
  • Loading branch information
TudorOrban committed Jul 27, 2024
1 parent a7628b3 commit 813e658
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/chainoptim/desktop/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Warehouse> {

// 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<List<Compartment>> handleCompartmentsResponse(Result<List<Compartment>> result) {
Platform.runLater(() -> {
if (result.getError() != null) {
fallbackManager.setErrorMessage(result.getError().getMessage());
return;
}

fallbackManager.setLoading(false);

renderCompartments(result.getData());
});

return result;
}

private Result<List<Compartment>> handleCompartmentsError(Throwable throwable) {
fallbackManager.setErrorMessage("Failed to load compartments");

return new Result<>();
}

private void renderCompartments(List<Compartment> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<CrateSpec> crateSpecs;
private List<CrateData> currentCrates;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Result<List<Compartment>>> getCompartmentsByWarehouseId(Integer warehouseId);
}
Original file line number Diff line number Diff line change
@@ -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<Result<List<Compartment>>> 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<List<Compartment>>() {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Feature, SearchOptions> 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
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>

<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.chainoptim.desktop.features.warehouse.controller.WarehouseStorageController"
prefHeight="400.0" prefWidth="600.0">

<VBox fx:id="compartmentsVBox"/>
</VBox>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<TabPane fx:id="tabPane" tabClosingPolicy="UNAVAILABLE">
<Tab fx:id="overviewTab" text="Overview"/>
<Tab fx:id="inventoryTab" text="Inventory"/>
<Tab fx:id="storageTab" text="Storage"/>
</TabPane>

<StackPane fx:id="fallbackContainer" styleClass="page-fallback-container"/>
Expand Down

0 comments on commit 813e658

Please sign in to comment.