diff --git a/kogito-quarkus-examples/pom.xml b/kogito-quarkus-examples/pom.xml index 1b555b56d0..1a3f0bbe88 100644 --- a/kogito-quarkus-examples/pom.xml +++ b/kogito-quarkus-examples/pom.xml @@ -67,6 +67,7 @@ pmml-event-driven-quarkus pmml-incubation-api-quarkus pmml-quarkus-example + process-business-calendar-example process-business-rules-quarkus process-decisions-quarkus process-decisions-rest-quarkus diff --git a/kogito-quarkus-examples/process-business-calendar-example/README.md b/kogito-quarkus-examples/process-business-calendar-example/README.md new file mode 100644 index 0000000000..b88068dcb2 --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/README.md @@ -0,0 +1,286 @@ +# Process Business Calendar Example + +This example demonstrates the impact of a business calendar on process execution within a Quarkus application. It showcases a business process involving credit card bill processing, which adapts to a business calendar defined in calendar.properties. This configuration modifies timer behaviors to respect working hours, holidays, and other schedule-based constraints. + +### Main Components + +**BPMN2-BusinessCalendarBankTransaction.bpmn2**: +Defines the workflow for processing credit card transactions. +Includes tasks such as processing the credit bill, verifying payment, handling timers, cancelling and bill settlement. + +**CreditCardService.java**: +Implements the logic for handling credit card payment processes. + +**calendar.properties**: +Configures business hours, holidays, and other calendar properties that affect scheduling and timer behavior. + +### BPMN Process Details + +The BPMN model (`BPMN2-BusinessCalendarBankTransaction.bpmn2`) defines a workflow that includes the following main elements: +

+ +### Start Event + +The initial trigger that starts the credit card bill processing workflow. + +### Process Credit Bill +* Process Credit Bill Properties (Top) +

+ +* Process Credit Card Bill Assignments +

+ +### Verify Payment +A user task where the credit card details are validated, ensuring the payment is processed under valid terms. + +* Verify Payment +

+ +### Timer + +Attached to a user task to simulate waiting for manual confirmation or user action. This timer can be configured to react differently based on the presence of the business calendar. +

+ +### Cancel Payment +Executed if the timer expires without human action, leading to the cancellation of the payment process. + +* Cancel Payment (Top) +

+ +* Cancel Payment Assignments +

+ +### Settle Payment + +The final step where the payment is settled successfully on manual verification. + +* Settle Payment (Top) +

+ +* Settle Payment Assignments +

