Skip to content

Commit

Permalink
Merge pull request #434 from informatici/release_1_14_0
Browse files Browse the repository at this point in the history
Merge develop for release 1.14.0
  • Loading branch information
mwithi committed Feb 18, 2024
2 parents 52395e2 + f68d8d3 commit b714550
Show file tree
Hide file tree
Showing 160 changed files with 12,873 additions and 3,405 deletions.
73 changes: 61 additions & 12 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,67 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout core
run: git clone --depth=50 --branch=develop https://github.com/informatici/openhospital-core.git openhospital-core
- name: Install core
run: cd openhospital-core && mvn install -DskipTests=true && cd ..
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Maven
run: mvn -B package --file pom.xml
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
java-package: jdk

- name: Checkout core
run: git clone --depth=50 --branch=develop https://github.com/informatici/openhospital-core.git openhospital-core

- name: Install core
run: cd openhospital-core && mvn install -DskipTests=true && cd ..

- name: Generate JWT Token
id: jwt
run: echo "token=7DlyD1SHR5pCa4HGgTLWSYm8YQ7oRL1wpPbxyjWyHU44vUrqrooRu3lHVFSXWChesc" >> $GITHUB_OUTPUT

- name: Store branch name
id: extract_branch
run: |
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
echo "branch=$(echo ${GITHUB_REF##*/})" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
else
echo "branch=INVALID_EVENT_BRANCH_UNKNOWN" >> $GITHUB_OUTPUT
fi
- name: Build with Maven
run: |
cp rsc/application.properties.dist rsc/application.properties
cp rsc/database.properties.dist rsc/database.properties
cp rsc/log4j.properties.dist rsc/log4j.properties
cp rsc/settings.properties.dist rsc/settings.properties
sed -e "s/JWT_TOKEN_SECRET/${{ steps.jwt.outputs.token }}/g" rsc/application.properties.dist > rsc/application.properties
mvn install -DskipTests=true
echo ${{ steps.extract_branch.outputs.branch }}
- name: Run API
run: |
cd target
java -cp "openhospital-api-0.1.0.jar:rsc/:static/" org.springframework.boot.loader.JarLauncher &
sleep 60
- name: Generate OpenAPI yaml
run: mvn springdoc-openapi:generate -Dspringdoc.outputFileName=oh_rev.yaml

- name: Running OpenAPI Spec breaking action
# run: |
# tenant_id=`curl -d '{"tenant": "oh", "email": "[email protected]"}' https://register.oasdiff.com/tenants | jq -r .id`
# curl -o output -X POST -F base=@openapi/oh.yaml -F revision=@openapi/oh_rev.yaml https://api.oasdiff.com/tenants/${tenant_id}/breaking-changes
# cat output
uses: oasdiff/oasdiff-action/breaking@main
with:
base: openapi/oh.yaml
revision: openapi/oh_rev.yaml
fail-on-diff: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bin
/static
!static/swagger-ui/

#Project related
.env

### STS ###
.apt_generated
Expand Down Expand Up @@ -37,3 +39,4 @@ bin
### VScode ###
.vscode
/deps/
OH_API_PID
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
4 changes: 2 additions & 2 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM maven:3.8-jdk-11
FROM maven:3.9-eclipse-temurin-17

ARG GITHUB_ORG
ARG OH_CORE_BRANCH
Expand All @@ -18,4 +18,4 @@ WORKDIR ./openhospital-api
RUN --mount=type=cache,target=/root/.m2 mvn clean install -DskipTests=true

