Auctionhouse websub #63

Merged
Maece97 merged 5 commits from auctionhouse-websub into dev 2021-11-14 21:16:15 +00:00
4 changed files with 27 additions and 22 deletions
Showing only changes of commit 333f6aab21 - Show all commits

View File

@ -27,23 +27,17 @@ public class TapasAuctionHouseApplication {
public static void main(String[] args) {
SpringApplication tapasAuctioneerApp = new SpringApplication(TapasAuctionHouseApplication.class);
// We will use these bootstrap methods in Week 6:
bootstrapMarketplaceWithWebSub();
// bootstrapMarketplaceWithMqtt();
tapasAuctioneerApp.run(args);
// We will use these bootstrap methods in Week 6:
// bootstrapMarketplaceWithMqtt();
bootstrapMarketplaceWithWebSub();
}
/**
* Discovers auction houses and subscribes to WebSub notifications
*/
private static void bootstrapMarketplaceWithWebSub() {
System.out.println("HAHA");
List<String> auctionHouseEndpoints = discoverAuctionHouseEndpoints();
LOGGER.info("Found auction house endpoints: " + auctionHouseEndpoints);
WebSubSubscriber subscriber = new WebSubSubscriber();

View File

@ -9,10 +9,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Subscribes to the WebSub hubs of auction houses discovered at run time. This class is instantiated
@ -38,6 +35,7 @@ public class WebSubSubscriber {
subscribeToWebSub(topic);
// Shoudl be done :D
// TODO Subscribe to the auction house endpoint via WebSub:
// 1. Send a request to the auction house in order to discover the WebSub hub to subscribe to.
// The request URI should depend on the design of the Auction House HTTP API.

View File

@ -1,6 +1,18 @@
package ch.unisg.tapas.auctionhouse.adapter.in.messaging.websub;
import ch.unisg.tapas.auctionhouse.adapter.common.formats.AuctionJsonRepresentation;
import ch.unisg.tapas.auctionhouse.application.handler.AuctionStartedHandler;
import ch.unisg.tapas.auctionhouse.application.port.in.AuctionStartedEvent;
import ch.unisg.tapas.auctionhouse.domain.Auction;
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionDeadline;
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionHouseUri;
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionId;
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionedTaskType;
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionedTaskUri;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import org.json.JSONArray;
import org.springframework.http.HttpStatus;
@ -20,16 +32,20 @@ public class AuctionStartedEventListenerWebSubAdapter {
/**
* Controller which listens to auction-started callbacks
* @return 200 OK
* @throws URISyntaxException
**/
@PostMapping(path = "/auction-started")
public ResponseEntity<Void> handleExecutorAddedEvent(@RequestBody String payload) {
public ResponseEntity<Void> handleExecutorAddedEvent(@RequestBody Collection<AuctionJsonRepresentation> payload) throws URISyntaxException {
// Payload should be a JSONArray with auctions
JSONArray jsonArray = new JSONArray(payload);
for (Object auction : jsonArray) {
System.out.println(auction);
// TODO logic to call handleAuctionStartedEvent()
// auctionStartedHandler.handleAuctionStartedEvent(auctionStartedEvent)
for (AuctionJsonRepresentation auction : payload) {
auctionStartedHandler.handleAuctionStartedEvent(
new AuctionStartedEvent(
new Auction(new AuctionId(auction.getAuctionId()),
new AuctionHouseUri(new URI(auction.getAuctionHouseUri())),
new AuctionedTaskUri(new URI(auction.getTaskUri())),
new AuctionedTaskType(auction.getTaskType()),
new AuctionDeadline(auction.getDeadline()))
));
}
return new ResponseEntity<>(HttpStatus.OK);

View File

@ -18,9 +18,6 @@ public class ValidateIntentWebSubAdapter {
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
@GetMapping(path = "/auction-started")
public ResponseEntity<String> handleExecutorAddedEvent(@RequestParam("hub.challenge") String challenge) {
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
// Different implementation depending on local development or production
if (environment.equalsIgnoreCase("development")) {
HttpHeaders headers = new HttpHeaders();

reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?
reynisson commented 2021-11-14 19:50:49 +00:00 (Migrated from github.com)
Review

Isn't the naming here a bit weird?

Isn't the naming here a bit weird?