Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factories #71

Merged
merged 13 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"d3": "^7.9.0"
"d3": "^7.9.0",
"leaflet": "^1.5.1"
},
"devDependencies": {
"@parcel/transformer-typescript-tsc": "^2.12.0",
"@types/d3": "^7.4.3",
"@types/leaflet": "^1.9.12",
"ts-loader": "^9.5.1",
"typescript": "^5.4.2",
"webpack": "^5.90.3",
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/chainoptim/desktop/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.chainoptim.desktop.core.main.service.CurrentSelectionService;
import org.chainoptim.desktop.core.main.service.NavigationService;
import org.chainoptim.desktop.core.main.service.NavigationServiceImpl;
import org.chainoptim.desktop.core.map.service.SupplyChainMapService;
import org.chainoptim.desktop.core.map.service.SupplyChainMapServiceImpl;
import org.chainoptim.desktop.core.notification.controller.NotificationManager;
import org.chainoptim.desktop.core.notification.model.NotificationUser;
import org.chainoptim.desktop.core.notification.service.NotificationPersistenceService;
Expand All @@ -18,6 +20,8 @@
import org.chainoptim.desktop.core.organization.service.OrganizationServiceImpl;
import org.chainoptim.desktop.core.overview.service.SupplyChainSnapshotService;
import org.chainoptim.desktop.core.overview.service.SupplyChainSnapshotServiceImpl;
import org.chainoptim.desktop.core.overview.service.UpcomingEventService;
import org.chainoptim.desktop.core.overview.service.UpcomingEventServiceImpl;
import org.chainoptim.desktop.core.settings.service.UserSettingsService;
import org.chainoptim.desktop.core.settings.service.UserSettingsServiceImpl;
import org.chainoptim.desktop.core.user.service.*;
Expand Down Expand Up @@ -122,6 +126,10 @@ protected void configure() {

// - Overview
bind(SupplyChainSnapshotService.class).to(SupplyChainSnapshotServiceImpl.class);
bind(UpcomingEventService.class).to(UpcomingEventServiceImpl.class);

// - Map
bind(SupplyChainMapService.class).to(SupplyChainMapServiceImpl.class);

// - Notifications
bind(NotificationPersistenceService.class).to(NotificationPersistenceServiceImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void setButtonGraphic(Button button, String imagePath){
button.setGraphic(imageView);
button.setGraphicTextGap(10);
} catch (Exception e) {
System.out.println("Icon not added yet: " + imagePath);
// Do nothing
}
}

Expand Down
92 changes: 92 additions & 0 deletions src/main/java/org/chainoptim/desktop/core/map/MapController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.chainoptim.desktop.core.map;

import org.chainoptim.desktop.core.map.model.SupplyChainMap;
import org.chainoptim.desktop.features.scanalysis.factorygraph.service.JavaConnector;
import org.chainoptim.desktop.shared.fallback.FallbackManager;
import org.chainoptim.desktop.shared.util.DataReceiver;
import com.google.inject.Inject;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;

import java.util.Objects;

import static org.chainoptim.desktop.shared.util.JsonUtil.prepareJsonString;

public class MapController implements DataReceiver<SupplyChainMap> {

SupplyChainMap supplyChainMap;

private final FallbackManager fallbackManager;

private WebView webView;
private JavaConnector javaConnector;

@FXML
private StackPane mapContainer;

@Inject
public MapController(FallbackManager fallbackManager) {
this.fallbackManager = fallbackManager;
}

@Override
public void setData(SupplyChainMap data) {
this.supplyChainMap = data;

if (supplyChainMap == null) {
return;
}

initializeWebView();

// displayMap();
}

private void initializeWebView() {
webView = new WebView();
webView.getEngine().load(Objects.requireNonNull(getClass().getResource("/html/supplychainmap.html")).toExternalForm());
webView.getEngine().getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == Worker.State.SUCCEEDED) {
JSObject jsObject = (JSObject) webView.getEngine().executeScript("window");
javaConnector = new JavaConnector();
jsObject.setMember("javaConnector", javaConnector);

try {
Object result = webView.getEngine().executeScript("typeof window.renderFactoryGraph");
System.out.println("SupplyChainMap renderFactoryGraph available: " + result);
} catch (Exception e) {
System.err.println("Failed to evaluate script: " + e.getMessage());
}
}
});
}