WORKDIR ./target
CMD java -cp "openhospital-api-0.0.2.jar:rsc/:static/" org.springframework.boot.loader.JarLauncher
CMD java -cp "openhospital-api-0.1.0.jar:rsc/:static/" org.springframework.boot.loader.JarLauncher
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is the API project of [Open Hospital][openhospital]: it exposes a REST API
+ [Using Swagger-UI](#using-swagger-ui)
+ [Using Postman](#using-postman)
* [How to deploy backend in docker environment](#how-to-deploy-backend-in-docker-environment)
* [How to generate openapi specs](#how-to-generate-openapi-specs)
* [Cleaning](#cleaning)
* [How to contribute](#how-to-contribute)
* [Community](#community)
Expand Down Expand Up @@ -48,41 +49,39 @@ For the moment, to build this project you should
5. start openhospital-api (in `target` folder)

# Windows
java -cp "openhospital-api-0.0.2.jar;rsc/;static/" org.springframework.boot.loader.JarLauncher
java -cp "openhospital-api-0.1.0.jar;rsc/;static/" org.springframework.boot.loader.JarLauncher

# Linux
java -cp "openhospital-api-0.0.2.jar:rsc/:static/" org.springframework.boot.loader.JarLauncher
java -cp "openhospital-api-0.1.0.jar:rsc/:static/" org.springframework.boot.loader.JarLauncher
6. call services
- URL base: http:https://localhost:8080
- URL login: http:https://localhost:8080/auth/login
- URL patients: http:https://localhost:8080/patients
- URL swagger: http:https://localhost:8080/swagger-ui/
- URL swagger: http:https://localhost:8080/swagger-ui.html

You can see Swagger Api Documentation at: http:https://localhost:8080/swagger-ui/
You can see Swagger API Documentation at: http:https://localhost:8080/swagger-ui/index.html

![image](https://github.com/informatici/openhospital-api/assets/2938553/ea855a4a-2a57-4b6e-aa62-f218d4937ed8)

![image](https://user-images.githubusercontent.com/2938553/215335720-73d59075-f0df-44c4-93ed-eae79945bb71.png)

### Using Swagger-UI

1. use endpoint /auth/login to login and get the token

![image](https://user-images.githubusercontent.com/2938553/228294801-4d27dd2c-9053-4f62-9497-690706232c9f.png)
![image](https://user-images.githubusercontent.com/2938553/228294867-79d6a326-9e7d-4ca0-93cd-ce34c7b7373f.png)
2. use the Authorize button at the top of the Swagger-UI and paste the token form step #1 prefixed by the string "Bearer " and click Authorize
![image](https://github.com/informatici/openhospital-api/assets/2938553/d77d88a7-893d-4163-a89d-06c0bbdccb4b)
![image](https://github.com/informatici/openhospital-api/assets/2938553/ce1a6ace-b4db-4672-9f36-b6d5aefc005f)

2. use the Authorize button at the top of the Swagger-UI, paste the token from step #1 and click Authorize

![image](https://user-images.githubusercontent.com/2938553/228296149-64905464-441f-4b20-80af-4dcfb40aef4c.png)
![image](https://github.com/informatici/openhospital-api/assets/2938553/388450d5-7b8b-4f54-8210-ef37e5f85324)

3. close the dialog

![image](https://user-images.githubusercontent.com/2938553/228294994-56c1ae3b-f7cb-49b6-94d4-c899fa20374e.png)
![image](https://github.com/informatici/openhospital-api/assets/2938553/787546c1-8378-4aac-99a1-ace2e28af160)

4. now all the endpoints are automatically secured and the token will be added to the request

![image](https://user-images.githubusercontent.com/2938553/228295504-910a6036-4656-4645-8756-3dec0154eed4.png)
![image](https://user-images.githubusercontent.com/2938553/228295166-d1948976-fbdb-4f7e-ab12-8f0621b21373.png)

![image](https://github.com/informatici/openhospital-api/assets/2938553/131aa220-b134-4afc-a508-5e369427c0b8)

### Using Postman

Expand All @@ -95,13 +94,26 @@ Make sure you have docker with docker-compose installed, then run the following
- copy `dotenv` file into `.env` and set variables as needed (the SHA-256 jwt token is needed)
- run `make`
- run `docker compose up -d database` (wait for some seconds the very first time to build the DB)
- (optional - demo data) run `docker compose run --rm oh-database-init`
- (optional - demo data after set the database container) run `docker compose run --rm oh-database-init`
- run `docker compose up backend`

When done successfully, head over at http:https://localhost:[API_PORT]/swagger-ui/

You can change the deployment branch using an .env file.

## How to generate openapi specs

Make sure to have API started without errors.

Run the Maven command and it will overwrite the `openapi/oh.yaml`

mvn springdoc-openapi:generate

To redirect the output to another file, use:

mvn springdoc-openapi:generate -Dspringdoc.outputFileName=my_revision.yaml


## Cleaning

docker compose rm --stop --volumes --force
Expand Down
Loading

0 comments on commit b714550

Please sign in to comment.