Merging dev to main #107

Merged
Maece97 merged 52 commits from dev into main 2021-12-23 16:12:19 +00:00
5 changed files with 211 additions and 0 deletions
Showing only changes of commit 0b89e88905 - Show all commits

View File

@ -0,0 +1,45 @@
package ch.unisg.tapas.auctionhouse.adapter.common.formats;
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
public class AuctionHouseDiscoveryJsonRepresentation {
public static final String MEDIA_TYPE = "application/auctionhousediscovery + json";
@Getter @Setter
private String auctionHouseUri;
@Getter @Setter
private String webSubUri;
@Getter @Setter
private String taskTypes;
@Getter @Setter
private String timeStamp;
@Getter @Setter
private String groupName;
public AuctionHouseDiscoveryJsonRepresentation() {}
public AuctionHouseDiscoveryJsonRepresentation(AuctionHouseDiscoveryInformation auctionHouseDiscoveryInformation){
this.auctionHouseUri = auctionHouseDiscoveryInformation.getAuctionHouseUri().getValue();
this.webSubUri = auctionHouseDiscoveryInformation.getWebSubUri().getValue();
this.taskTypes = auctionHouseDiscoveryInformation.getTaskTypes().toString();
this.timeStamp = auctionHouseDiscoveryInformation.getTimeStamp().getValue();
this.groupName = auctionHouseDiscoveryInformation.getGroupName().getValue();
}
public static String serialize(AuctionHouseDiscoveryInformation auctionHouseDiscoveryInformation) throws JsonProcessingException {
AuctionHouseDiscoveryJsonRepresentation representation = new AuctionHouseDiscoveryJsonRepresentation(auctionHouseDiscoveryInformation);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper.writeValueAsString(representation);
}
}

View File

@ -0,0 +1,56 @@
package ch.unisg.tapas.auctionhouse.adapter.in.web;
import ch.unisg.tapas.auctionhouse.adapter.common.formats.AuctionHouseDiscoveryJsonRepresentation;
import ch.unisg.tapas.auctionhouse.application.port.in.AuctionHouseDiscoveryUseCase;
import ch.unisg.tapas.auctionhouse.application.port.in.AuctionHouseDiscoveryCommand;
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
/**
* Controller that handles HTTP requests for the auction house discovery. This controller implements
* the {@link AuctionHouseDiscoveryUseCase} use case using the {@link AuctionHouseDiscoveryCommand} command.
*/
@RestController
public class AuctionHouseDiscoveryWebController {
private final AuctionHouseDiscoveryUseCase auctionHouseDiscoveryUseCase;
public AuctionHouseDiscoveryWebController(AuctionHouseDiscoveryUseCase auctionHouseDiscoveryUseCase) {
this.auctionHouseDiscoveryUseCase = auctionHouseDiscoveryUseCase;
}
@GetMapping(path="/discovery/", consumes = AuctionHouseDiscoveryJsonRepresentation.MEDIA_TYPE)
public ResponseEntity<String> auctionHouseDiscovery(@RequestBody AuctionHouseDiscoveryJsonRepresentation payload) {
AuctionHouseDiscoveryInformation.GroupName groupName = (payload.getGroupName() == null) ?
null : new AuctionHouseDiscoveryInformation.GroupName(payload.getGroupName());
AuctionHouseDiscoveryCommand command = new AuctionHouseDiscoveryCommand(
new AuctionHouseDiscoveryInformation.AuctionHouseUri(payload.getAuctionHouseUri()),
new AuctionHouseDiscoveryInformation.WebSubUri(payload.getAuctionHouseUri()),
new AuctionHouseDiscoveryInformation.TaskTypes(payload.getTaskTypes()),
new AuctionHouseDiscoveryInformation.TimeStamp(payload.getTimeStamp()),
groupName
);
AuctionHouseDiscoveryInformation auctionHouseDiscoveryInformation = auctionHouseDiscoveryUseCase.auctionHouseDiscovery(command);
try {
AuctionHouseDiscoveryJsonRepresentation representation = new AuctionHouseDiscoveryJsonRepresentation(auctionHouseDiscoveryInformation);
String auctionHouseDiscoveryJson = AuctionHouseDiscoveryJsonRepresentation.serialize(auctionHouseDiscoveryInformation);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, AuctionHouseDiscoveryJsonRepresentation.MEDIA_TYPE);
return new ResponseEntity<>(auctionHouseDiscoveryJson, responseHeaders, HttpStatus.OK);
} catch (JsonProcessingException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1,40 @@
package ch.unisg.tapas.auctionhouse.application.port.in;
import ch.unisg.tapas.auctionhouse.domain.Auction;
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;
import ch.unisg.tapas.common.SelfValidating;
import lombok.Value;
import javax.validation.constraints.NotNull;
@Value
public class AuctionHouseDiscoveryCommand extends SelfValidating<AuctionHouseDiscoveryCommand> {
@NotNull
private final AuctionHouseDiscoveryInformation.AuctionHouseUri auctionHouseUri;
@NotNull
private final AuctionHouseDiscoveryInformation.WebSubUri webSubUri;
@NotNull
private final AuctionHouseDiscoveryInformation.TaskTypes taskTypes;
@NotNull
private final AuctionHouseDiscoveryInformation.TimeStamp timeStamp;
//Didn't put @NotNull here since the GroupName is not required
private final AuctionHouseDiscoveryInformation.GroupName groupName;
public AuctionHouseDiscoveryCommand(AuctionHouseDiscoveryInformation.AuctionHouseUri auctionHouseUri,
AuctionHouseDiscoveryInformation.WebSubUri webSubUri,
AuctionHouseDiscoveryInformation.TaskTypes taskTypes,
AuctionHouseDiscoveryInformation.TimeStamp timeStamp,
AuctionHouseDiscoveryInformation.GroupName groupName) {
this.auctionHouseUri = auctionHouseUri;
this.webSubUri = webSubUri;
this.taskTypes = taskTypes;
this.timeStamp = timeStamp;
this.groupName = groupName;
this.validateSelf();
}
}

View File

@ -0,0 +1,8 @@
package ch.unisg.tapas.auctionhouse.application.port.in;
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;
public interface AuctionHouseDiscoveryUseCase {
AuctionHouseDiscoveryInformation auctionHouseDiscovery(AuctionHouseDiscoveryCommand command);
}

View File

@ -0,0 +1,62 @@
package ch.unisg.tapas.auctionhouse.domain;
import lombok.Getter;
import lombok.Value;
import java.util.ArrayList;
//TODO: change to array type
public class AuctionHouseDiscoveryInformation {
@Getter
private final AuctionHouseUri auctionHouseUri;
@Getter
private final WebSubUri webSubUri;
@Getter
private final TaskTypes taskTypes;
@Getter
private final TimeStamp timeStamp;
//Had to initialize this in the constructor, but it's not required, so I'm not sure
//if this is correct
@Getter
private final GroupName groupName;
public AuctionHouseDiscoveryInformation(AuctionHouseUri auctionHouseUri, WebSubUri webSubUri,
TaskTypes taskTypes, TimeStamp timeStamp, GroupName groupName){
this.auctionHouseUri = auctionHouseUri;
this.webSubUri = webSubUri;
this.taskTypes = taskTypes;
this.timeStamp = timeStamp;
this.groupName = groupName; //see above
}
@Value
public static class AuctionHouseUri {
private String value;
}
@Value
public static class WebSubUri {
private String value;
}
@Value
public static class TaskTypes {
private String value;
}
@Value
public static class TimeStamp {
private String value;
}
@Value
public static class GroupName {
private String value;
}
}