An API used by the NOMIS application to sync with the Prisoner Finance Ledger.
It is built using Spring Boot and Kotlin as well as the following technologies for its infrastructure:
- AWS - Services utilise AWS features through Cloud Platform.
- Cloud Platform - Ministry of Justice's (MOJ) cloud hosting platform built on top of AWS which offers numerous tools such as logging, monitoring and alerting for our services.
- Docker - The API is built into docker images which are deployed to our containers.
- Kubernetes - Creates 'pods' to host our environment. Manages auto-scaling, load balancing and networking to our application.
Enable pre-commit hooks for formatting and linting code with the following command;
./gradlew addKtlintFormatGitPreCommitHook addKtlintCheckGitPreCommitHookThe Dockerfile relies on the application being built first. Steps to build the docker image:
- Build the jar files
./gradlew clean assemble- Copy the jar files to the base directory so that the docker build can find them
cp build/libs/*.jar .- Build the docker image with required arguments
docker build --build-arg GIT_REF=21345 --build-arg GIT_BRANCH=bob --build-arg BUILD_NUMBER=$(date '+%Y-%m-%d') .- Run the docker image, setting the auth url so that it starts up
docker run -e HMPPS_AUTH_URL="https://sign-in-dev.hmpps.service.justice.gov.uk/auth" <sha from step 3>The application comes with a local spring profile that includes default settings for running locally.
There is also a docker-compose.yml that can be used to run a local instance in docker and also an
instance of HMPPS Auth.
make servewill build the application and run it and HMPPS Auth within a local docker instance.
To verify the app has started,
- ensure the containers are visible (and running) in Docker, and
- visit http://localhost:8080/health ensuring the result contains "status: UP"
make serve-environmentwill just start a docker instance of HMPPS Auth with a PostgreSQL database. The application should then be started with
a local active profile in Intellij.
make serve-clean-environmentwill also reset the database
This project uses Testcontainers for integration testing.
You do not need to manually start any Docker containers to run the tests. The test suite will automatically spin up a LocalStack container on a random port.
./gradlew check
# or
./gradlew integrationTestSimply run the test class or method.
- If port 4566 is free, Testcontainers will start a managed LocalStack instance.
- If port 4566 is in use the tests will detect this and use your running instance instead.
For details of the current proposed architecture view our C4 documentation
- Build the project
- Go to Run in the main menu.
- Select Manage Coverage Reports
- Add the files in build/jacoco/
- Click OK. The coverage report will now appear in the Coverage Tool Window and the code will be highlighted in the editor.
To visualize the reports in the browser:
- Build the project
- Open the
index.htmlfiles in the folders underbuild/reports/jacoco
Is available on a running local server at http://localhost:8080/swagger-ui/index.html#/
/health: provides information about the application health and its dependencies./info: provides information about the version of deployed application.
DPS event driven architecture requires subscription to queues. To emulate this environment for local development we use LocalStack.
This is included automatically in the docker-compose.yml file on port 4566.
If you wish to run LocalStack in isolation (for example, to support running tests repeatedly), you can use the dedicated compose file:
docker-compose -f docker-compose-localstack.yaml up -d-
Use this command to request a local auth token:
curl -X POST "http://localhost:8090/auth/oauth/token?grant_type=client_credentials" -H 'Content-Type: application/json' -H "Authorization: Basic $(echo -n hmpps-prisoner-finance-sync-api-1:clientsecret | base64)"
-
The response body will contain an access token something like this:
{ "access_token": "eyJhbGciOiJSUzI1NiIsInR5...BAtWD653XpCzn8A", "token_type": "bearer", "expires_in": 3599, "scope": "read write", "sub": "hmpps-prisoner-finance-sync-api-1" } -
Use the value of
access_tokenas a Bearer Token to authenticate when calling the local API endpoints.
We use OpenAPI Generator to automatically generate the Kotlin client and data models for the General Ledger API.
The configuration is in build.gradle.kts under apiSpecs. This creates two tasks:
writeGeneralledgerJson: Downloads the latest API specification from the Dev environment to openapi-specs/generalledger.json.
buildGeneralledgerApiClient: Generates the Kotlin data classes (Models) and WebClient interfaces (API) from the local JSON file.
If the General Ledger API changes:
Download the latest spec:
./gradlew writeGeneralledgerJsonbuild API client:
./gradlew buildGeneralledgerApiClientVerify & Regenerate: Check the diff in openapi-specs/generalledger.json and run a build to ensure the code compiles.
./gradlew clean buildCommit: Commit the updated .json file. Do not commit the generated code in build/.