Dev #65
|
@ -27,23 +27,17 @@ public class TapasAuctionHouseApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication tapasAuctioneerApp = new SpringApplication(TapasAuctionHouseApplication.class);
|
SpringApplication tapasAuctioneerApp = new SpringApplication(TapasAuctionHouseApplication.class);
|
||||||
|
|
||||||
|
// We will use these bootstrap methods in Week 6:
|
||||||
|
bootstrapMarketplaceWithWebSub();
|
||||||
|
// bootstrapMarketplaceWithMqtt();
|
||||||
|
|
||||||
tapasAuctioneerApp.run(args);
|
tapasAuctioneerApp.run(args);
|
||||||
|
|
||||||
// We will use these bootstrap methods in Week 6:
|
|
||||||
|
|
||||||
// bootstrapMarketplaceWithMqtt();
|
|
||||||
bootstrapMarketplaceWithWebSub();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discovers auction houses and subscribes to WebSub notifications
|
* Discovers auction houses and subscribes to WebSub notifications
|
||||||
*/
|
*/
|
||||||
private static void bootstrapMarketplaceWithWebSub() {
|
private static void bootstrapMarketplaceWithWebSub() {
|
||||||
System.out.println("HAHA");
|
|
||||||
List<String> auctionHouseEndpoints = discoverAuctionHouseEndpoints();
|
List<String> auctionHouseEndpoints = discoverAuctionHouseEndpoints();
|
||||||
LOGGER.info("Found auction house endpoints: " + auctionHouseEndpoints);
|
|
||||||
|
|
||||||
WebSubSubscriber subscriber = new WebSubSubscriber();
|
WebSubSubscriber subscriber = new WebSubSubscriber();
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
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.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to the WebSub hubs of auction houses discovered at run time. This class is instantiated
|
* 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);
|
subscribeToWebSub(topic);
|
||||||
|
|
||||||
|
// Shoudl be done :D
|
||||||
// TODO Subscribe to the auction house endpoint via WebSub:
|
// 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.
|
// 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.
|
// The request URI should depend on the design of the Auction House HTTP API.
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
package ch.unisg.tapas.auctionhouse.adapter.in.messaging.websub;
|
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.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.json.JSONArray;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -20,16 +32,20 @@ public class AuctionStartedEventListenerWebSubAdapter {
|
||||||
/**
|
/**
|
||||||
* Controller which listens to auction-started callbacks
|
* Controller which listens to auction-started callbacks
|
||||||
* @return 200 OK
|
* @return 200 OK
|
||||||
|
* @throws URISyntaxException
|
||||||
**/
|
**/
|
||||||
@PostMapping(path = "/auction-started")
|
@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
|
for (AuctionJsonRepresentation auction : payload) {
|
||||||
JSONArray jsonArray = new JSONArray(payload);
|
auctionStartedHandler.handleAuctionStartedEvent(
|
||||||
for (Object auction : jsonArray) {
|
new AuctionStartedEvent(
|
||||||
System.out.println(auction);
|
new Auction(new AuctionId(auction.getAuctionId()),
|
||||||
// TODO logic to call handleAuctionStartedEvent()
|
new AuctionHouseUri(new URI(auction.getAuctionHouseUri())),
|
||||||
// auctionStartedHandler.handleAuctionStartedEvent(auctionStartedEvent)
|
new AuctionedTaskUri(new URI(auction.getTaskUri())),
|
||||||
|
new AuctionedTaskType(auction.getTaskType()),
|
||||||
|
new AuctionDeadline(auction.getDeadline()))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
|
|
@ -18,9 +18,6 @@ public class ValidateIntentWebSubAdapter {
|
||||||
|
|
||||||
@GetMapping(path = "/auction-started")
|
@GetMapping(path = "/auction-started")
|
||||||
public ResponseEntity<String> handleExecutorAddedEvent(@RequestParam("hub.challenge") String challenge) {
|
public ResponseEntity<String> handleExecutorAddedEvent(@RequestParam("hub.challenge") String challenge) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Different implementation depending on local development or production
|
// Different implementation depending on local development or production
|
||||||
if (environment.equalsIgnoreCase("development")) {
|
if (environment.equalsIgnoreCase("development")) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user