Skip to content

Commit

Permalink
Merge pull request #75 from gappc/implement-support-for-2022-10
Browse files Browse the repository at this point in the history
Add support for AlpineBits HotelData 2022-10
  • Loading branch information
RudiThoeni authored Jun 10, 2024
2 parents c18e552 + 9762bf0 commit 5040906
Show file tree
Hide file tree
Showing 26 changed files with 4,490 additions and 56 deletions.
4 changes: 2 additions & 2 deletions application-common/environment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>application-common</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>application-common-environment</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>AlpineBits Server common environment</name>

Expand Down
4 changes: 2 additions & 2 deletions application-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>alpinebitsserver-odh-root</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>application-common</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<packaging>pom</packaging>
<name>AlpineBits Server common</name>
Expand Down
4 changes: 2 additions & 2 deletions application-common/routing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>application-common</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>application-common-routing</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>AlpineBits Server common routing</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package it.bz.opendatahub.alpinebitsserver.application.common.routing;

import it.bz.opendatahub.alpinebits.common.constants.AlpineBitsCapability;
import it.bz.opendatahub.alpinebits.common.constants.AlpineBitsVersion;
import it.bz.opendatahub.alpinebits.handshaking.DefaultContextSerializer;
import it.bz.opendatahub.alpinebits.handshaking.middleware.HandshakingMiddleware;
import it.bz.opendatahub.alpinebits.routing.DefaultRouter;
import it.bz.opendatahub.alpinebits.routing.RoutingBuilder;
import it.bz.opendatahub.alpinebits.routing.constants.Action;
import it.bz.opendatahub.alpinebitsserver.odh.freerooms.HotelInvCountNotifPushMiddlewareBuilder;
import it.bz.opendatahub.alpinebitsserver.odh.inventory.v_2022_10.InventoryPullMiddlewareBuilder;
import it.bz.opendatahub.alpinebitsserver.odh.inventory.v_2022_10.InventoryPushMiddlewareBuilder;