public void displayMap() {
if (webView.getEngine().getLoadWorker().getState() == Worker.State.SUCCEEDED) {
renderMap();
}
webView.getEngine().getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == Worker.State.SUCCEEDED) {
// Execute script for rendering map (using timeout for now to ensure bundle is loaded at this point)
renderMap();
}
});

mapContainer.getChildren().add(webView);
}

public void renderMap() {
String escapedJsonString = prepareJsonString(supplyChainMap);

String script = "window.renderMap('" + escapedJsonString + "');";
try {
webView.getEngine().executeScript(script);
} catch (Exception e) {
fallbackManager.setErrorMessage("Error drawing map. Please try again.");
e.printStackTrace();
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/chainoptim/desktop/core/map/model/Facility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.chainoptim.desktop.core.map.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Facility {

private Integer id;
private String name;
private FacilityType type;
private Double latitude;
private Double longitude;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.chainoptim.desktop.core.map.model;

public enum FacilityType {
FACTORY,
WAREHOUSE,
SUPPLIER,
CLIENT
}
15 changes: 15 additions & 0 deletions src/main/java/org/chainoptim/desktop/core/map/model/MapData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.chainoptim.desktop.core.map.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MapData {

private List<Facility> facilities;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.chainoptim.desktop.core.map.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SupplyChainMap {

private Integer id;
private Integer organizationId;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private MapData mapData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.chainoptim.desktop.core.map.service;

import org.chainoptim.desktop.core.map.model.SupplyChainMap;
import org.chainoptim.desktop.shared.httphandling.Result;

import java.util.concurrent.CompletableFuture;

public interface SupplyChainMapService {

CompletableFuture<Result<SupplyChainMap>> getMapByOrganizationId(Integer organizationId, boolean refresh);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.chainoptim.desktop.core.map.service;

import org.chainoptim.desktop.core.map.model.SupplyChainMap;
import org.chainoptim.desktop.core.organization.model.Organization;
import org.chainoptim.desktop.core.user.service.TokenManager;
import org.chainoptim.desktop.shared.httphandling.RequestBuilder;
import org.chainoptim.desktop.shared.httphandling.RequestHandler;
import org.chainoptim.desktop.shared.httphandling.Result;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.inject.Inject;

import java.net.http.HttpRequest;
import java.util.concurrent.CompletableFuture;

public class SupplyChainMapServiceImpl implements SupplyChainMapService {

private final RequestHandler requestHandler;
private final RequestBuilder requestBuilder;
private final TokenManager tokenManager;

@Inject
public SupplyChainMapServiceImpl(RequestHandler requestHandler,
RequestBuilder requestBuilder,
TokenManager tokenManager) {
this.requestHandler = requestHandler;
this.requestBuilder = requestBuilder;
this.tokenManager = tokenManager;
}

public CompletableFuture<Result<SupplyChainMap>> getMapByOrganizationId(Integer organizationId, boolean refresh) {
String routeAddress = "http://localhost:8080/api/v1/supply-chain-maps/" + organizationId.toString()
+ (refresh ? "/refresh" : "");

HttpRequest request = requestBuilder.buildReadRequest(routeAddress, tokenManager.getToken());

return requestHandler.sendRequest(request, new TypeReference<SupplyChainMap>() {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.chainoptim.desktop.core.abstraction.ControllerFactory;
import org.chainoptim.desktop.core.organization.model.CustomRole;
import org.chainoptim.desktop.core.organization.model.OrganizationViewData;
import org.chainoptim.desktop.shared.confirmdialog.controller.GenericConfirmDialogController;
import org.chainoptim.desktop.shared.confirmdialog.controller.RunnableConfirmDialogActionListener;
import org.chainoptim.desktop.shared.confirmdialog.model.ConfirmDialogInput;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.GenericConfirmDialogController;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.RunnableConfirmDialogActionListener;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.model.ConfirmDialogInput;
import org.chainoptim.desktop.shared.util.DataReceiver;
import org.chainoptim.desktop.shared.util.resourceloader.FXMLLoaderService;
import com.google.inject.Inject;
Expand Down Expand Up @@ -70,7 +70,7 @@ private void setupListeners() {

private void loadUpdateConfirmDialog() {
// Load confirm dialog
FXMLLoader loader = fxmlLoaderService.setUpLoader("/org/chainoptim/desktop/shared/confirmdialog/GenericConfirmDialogView.fxml", controllerFactory::createController);
FXMLLoader loader = fxmlLoaderService.setUpLoader("/org/chainoptim/desktop/shared/common/uielements/confirmdialog/GenericConfirmDialogView.fxml", controllerFactory::createController);

ConfirmDialogInput confirmDialogInput = new ConfirmDialogInput("Confirm Custom Role Update", "Are you sure you want to update this role?", "/org/chainoptim/desktop/core/user/UsersListByCustomRoleView.fxml");
CustomRole customRole = new CustomRole();
Expand All @@ -89,7 +89,7 @@ private void loadUpdateConfirmDialog() {

private void loadDeleteConfirmDialog() {
// Load confirm dialog
FXMLLoader loader = fxmlLoaderService.setUpLoader("/org/chainoptim/desktop/shared/confirmdialog/GenericConfirmDialogView.fxml", controllerFactory::createController);
FXMLLoader loader = fxmlLoaderService.setUpLoader("/org/chainoptim/desktop/shared/common/uielements/confirmdialog/GenericConfirmDialogView.fxml", controllerFactory::createController);

ConfirmDialogInput confirmDialogInput = new ConfirmDialogInput("Confirm Custom Role Delete", "Are you sure you want to delete this role?", "/org/chainoptim/desktop/core/user/UsersListByCustomRoleView.fxml");
CustomRole customRole = new CustomRole();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.chainoptim.desktop.core.organization.controller;

import org.chainoptim.desktop.core.organization.model.CustomRole;
import org.chainoptim.desktop.core.organization.model.FeaturePermissions;
import org.chainoptim.desktop.core.user.model.User;
import org.chainoptim.desktop.shared.confirmdialog.controller.GenericConfirmDialogActionListener;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.GenericConfirmDialogActionListener;
import org.chainoptim.desktop.shared.util.DataReceiver;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -16,11 +14,8 @@
import javafx.util.Pair;
import lombok.Setter;

import java.util.List;
import java.util.Objects;

import static org.chainoptim.desktop.core.user.model.User.Role.ADMIN;

public class OrganizationAssignBasicRoleController implements DataReceiver<User> {

// State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.chainoptim.desktop.core.organization.model.CustomRole;
import org.chainoptim.desktop.core.organization.model.FeaturePermissions;
import org.chainoptim.desktop.core.user.model.User;
import org.chainoptim.desktop.shared.confirmdialog.controller.GenericConfirmDialogActionListener;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.GenericConfirmDialogActionListener;
import org.chainoptim.desktop.shared.util.DataReceiver;

import javafx.event.ActionEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.chainoptim.desktop.core.organization.dto.UpdateCustomRoleDTO;
import org.chainoptim.desktop.core.organization.model.*;
import org.chainoptim.desktop.core.organization.service.CustomRoleService;
import org.chainoptim.desktop.shared.confirmdialog.controller.GenericConfirmDialogController;
import org.chainoptim.desktop.shared.confirmdialog.controller.RunnableConfirmDialogActionListener;
import org.chainoptim.desktop.shared.confirmdialog.model.ConfirmDialogInput;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.GenericConfirmDialogController;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.controller.RunnableConfirmDialogActionListener;
import org.chainoptim.desktop.shared.common.uielements.confirmdialog.model.ConfirmDialogInput;
import org.chainoptim.desktop.shared.fallback.FallbackManager;
import org.chainoptim.desktop.shared.httphandling.Result;
import org.chainoptim.desktop.shared.util.DataReceiver;
Expand Down Expand Up @@ -154,7 +154,7 @@ private void setupListeners() {
private void loadConfirmUpdateDialog() {
// Load view into fallbackContainer
FXMLLoader loader = fxmlLoaderService.setUpLoader(
"/org/chainoptim/desktop/shared/confirmdialog/GenericConfirmDialogView.fxml",
"/org/chainoptim/desktop/shared/common/uielements/confirmdialog/GenericConfirmDialogView.fxml",
controllerFactory::createController
);
try {
Expand All @@ -170,7 +170,7 @@ private void loadConfirmUpdateDialog() {
private void loadConfirmDeleteDialog() {
// Load view into fallbackContainer
FXMLLoader loader = fxmlLoaderService.setUpLoader(
"/org/chainoptim/desktop/shared/confirmdialog/GenericConfirmDialogView.fxml",
"/org/chainoptim/desktop/shared/common/uielements/confirmdialog/GenericConfirmDialogView.fxml",
controllerFactory::createController
);
try {
Expand Down
Loading
Loading