diff --git a/src/main/java/nl/han/aim/asd/veilveilig/core/application/usecases/AccountService.java b/src/main/java/nl/han/aim/asd/veilveilig/core/application/usecases/AccountService.java index eb83348c5d542454521591d0a3af6ec7bd5e7a2c..9a6b0bfcdb57f9ab544dabc432b42adb0a013e55 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/core/application/usecases/AccountService.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/core/application/usecases/AccountService.java @@ -1,6 +1,7 @@ package nl.han.aim.asd.veilveilig.core.application.usecases; import com.google.inject.Inject; +import lombok.Getter; import lombok.Setter; import nl.han.aim.asd.veilveilig.core.application.dtos.UserDTO; import nl.han.aim.asd.veilveilig.core.application.dtos.UserSessionDTO; @@ -8,6 +9,7 @@ import nl.han.aim.asd.veilveilig.core.application.ports.IStoragePort; @Setter //This is added for testing purposes. public class AccountService implements IAccountService { + @Getter @Inject IStoragePort storagePort; diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/http/BootstrapHelper.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/http/BootstrapHelper.java deleted file mode 100644 index 2af093aa5d7ab9ab6b9e19181f704661e27d5f0a..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/http/BootstrapHelper.java +++ /dev/null @@ -1,85 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.networkmodule.http; - -import com.google.gson.Gson; -import nl.han.aim.asd.veilveilig.modules.infrastructure.networkmodule.models.JoinNetworkRequest; -import nl.han.aim.asd.veilveilig.modules.infrastructure.networkmodule.models.JoinNetworkResponse; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; - -@Deprecated -public class BootstrapHelper { - public static JoinNetworkResponse sendJoinRequest(JoinNetworkRequest request, String address) { - try { - URL url = new URL(address + "/joinNetwork"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setDoOutput(true); - - Gson gson = new Gson(); - String jsonInputString = gson.toJson(request); - try (OutputStream os = connection.getOutputStream()) { - byte[] input = jsonInputString.getBytes("utf-8"); - os.write(input, 0, input.length); - } - - JoinNetworkResponse response; - int statusCode = connection.getResponseCode(); - if (statusCode == 200) { - response = gson.fromJson(getResponseBody(connection), JoinNetworkResponse.class); - response.setMaster(false); - } else if (statusCode == 201 || statusCode == 208) { - response = new JoinNetworkResponse(); - response.setMaster(true); - } else { - throw new Exception("Unexpected HTTP status code: " + statusCode); - } - - connection.disconnect(); - - return response; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static void sendNewMasterRequest(JoinNetworkRequest request, String address) { - try { - URL url = new URL(address + "/updateMaster"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setDoOutput(true); - - Gson gson = new Gson(); - String jsonInputString = gson.toJson(request); - try (OutputStream os = connection.getOutputStream()) { - byte[] input = jsonInputString.getBytes("utf-8"); - os.write(input, 0, input.length); - } - - int statusCode = connection.getResponseCode(); - if(statusCode != 200){ - throw new Exception("Unexpected HTTP status code: " + statusCode); - } - - connection.disconnect(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static String getResponseBody(HttpURLConnection connection) throws Exception { - StringBuilder responseBuilder = new StringBuilder(); - try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) { - String responseLine = null; - while ((responseLine = br.readLine()) != null) { - responseBuilder.append(responseLine.trim()); - } - } - return responseBuilder.toString(); - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkRequest.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkRequest.java deleted file mode 100644 index a71ae7d62a73e53d22027f572d85d38d274ce06f..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.networkmodule.models; - -@Deprecated -public class JoinNetworkRequest { - private String ip; - private int port; - private String email; - private String password; - - // TODO: deze token hier weghalen - private String token = "79f9d26a-c1b1-4c21-9b8e-b61f58f0a657"; - - public JoinNetworkRequest(String ip, int port, String email, String password) { - this.ip = ip; - this.port = port; - this.email = email; - this.password = password; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkResponse.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkResponse.java deleted file mode 100644 index 33c7a5af9e79b7a9886a94f7e2ef2ed8384335e2..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/networkmodule/models/JoinNetworkResponse.java +++ /dev/null @@ -1,32 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.networkmodule.models; - -@Deprecated -public class JoinNetworkResponse { - private String ip; - private int port; - private boolean isMaster; - - public boolean isMaster() { - return isMaster; - } - - public void setMaster(boolean master) { - isMaster = master; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/AuctionDTO.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/AuctionDTO.java deleted file mode 100644 index 23e8c9366c21119796ac503897ae7c17c735b8cf..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/AuctionDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO; - - -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -import java.util.Date; - -@Builder -@Getter -@Setter -public class AuctionDTO { - private String auctionId; - private CategoryDTO category; - private String auctionType; - private Date stratDate; - private Date endDate; -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UILotDTO.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UILotDTO.java deleted file mode 100644 index a9becd48619a8326b06d27671c4edc35aa8f0433..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UILotDTO.java +++ /dev/null @@ -1,43 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO; - -public class UILotDTO { - private String lotName; - - private String lotId; - - private int reservePrice; - private String lotDescription; - private int quantity; - - public UILotDTO(String lotName, String lotId, int reservePrice, String lotDescription, int quantity) { - this.lotName = lotName; - this.lotId = lotId; - this.reservePrice = reservePrice; - this.lotDescription = lotDescription; - this.quantity = quantity; - } - - public String lotNameProperty() { - return lotName; - } - - public String getLotId() { - return lotId; - } - - public int getReservePrice() { - return reservePrice; - } - - public int getQuantity() { - return quantity; - } - - public String getLotDescription() { - return lotDescription; - } - - public String getLotName() { - return lotName; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UserDTO.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UserDTO.java deleted file mode 100644 index cc39066b0928c0b67b3a01e9b48ed8b0c751c733..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/DTO/UserDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class UserDTO { - private String email; - private String company; - private String firstname; - private String lastname; - private String address; - private boolean seller; - - public UserDTO(String email, String company, String firstname, String lastname, String address, Boolean seller){ - this.email = email; - this.company = company; - this.firstname = firstname; - this.lastname = lastname; - this.address = address; - this.seller = seller; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/TestApi.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/TestApi.java deleted file mode 100644 index 83cb8ef91eb3a3f087af0fe81b390bc8e2dc4011..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/TestApi.java +++ /dev/null @@ -1,69 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui; - -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.AuctionDTO; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.CategoryDTO; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.UILotDTO; - -import java.util.Date; -import java.util.List; -import java.util.stream.Stream; - -public class TestApi { - public List<AuctionDTO> fetchAuctions() { - return Stream.of( - AuctionDTO - .builder() - .auctionId("id1").auctionType("type1") - .category(CategoryDTO.builder() - .category("Auction A").build()) - .stratDate(new Date()) - .endDate(new Date()) - .build(), - AuctionDTO - .builder() - .auctionId("id2").auctionType("type2") - .category(CategoryDTO.builder() - .category("Auction B").build()) - .stratDate(new Date()) - .endDate(new Date()) - .build(), - AuctionDTO - .builder() - .auctionId("id3").auctionType("type3") - .category(CategoryDTO.builder() - .category("Auction C").build()) - .stratDate(new Date()) - .endDate(new Date()) - .build(), - AuctionDTO - .builder() - .auctionId("id4").auctionType("type4") - .category(CategoryDTO.builder() - .category("Auction D").build()) - .stratDate(new Date()) - .endDate(new Date()) - .build(), - AuctionDTO - .builder() - .auctionId("id5").auctionType("type5") - .category(CategoryDTO.builder() - .category("Auction E").build()) - .stratDate(new Date()) - .endDate(new Date()) - .build() - ) - .map(this::createAuctionData).toList(); - } - - public List<UILotDTO> fetchLots() { - return Stream.of(new UILotDTO("Lotto", "Lot01", 100, "Mooie Grote Stoelen", 5), new UILotDTO("Duo Pelotti", "Lot02", 1, "Kleine dwerghamsters", 200), new UILotDTO("Lötti", "Lot03", 3000, "Mooie Grote Zweedse Tafels", 2)).map(this::createLotData).toList(); - } - - private AuctionDTO createAuctionData(AuctionDTO auction) { - return auction; - } - - private UILotDTO createLotData(UILotDTO lot) { - return lot; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/AuctionDetailsBuilder.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/AuctionDetailsBuilder.java index 608bd2285e80144ed37a09c85ad8f0fb6ee26c3c..99c0269ec6e2d010c474af0f0142812fe0f5fd9a 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/AuctionDetailsBuilder.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/AuctionDetailsBuilder.java @@ -84,11 +84,11 @@ public class AuctionDetailsBuilder implements Builder<Region> { buttonBar.setSpacing(20); buttonBar.getChildren().add(makeLot); buttonBar.getChildren().add(startAuction); + auctionDetailBox.getChildren().add(buttonBar); auctionDetailsModel.getLotList().addListener((InvalidationListener) observable -> { auctionDetailBox.getChildren().clear(); - auctionDetailBox.getChildren().add(buttonBar); - auctionDetailBox.getChildren().addAll(loadLots().stream().map(lotModel -> + auctionDetailBox.getChildren().addAll(auctionDetailsModel.getLotList().stream().map(lotModel -> new LotController(lotModel).getView()).toList()); }); @@ -98,20 +98,7 @@ public class AuctionDetailsBuilder implements Builder<Region> { return scrollPane; } - private List<LotModel> loadLots(){ - List<LotDTO> lots = lotService.getLotsForAuction(auctionDetailsModel.getAuctionID()); - List<LotModel> lotModels = new ArrayList<>(); - for (LotDTO lot: lots) { - LotModel lotModel = new LotModel(); - lotModel.setLotName(lot.getObjectName()); - lotModel.setLotId(lot.getLotid()); - lotModel.setQuantity(lot.getQuantity()); - lotModel.setLotDescription(lot.getDescription()); - lotModel.setReservePrice(lot.getReservePrice()); - lotModels.add(lotModel); - } - return lotModels; - } + private void startAuction() { AuctionDTO auctionDTO = auctionService.getAuctionById(auctionDetailsModel.getAuctionID()); List<LotDTO> lotDTOS = lotService.getLotsForAuction(auctionDetailsModel.getAuctionID()); diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/LotCreationBuilder.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/LotCreationBuilder.java index e20e6d4e00265a0110ef3521c77d9aedd5694d31..20e3fcaeb944244faf3e56ecbda6722ae11df9fc 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/LotCreationBuilder.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/builder/LotCreationBuilder.java @@ -1,5 +1,6 @@ package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.builder; +import com.google.inject.Inject; import com.sun.javafx.scene.control.IntegerField; import javafx.scene.control.*; import javafx.scene.layout.BorderPane; @@ -9,9 +10,9 @@ import javafx.util.Builder; import lombok.Getter; import lombok.Setter; import nl.han.aim.asd.veilveilig.core.application.dtos.LotDTO; +import nl.han.aim.asd.veilveilig.core.application.usecases.IAccountService; import nl.han.aim.asd.veilveilig.core.application.usecases.ILotService; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.InjectorFactory; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.UILotDTO; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.controllers.AuctionDetailsController; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.LotCreationModel; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.buttons.ButtonWidgets; @@ -36,12 +37,17 @@ public class LotCreationBuilder implements Builder<Region> { private TextField lotDetailField; private IntegerField priceField; private IntegerField quantityField; + private IAccountService accountService; public LotCreationBuilder(LotCreationModel lotCreationModel,String auctionID) { this.lotCreationModel = lotCreationModel; lotCreationModel.setParrentAuctionID(auctionID); } + public IAccountService getAccountService() { + return InjectorFactory.injector.getInstance(IAccountService.class); + } + public ILotService getLotService() { return InjectorFactory.injector.getInstance(ILotService.class); } @@ -78,10 +84,16 @@ public class LotCreationBuilder implements Builder<Region> { public void buildAction(GridPane lotCreationForm) { submitLotFormButton = ButtonWidgets.actionButton("Maak Kavel", actionEvent -> { + accountService = getAccountService(); if (validForm(nameField, lotDetailField, priceField, quantityField)) { - UILotDTO lotDTO = new UILotDTO(nameField.getText(), "id", priceField.getValue(), lotDetailField.getText(), quantityField.getValue()); + LotDTO lotDTO = new LotDTO(); + lotDTO.setObjectName(nameField.getText()); + lotDTO.setReservePrice(priceField.getValue()); + lotDTO.setDescription(lotDetailField.getText()); + lotDTO.setQuantity(quantityField.getValue()); + lotDTO.setUserEmail(accountService.getCurrentUserSession().getUserId()); lotService.addLotToAuction( - lotCreationModel.getParrentAuctionID(), buildLot(lotDTO.getLotName(), lotDTO.getLotDescription(), lotDTO.getReservePrice(), lotDTO.getQuantity(), "Test mail") + lotCreationModel.getParrentAuctionID(), buildLot(lotDTO.getObjectName(), lotDTO.getDescription(), lotDTO.getReservePrice(), lotDTO.getQuantity(), lotDTO.getUserEmail()) ); setCenter(lotCreationForm); } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsController.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsController.java index 006c19281d3b53cd6b7f01f8f6ed636ad8027b83..35fa9b87f6b0cc6a68e88411af940a3abcf6da10 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsController.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsController.java @@ -27,7 +27,7 @@ public class AuctionDetailsController { private void loadData() { Task<Void> loadTask = new Task<>() { @Override - protected Void call() throws Exception { + protected Void call() { auctionDetailsInteractor.loadData(); return null; } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsInteractor.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsInteractor.java index 6dc00ed618e6089e75398872e7d456a926f534fa..719f304ecd9be73cac1d3cbe43626cca41b4cadb 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsInteractor.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionDetailsInteractor.java @@ -1,7 +1,8 @@ package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.controllers; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.UILotDTO; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.TestApi; +import nl.han.aim.asd.veilveilig.core.application.dtos.LotDTO; +import nl.han.aim.asd.veilveilig.core.application.usecases.ILotService; +import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.InjectorFactory; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.AuctionDetailsModel; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.LotModel; @@ -10,27 +11,39 @@ import java.util.List; public class AuctionDetailsInteractor { private final AuctionDetailsModel model; - private final List<UILotDTO> lots = new ArrayList<>(); - private final TestApi api = new TestApi(); - + private ILotService lotService; + private final List<LotDTO> lots = new ArrayList<>(); public AuctionDetailsInteractor(AuctionDetailsModel model) { + this.model = model; + lotService = InjectorFactory.injector.getInstance(ILotService.class); } void loadData() { lots.clear(); - lots.addAll(api.fetchLots()); + List<LotDTO> list = new ArrayList<>(); + list.add(new LotDTO()); + lots.addAll(list); } void loadModel() { - model.getLotList().addAll(lots.stream().map(this::createLotModel).toList()); + model.getLotList().addAll(loadLots()); + } + + private List<LotModel> loadLots(){ + List<LotDTO> lots = lotService.getLotsForAuction(model.getAuctionID()); + List<LotModel> lotModels = new ArrayList<>(); + for (LotDTO lot: lots) { + lotModels.add(createLotModel(lot)); + } + return lotModels; } - private LotModel createLotModel(UILotDTO lot) { + private LotModel createLotModel(LotDTO lot) { LotModel result = new LotModel(); - result.setLotDescription(lot.getLotDescription()); - result.setLotName(lot.getLotName()); - result.setLotId(lot.getLotId()); + result.setLotName(lot.getObjectName()); + result.setLotDescription(lot.getDescription()); + result.setLotId(lot.getLotid()); result.setReservePrice(lot.getReservePrice()); result.setQuantity(lot.getQuantity()); diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionsInteractor.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionsInteractor.java index add05b548f993a5d0d182f6d4f86a58b27f17e65..2a44ef923557a19eadcf5c64809b889909cc3d5f 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionsInteractor.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/controllers/AuctionsInteractor.java @@ -2,9 +2,9 @@ package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.controllers; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import nl.han.aim.asd.veilveilig.core.application.dtos.AuctionDTO; import nl.han.aim.asd.veilveilig.core.application.usecases.IAuctionService; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.InjectorFactory; -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.DTO.AuctionDTO; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.AuctionModel; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.AuctionsModel; diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/models/Kavel.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/models/Kavel.java deleted file mode 100644 index 7d6248b82fef8699196af7c37f1bfe12c88f3ee7..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/models/Kavel.java +++ /dev/null @@ -1,9 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models; - -public class Kavel { - private String objectName; - private Integer reservePrice; - private String description; - private Integer quantity; - private String category; -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenController.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenController.java deleted file mode 100644 index 71e1d280adc4421a13600866c762968c77bbd3b5..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenController.java +++ /dev/null @@ -1,38 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.mvci; - -import javafx.concurrent.Task; -import javafx.scene.layout.Region; -import javafx.util.Builder; - -public abstract class ScreenController<ViewModelClass> { - - protected Builder<Region> viewBuilder; - protected Region view; - - - protected void load(Runnable postFetchGui) { - Task<Void> fetchTask = new Task<>() { - @Override - protected Void call() { - getInteractor().fetchData(); - return null; - } - }; - fetchTask.setOnSucceeded(evt -> { - getInteractor().updateModel(); - postFetchGui.run(); - }); - Thread fetchThread = new Thread(fetchTask); - fetchThread.start(); - } - - protected abstract ScreenInteractor<ViewModelClass> getInteractor(); - - public Region getView() { - if (view == null) { - view = viewBuilder.build(); - } - return view; - } - -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenInteractor.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenInteractor.java deleted file mode 100644 index a3e4e2b579448fac42578db44dee54f15338cfd0..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ScreenInteractor.java +++ /dev/null @@ -1,29 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.mvci; - -public abstract class ScreenInteractor<ViewModelClass> { - - protected final ViewModelClass viewModel; - - protected ScreenInteractor(ViewModelClass viewModel) { - this.viewModel = viewModel; - } - - /** - * Method designed to be run in a background thread called by the - * ScreenController load() method from inside a Task call() method. - * Ideally, this method should contain all of the initialization of - * Domain objects from external API's and the persistence layer - */ - - public abstract void fetchData(); - - /** - * Method designed to be run on the FXAT to load data received via - * the fetchData() method into the ViewModel. This method is called - * from the load() method of the ScreenController via the setOnSucceeded() - * method of a Task. - */ - - public abstract void updateModel(); - -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ViewBuilder.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ViewBuilder.java deleted file mode 100644 index 2cc01f5422e9dc81ac9ec41f267a59a79813df96..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/ViewBuilder.java +++ /dev/null @@ -1,13 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.mvci; - -import javafx.scene.layout.Region; -import javafx.util.Builder; - -public abstract class ViewBuilder<ViewModelClass> implements Builder<Region> { - - protected ViewModelClass viewModel; - - public ViewBuilder(ViewModelClass viewModel) { - this.viewModel = viewModel; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/package-info.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/package-info.java deleted file mode 100644 index d4c4f5843ae4dc5fdb2c104580776238c04c7e5d..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/mvci/package-info.java +++ /dev/null @@ -1,33 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.mvci; - -/* - Implementation of Model-View-Controller-Interactor for JavaFX. - <p> - This construct marries Model-View-Controller with - Entity-Boundary-Controller to provide a framework to allow - a JavaFX GUI to interact with external API's, a persistence layer - and other non-GUI aspects of an application. Coupling is kept to - a minimum. - <p> - Elements: - <p> - Model - Model should be a POJO with JavaFX Observable classes as - the fields. - <p> - View - Strictly the GUI layout, elements in the GUI should be bound - to the fields in the Model as required. This way the View - and the Model are constantly in sync. - <p> - Controller - The Controller handles instantiation of all of the other elements - and all of the threading required to handle non-GUI processing - off the FXAT - <p> - Interactor - The Interactor contains all of the business logic and interface - to the non-GUI aspects of the system. The Interactor is given - a reference to the Model, and is able to read from it and update - it as appropriate. - <p> - It is recommended that JavaFX classes are extended only to broaden their functionality - and that they are not extended merely for configuration. For this reason, the View - is to be constructed by an implementation of the Builder interface. - */ \ No newline at end of file diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ConfigurableColumn.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ConfigurableColumn.java deleted file mode 100644 index e2270f718c7614d91728d920c86c1f43b66bbfab..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ConfigurableColumn.java +++ /dev/null @@ -1,29 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - - -import javafx.scene.control.TableColumn; - -public abstract class ConfigurableColumn<CHILD extends ConfigurableColumn<CHILD, S, T>, S, T> extends TableColumn<S, T> { - - public ConfigurableColumn(String columnHeading) { - super(columnHeading); - } - - protected abstract CHILD getThis(); - - public CHILD withMinWidth(double width) { - setMinWidth(width); - return getThis(); - } - - public CHILD withMaxWidth(double width) { - setMaxWidth(width); - return getThis(); - } - - public CHILD withFixedWidth(double width) { - setMinWidth(width); - setMaxWidth(width); - return getThis(); - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateCell.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateCell.java deleted file mode 100644 index cfa11f7da94222aac571bde999c82b56bb980204..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateCell.java +++ /dev/null @@ -1,28 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.DateWidgets; -import javafx.beans.binding.Bindings; -import javafx.geometry.Pos; -import javafx.scene.control.TableCell; -import javafx.scene.text.Text; - -import java.time.LocalDate; - -public class DateCell<TableModel> extends TableCell<TableModel, LocalDate> { - - Text text = new Text(); - - public DateCell() { - super(); - initialize(); - } - - private void initialize() { - text.getStyleClass().add("data-text-cell"); - text.textProperty().bind(Bindings.createStringBinding(() -> (itemProperty().get() != null) ? - DateWidgets.formatDate(itemProperty().get()) : "", itemProperty())); - setGraphic(text); - setAlignment(Pos.CENTER_RIGHT); - } - -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateColumn.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateColumn.java deleted file mode 100644 index 5fac53a685f6e60828e55d4cad61d056c06c6edf..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DateColumn.java +++ /dev/null @@ -1,31 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.value.ObservableValue; -import javafx.util.Callback; - -import java.time.LocalDate; - -public class DateColumn<TableModel> extends ConfigurableColumn<DateColumn<TableModel>, TableModel, LocalDate> { - - public DateColumn(String columnHeading) { - super(columnHeading); - initialize(); - } - - public DateColumn(String columnHeading, Callback<CellDataFeatures<TableModel, LocalDate>, ObservableValue<LocalDate>> valueCallback) { - super(columnHeading); - setCellValueFactory(valueCallback); - initialize(); - } - - private void initialize() { - setMinWidth(80); - setMaxWidth(80); - setCellFactory(column -> new DateCell<>()); - } - - @Override - protected DateColumn<TableModel> getThis() { - return this; - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalCell.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalCell.java deleted file mode 100644 index 2ad0084ccdac8746f1ee03073788657e84ff37b7..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalCell.java +++ /dev/null @@ -1,33 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.binding.Bindings; -import javafx.geometry.Pos; -import javafx.scene.control.TableCell; -import javafx.scene.text.Text; - -import java.text.DecimalFormat; - -public class DecimalCell<TableModel> extends TableCell<TableModel, Double> { - - Text text = new Text(); - DecimalFormat df = new DecimalFormat("#.00"); - - public DecimalCell() { - super(); - initialize(); - } - - public DecimalCell(String formatPattern) { - super(); - df = new DecimalFormat(formatPattern); - initialize(); - } - - private void initialize() { - text.getStyleClass().add("data-text"); - text.textProperty().bind(Bindings.createStringBinding(() -> (itemProperty().get() != null) ? df.format(itemProperty().get()) : "", - itemProperty())); - setGraphic(text); - setAlignment(Pos.CENTER_RIGHT); - } -} \ No newline at end of file diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalColumn.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalColumn.java deleted file mode 100644 index c07423c5ccff11d85528c559acc330b0525eea1e..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/DecimalColumn.java +++ /dev/null @@ -1,33 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.value.ObservableValue; -import javafx.util.Callback; - -public class DecimalColumn<TableModel> extends ConfigurableColumn<DecimalColumn<TableModel>, TableModel, Double> { - - private String formatString = "#.00"; - - public DecimalColumn(String columnHeading) { - super(columnHeading); - setCellFactory(column -> new DecimalCell<>(formatString)); - } - - @Override - protected DecimalColumn<TableModel> getThis() { - return this; - } - - public DecimalColumn(String columnHeading, - Callback<CellDataFeatures<TableModel, Double>, ObservableValue<Double>> valueCallback) { - super(columnHeading); - setCellFactory(column -> new DecimalCell<>(formatString)); - setCellValueFactory(valueCallback); - } - - public DecimalColumn<TableModel> withFormat(String formatString) { - this.formatString = formatString; - setCellFactory(column -> new DecimalCell<>(formatString)); - return this; - } - -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerCell.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerCell.java deleted file mode 100644 index 931cbf0b10d48ea08cec9917f836b858bca4ad8a..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerCell.java +++ /dev/null @@ -1,19 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.binding.Bindings; -import javafx.geometry.Pos; -import javafx.scene.control.TableCell; -import javafx.scene.text.Text; - -public class IntegerCell<TableModel> extends TableCell<TableModel, Integer> { - - Text text = new Text(); - - public IntegerCell() { - text.getStyleClass().add("data-text"); - text.textProperty().bind(Bindings.createStringBinding(() -> (itemProperty().get() != null) ? itemProperty().get().toString() : "", - itemProperty())); - setGraphic(text); - setAlignment(Pos.CENTER_RIGHT); - } -} \ No newline at end of file diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerColumn.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerColumn.java deleted file mode 100644 index d0d337c9b7e15fbcc145b414e24fd8e9c7800cfd..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/IntegerColumn.java +++ /dev/null @@ -1,29 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.value.ObservableValue; -import javafx.util.Callback; - -public class IntegerColumn<TableModel> extends ConfigurableColumn<IntegerColumn<TableModel>, TableModel, Integer> { - - public IntegerColumn(String columnHeading) { - super(columnHeading); - setCellFactory(column -> new IntegerCell<>()); - } - - @Override - protected IntegerColumn<TableModel> getThis() { - return this; - } - - public IntegerColumn(String columnHeading, Callback<CellDataFeatures<TableModel, Integer>, ObservableValue<Integer>> valueCallback) { - super(columnHeading); - setCellFactory(column -> new IntegerCell<>()); - setCellValueFactory(valueCallback); - } - - public IntegerColumn<TableModel> withPreferredWidth(double width) { - setPrefWidth(width); - return this; - } - -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ProgressPlaceholder.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ProgressPlaceholder.java deleted file mode 100644 index 36cef7e168159c132ed7b88c8cdc60b3063eb9c6..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/ProgressPlaceholder.java +++ /dev/null @@ -1,16 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.text.Texts; -import javafx.geometry.Pos; -import javafx.scene.control.ProgressIndicator; -import javafx.scene.layout.VBox; - -public class ProgressPlaceholder extends VBox { - - public ProgressPlaceholder(String message) { - setSpacing(10); - getChildren().addAll(new ProgressIndicator(-1), Texts.label(message)); - setFillWidth(true); - setAlignment(Pos.CENTER); - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextCell.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextCell.java deleted file mode 100644 index 927f703599f5562bcec3726361f8cd8665edddc7..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextCell.java +++ /dev/null @@ -1,24 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.scene.control.TableCell; -import javafx.scene.text.Text; - -public class TextCell<TableModel> extends TableCell<TableModel, String> { - - Text text = new Text(); - - public TextCell() { - initialize(); - } - - public TextCell(double wrappingWidth) { - initialize(); - text.setWrappingWidth(wrappingWidth); - } - - private void initialize() { - text.getStyleClass().add("data-text-cell"); - text.textProperty().bind(itemProperty()); - setGraphic(text); - } -} diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextColumn.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextColumn.java deleted file mode 100644 index 05c78f62fd7f0f6ad6e2446174c9e6832e9b7fcd..0000000000000000000000000000000000000000 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/infrastructure/ui/widgetsfx/tables/TextColumn.java +++ /dev/null @@ -1,28 +0,0 @@ -package nl.han.aim.asd.veilveilig.modules.infrastructure.ui.widgetsfx.tables; - -import javafx.beans.value.ObservableValue; -import javafx.util.Callback; - -public class TextColumn<TableModel> extends ConfigurableColumn<TextColumn<TableModel>, TableModel, String> { - - public TextColumn(String columnHeading) { - super(columnHeading); - setCellFactory(column -> new TextCell<>()); - } - - @Override - protected TextColumn<TableModel> getThis() { - return this; - } - - public TextColumn(String columnHeading, Callback<CellDataFeatures<TableModel, String>, ObservableValue<String>> valueCallback) { - super(columnHeading); - setCellFactory(column -> new TextCell<>()); - setCellValueFactory(valueCallback); - } - - public TextColumn<TableModel> withWrappingWidth(double wrappingWidth) { - setCellFactory(column -> new TextCell<>(wrappingWidth)); - return this; - } -} diff --git a/src/test/java/nl/han/aim/asd/veilveilig/core/application/usecases/LotServiceIntegrationTest.java b/src/test/java/nl/han/aim/asd/veilveilig/core/application/usecases/LotServiceIntegrationTest.java index c8b1d51cf4b5bb653e27d07d956ec6d0b9ffcf2d..6567a2e9163d9bb223ba8bcb3957ab0cfd9d9a9c 100644 --- a/src/test/java/nl/han/aim/asd/veilveilig/core/application/usecases/LotServiceIntegrationTest.java +++ b/src/test/java/nl/han/aim/asd/veilveilig/core/application/usecases/LotServiceIntegrationTest.java @@ -6,6 +6,7 @@ import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import nl.han.aim.asd.veilveilig.core.application.adapters.StorageAdapter; import nl.han.aim.asd.veilveilig.core.application.dtos.LotDTO; +import nl.han.aim.asd.veilveilig.core.application.dtos.UserSessionDTO; import nl.han.aim.asd.veilveilig.core.application.ports.IStoragePort; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.builder.LotCreationBuilder; import nl.han.aim.asd.veilveilig.modules.infrastructure.ui.models.LotCreationModel; @@ -33,6 +34,7 @@ class LotServiceIntegrationTest { private LotCreationModel lotCreationModel; @Mock private IStoragePort storagePort; + @Mock IAccountService accountService; @BeforeAll static void init() { @@ -42,20 +44,32 @@ class LotServiceIntegrationTest { } } + /* + * We only test if the lotservice storage is verified. AccountService is mocked. + */ @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); storagePort = Mockito.mock(StorageAdapter.class); when(lotCreationModel.getParrentAuctionID()).thenReturn("auctionID"); + accountService = mock(AccountService.class); lotService = new LotService(); sut = mock(LotCreationBuilder.class); // Use the mock object instead of creating a new instance when(sut.getLotService()).thenReturn(new LotService()); + + UserSessionDTO usDTO = new UserSessionDTO(); + usDTO.setUserId("SomeId"); + doCallRealMethod().when(accountService).setUserSession(any()); + when(sut.getAccountService()).thenReturn(accountService); + when(accountService.getCurrentUserSession()).thenReturn(usDTO); + doNothing().when(accountService).setUserSession(any()); + accountService.setUserSession(usDTO); doCallRealMethod().when(sut).buildAction(any(GridPane.class)); doCallRealMethod().when(sut).validForm(any(TextField.class), any(TextField.class), any(IntegerField.class), any(IntegerField.class)); doCallRealMethod().when(sut).getSubmitLotFormButton(); - + doCallRealMethod().when(sut).setAccountService(accountService); doCallRealMethod().when(sut).setNameField(any(TextField.class)); doCallRealMethod().when(sut).setLotDetailField(any(TextField.class)); doCallRealMethod().when(sut).setPriceField(any(IntegerField.class));