Skip to content

OPEN-ENT-NG/flashquizz-api

Repository files navigation

À propos de l'application Flashquizz API

  • Licence : AGPL v3 - Copyright Région Nouvelle Aquitaine
  • Propriétaire(s) : CGI
  • Mainteneur(s) : CGI
  • Financeur(s) : Région Nouvelle Aquitaine
  • Description : Module permettant de créer des quizz intéractifs

Introduction

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

Requirements

  • OpenJDK 21+
  • Docker version 20+ (24.0.0 if possible)

Configuration settings.xml

Pour pouvoir utiliser le repository privé de CGI learning hub, il faut ajouter le fichier settings.xml dans le dossier .m2 de votre répertoire utilisateur.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>nexus-snapshots</id>
      <username>${NEXUS_USERNAME}</username>
      <password>${NEXUS_PASSWD}</password>
    </server>
    <server>
      <id>nexus-releases</id>
      <username>${NEXUS_USERNAME}</username>
      <password>${NEXUS_PASSWD}</password>
    </server>
    <server>
      <id>hub-snapshots</id>
      <username>${NEXUS_USERNAME}</username>
      <password>${NEXUS_PASSWD}</password>
    </server>
    <server>
      <id>hub-releases</id>
      <username>${NEXUS_USERNAME}</username>
      <password>${NEXUS_PASSWD}</password>
    </server>
  </servers>
</settings>                                                                                                                                                     

Remplacer les variables ${NEXUS_USERNAME} et ${NEXUS_PASSWD} par vos identifiants de connexion.

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw compile quarkus:dev

NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/ Swagger at http://localhost:8080/api/q/swagger-ui/ (see Authenticate with Swagger)

Authenticate with Swagger

To try the api in swagger you must click on authorize and go to SecurityScheme (OAuth2 ,implicit) with client id only . Enter the client id "console". Login with a user. Close the window and you are connected.

If you want to log out you must clear the cookies and do :

./mvnw clean compile quarkus:dev

You can also authenticate yourself :

# Example
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=flashquizz" \
-d "client_secret=A48tbgcY9VyKxuS5OrhMR1sWl5UJCIzS" \
-d "username=e77e6d72-c7c1-4f51-ba1d-dbaa81abec9d" \
-d "password=password" \
-d "scope=openid" \
-d "grant_type=password" \
"http://localhost:9001/realms/{realmsId}/protocol/openid-connect/token"

Use access_token for Authorize button

Use ENT API

Un Springboard local est nécessaire pour utiliser l'API ENT.

Vous pouvez utiliser le Springboard local pour créer un connecteur en suivant les instructions sur le lien suivant :

Provisioning user ENT with keycloak

Simulation utilisateur ENT dans le keycloak ici :

Configuration générale


Remarques

  • Les propriétés avec le préfixe %dev sont utilisées uniquement dans l'environnement de développement.
  • Les propriétés avec le préfixe %test sont utilisées uniquement dans l'environnement de test.

Keycloak config

# access keycloak admin
admin // admin

# authent user
e77e6d72-c7c1-4f51-ba1d-dbaa81abec9d // password

# si vous utiliez d'autres utilisateurs ENT,
# créer votre propre user en prenant l'user id de l'ENT en username

MAJ config realm.json Keycloak

WIP export with user KO

Pour mettre à jour le realm :

Depuis le container keycloak :

 /opt/keycloak/bin/kc.sh export --dir <import-target> --users realm_file --realm flashquizz

Add Debug for Java with vscode

create a folder .vscode and inside this folder launch.json

You must add

# .vscode/launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [     
        {
            "type": "java",
            "name": "Remote Debug (Attach Quarkus)",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
        },
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
    ]
}
# from vscode UI : Run -> Start Debugging

Debug HTTP Rest

To debug HTTP requests from clients add the following to the application.properties file :

quarkus.rest-client.logging.scope=request-response
quarkus.rest-client.logging.body-limit=1024
quarkus.log.category."request.tracer".level=DEBUG
quarkus.log.category."response.tracer".level=DEBUG
quarkus.log.category."org.apache.http".level=DEBUG
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG

Packaging and running the application

The application can be packaged using:

./mvnw package

It produces the quarkus-run.jar file in the target/quarkus-app/ directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/ directory.

The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar.

If you want to build an über-jar, execute the following command:

./mvnw package -Dquarkus.package.jar.type=uber-jar

The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar.

Creating a native executable

You can create a native executable using:

./mvnw package -Dnative

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:

./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.additional-build-args=-J-Xmx6g,-march=compatibility -Dquarkus.native.native-image-xmx=6G

You can then execute your native executable with: ./target/flashquizz-api-1.0-SNAPSHOT-runner

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.

Provided Code

REST

Easily start your REST Web Services

Related guide section...

Connect to Database

# For host you need to inspect postgres docker
docker inspect <docker_container_id>
# And search in "NetworkSettings" check "IPAddress"
IPAddress: 172.18.0.3


host: 172.18.0.3
user: quarkus
password: quarkus
database: quarkus
port: 5432
docker exec -ti <docker_container_id> psql -U quarkus -d quarkus

# alternative
docker exec -ti <docker_container_id> bash
su postgres
psql -U quarkus -d quarkus

# list schemas
\dn

# list tables in schema
\dt <schema>.*

Add a realm with multitenant

You can create a realm and export the JSON file in Realm Settings > Action > Partial exports

/!\ users are not exported

Add the json file in /config folder

In applications.properties

# applications.properties
%dev.quarkus.keycloak.devservices.realm-path=localdev.json,localhost.json,<your-conf-file>

quarkus.dev-ui.hosts=localdev,localhost,<your-host>

Now your realm is deployed when quarkus is started

Tenant mapper

You can create a map to link your domain and your tenant

In applications.properties

# applications.properties
flashquizz.tenant.mapping=localhost:3000=localhost,localdev:3000=localdev,<domain>=<tenant>

Flyway

Add your different schemas

quarkus.flyway.schemas=localhost,localdev

Open your DEV UI (localhost:8085) and open Datasource in Flyway Panel

If you don't have sql script in config/db/migrations, you can create a new migration file

At start of server, the migration file set up all schemas in database

Debug / Lancement Native

Lancer d'abord le postgres en local

docker-compose up -d

Compiler ensuite le quarkus native et pour l'executer :

./target/flashquizz-api-<version>-runner -Dquarkus.config.locations=src/main/resources/application-native-dev.properties

# shortcut
rm -rf target && ./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.additional-build-args=-J-Xmx6g,-march=compatibility -Dquarkus.native.native-image-xmx=4G && ./target/flashquizz-api-1.0-SNAPSHOT-runner  -Dquarkus.config.locations=src/main/resources/application-native-dev.properties

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages