From 74a51cfcf681f8acd804eef2b24dc341e61e419b Mon Sep 17 00:00:00 2001 From: "julius.lautz" Date: Wed, 10 Nov 2021 11:03:57 +0000 Subject: [PATCH 1/3] changed deadline to timestamp and the logic to schedule an auction --- .../application/port/in/LaunchAuctionCommand.java | 5 +++-- .../application/service/StartAuctionService.java | 3 ++- .../java/ch/unisg/tapas/auctionhouse/domain/Auction.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java index 626fa49..37eb5db 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java @@ -1,10 +1,11 @@ package ch.unisg.tapas.auctionhouse.application.port.in; import ch.unisg.tapas.auctionhouse.domain.Auction; -import ch.unisg.tapas.common.SelfValidating; +import ch.unisg.common.SelfValidating; +import lombok.NonNull; import lombok.Value; -import javax.validation.constraints.NotNull; +import javax.validation.constraint.NotNull; /** * Command for launching an auction in this auction house. diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java index 42c6e37..b9d9d3d 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java @@ -2,6 +2,7 @@ package ch.unisg.tapas.auctionhouse.application.service; import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionCommand; import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase; +import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase; import ch.unisg.tapas.auctionhouse.application.port.out.AuctionWonEventPort; import ch.unisg.tapas.auctionhouse.application.port.out.AuctionStartedEventPort; import ch.unisg.tapas.auctionhouse.domain.*; @@ -63,7 +64,7 @@ public class StartAuctionService implements LaunchAuctionUseCase { auctions.addAuction(auction); // Schedule the closing of the auction at the deadline - service.schedule(new CloseAuctionTask(auction.getAuctionId()), deadline.getValue(), + service.schedule(new CloseAuctionTask(auction.getAuctionId()), deadline.getValue().getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS); // Publish an auction started event diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java index 3e51ef7..c6d9333 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/domain/Auction.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.Value; import java.net.URI; +import java.sql.Timestamp; import java.util.*; /** @@ -166,6 +167,6 @@ public class Auction { @Value public static class AuctionDeadline { - int value; + Timestamp value; } } From 2f42da485d68f50e102e9329f3ac4a56a15de113 Mon Sep 17 00:00:00 2001 From: reynisson Date: Fri, 12 Nov 2021 13:30:16 +0100 Subject: [PATCH 2/3] Fixed imports so that the class builds --- .../application/port/in/LaunchAuctionCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java index 37eb5db..626fa49 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/port/in/LaunchAuctionCommand.java @@ -1,11 +1,10 @@ package ch.unisg.tapas.auctionhouse.application.port.in; import ch.unisg.tapas.auctionhouse.domain.Auction; -import ch.unisg.common.SelfValidating; -import lombok.NonNull; +import ch.unisg.tapas.common.SelfValidating; import lombok.Value; -import javax.validation.constraint.NotNull; +import javax.validation.constraints.NotNull; /** * Command for launching an auction in this auction house. From b37141f5cefcdcfef0c4b17778670f090b5e259e Mon Sep 17 00:00:00 2001 From: "julius.lautz" Date: Sun, 14 Nov 2021 16:51:42 +0100 Subject: [PATCH 3/3] fixed issues --- .../adapter/common/formats/AuctionJsonRepresentation.java | 6 ++++-- .../application/service/StartAuctionService.java | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java index 4500423..ea4cf2c 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/common/formats/AuctionJsonRepresentation.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import lombok.Setter; +import java.sql.Timestamp; + /** * Used to expose a representation of the state of an auction through an interface. This class is * only meant as a starting point when defining a uniform HTTP API for the Auction House: feel free @@ -28,12 +30,12 @@ public class AuctionJsonRepresentation { private String taskType; @Getter @Setter - private Integer deadline; + private Timestamp deadline; public AuctionJsonRepresentation() { } public AuctionJsonRepresentation(String auctionId, String auctionHouseUri, String taskUri, - String taskType, Integer deadline) { + String taskType, Timestamp deadline) { this.auctionId = auctionId; this.auctionHouseUri = auctionHouseUri; this.taskUri = taskUri; diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java index b9d9d3d..60c5f24 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/application/service/StartAuctionService.java @@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.sql.Timestamp; import java.util.Optional; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit; public class StartAuctionService implements LaunchAuctionUseCase { private static final Logger LOGGER = LogManager.getLogger(StartAuctionService.class); - private final static int DEFAULT_AUCTION_DEADLINE_MILLIS = 10000; + private final Timestamp DEFAULT_AUCTION_DEADLINE_MILLIS = Timestamp.valueOf("1970-01-01 00:00:01"); // Event port used to publish an auction started event private final AuctionStartedEventPort auctionStartedEventPort;