Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/main/java/seatsio/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,39 +370,48 @@ public ChangeObjectStatusResult changeObjectStatus(List<String> eventKeys, List<
public ChangeObjectStatusResult changeObjectStatus(List<String> eventKeys, List<?> objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
String response = unirest.stringResponse(post(baseUrl + "/events/groups/actions/change-object-status")
.queryString("expand", "objects")
.body(changeObjectStatusRequest(CHANGE_STATUS_TO, eventKeys, toObjects(objects), status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null, null).toString()));
.body(changeObjectStatusRequest(CHANGE_STATUS_TO, eventKeys, toObjects(objects), null, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null, null).toString()));
return gson().fromJson(response, ChangeObjectStatusResult.class);
}

public ChangeObjectStatusResult changeObjectStatus(List<String> eventKeys, List<?> objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
String response = unirest.stringResponse(post(baseUrl + "/events/groups/actions/change-object-status")
.queryString("expand", "objects")
.body(changeObjectStatusRequest(CHANGE_STATUS_TO, eventKeys, toObjects(objects), status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId).toString()));
.body(changeObjectStatusRequest(CHANGE_STATUS_TO, eventKeys, toObjects(objects), null, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId).toString()));
return gson().fromJson(response, ChangeObjectStatusResult.class);
}

public void overrideSeasonObjectStatus(String eventKey, List<String> objects) {
overrideSeasonObjectStatus(eventKey, objects, null);
}

public void overrideSeasonObjectStatus(String eventKey, List<String> objects, String season) {
unirest.stringResponse(post(baseUrl + "/events/{eventKey}/actions/override-season-status")
.routeParam("eventKey", eventKey)
.body(useOrOverrideSeasonObjectStatusRequest(objects).toString()));
.body(useOrOverrideSeasonObjectStatusRequest(objects, season).toString()));
}

public void useSeasonObjectStatus(String eventKey, List<String> objects) {
useSeasonObjectStatus(eventKey, objects, null);
}

public void useSeasonObjectStatus(String eventKey, List<String> objects, String season) {
unirest.stringResponse(post(baseUrl + "/events/{eventKey}/actions/use-season-status")
.routeParam("eventKey", eventKey)
.body(useOrOverrideSeasonObjectStatusRequest(objects).toString()));
.body(useOrOverrideSeasonObjectStatusRequest(objects, season).toString()));
}

