Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
3a07bb6
JBTM-1488 LRA Implementation
mmusgrov Aug 18, 2017
7c10d25
Updated to 5.7.0.Final
tomjenkinson Sep 26, 2017
08f6988
Updated to 5.7.1.Final-SNAPSHOT
tomjenkinson Sep 26, 2017
255ee92
JBTM-2940 Spec compliance
mmusgrov Oct 6, 2017
ef64346
Updated to 5.7.1.Final
tomjenkinson Oct 19, 2017
4d3ed91
Updated to 5.7.2.Final-SNAPSHOT
tomjenkinson Oct 19, 2017
7643982
Merge branch 'master' of https://github.com/jbosstm/narayana
nmcl Aug 10, 2018
8bbce0f
Updated to 5.9.1.Final
tomjenkinson Dec 4, 2018
8574580
Updated to 5.9.2.Final-SNAPSHOT
tomjenkinson Dec 4, 2018
d27ed3d
Updated to 5.9.2.Final
ochaloup Dec 14, 2018
c97422c
Updated to 5.9.3.Final-SNAPSHOT
ochaloup Dec 14, 2018
98e709e
Updated to 5.9.3.Final
tomjenkinson Feb 21, 2019
3ef09f0
Updated to 5.9.4.Final-SNAPSHOT
tomjenkinson Feb 21, 2019
5cff5ad
test formatting fixes for lra&rts&jts
ochaloup Mar 19, 2019
63030b0
Updated to 5.9.4.Final
ochaloup Mar 27, 2019
b186fd6
Updated to 5.9.5.Final-SNAPSHOT
ochaloup Mar 27, 2019
4eec9b3
Updated to 5.9.5.Final
tomjenkinson Mar 28, 2019
8260847
Updated to 5.9.6.Final-SNAPSHOT
tomjenkinson Mar 28, 2019
10d2525
JBTM-3150 Migrate from swarm to thorntail
mmusgrov Jun 4, 2019
ba08832
JBTM-3145 do not use scope test for resteasy dependency (and upgrade …
mmusgrov Jun 7, 2019
c42e441
RTS SRA not needed all microprofile fractions as dependencies
ochaloup Jul 30, 2019
308c20e
Updated to 5.9.6.Final
ochaloup Aug 7, 2019
e679577
Updated to 5.9.7.Final-SNAPSHOT
ochaloup Aug 7, 2019
784e67a
Updated to 5.9.7.Final
tomjenkinson Aug 23, 2019
398b85e
Updated to 5.9.8.Final-SNAPSHOT
tomjenkinson Aug 23, 2019
c745343
Updated to 5.9.8.Final
tomjenkinson Sep 2, 2019
c7940be
Updated to 5.9.9.Final-SNAPSHOT
tomjenkinson Sep 2, 2019
1a151a4
Updated to 5.10.0.Final-SNAPSHOT
tomjenkinson Oct 7, 2019
948e2c3
Updated to 5.10.0.Final
mmusgrov Oct 28, 2019
c777946
Updated to 5.10.1.Final-SNAPSHOT
mmusgrov Oct 28, 2019
6a7ce16
Updated to 5.10.1.Final
tomjenkinson Dec 4, 2019
51dc28b
Updated to 5.10.2.Final-SNAPSHOT
tomjenkinson Dec 4, 2019
b4d4996
Updated to 5.10.3.Final
tomjenkinson Jan 23, 2020
1a49ce7
Updated to 5.10.4.Final-SNAPSHOT
tomjenkinson Jan 23, 2020
6443f2c
Updated to 5.10.4.Final
tomjenkinson Jan 30, 2020
b9a8f30
Updated to 5.10.5.Final-SNAPSHOT
tomjenkinson Jan 30, 2020
6980a13
Updated to 5.10.5.Final
ochaloup May 20, 2020
96165b6
Updated to 5.10.6.Final-SNAPSHOT
ochaloup May 20, 2020
eaf41cf
Updated to 5.10.6.Final
ochaloup Sep 3, 2020
a65a46c
Updated to 5.10.7.Final-SNAPSHOT
ochaloup Sep 3, 2020
a01f215
Updated to 5.11.0.Final
ochaloup Mar 19, 2021
1f7363a
Updated to 5.11.1.Final-SNAPSHOT
ochaloup Mar 19, 2021
b160cd6
Updated to 5.11.1.Final
ochaloup Apr 13, 2021
9006d9c
Updated to 5.11.2.Final-SNAPSHOT
ochaloup Apr 13, 2021
430dfb6
Changes for JBTM-3461 using quarkus instead of thorntail
swetapatra Apr 16, 2021
e914c51
Additional changes for JBTM-3461 SRA Demo
swetapatra Apr 20, 2021
dbe6978
Updated to 5.11.2.Final
ochaloup May 5, 2021
a759337
Updated to 5.11.3.Final-SNAPSHOT
ochaloup May 5, 2021
7eb476b
JBTM-3464 and JBTM-3460 move annotation code,add unit test and get th…
mmusgrov May 17, 2021
80c0e24
Updated to 5.12.0.Final
ochaloup Jun 9, 2021
94072db
Updated to 5.12.1.Final-SNAPSHOT
ochaloup Jun 9, 2021
20e9c6d
Updated to 5.12.1.Final
ochaloup Sep 14, 2021
6dc28b6
Updated to 5.12.2.Final-SNAPSHOT
ochaloup Sep 14, 2021
8dbdcd3
Updated to 5.12.2.Final
mmusgrov Nov 26, 2021
4274413
Updated to 5.12.3.Final-SNAPSHOT
mmusgrov Nov 26, 2021
a4055b7
Updated to 5.12.3.Final
mmusgrov Nov 27, 2021
25f5aa2
Updated to 5.12.4.Final-SNAPSHOT
mmusgrov Nov 27, 2021
a7c29c5
Updated to 5.12.4.Final
mmusgrov Nov 28, 2021
2a34c98
Updated to 5.12.5.Final-SNAPSHOT
mmusgrov Nov 28, 2021
733949c
Updated to 5.12.5.Final
mmusgrov Jan 19, 2022
019765b
Updated to 5.12.6.Final-SNAPSHOT
mmusgrov Jan 19, 2022
713ae1d
Updated to 5.12.6.Final
mmusgrov Apr 4, 2022
2311003
Updated to 5.12.7.Final-SNAPSHOT
mmusgrov Apr 4, 2022
63ff941
Change the semantics of the annotation attribute SRA#delayCommit
marcosgopen May 13, 2022
7b5de14
Updated to 5.12.7.Final
mmusgrov Jun 22, 2022
86d1ba7
Updated to 5.12.8.Final-SNAPSHOT
mmusgrov Jun 22, 2022
d44e012
Updated to 5.13.0.Final
mmusgrov Jul 23, 2022
706ef3c
Updated to 5.13.1.Final-SNAPSHOT
mmusgrov Jul 23, 2022
801a8f5
Updated to 5.13.1.Alpha1
mmusgrov Aug 3, 2022
ac97bbc
Updated to 5.13.1.Final-SNAPSHOT
mmusgrov Aug 3, 2022
6e01f9d
Updated to 5.13.1.Final
mmusgrov Nov 14, 2022
a121f6f
Updated to 6.0.0.Final-SNAPSHOT
mmusgrov Nov 14, 2022
cdae623
JBTM-3658 Fix the trace logging test properties for WFLY coordinator
xstefank Nov 21, 2022
7f90d3f
JBTM-3588 initial conversion using org.eclipse.transformer.cli-0.6.0-…
mmusgrov Sep 3, 2022
f263242
JBTM-3588 wip getting most of the tests working
mmusgrov Sep 6, 2022
2e1d18d
Ensure that the rest-at and sra tests work with jakarta
marcosgopen Sep 7, 2022
a48f302
restore services deleted by jakarta transformation
marcosgopen Oct 12, 2022
a7caa63
Removed unused/javax dependencies from RTS
jmfinelli Oct 27, 2022
7add187
Updated to 6.0.0.CR1
mmusgrov Jan 17, 2023
7599282
Updated to 6.0.0.Final-SNAPSHOT
mmusgrov Jan 17, 2023
7e28e65
Updated to 6.0.0.Final
mmusgrov Feb 16, 2023
bff2c56
Updated to 6.0.1.Final-SNAPSHOT
mmusgrov Feb 16, 2023
1768f23
JBTM-3756 update schema version all beans.xml files (and bean discove…
mmusgrov Mar 1, 2023
b18d70d
Implement BOM in all the Narayana Module
moulalis Mar 9, 2023
12d12b1
Updated to 6.0.1.Final
mmusgrov Apr 21, 2023
5d57fde
Updated to 6.0.2.Final-SNAPSHOT
mmusgrov Apr 21, 2023
1f3caa6
[JBTM:3462] Migrate the SRA demo package (io.narayana.sra.demo) over …
moulalis Apr 11, 2023
700656c
[JBTM-3463] split up each service (hotel, flight and trip) so that th…
moulalis May 23, 2023
0c58146
JBTM-1488 LRA Implementation
mmusgrov Aug 18, 2017
5605dfa
Updated to 5.7.0.Final
tomjenkinson Sep 26, 2017
c1f0735
Updated to 5.7.1.Final-SNAPSHOT
tomjenkinson Sep 26, 2017
1436255
JBTM-2940 Spec compliance
mmusgrov Oct 6, 2017
900b5cb
Updated to 5.7.1.Final
tomjenkinson Oct 19, 2017
33fb382
Updated to 5.7.2.Final-SNAPSHOT
tomjenkinson Oct 19, 2017
7f7f926
Merge branch 'master' of https://github.com/jbosstm/narayana
nmcl Aug 10, 2018
bfc6262
Updated to 5.9.1.Final
tomjenkinson Dec 4, 2018
a210edb
Updated to 5.9.2.Final-SNAPSHOT
tomjenkinson Dec 4, 2018
b05ca2d
Updated to 5.9.2.Final
ochaloup Dec 14, 2018
42bcad0
Updated to 5.9.3.Final-SNAPSHOT
ochaloup Dec 14, 2018
7e6eb17
Updated to 5.9.3.Final
tomjenkinson Feb 21, 2019
85b5d4e
Updated to 5.9.4.Final-SNAPSHOT
tomjenkinson Feb 21, 2019
2426117
test formatting fixes for lra&rts&jts
ochaloup Mar 19, 2019
8030eb4
Updated to 5.9.4.Final
ochaloup Mar 27, 2019
b2d75c2
Updated to 5.9.5.Final-SNAPSHOT
ochaloup Mar 27, 2019
46f3186
Updated to 5.9.5.Final
tomjenkinson Mar 28, 2019
b4f281d
Updated to 5.9.6.Final-SNAPSHOT
tomjenkinson Mar 28, 2019
89d2360
JBTM-3150 Migrate from swarm to thorntail
mmusgrov Jun 4, 2019
c2cb2a9
JBTM-3145 do not use scope test for resteasy dependency (and upgrade …
mmusgrov Jun 7, 2019
4e6bab9
RTS SRA not needed all microprofile fractions as dependencies
ochaloup Jul 30, 2019
e3e99f7
Updated to 5.9.6.Final
ochaloup Aug 7, 2019
ebd3e3c
Updated to 5.9.7.Final-SNAPSHOT
ochaloup Aug 7, 2019
a9ee3b9
Updated to 5.9.7.Final
tomjenkinson Aug 23, 2019
9b208d4
Updated to 5.9.8.Final-SNAPSHOT
tomjenkinson Aug 23, 2019
e6f6e06
Updated to 5.9.8.Final
tomjenkinson Sep 2, 2019
371208a
Updated to 5.9.9.Final-SNAPSHOT
tomjenkinson Sep 2, 2019
a728452
Updated to 5.10.0.Final-SNAPSHOT
tomjenkinson Oct 7, 2019
b84912a
Updated to 5.10.0.Final
mmusgrov Oct 28, 2019
f08abf2
Updated to 5.10.1.Final-SNAPSHOT
mmusgrov Oct 28, 2019
69679fa
Updated to 5.10.1.Final
tomjenkinson Dec 4, 2019
520eade
Updated to 5.10.2.Final-SNAPSHOT
tomjenkinson Dec 4, 2019
afe6e36
Updated to 5.10.3.Final
tomjenkinson Jan 23, 2020
3a7cd79
Updated to 5.10.4.Final-SNAPSHOT
tomjenkinson Jan 23, 2020
b367ad5
Updated to 5.10.4.Final
tomjenkinson Jan 30, 2020
e87abaf
Updated to 5.10.5.Final-SNAPSHOT
tomjenkinson Jan 30, 2020
1a9b742
Updated to 5.10.5.Final
ochaloup May 20, 2020
95e21c9
Updated to 5.10.6.Final-SNAPSHOT
ochaloup May 20, 2020
54e74df
Updated to 5.10.6.Final
ochaloup Sep 3, 2020
fd6516d
Updated to 5.10.7.Final-SNAPSHOT
ochaloup Sep 3, 2020
a08f013
Updated to 5.11.0.Final
ochaloup Mar 19, 2021
612847e
Updated to 5.11.1.Final-SNAPSHOT
ochaloup Mar 19, 2021
b0916a0
Updated to 5.11.1.Final
ochaloup Apr 13, 2021
4f79124
Updated to 5.11.2.Final-SNAPSHOT
ochaloup Apr 13, 2021
a999288
Changes for JBTM-3461 using quarkus instead of thorntail
swetapatra Apr 16, 2021
cf79e10
Additional changes for JBTM-3461 SRA Demo
swetapatra Apr 20, 2021
73a6637
Updated to 5.11.2.Final
ochaloup May 5, 2021
72032ff
Updated to 5.11.3.Final-SNAPSHOT
ochaloup May 5, 2021
188c302
JBTM-3464 and JBTM-3460 move annotation code,add unit test and get th…
mmusgrov May 17, 2021
be721e5
Updated to 5.12.0.Final
ochaloup Jun 9, 2021
a4526ee
Updated to 5.12.1.Final-SNAPSHOT
ochaloup Jun 9, 2021
aee1cd7
Updated to 5.12.1.Final
ochaloup Sep 14, 2021
a59743b
Updated to 5.12.2.Final-SNAPSHOT
ochaloup Sep 14, 2021
72a9bab
Updated to 5.12.2.Final
mmusgrov Nov 26, 2021
c0c08a2
Updated to 5.12.3.Final-SNAPSHOT
mmusgrov Nov 26, 2021
38bda7c
Updated to 5.12.3.Final
mmusgrov Nov 27, 2021
913f494
Updated to 5.12.4.Final-SNAPSHOT
mmusgrov Nov 27, 2021
dfde3b6
Updated to 5.12.4.Final
mmusgrov Nov 28, 2021
d0f797e
Updated to 5.12.5.Final-SNAPSHOT
mmusgrov Nov 28, 2021
f368526
Updated to 5.12.5.Final
mmusgrov Jan 19, 2022
d44ff74
Updated to 5.12.6.Final-SNAPSHOT
mmusgrov Jan 19, 2022
41956b8
Updated to 5.12.6.Final
mmusgrov Apr 4, 2022
3c03695
Updated to 5.12.7.Final-SNAPSHOT
mmusgrov Apr 4, 2022
9a762ff
Change the semantics of the annotation attribute SRA#delayCommit
marcosgopen May 13, 2022
2d1cca4
Updated to 5.12.7.Final
mmusgrov Jun 22, 2022
e346bdc
Updated to 5.12.8.Final-SNAPSHOT
mmusgrov Jun 22, 2022
75e3715
Updated to 5.13.0.Final
mmusgrov Jul 23, 2022
65816c5
Updated to 5.13.1.Final-SNAPSHOT
mmusgrov Jul 23, 2022
6c8a924
Updated to 5.13.1.Alpha1
mmusgrov Aug 3, 2022
eb56760
Updated to 5.13.1.Final-SNAPSHOT
mmusgrov Aug 3, 2022
724d3fb
Updated to 5.13.1.Final
mmusgrov Nov 14, 2022
164ba9e
Updated to 6.0.0.Final-SNAPSHOT
mmusgrov Nov 14, 2022
0149ac2
JBTM-3658 Fix the trace logging test properties for WFLY coordinator
xstefank Nov 21, 2022
a854d75
JBTM-3588 initial conversion using org.eclipse.transformer.cli-0.6.0-…
mmusgrov Sep 3, 2022
d195bd8
JBTM-3588 wip getting most of the tests working
mmusgrov Sep 6, 2022
f22d6b8
Ensure that the rest-at and sra tests work with jakarta
marcosgopen Sep 7, 2022
cbb0a0c
restore services deleted by jakarta transformation
marcosgopen Oct 12, 2022
f4a0e15
Removed unused/javax dependencies from RTS
jmfinelli Oct 27, 2022
0d98857
Updated to 6.0.0.CR1
mmusgrov Jan 17, 2023
315412a
Updated to 6.0.0.Final-SNAPSHOT
mmusgrov Jan 17, 2023
10dcbb7
Updated to 6.0.0.Final
mmusgrov Feb 16, 2023
100566f
Updated to 6.0.1.Final-SNAPSHOT
mmusgrov Feb 16, 2023
85ab346
JBTM-3756 update schema version all beans.xml files (and bean discove…
mmusgrov Mar 1, 2023
f5b33e2
Implement BOM in all the Narayana Module
moulalis Mar 9, 2023
eb47113
Updated to 6.0.1.Final
mmusgrov Apr 21, 2023
fe485da
Updated to 6.0.2.Final-SNAPSHOT
mmusgrov Apr 21, 2023
ae84359
[JBTM:3462] Migrate the SRA demo package (io.narayana.sra.demo) over …
moulalis Apr 11, 2023
ea72317
[JBTM-3463] split up each service (hotel, flight and trip) so that th…
moulalis May 23, 2023
cc40fd0
[JBTM-3794] Write Test CI to test annotation example
moulalis Aug 7, 2023
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
3 changes: 3 additions & 0 deletions rts/at/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ Demonstrator
An example using the ruby language showing how to start and end a transaction using REST style semantics
and how services can recover from failures during the commitment protocol.

Annotations
============
A quickstart that demonstrates how to use REST-AT annotations to define transactional microservices.
45 changes: 45 additions & 0 deletions rts/at/annotation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
OVERVIEW
--------
A example that demonstrates how to use [REST-AT annotations](https://github.com/jbosstm/narayana/tree/main/rts/at/tx/src/main/java/org/jboss/jbossts/star/annotation) to define transactional microservices.

USAGE
--------------------

Prior to running the example make sure that the [REST-AT coordinator is deployed](../README.md#usage).

Once REST-AT coordinator is deployed build and run the annotation example application to run on port 8082, 8083 and 8084 as it in configured in application.properties

cd <narayana-repo>/rts/at/annotation/
mvn clean package -DskipTests
java -jar flight-service/target/quarkus-app/quarkus-run.jar &
java -jar hotel-service/target/quarkus-app/quarkus-run.jar &
java -jar trip-service/target/quarkus-app/quarkus-run.jar &

Book a trip within a transaction, refer to the [`bookTrip` method in the trip service](./trip-service/src/main/java/io/narayana/sra/demo/api/TripController.java) to see how it is annotated. The following curl command will invoke the resource.

curl -XPOST http://localhost:8082/trip/book?hotelName=Rex&flightNumber=123
curl http://localhost:8082/trip/status?sraId={paste sraId here}



Since the `bookTrip` resource is annotated with `@SRA(value = SRA.Type.REQUIRED)`, the curl request will start a new REST-AT transaction and you can verify that it is running by querying the coordinator: `curl http://localhost:8080/rest-at-coordinator/tx/transaction-manager`.

EXPECTED OUTPUT
---------------
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating flight participant state to: TransactionPrepared
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating hotel participant state to: TransactionPrepared
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating trip participant state to: TransactionPrepared
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating trip participant state to: TransactionCommitted
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating hotel participant state to: TransactionCommitted
SRA: 0_ffff0ad775f3_-2e0999fe_64d0a461_3f8: Updating flight participant state to: TransactionCommitted
{"cancelPending":false,"details":[{"cancelPending":false,"details":[],"encodedId":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","id":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","name":"Rex","quantity":1,"sraId":"http://localhost:8080/rest-at-coordinator/tx/transaction-manager/0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","status":"PROVISIONAL","type":"Hotel"},{"cancelPending":false,"details":[],"encodedId":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","id":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","name":"456","quantity":1,"sraId":"http://localhost:8080/rest-at-coordinator/tx/transaction-manager/0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","status":"PROVISIONAL","type":"Flight"}],"encodedId":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","id":"0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","name":"Aggregate Booking","quantity":1,"sraId":"http://localhost:8080/rest-at-coordinator/tx/transaction-manager/0_ffff0ad775f3_-2e0999fe_64d0a461_3f8","status":"CONFIRMED","type":"Trip"}
Confirming tripBooking id 0_ffff0ad775f3_-2e0999fe_64d0a461_4a4 (Aggregate Booking) status: CONFIRMED

WHAT JUST HAPPENED?
-------------------

1. Build and run the REST-AT annotation application, it starts all three microservice on different port i.e 8082, 8083 and 8084 which is configured in application.properties such as in [flight-service](flight-service/src/main/resources/application.properties), [hotel-service](hotel-service/src/main/resources/application.properties) and [trip-service](flight-service/src/main/resources/application.properties).

2. Invoke book trip which start REST-AT transaction and calls individual hotel and flight service issuing the POST request to the trip service.

> **_NOTE:_** The quickstart marks the services as REST-AT aware participants because they are extending a [helper](https://github.com/jbosstm/narayana/blob/main/rts/at/tx/src/main/java/org/jboss/jbossts/star/client/SRAParticipant.java) class that provides the relevant REST-AT support.
19 changes: 19 additions & 0 deletions rts/at/annotation/common-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.narayana.quickstart.rts</groupId>
<artifactId>annotation</artifactId>
<version>7.0.1.Final-SNAPSHOT</version>
</parent>
<groupId>org.jboss.narayana.quickstart.rts</groupId>
<artifactId>common-service</artifactId>
<packaging>jar</packaging>
<name>common-service</name>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.narayana.sra.demo.constant;

public class ServiceConstant {
public static final String HOTEL_PATH = "/hotel";
public static final String HOTEL_NAME_PARAM = "hotelName";
public static final String HOTEL_BEDS_PARAM = "beds";

public static final String FLIGHT_PATH = "/flight";
public static final String FLIGHT_NUMBER_PARAM = "flightNumber";
public static final String ALT_FLIGHT_NUMBER_PARAM = "altFlightNumber";
public static final String FLIGHT_SEATS_PARAM = "flightSeats";

public static final String TRIP_PATH = "/trip";
public static final String SERVICE_PORT_PROPERTY = "quarkus.http.port";

public static final String HOTEL_SERVICE_PORT_PROPERTY = "hotel.quarkus.http.port";

public static final String FLIGHT_SERVICE_PORT_PROPERTY = "flight.quarkus.http.port";

public static final String BOOKING_ID = "bookingId";
public static final String SRA_ID = "sraId";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
package io.narayana.sra.demo.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;

public class Booking {
@JsonProperty("id")
private String id;

@JsonProperty("sraId")
private String sraId;
@JsonProperty("name")
private String name;
@JsonProperty("quantity")
private Integer quantity;
@JsonProperty("status")
private BookingStatus status;
@JsonProperty("type")
private String type;
@JsonProperty("details")
private Booking[] details;

private IOException decodingException;

public Booking() {
this("", "", 0, "");
}

public Booking(String id, String name, Integer quantity, String type) {
this(id, name, quantity, type, BookingStatus.PROVISIONAL, null);
}

public Booking(String id, String type, Booking... bookings) {
this(id, "Aggregate Booking", 1, type, BookingStatus.PROVISIONAL, bookings);
}

@JsonCreator
public Booking(@JsonProperty("id") String id,
@JsonProperty("name") String name,
@JsonProperty("quantity") Integer quantity,
@JsonProperty("type") String type,
@JsonProperty("status") BookingStatus status,
@JsonProperty("details") Booking[] details) {

init(id, name, quantity, type, status, details);
}

public Booking(IOException decodingException) {
this.decodingException = decodingException;
}

public Booking(Booking booking) {
this.init(booking.getId(), booking.getName(), booking.getQuantity(), booking.getType(), booking.getStatus(), null);

details = new Booking[booking.getDetails().length];

IntStream.range(0, details.length).forEach(i -> details[i] = new Booking(booking.getDetails()[i]));
}

public void setId(String id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setQuantity(Integer quantity) {
this.quantity = quantity;
}

public void setType(String type) {
this.type = type;
}

public void setDetails(Booking[] details) {
this.details = details;
}

public void setDecodingException(IOException decodingException) {
this.decodingException = decodingException;
}

public static Booking fromJson(String json) {
try {
return new ObjectMapper().readValue(json, Booking.class);
} catch (IOException e) {
return new Booking(e);
}
}

public static List<Booking> listFromJson(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();

return Arrays.asList(mapper.readValue(json, Booking[].class));
}

private void init(String id, String name, Integer quantity, String type, BookingStatus status, Booking[] details) {
this.sraId = id;
String[] segments = id.split("/");

this.id = segments[segments.length - 1];// this is just a demo so don't check for a single /

this.name = name == null ? "" : name;
this.quantity = quantity;
this.type = type == null ? "" : type;
this.status = status;
this.details = details == null ? new Booking[0] : removeNullEnElements(details);
}

@SuppressWarnings("unchecked")
private <T> T[] removeNullEnElements(T[] a) {
List<T> list = new ArrayList<T>(Arrays.asList(a));
list.removeAll(Collections.singleton(null));
return list.toArray((T[]) Array.newInstance(a.getClass().getComponentType(), list.size()));
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public Integer getQuantity() {
return quantity;
}

public String getType() {
return type;
}

public Booking[] getDetails() {
return details;
}

public BookingStatus getStatus() {
return status;
}

public void setStatus(BookingStatus status) {
this.status = status;
}

public void requestCancel() {
status = BookingStatus.CANCEL_REQUESTED;
}

public String getSraId() {
return sraId;
}

public void setSraId(String sraId) {
this.sraId = sraId;
}

public void setConfirmed() {
status = BookingStatus.CONFIRMED;
}

public String toString() {
return String.format("{\"id\":\"%s\",\"name\":\"%s\",\"quantity\":\"%d\",\"type\":\"%s\",\"status\":\"%s\"}",
id, name, quantity, type, status);
}

public void setCanceled() {
status = BookingStatus.CANCELLED;
}

public void setConfirming() {
status = BookingStatus.CONFIRMING;
}

@JsonIgnore
public boolean isCancelPending() {
return status == BookingStatus.CANCEL_REQUESTED;
}

public boolean merge(Booking booking) {
if (!id.equals(booking.getId()))
return false; // or throw an exception

name = booking.getName();
quantity = booking.getQuantity();
status = booking.getStatus();

return true;
}

@JsonIgnore
public String getEncodedId() {
try {
return URLEncoder.encode(id, "UTF-8");
} catch (UnsupportedEncodingException e) {
return id; // TODD do it in the constructor
}
}

public String toJson() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();

return objectMapper.writeValueAsString(this);
}

@JsonIgnore
public IOException getDecodingException() {
return decodingException;
}

/* @Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Booking)) return false;

Booking booking = (Booking) o;

return getId().equals(booking.getId());
}

@Override
public int hashCode() {
return getId().hashCode();
}*/

public enum BookingStatus {
CONFIRMED, CANCELLED, PROVISIONAL, CONFIRMING, CANCEL_REQUESTED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.narayana.sra.demo.service;

public class BookingException extends Exception {
int reason;

public BookingException(int reason, String message) {
super(message);

this.reason = reason;

}

public int getReason() {
return reason;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.narayana.sra.demo.service;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

@Provider
public class BookingExceptionMapper implements ExceptionMapper<BookingException> {
@Override
public Response toResponse(BookingException exception) {

return Response.status(exception.getReason())
.entity(exception.getMessage()).build();
}
}
Loading