/**
* Route definitions for AlpineBits 2022-10.
*/
public final class RoutesFor202210 {

private RoutesFor202210() {
// Empty
}

/**
* Add 2022-10 routes to the given builder.
*
* @param builder The routes will be added to this builder.
* @return A {@link RoutingBuilder.FinalBuilder} that can be used for further route building.
*/
public static RoutingBuilder.FinalBuilder routes(DefaultRouter.Builder builder) {
if (builder == null) {
throw new IllegalArgumentException("The builder must not be null");
}
return builder.version(AlpineBitsVersion.V_2022_10)
.supportsAction(Action.HANDSHAKING)
.withCapabilities(AlpineBitsCapability.HANDSHAKING)
.using(new HandshakingMiddleware(new DefaultContextSerializer(AlpineBitsVersion.V_2022_10)))
.and()
.supportsAction(Action.INVENTORY_BASIC_PULL)
.withCapabilities(AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_INFO_INVENTORY)
.using(InventoryPullMiddlewareBuilder.buildInventoryPullMiddleware())
.and()
.supportsAction(Action.INVENTORY_HOTEL_INFO_PULL)
.withCapabilities(AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_INFO_INFO)
.using(InventoryPullMiddlewareBuilder.buildInventoryPullMiddleware())
.and()
.supportsAction(Action.INVENTORY_BASIC_PUSH)
.withCapabilities(
AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_CONTENT_NOTIF_INVENTORY,
AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_CONTENT_NOTIF_INVENTORY_USE_ROOMS,
AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_CONTENT_NOTIF_OCCUPANCY_CHILDREN
)
.using(InventoryPushMiddlewareBuilder.buildInventoryPushMiddleware())
.and()
.supportsAction(Action.INVENTORY_HOTEL_INFO_PUSH)
.withCapabilities(AlpineBitsCapability.INVENTORY_HOTEL_DESCRIPTIVE_CONTENT_NOTIF_INFO)
.using(InventoryPushMiddlewareBuilder.buildInventoryPushMiddleware())
.and()
.supportsAction(Action.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_FREE_ROOMS)
.withCapabilities(
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_ROOMS,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_CATEGORIES,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_OUT_OF_ORDER,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_OUT_OF_MARKET,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_CLOSING_SEASONS,
AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_COMPLETE_SET
)
.using(HotelInvCountNotifPushMiddlewareBuilder.buildFreeRoomsPushMiddleware(AlpineBitsVersion.V_2022_10))
.versionComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ private RoutingMiddlewareProvider() {
*/
public static Middleware buildRoutingMiddleware() {
DefaultRouter.Builder builder = new DefaultRouter.Builder();
RoutingBuilder.FinalBuilder fb = RoutesFor202010.routes(builder);
RoutingBuilder.FinalBuilder fb = RoutesFor202210.routes(builder);
fb = RoutesFor202010.routes(fb.and());
fb = RoutesFor201810.routes(fb.and());
fb = RoutesFor201710.routes(fb.and());
return new RoutingMiddleware(fb.buildRouter());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package it.bz.opendatahub.alpinebitsserver.application.common.routing;

import it.bz.opendatahub.alpinebits.common.constants.AlpineBitsCapability;
import it.bz.opendatahub.alpinebits.common.constants.AlpineBitsVersion;
import it.bz.opendatahub.alpinebits.routing.DefaultRouter;
import it.bz.opendatahub.alpinebits.routing.Router;
import it.bz.opendatahub.alpinebits.routing.RoutingBuilder;
import it.bz.opendatahub.alpinebits.routing.constants.Action;
import org.testng.annotations.Test;

import java.util.Set;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* Tests for {@link RoutesFor202210}.
*/
public class RoutesFor202210Test {

private static final String ALPINEBITS_VERSION = AlpineBitsVersion.V_2022_10;

@Test(expectedExceptions = IllegalArgumentException.class)
public void testRoutes_ShouldThrow_WhenBuilderIsNull() {
RoutesFor202210.routes(null);
}

@Test
public void testRoutes_ShouldReturnFinalBuild_OnSuccess() {
RoutingBuilder.FinalBuilder builder = RoutesFor202210.routes(new DefaultRouter.Builder());
Router router = builder.buildRouter();

assertEquals(router.getVersions().size(), 1);
assertTrue(router.getVersions().contains(ALPINEBITS_VERSION));

assertTrue(router.getActionsForVersion(ALPINEBITS_VERSION).isPresent());
Set<Action> actions = router.getActionsForVersion(ALPINEBITS_VERSION).get();

assertEquals(actions.size(), 6);
assertTrue(actions.contains(Action.HANDSHAKING));
assertTrue(actions.contains(Action.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_FREE_ROOMS));

assertTrue(router.getCapabilitiesForVersion(ALPINEBITS_VERSION).isPresent());
Set<String> capabilities = router.getCapabilitiesForVersion(ALPINEBITS_VERSION).get();

assertEquals(capabilities.size(), 14);
assertTrue(capabilities.contains(AlpineBitsCapability.HANDSHAKING));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_CATEGORIES));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_ROOMS));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_OUT_OF_ORDER));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_OUT_OF_MARKET));
assertTrue(capabilities.contains(AlpineBitsCapability.FREE_ROOMS_HOTEL_INV_COUNT_NOTIF_ACCEPT_CLOSING_SEASONS));
}


}
4 changes: 2 additions & 2 deletions application-common/utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>application-common</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>application-common-middleware-config</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>AlpineBits Server common middleware config</name>

Expand Down
8 changes: 2 additions & 6 deletions application-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>alpinebitsserver-odh-root</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>application-spring</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<packaging>jar</packaging>
<name>Standalone Spring application, providing an AlpineBits Server with Open Data Hub (ODH) backend</name>
Expand All @@ -37,10 +37,6 @@ SPDX-License-Identifier: CC0-1.0
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion build-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>alpinebitsserver-odh-root</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions odh-backend/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>odh-backend</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>odh-backend-api</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>ODH backend API</name>