private static JsonObject useOrOverrideSeasonObjectStatusRequest(List<String> objects) {
private static JsonObject useOrOverrideSeasonObjectStatusRequest(List<String> objects, String season) {
return aJsonObject()
.withPropertyIfNotNull("season", season)
.withProperty("objects", aJsonArray().withItems(objects.toArray(new String[]{})).build())
.build();
}

public List<ChangeObjectStatusResult> changeObjectStatus(List<StatusChangeRequest> statusChangeRequests) {
List<JsonElement> statusChangeRequestsAsJson = statusChangeRequests
.stream()
.map(s -> changeObjectStatusRequest(s.type(), s.eventKey(), toObjects(s.objects()), s.status(), s.holdToken(), s.orderId(), s.keepExtraData(), s.ignoreChannels(), s.channelKeys(), s.allowedPreviousStatuses(), s.rejectedPreviousStatuses(), s.resaleListingId()))
.map(s -> changeObjectStatusRequest(s.type(), s.eventKey(), toObjects(s.objects()), s.season(), s.status(), s.holdToken(), s.orderId(), s.keepExtraData(), s.ignoreChannels(), s.channelKeys(), s.allowedPreviousStatuses(), s.rejectedPreviousStatuses(), s.resaleListingId()))
.collect(toList());
JsonObject request = aJsonObject()
.withProperty("statusChanges", aJsonArray().withItems(statusChangeRequestsAsJson).build())
Expand All @@ -423,36 +432,37 @@ private List<ObjectProperties> toObjects(List<?> objects) {
.collect(toList());
}

private JsonObject changeObjectStatusRequest(StatusChangeType type, String eventKey, List<ObjectProperties> objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
private JsonObject changeObjectStatusRequest(StatusChangeType type, String eventKey, List<ObjectProperties> objects, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, season, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
request.withProperty("event", eventKey);
request.withProperty("objects", objects, object -> gson().toJsonTree(object));
return request.build();
}

private JsonObject changeObjectStatusRequest(StatusChangeType type, List<String> eventKeys, List<ObjectProperties> objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
private JsonObject changeObjectStatusRequest(StatusChangeType type, List<String> eventKeys, List<ObjectProperties> objects, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, season, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
request.withProperty("events", eventKeys);
request.withProperty("objects", objects, object -> gson().toJsonTree(object));
return request.build();
}

private JsonObject changeObjectStatusRequest(BestAvailableParams bestAvailableParams, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(CHANGE_STATUS_TO, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null, null);
JsonObjectBuilder request = changeObjectStatusRequestBuilder(CHANGE_STATUS_TO, null, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null, null);
request.withProperty("bestAvailable", gson().toJsonTree(bestAvailableParams));
return request.build();
}

private JsonObject releaseObjectsRequest(List<String> eventKeys, List<ObjectProperties> objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(RELEASE, null, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, null);
JsonObjectBuilder request = changeObjectStatusRequestBuilder(RELEASE, null, null, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, null);
request.withProperty("events", eventKeys);
request.withProperty("objects", objects, object -> gson().toJsonTree(object));
return request.build();
}

private JsonObjectBuilder changeObjectStatusRequestBuilder(StatusChangeType type, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
private JsonObjectBuilder changeObjectStatusRequestBuilder(StatusChangeType type, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses, String resaleListingId) {
return aJsonObject()
.withProperty("type", type)
.withPropertyIfNotNull("season", season)
.withPropertyIfNotNull("status", type == RELEASE ? null : status)
.withPropertyIfNotNull("holdToken", holdToken)
.withPropertyIfNotNull("orderId", orderId)
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seatsio/events/StatusChangeRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import static seatsio.events.StatusChangeType.CHANGE_STATUS_TO;

public record StatusChangeRequest(StatusChangeType type, String eventKey, List<?> objects, String status,
public record StatusChangeRequest(StatusChangeType type, String eventKey, List<?> objects, String season, String status,
String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels,
Set<String> channelKeys, Set<String> allowedPreviousStatuses,
Set<String> rejectedPreviousStatuses, String resaleListingId) {
Comment thread
mroloux marked this conversation as resolved.
Expand All @@ -14,6 +14,7 @@ public static class Builder {
private StatusChangeType type = CHANGE_STATUS_TO;
private String eventKey;
private List<?> objects;
private String season;
private String status;
private String holdToken;
private String orderId;
Expand All @@ -39,6 +40,11 @@ public Builder withObjects(List<?> objects) {
return this;
}

public Builder withSeason(String season) {
this.season = season;
return this;
}

public Builder withStatus(String status) {
this.status = status;
return this;
Expand Down Expand Up @@ -85,7 +91,7 @@ public Builder withResaleListingId(String resaleListingId) {
}

public StatusChangeRequest build() {
return new StatusChangeRequest(type, eventKey, objects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
return new StatusChangeRequest(type, eventKey, objects, season, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId);
}
}
}
56 changes: 56 additions & 0 deletions src/test/java/seatsio/events/ChangeObjectStatusInBatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seatsio.events.EventObjectInfo.*;
import static seatsio.events.StatusChangeType.*;

Expand Down Expand Up @@ -122,6 +123,32 @@ public void overrideSeasonStatus() {
assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(FREE);
}

@Test
public void overrideSeasonStatus_partialSeason() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));

List<ChangeObjectStatusResult> result = client.events.changeObjectStatus(List.of(
new StatusChangeRequest.Builder().withType(OVERRIDE_SEASON_STATUS).withEventKey("event1").withSeason("aPartialSeason").withObjects(List.of("A-1")).build()
));

assertThat(result.get(0).objects().get("A-1").status()).isEqualTo(FREE);
assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(FREE);
}

@Test
public void overrideSeasonStatus_partialSeason_invalid() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of());

assertThrows(SeatsioException.class, () -> client.events.changeObjectStatus(List.of(
new StatusChangeRequest.Builder().withType(OVERRIDE_SEASON_STATUS).withEventKey("event1").withSeason("aPartialSeason").withObjects(List.of("A-1")).build()
)));
}

@Test
public void useSeasonStatus() {
String chartKey = createTestChart();
Expand All @@ -137,6 +164,35 @@ public void useSeasonStatus() {
assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(BOOKED);
}

@Test
public void useSeasonStatus_partialSeason() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));
client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

List<ChangeObjectStatusResult> result = client.events.changeObjectStatus(List.of(
new StatusChangeRequest.Builder().withType(USE_SEASON_STATUS).withEventKey("event1").withSeason("aPartialSeason").withObjects(List.of("A-1")).build()
));

assertThat(result.get(0).objects().get("A-1").status()).isEqualTo(BOOKED);
assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(BOOKED);
}

@Test
public void useSeasonStatus_partialSeason_invalid() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1", "event2")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));
client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

assertThrows(SeatsioException.class, () -> client.events.changeObjectStatus(List.of(
new StatusChangeRequest.Builder().withType(USE_SEASON_STATUS).withEventKey("event2").withSeason("aPartialSeason").withObjects(List.of("A-1")).build()
)));
}

@Test
public void resaleListingId() {
String chartKey1 = createTestChart();
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/seatsio/events/OverrideSeasonObjectStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.junit.jupiter.api.Test;
import seatsio.SeatsioClientTest;
import seatsio.SeatsioException;
import seatsio.seasons.CreateSeasonParams;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seatsio.events.EventObjectInfo.FREE;

public class OverrideSeasonObjectStatusTest extends SeatsioClientTest {
Expand All @@ -21,4 +23,26 @@ public void test() {

assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(FREE);
}

@Test
public void test_partialSeason() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));

client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(FREE);
}

@Test
public void test_partialSeason_invalid() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of());
client.events.book("aPartialSeason", List.of("A-1"));

assertThrows(SeatsioException.class, () -> client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason"));
}
}
26 changes: 26 additions & 0 deletions src/test/java/seatsio/events/UseSeasonObjectStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.junit.jupiter.api.Test;
import seatsio.SeatsioClientTest;
import seatsio.SeatsioException;
import seatsio.seasons.CreateSeasonParams;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seatsio.events.EventObjectInfo.BOOKED;

public class UseSeasonObjectStatusTest extends SeatsioClientTest {
Expand All @@ -22,4 +24,28 @@ public void test() {

assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(BOOKED);
}

@Test
public void test_partialSeason() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));
client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

client.events.useSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

assertThat(client.events.retrieveObjectInfo("event1", "A-1").status()).isEqualTo(BOOKED);
}

@Test
public void test_partialSeason_invalid() {
String chartKey = createTestChart();
client.seasons.create(chartKey, new CreateSeasonParams().key("aSeason").eventKeys(List.of("event1", "event2")));
client.seasons.createPartialSeason("aSeason", "aPartialSeason", null, List.of("event1"));
client.events.book("aPartialSeason", List.of("A-1"));
client.events.overrideSeasonObjectStatus("event1", List.of("A-1"), "aPartialSeason");

assertThrows(SeatsioException.class, () -> client.events.useSeasonObjectStatus("event2", List.of("A-1"), "aPartialSeason"));
}
}
Loading