-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Compartment service and Warehouse Storage tab
- Loading branch information
1 parent
a7628b3
commit 813e658
Showing
13 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...java/org/chainoptim/desktop/features/warehouse/controller/WarehouseStorageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/chainoptim/desktop/features/warehouse/model/Compartment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/chainoptim/desktop/features/warehouse/model/CompartmentData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/chainoptim/desktop/features/warehouse/model/Crate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/chainoptim/desktop/features/warehouse/model/CrateSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/chainoptim/desktop/features/warehouse/service/CompartmentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>() {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/resources/org/chainoptim/desktop/features/warehouse/WarehouseStorageView.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters