diff --git a/src/main/java/seatsio/events/Events.java b/src/main/java/seatsio/events/Events.java index 27fe90a..2ae0afe 100644 --- a/src/main/java/seatsio/events/Events.java +++ b/src/main/java/seatsio/events/Events.java @@ -370,31 +370,40 @@ public ChangeObjectStatusResult changeObjectStatus(List eventKeys, List< public ChangeObjectStatusResult changeObjectStatus(List eventKeys, List objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set 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 eventKeys, List objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set 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 objects) { + overrideSeasonObjectStatus(eventKey, objects, null); + } + + public void overrideSeasonObjectStatus(String eventKey, List 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 objects) { + useSeasonObjectStatus(eventKey, objects, null); + } + + public void useSeasonObjectStatus(String eventKey, List 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 objects) { + private static JsonObject useOrOverrideSeasonObjectStatusRequest(List objects, String season) { return aJsonObject() + .withPropertyIfNotNull("season", season) .withProperty("objects", aJsonArray().withItems(objects.toArray(new String[]{})).build()) .build(); } @@ -402,7 +411,7 @@ private static JsonObject useOrOverrideSeasonObjectStatusRequest(List ob public List changeObjectStatus(List statusChangeRequests) { List 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()) @@ -423,36 +432,37 @@ private List toObjects(List objects) { .collect(toList()); } - private JsonObject changeObjectStatusRequest(StatusChangeType type, String eventKey, List objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set rejectedPreviousStatuses, String resaleListingId) { - JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId); + private JsonObject changeObjectStatusRequest(StatusChangeType type, String eventKey, List objects, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set 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 eventKeys, List objects, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set rejectedPreviousStatuses, String resaleListingId) { - JsonObjectBuilder request = changeObjectStatusRequestBuilder(type, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses, resaleListingId); + private JsonObject changeObjectStatusRequest(StatusChangeType type, List eventKeys, List objects, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set 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 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 eventKeys, List objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set 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 channelKeys, Set allowedPreviousStatuses, Set rejectedPreviousStatuses, String resaleListingId) { + private JsonObjectBuilder changeObjectStatusRequestBuilder(StatusChangeType type, String season, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set channelKeys, Set allowedPreviousStatuses, Set rejectedPreviousStatuses, String resaleListingId) { return aJsonObject() .withProperty("type", type) + .withPropertyIfNotNull("season", season) .withPropertyIfNotNull("status", type == RELEASE ? null : status) .withPropertyIfNotNull("holdToken", holdToken) .withPropertyIfNotNull("orderId", orderId) diff --git a/src/main/java/seatsio/events/StatusChangeRequest.java b/src/main/java/seatsio/events/StatusChangeRequest.java index 956b929..75e0454 100644 --- a/src/main/java/seatsio/events/StatusChangeRequest.java +++ b/src/main/java/seatsio/events/StatusChangeRequest.java @@ -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 channelKeys, Set allowedPreviousStatuses, Set rejectedPreviousStatuses, String resaleListingId) { @@ -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; @@ -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; @@ -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); } } } diff --git a/src/test/java/seatsio/events/ChangeObjectStatusInBatchTest.java b/src/test/java/seatsio/events/ChangeObjectStatusInBatchTest.java index dfb10ca..e2dba1c 100644 --- a/src/test/java/seatsio/events/ChangeObjectStatusInBatchTest.java +++ b/src/test/java/seatsio/events/ChangeObjectStatusInBatchTest.java @@ -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.*; @@ -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 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(); @@ -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 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(); diff --git a/src/test/java/seatsio/events/OverrideSeasonObjectStatusTest.java b/src/test/java/seatsio/events/OverrideSeasonObjectStatusTest.java index 0c8d8a2..ccc19bc 100644 --- a/src/test/java/seatsio/events/OverrideSeasonObjectStatusTest.java +++ b/src/test/java/seatsio/events/OverrideSeasonObjectStatusTest.java @@ -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 { @@ -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")); + } } diff --git a/src/test/java/seatsio/events/UseSeasonObjectStatusTest.java b/src/test/java/seatsio/events/UseSeasonObjectStatusTest.java index 17f0bef..a66eef7 100644 --- a/src/test/java/seatsio/events/UseSeasonObjectStatusTest.java +++ b/src/test/java/seatsio/events/UseSeasonObjectStatusTest.java @@ -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 { @@ -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")); + } }