+ +## Build and run + +### Prerequisites + +You will need: +- Java 17+ installed +- Environment variable JAVA_HOME set accordingly +- Maven 3.9.6+ installed + +### Compile and Run in Local Dev Mode + +```sh +mvn clean compile quarkus:dev +``` + +NOTE: With dev mode of Quarkus you can take advantage of hot reload for business assets like processes, rules, decision tables and java code. No need to redeploy or restart your running application. + +### Package and Run in JVM mode + +```sh +mvn clean package +java -jar target/quarkus-app/quarkus-run.jar +``` + +or on windows + +```sh +mvn clean package +java -jar target\quarkus-app\quarkus-run.jar +``` + +### OpenAPI (Swagger) documentation +[Specification at swagger.io](https://swagger.io/docs/specification/about/) + +You can take a look at the [OpenAPI definition](http://localhost:8080/openapi?format=json) - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available [Swagger UI](https://editor.swagger.io). + +In addition, various clients to interact with this service can be easily generated using this OpenAPI definition. + +When running in either Quarkus Development or Native mode, we also leverage the [Quarkus OpenAPI extension](https://quarkus.io/guides/openapi-swaggerui#use-swagger-ui-for-development) that exposes [Swagger UI](http://localhost:8080/q/swagger-ui/) that you can use to look at available REST endpoints and send test requests. + +## curl command can be found below: + +### To start the process + +```sh +curl -X POST http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-d '{"creditCardNumber": null, "creditCardDetails": {"cardNumber": "434353433", "status": "Bill Due"}}' + +``` + +### To retrieve instances + +```sh +curl -X GET http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" + +``` +### To retrieve status of particular instance using id + +```sh +curl -X GET http://localhost:8080/BusinessCalendarCreditBill/{id} \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" + +``` + +## Understanding calendar.properties +**Default Behavior**: If you do not input custom values in a calendar.properties file, the system will use the following default settings: + +* **business.days.per.week** defaults to 5, meaning only Monday to Friday are considered working days. + +* **business.hours.per.day** defaults to 8, representing an 8-hour workday. + +* **business.start.hour** defaults to 9, and business.end.hour defaults to 17 (i.e.,9 AM to 5 PM workday). + +* **business.weekend.days** defaults to Saturday and Sunday (Sunday-1, Monday-2, Tuesday-3, Wednesday-4, Thursday-5, Friday-6, Saturday-7). + +* **business.holiday.date.format** defaults to yyyy-MM-dd, (input must match format defined format). + +* **business.holidays** by default will be considered empty, meaning no predefined holidays unless specified, if specified, it should be in the format defined by business.holiday.date.format, Holidays can be specified as individual dates (e.g., 2024-12-25,2024-12-31) or as a range of dates (e.g., 2024-11-12:2024-11-14). + +* **business.cal.timezone** defaults to the system’s default timezone, if configured, valid time-zone as per Valid timezone as per https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html should be specfied. + +**Behavior**: +* Considering the default properties as mentioned above, if a task is executed after working hours i.e., non-working hours (e.g., at 7 PM), the system will delay its execution until the start of the next working hour/working day (9 AM). For example, if a task timer is set to trigger at 7 PM on a Friday, it will not execute until 9 AM on Monday (assuming a standard 5-day workweek). +* If a task becomes due or is scheduled to start outside business hours, it will remain in a pending state until business hours resume. +* If the business calendar is configured with a 5-day workweek (business.days.per.week=5), any tasks scheduled over the weekend will not resume until the following Monday at the start of business hours. + + +## Configuring Custom Calendar.Properties +### Note: Important Guidelines for Configuring `calendar.properties` +To override default values, configure calendar.properties file based on requirements. In order to ensure more aligned functionality, please follow the rules outlined below. Adhering to these guidelines will help ensure that tasks are executed as expected. Incorrect configurations may result in unintended behavior, so it's recommended to input accurate values. + +| Property | Valid Range | Description | +|------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `business.start.hour` | 0-23 | Start hour of the workday | +| `business.end.hour` | 0-23 | End hour of the workday | +| `business.hours.per.day` | 1-24 | Total working hours in a day | +| `business.days.per.week` | 1-7 | Total working days per week | +| `business.weekend.days` | 0-7 | Days considered as weekends (e.g., 1 = Sunday, 7 = Saturday). In case you want to consider all the days as working days i.e., no weekend days, input 0 as value considering working days as 7. | +| `business.holiday.date.format` | (yyyy-MM-dd) | List of holidays | +| `business.holidays` | Dates aligned with business.holiday.date.format | Date format for holidays | +| `business.cal.timezone` | Valid timezone as per [Java TimeZone Documentation](https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) | Timezone for calculations | + +### Example of custom calendar.properties +```Properties +business.end.hour=23 +business.hours.per.day=24 +business.start.hour=0 +business.holiday.date.format=yyyy-MM-dd +business.holidays=2024-10-30 +business.days.per.week=5 +business.weekend.days=6,7 +business.cal.timezone=America/Toronto +``` +**Behavior**: +* **Tasks within working hours**: When a task or timer is scheduled within the defined working hours (e.g., between business.start.hour=0 and business.end.hour=24), the task will be completed immediately once it becomes due. For example, if a task is scheduled to trigger at 10 AM on a Tuesday, and your working hours are from 0 to 24, the task will execute as expected at 10 AM. +* **Handling custom working days**: If calendar.properties file specifies business.days.per.week=6, the system will treat these days as working days, tasks scheduled on any of these days will be processed during the defined working hours. For example, if a task is due at 10 AM on Saturday, and you’ve configured Saturday as a working day, the task will execute as completed. +* **Weekend handling**: Even if a task is executed within the defined working hours, it will be delayed if it falls on a configured weekend. For example, if you have business.days.per.week =5 and business.weekend.days=6,7 the task will not execute on the weekend days mentioned. Instead, it will be postponed to the next working day at the defined business.start.hour. This ensures that no tasks are executed on days that are considered holidays, even if they fall within regular business hours. +* **Holiday handling**: if a task is executed within the defined working hours, it will be delayed if it falls on a configured holiday. For example, if you have business.holdays = 2024-10-30 and a task is executed on the same day in a working hour, it will not execute, instead it will be postponed to the next working day at the defined business.start.hour. This ensures that no tasks are executed on days that are considered holidays, even if they fall within regular business hours. +* **Timezone**: If you specify a timezone using business.cal.timezone, the calendar will adjust all scheduling based on this timezone, regardless of system time else systems time will be considered. + +## Testing with default calendar.properties (working hours) +**Note**: The test was performed at 16:13 on Monday, which falls under default working hours + +* The timer for the Verify Payment task will follow a straightforward countdown based on real time. If the specified time elapses i.e., 1 second, it immediately moves to cancel payment task. + +* POST/ BusinessCalendarCreditBill +```sh +curl -X POST http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-d '{"creditCardNumber": null, "creditCardDetails": {"cardNumber": "434353433", "status": "Bill Due"}}' + +``` +