Expand Down
4 changes: 2 additions & 2 deletions odh-backend/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>odh-backend</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>odh-backend-impl</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>ODH backend impl</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/**
* Custom Jackson serializer / deserializer module for ODH support.
*/
// TODO: rename package?
public class OtaModule202010 extends SimpleModule {

private static final long serialVersionUID = 1L;
Expand Down
4 changes: 2 additions & 2 deletions odh-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>alpinebitsserver-odh-root</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>odh-backend</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<packaging>pom</packaging>
<name>ODH backend</name>
Expand Down
4 changes: 2 additions & 2 deletions odh-freerooms/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>odh-freerooms</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>odh-freerooms-api</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>AlpineBits FreeRooms action with ODH backend API</name>

Expand Down
4 changes: 2 additions & 2 deletions odh-freerooms/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ SPDX-License-Identifier: CC0-1.0
<parent>
<groupId>it.bz.opendatahub.alpinebitsserver.odh</groupId>
<artifactId>odh-freerooms</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>odh-freerooms-impl</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>

<name>AlpineBits FreeRooms action with ODH backend impl</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package it.bz.opendatahub.alpinebitsserver.odh.freerooms;

import it.bz.opendatahub.alpinebits.common.constants.AlpineBitsVersion;
import it.bz.opendatahub.alpinebits.common.utils.middleware.ComposingMiddlewareBuilder;
import it.bz.opendatahub.alpinebits.common.utils.response.ResponseOutcomeBuilder;
import it.bz.opendatahub.alpinebits.middleware.Key;
Expand All @@ -19,7 +20,6 @@
import it.bz.opendatahub.alpinebits.validation.context.freerooms.HotelInvCountNotifContext;
import it.bz.opendatahub.alpinebits.validation.context.freerooms.HotelInvCountNotifContextProvider;
import it.bz.opendatahub.alpinebits.validation.middleware.ValidationMiddleware;
import it.bz.opendatahub.alpinebits.validation.schema.v_2020_10.freerooms.OTAHotelInvCountNotifRQValidator;
import it.bz.opendatahub.alpinebits.xml.schema.ota.OTAHotelInvCountNotifRQ;
import it.bz.opendatahub.alpinebits.xml.schema.ota.OTAHotelInvCountNotifRS;
import it.bz.opendatahub.alpinebitsserver.application.common.utils.ActionExceptionHandler;
Expand All @@ -44,6 +44,9 @@ private HotelInvCountNotifPushMiddlewareBuilder() {
}

public static Middleware buildFreeRoomsPushMiddleware(String alpineBitsVersion) {
if (alpineBitsVersion == null) {
throw new IllegalArgumentException("The AlpineBits version must not be null");
}
return ComposingMiddlewareBuilder.compose(Arrays.asList(
new ActionExceptionHandler<>(alpineBitsVersion, OTA_FREE_ROOMS_PUSH_RESPONSE, ResponseOutcomeBuilder::forOTAHotelInvCountNotifRS),
XmlMiddlewareBuilder.buildXmlToObjectConvertingMiddleware(OTA_FREE_ROOMS_PUSH_REQUEST, alpineBitsVersion),
Expand All @@ -54,18 +57,28 @@ public static Middleware buildFreeRoomsPushMiddleware(String alpineBitsVersion)
HotelCodeExtractor::hasHotelCode,
ResponseOutcomeBuilder::forOTAHotelInvCountNotifRS
),
buildValidationMiddleware(),
buildValidationMiddleware(alpineBitsVersion),
new HotelInvCountNotifPushMiddleware(
OTA_FREE_ROOMS_PUSH_REQUEST,
OTA_FREE_ROOMS_PUSH_RESPONSE
)
));
}

private static Middleware buildValidationMiddleware() {
Validator<OTAHotelInvCountNotifRQ, HotelInvCountNotifContext> validator = new OTAHotelInvCountNotifRQValidator();
private static Middleware buildValidationMiddleware(String alpineBitsVersion) {
Validator<OTAHotelInvCountNotifRQ, HotelInvCountNotifContext> validator = getValidator(alpineBitsVersion);
ValidationContextProvider<HotelInvCountNotifContext> validationContextProvider = new HotelInvCountNotifContextProvider();
return new ValidationMiddleware<>(OTA_FREE_ROOMS_PUSH_REQUEST, validator, validationContextProvider);
}

private static Validator<OTAHotelInvCountNotifRQ, HotelInvCountNotifContext> getValidator(String alpineBitsVersion) {
if (AlpineBitsVersion.V_2020_10.equals(alpineBitsVersion)) {
return new it.bz.opendatahub.alpinebits.validation.schema.v_2020_10.freerooms.OTAHotelInvCountNotifRQValidator();
}
if (AlpineBitsVersion.V_2022_10.equals(alpineBitsVersion)) {
return new it.bz.opendatahub.alpinebits.validation.schema.v_2022_10.freerooms.OTAHotelInvCountNotifRQValidator();
}
throw new IllegalArgumentException("The AlpineBits version " + alpineBitsVersion + " is not supported for OTAHotelInvCountNotifRQ");
}

}
Loading

0 comments on commit 5040906

Please sign in to comment.