:projectKey: optaweb-employee-rostering
:sonarBadge: image:https://sonarcloud.io/api/project_badges/measure?project={projectKey}
:sonarLink: link="https://sonarcloud.io/dashboard?id={projectKey}"

= Employee Rostering Optimization as a Service

image:https://img.shields.io/badge/stackoverflow-ask_question-orange.svg?logo=stackoverflow&style=for-the-badge["Ask question on Stack Overflow", link="https://stackoverflow.com/questions/tagged/optaweb-employee-rostering"]
image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg?logo=zulip&style=for-the-badge[
"Join Zulip Chat", link="https://kie.zulipchat.com/#narrow/stream/232679-optaplanner"]
image:https://img.shields.io/github/commit-activity/m/kiegroup/optaweb-employee-rostering?label=commits&style=for-the-badge["Commit Activity", link="https://github.com/kiegroup/optaweb-employee-rostering/pulse"]
image:https://img.shields.io/github/license/kiegroup/optaweb-employee-rostering?style=for-the-badge&logo=apache["License", link="https://www.apache.org/licenses/LICENSE-2.0"]
image:https://img.shields.io/badge/JVM-11-green?style=for-the-badge["JVM support", link="https://github.com/dupliaka/optaweb-employee-rostering/actions"]
image:https://img.shields.io/badge/Maven-3.x-blue?style=for-the-badge["Maven",link="https://maven.apache.org/install.html"]

{sonarBadge}&metric=alert_status["Quality Gate Status", {sonarLink}]
{sonarBadge}&metric=reliability_rating["Reliability Rating", {sonarLink}]
{sonarBadge}&metric=security_rating["Security Rating", {sonarLink}]
{sonarBadge}&metric=sqale_rating["Maintainability Rating", {sonarLink}]
{sonarBadge}&metric=ncloc["Lines of Code", {sonarLink}]
{sonarBadge}&metric=coverage["Coverage", {sonarLink}]

An end-to-end https://www.optaplanner.org/[OptaPlanner] web application ready to deploy on https://www.openshift.com/[OpenShift 4].

See https://youtu.be/3CvadujUN1k[the video demo].

== Building

Build the project with maven in the project's root directory:

[source,shell]
----
mvn clean install -DskipTests -DskipITs
----

== Running

Run the application with the `runLocally.sh` script:

[source,shell]
----
./runLocally.sh
----

Then open http://localhost:8080/ to see the web application.

Alternatively, run `npm start` in `optaweb-employee-rostering-frontend` to start the frontend in one terminal,
and run `mvn quarkus:dev` in `optaweb-employee-rostering-backend` to start the backend in another terminal.

=== Use a different port

To run on an another port use `-Dquarkus.http.port=...`:

[source,shell]
----
./runLocally.sh -Dquarkus.http.port=18080
----

== Benchmark Application

After building the project above, run the benchmark application with:

[source,shell]
----
java -jar optaweb-employee-rostering-benchmark/target/quarkus-app/quarkus-run.jar
----

Note: make sure to run the project application and benchmark application on different ports if they are run
simultaneously.

After benchmarking is complete, a benchmark report will be generated in the `local/benchmarkReport` directory.
Open the `index.html` file in your browser to view the benchmark results.

=== Configure the benchmarker

To configure the benchmarker, modify the `employeeRosteringBenchmarkConfig.xml` file found in the
`optaweb-employee-rostering-benchmark/src/main/resources` directory. Make sure to rebuild the project after modifying the
config file for the benchmarker changes to be applied.

Refer to the https://docs.optaplanner.org/latestFinal/optaplanner-docs/html_single/index.html#benchmarker[OptaPlanner
 Docs] for more information on benchmark tweaking.

== Running on a local OpenShift cluster

Use https://developers.redhat.com/products/codeready-containers[Red Hat CodeReady Containers]
to easily set up a single-node OpenShift 4 cluster on your local computer.

.Prerequisites
You have successfully built the project with Maven.

.Procedure
1. To install CRC, follow the https://code-ready.github.io/crc/[Getting Started Guide].

2. When the cluster has started,

a. add oc command-line interface to your `$PATH`:
+
[source,shell]
----
eval $(crc oc-env)
----

b. log in as "developer".

3. Create a new project
+
[source,subs="quotes"]
----
oc new-project _project_name_
----

4. Run the script:
+
[source,shell]
----
./runOnOpenShift.sh
----

=== Updating the deployed application with local changes

==== Backend

Change the source code and build the backend module with Maven.
Then start OpenShift build:

[source,shell]
----
cd optaweb-employee-rostering-backend
oc start-build backend --from-dir=. --follow
----

==== Frontend

Change the source code and build the frontend module with npm.
Then start OpenShift build:

[source,shell]
----
cd optaweb-employee-rostering-frontend
oc start-build frontend --from-dir=docker --follow
----

== Development

=== Code formatter

IntelliJ, Eclipse and VS Code formatters https://github.com/kiegroup/optaplanner/blob/main/build/optaplanner-ide-config/ide-configuration.adoc#ide-setup-instructions[IDE setup instructions].

=== Backend

Configure your IDE to run the main class, which is in
`org.optaweb.employeerostering.OptaWebEmployeeRosteringApplication` in `optaweb-employee-rostering-backend` repository.

=== Frontend

Run `npm install` and then `npm start` in the `optaweb-employee-rostering-frontend` directory. You can run `npm run lint` locally to see all code style issues. You can run `npm run lint:fix` to reformat the code and fix issues without using an IDE.