+ +* After 1 second when we send request for GET/ BusinessCalendarCreditBill again we get empty array representing the cancellation. +```sh +curl -X GET http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" + +``` +

+ +### Example of logs representing the process from start to completion +

+ +* At 16:13:20,606, job 18e97326-897b-4f1b-8121-b09ea9eb37d7 was started, indicating that the timer was triggered approximately after one second as expected. + +## Testing with default calendar.properties (non-working hours) +**Note**: The test was performed at 08:27 on Monday, which does not fall in the default working hours range + +* During non-working hours, the timer for the Verify Payment task will not trigger and the process remains in active state, does not move to cancel payment task. + +* POST/ BusinessCalendarCreditBill +```sh +curl -X POST http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-d '{"creditCardNumber": null, "creditCardDetails": {"cardNumber": "434353433", "status": "Bill Due"}}' +``` +

+ + +* GET/ BusinessCalendarCreditBill +```sh +curl -X GET http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" + +``` +* Now, even after 1 second, the process will be in Active State but not completed state. + +

+ +### Example of logs representing the active state during non-working hours + +

+ +## Testing with calendar.properties (During non-working hours/Specified Holiday) +**Note**: The test was performed considering 24-hour workday properties with configured holiday i.e., business.holidays=2024-11-07 + +* After calendar.properties file is added, build the example again "mvn clean compile quarkus:dev" or type 's' in the quarkus terminal and hit enter just to restart. + +* POST/ BusinessCalendarCreditBill +```sh +curl -X POST http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-d '{"creditCardNumber": null, "creditCardDetails": {"cardNumber": "434353433", "status": "Bill Due"}}' +``` +

+ + +* GET/ BusinessCalendarCreditBill +```sh +curl -X GET http://localhost:8080/BusinessCalendarCreditBill \ +-H "Content-Type: application/json" \ +-H "Accept: application/json" + +``` +* Now, even after 1 second, the process will be in Active State. + +

+ +### Example of logs representing the active state during non-working hours/specified holiday + +

