https://app.circleci.com/pipelines/github/ministryofjustice/hmpps-tier
- Java JDK 21
- An editor/IDE
- Gradle
- Docker
- OAuth token
Listens to events from Delius, calculates a new offender tier and writes it back into Delius
Integration points:
- tier calculation events from Delius via SQS
- Community-api read
- Assessment-api read
- writes updated tiers to SNS for https://github.com/ministryofjustice/hmpps-tier-to-delius-update to consume
In order to run the service locally you need to add HMPPS auth token to your requests
Make sure you have the necessary Access key and secret set as environment variables. You can do that by running this command before starting the app
eval $(cloud-platform decode-secret -n hmpps-tier-dev -s hmpps-tier-offender-events-sqs-instance-output --export-aws-credentials)
This uses SPRING_PROFILES_ACTIVE=dev which has an in-memory database.
./gradlew bootRun
This will bring up community-api, assessments-api and all the required queues and topics. The seed data will allow a successful tier calculation for CRN X320741. Make sure you have allocated enough memory to Docker to allow it to start all these containers - 2GB may not be enough
docker compose up -d
Run the HmppsTier application with SPRING_PROFILES_ACTIVE=dev,localstack,docker
If you want to write the tier back into community-api, also run hmpps-tier-to-delius-update locally
Localstack has SQS and SNS. The queue and topic are set up and populated in setup-sqs.sh
You can access them from the command line as per the following example
Force a local tier calculation by calling the /calculations
API
curl --json '["A123456"]' 'http://localhost:8080/calculations?dryRun=false'
View the tier calculation complete event:
AWS_ACCESS_KEY_ID=key AWS_SECRET_ACCESS_KEY=secret aws sqs receive-message --queue-url http://localhost:4576/queue/Digital-Prison-Services-dev-hmpps_tier_calculation_complete_queue --endpoint-url=http://localhost:4576
Run lint and test
The integration and cucumber tests need localstack running
docker compose up localstack postgres -d
./gradlew check
This runs tests and generate a coverage report in build/reports/coverage/index.html
You cannot run cucumber tests directly from IntelliJ. See gradle/gradle#4773 Instead run
docker compose up localstack postgres -d
./gradlew cucumber
If you want to run a single feature/scenario, tag it @single and add this to the cucumber task definition in build.gradle.kts
args("--include-tag", "single")
The application is configurable with conventional Spring parameters.
The Spring documentation can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
By default, the application starts on port '8080'. To override, set server.port (e.g. SERVER_PORT=8099 java -jar build/libs/csr-api-<yyyy-mm-dd>.jar
)
The generated documentation for the api can be viewed at http://localhost:8080/swagger-ui.html
/ping
: will respondpong
to all requests. This should be used by dependent systems to check connectivity to
csr-api, rather than calling the/health
endpoint./health
: provides information about the application health and its dependencies. This should only be used
by csr-api health monitoring (e.g. pager duty) and not other systems who wish to find out the
state of csr-api./info
: provides information about the version of deployed application.
curl -X GET http://localhost:8080/info
curl -X GET http://localhost:8080/health
curl -X GET http://localhost:8080/ping