+ +* The node 'Start' for the process 'BusinessCalendarCreditBill', identified by 08ea5258-9d91-4f05-a8d8-184107c042ed, was triggered at 08:54:28,621. + +* At 08:54:28,629, the 'Process Credit Bill' node was activated. + +* At 08:54:28,653, verification step through the 'Verify Payment' node was started. + +* Subsequently, a human task was registered at 08:54:28,773. + +* The workflow transitioned to an 'Active' state at 08:54:28,808. + +* Due to mentioned "business.holidays property" in calendar.properties, timer does not trigger and the state remains active. + +* On next business day, timer will resume at the beginning of the next working hour/day, after the non-working hour/holiday has ended. The timer is set to fire after one second of active business time. + diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentAssign.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentAssign.png new file mode 100644 index 0000000000..9306de7df6 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentAssign.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentTop.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentTop.png new file mode 100644 index 0000000000..4ad4b8cb53 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CancelPaymentTop.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/CreditCardModel.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CreditCardModel.png new file mode 100644 index 0000000000..c05c5e3e37 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/CreditCardModel.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get1.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get1.png new file mode 100644 index 0000000000..936601bd78 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get1.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get2.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get2.png new file mode 100644 index 0000000000..ed77865a27 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get2.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get3.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get3.png new file mode 100644 index 0000000000..d1888c96c9 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Get3.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post1.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post1.png new file mode 100644 index 0000000000..04686a9e71 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post1.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post2.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post2.png new file mode 100644 index 0000000000..610d6b040e Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post2.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post3.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post3.png new file mode 100644 index 0000000000..fed2c0c92e Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Post3.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillAssign.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillAssign.png new file mode 100644 index 0000000000..05b50c61ab Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillAssign.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillTop.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillTop.png new file mode 100644 index 0000000000..97594f6d0d Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/ProcessCreditBillTop.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentAssign.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentAssign.png new file mode 100644 index 0000000000..b3f5b205da Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentAssign.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentTop.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentTop.png new file mode 100644 index 0000000000..3f23e21187 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/SettlePaymentTop.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/Timer.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Timer.png new file mode 100644 index 0000000000..036c23649e Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/Timer.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/VerifyPayment.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/VerifyPayment.png new file mode 100644 index 0000000000..5c40e3d571 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/VerifyPayment.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithPropertiesLogs.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithPropertiesLogs.png new file mode 100644 index 0000000000..cfa3d7c0ec Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithPropertiesLogs.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogs.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogs.png new file mode 100644 index 0000000000..ccfc797af4 Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogs.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogsNW.png b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogsNW.png new file mode 100644 index 0000000000..fb73b2d62c Binary files /dev/null and b/kogito-quarkus-examples/process-business-calendar-example/docs/images/WithoutPropertiesLogsNW.png differ diff --git a/kogito-quarkus-examples/process-business-calendar-example/pom.xml b/kogito-quarkus-examples/process-business-calendar-example/pom.xml new file mode 100644 index 0000000000..a1cfa1a138 --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/pom.xml @@ -0,0 +1,128 @@ + + + + 4.0.0 + + + org.kie.kogito.examples + kogito-quarkus-examples + 999-SNAPSHOT + + + process-business-calendar-example + Kogito Example :: Process Business Calendar + + + 3.8.6 + quarkus-bom + io.quarkus + 3.8.6 + org.kie.kogito + kogito-bom + 999-SNAPSHOT + 999-SNAPSHOT + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + ${kogito.bom.group-id} + ${kogito.bom.artifact-id} + ${kogito.bom.version} + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + org.jbpm + jbpm-with-drools-quarkus + + + org.jbpm + jbpm-quarkus + + + org.kie.kogito + jbpm-flow + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + javax.enterprise + cdi-api + 2.0 + provided + + + io.quarkus + quarkus-smallrye-health + + + + ${project.artifactId} + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + + \ No newline at end of file diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardDetails.java b/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardDetails.java new file mode 100644 index 0000000000..011beebf20 --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardDetails.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.calendar.bill; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CreditCardDetails { + private String cardNumber; + private String status = "Bill Due"; + + public CreditCardDetails() { + } + + public CreditCardDetails(String cardNumber) { + this.cardNumber = cardNumber; + } + + public String getCardNumber() { + return cardNumber; + } + + public String getStatus() { + return status; + } + + public void setCardNumber(String cardNumber) { + this.cardNumber = cardNumber; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardService.java b/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardService.java new file mode 100644 index 0000000000..92313279cc --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/main/java/org/kie/kogito/calendar/bill/CreditCardService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.calendar.bill; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class CreditCardService { + + private Logger logger = LoggerFactory.getLogger(CreditCardService.class); + + public CreditCardDetails processCreditBill(String creditCardNumber) { + logger.info("Paying credit card"); + return new CreditCardDetails(creditCardNumber); + } + + public CreditCardDetails settleBill(CreditCardDetails creditCardDetails) { + creditCardDetails.setStatus("Bill paid"); + logger.info("settling bill"); + return creditCardDetails; + } + + public CreditCardDetails cancelPayment(CreditCardDetails creditCardDetails) { + creditCardDetails.setStatus("Payment cancelled, money will be refunded if it is debited"); + logger.info("cancelling bill"); + return creditCardDetails; + } +} diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/application.properties b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/application.properties new file mode 100644 index 0000000000..fdac783f41 --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +quarkus.swagger-ui.always-include=true +quarkus.log.level=INFO \ No newline at end of file diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/calendar.properties b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/calendar.properties new file mode 100644 index 0000000000..eddf031d2c --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/calendar.properties @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +business.end.hour=23 +business.hours.per.day=24 +business.start.hour=0 +business.holiday.date.format=yyyy-MM-dd +business.holidays=2024-11-07 +business.days.per.week=6 +business.weekend.days=1 + diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/org/kie/kogito/calendar/bill/BPMN2-BusinessCalendarBankTransaction.bpmn2 b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/org/kie/kogito/calendar/bill/BPMN2-BusinessCalendarBankTransaction.bpmn2 new file mode 100644 index 0000000000..c26518955c --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/main/resources/org/kie/kogito/calendar/bill/BPMN2-BusinessCalendarBankTransaction.bpmn2 @@ -0,0 +1,359 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_InMessage + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_OutMessage + + + + + + + _D350DC2A-D283-4357-9B87-3E295C348D50_InMessage + _D350DC2A-D283-4357-9B87-3E295C348D50_OutMessage + + + + + + + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_InMessage + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_OutMessage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _3319AF07-1259-4E0B-95FB-4D7439C2D1BB + _445DAFA9-C397-4051-B9A4-13673ACB2857 + + + + + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_creditCardDetailsInputX + + + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_resultOutputX + + + + creditCardDetails + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_creditCardDetailsInputX + + + _049D6ACC-0D5B-4C91-9382-D5B8417F3902_resultOutputX + creditCardDetails + + + + _E15E86A8-BF0E-400F-8147-9CDCA638DBF6 + + + + + + + + + _1EA09C74-739D-41E1-A05A-E3C34942E6D2 + _3319AF07-1259-4E0B-95FB-4D7439C2D1BB + + + + + _C10EDD5D-0C5F-4ADB-9B85-28D3B9C7D2A7_TaskNameInputX + _C10EDD5D-0C5F-4ADB-9B85-28D3B9C7D2A7_SkippableInputX + + + + _C10EDD5D-0C5F-4ADB-9B85-28D3B9C7D2A7_TaskNameInputX + + + + + + + _C10EDD5D-0C5F-4ADB-9B85-28D3B9C7D2A7_SkippableInputX + + + + + + + + + + + + + _A60B1BA8-2BCB-4765-8C9C-EFFCA75D8CA9 + _E15E86A8-BF0E-400F-8147-9CDCA638DBF6 + + + + + _D350DC2A-D283-4357-9B87-3E295C348D50_creditCardDetailsInputX + + + _D350DC2A-D283-4357-9B87-3E295C348D50_resultOutputX + + + + creditCardDetails + _D350DC2A-D283-4357-9B87-3E295C348D50_creditCardDetailsInputX + + + _D350DC2A-D283-4357-9B87-3E295C348D50_resultOutputX + creditCardDetails + + + + + + + + + _BD039EC9-BD1C-44EB-8DB7-347E412D0F7A + _1EA09C74-739D-41E1-A05A-E3C34942E6D2 + + + + + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_creditCardNumberInputX + + + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_responseOutputX + + + + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_creditCardNumberInputX + + + + + + + _9726CC54-817D-4EBD-BC63-A3DBED0183A5_responseOutputX + creditCardDetails + + + + _BD039EC9-BD1C-44EB-8DB7-347E412D0F7A + + + _445DAFA9-C397-4051-B9A4-13673ACB2857 + + + _A60B1BA8-2BCB-4765-8C9C-EFFCA75D8CA9 + + PT1S + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _qtlLMHyCED2WA6aH6h3CCg + _qtlLMHyCED2WA6aH6h3CCg + + \ No newline at end of file diff --git a/kogito-quarkus-examples/process-business-calendar-example/src/test/java/org/kie/kogito/calendar/CreditCardProcessIT.java b/kogito-quarkus-examples/process-business-calendar-example/src/test/java/org/kie/kogito/calendar/CreditCardProcessIT.java new file mode 100644 index 0000000000..e8b9d28a30 --- /dev/null +++ b/kogito-quarkus-examples/process-business-calendar-example/src/test/java/org/kie/kogito/calendar/CreditCardProcessIT.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.calendar; + +import org.junit.jupiter.api.Test; +import org.kie.kogito.process.ProcessConfig; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@QuarkusTest +public class CreditCardProcessIT { + + private static final String PROCESS_ID = "BusinessCalendarCreditBill"; + private static final String CARD_NUMBER = "434354343"; + + @jakarta.inject.Inject + ProcessConfig processConfig; + + @Test + public void testCardPaymentInWorkingDay() throws Exception { + String id = given() + .contentType(ContentType.JSON) + .body("{}") + .when() + .post("/" + PROCESS_ID) + .then() + .statusCode(201) + .body("id", notNullValue()) + .body("creditCardDetails.cardNumber", is(CARD_NUMBER)) + .body("creditCardDetails.status", is("Bill Due")) + .extract() + .path("id"); + + Thread.sleep(2000); + BusinessCalendar businessCalendar = processConfig.getBusinessCalendar(); + assertThat(businessCalendar).isNotNull(); + long timeDuration = businessCalendar.calculateBusinessTimeAsDuration("1s"); + if (timeDuration > 1000L) { + given() + .when() + .get("/" + PROCESS_ID + "/" + id) + .then() + .statusCode(200) + .body("id", is(id)) + .body("creditCardDetails.cardNumber", is(CARD_NUMBER)) + .body("creditCardDetails.status", is("Bill Due")); + } else { + given() + .when() + .get("/" + PROCESS_ID) + .then() + .statusCode(200) + .body(equalTo("[]")); + } + + } +} \ No newline at end of file