Skip to content

Latest commit

 

History

History
101 lines (66 loc) · 5.02 KB

File metadata and controls

101 lines (66 loc) · 5.02 KB

code style: prettier

Beacons Registration API

This is a Spring Boot API to enable:

  • 406Mhz beacon owners to register their details with the Maritime & Coastguard Agency
  • Search and rescue Mission Control Centres to retrieve information about beacons during distress signal activations

Dependencies

The following dependencies are required to build and test the application.

Dependency Version
Java 17
Docker Latest
nodejs 22.x

Gradle is the build tool for the application. See the docs for updating the Gradle Wrapper.

Local development

Set the Node environment using nvm use (having installed nvm)

Install node packages (needed for code formatting): npm install

Configuration

  • Create a file in ./src/main/resources called application-dev.yml
  • Fill it with the contents of the 'Beacons service local application-dev.yml' entry in 1Password
    • Copying and pasting this into your new application-dev.yml can sometimes format the configuration incorrectly: please see the existing application.yml file for the pattern to follow
  • In IntelliJ, ensure your run configuration Environment variables include spring_profiles_active=dev. This will enable the IDE to use your new application-dev.yml configuration settings.

The service can be run either locally in your IDE of choice or from the command line by running: ./gradlew bootRun --args='--spring.profiles.active=dev'

Local development instances of the backing services, such as PostgreSQL and OpenSearch, can be initiated with the command docker compose up.

Testing

Configuration for Tests

  • The test project has its own application.yml file containing several sensitive MICROSOFT_GRAPH environment variables
  • These do not have values in the actual file as they are secrets. To ensure these variables have values at runtime, make a .sh file on your machine and fill it with the contents of 'Set Microsoft Graph sensitive values as local Bash env vars' in 1Password.
  • Make sure your environment includes the variables in the .envrc.sample file in the root of this repository.
  • The integration tests need these settings in order to create, update and delete a user in the test Azure AD B2C environment.

Integration tests use the naming convention <name>IntegrationTest. Unit tests use the naming convention <name>UnitTest.

Both unit and integration tests go in src/test/java/uk/gov/mca/beacons/api.

Running tests

Note that the integration tests require Docker to be running on your local development environment.

  • ./gradlew clean test runs unit tests
  • ./gradlew clean integrationTest runs integration tests
  • ./gradlew clean check runs both unit and integration tests

You can run the tests in Intellij for better click through, debugging etc. For the integration tests to work, make sure the run command in the run configuration starts with :integretionTest, not :test.

Style guide

We use Prettier-Java to format our code and use Husky to run the formatting as a pre-commit hook.

Wildcard imports, import java.util.*; should not be used within the application. See GDS Programming Languages guidance on this and how to configure IntelliJ to ensure it does not use wildcard imports.

As well as during the pre-commit hook, the formatter can be run manually with:

$ npm run format

Jobs

Manually adding all beacon registrations to OpenSearch (reindexing)

We use OpenSearch to support advanced querying of beacon registrations. Beacons are streamed into OpenSearch automatically on registration, though if necessary OpenSearch can be manually re-indexed using a job. This will update OpenSearch to the latest version of the data in Postgres.

To trigger the reindexSearch job, access the /admin path of the Backoffice application on the required environment, where you'll see a button to trigger the job.

The progress of the job can then be monitored in the logs.

Database schema diagram

With the Beacons Service API running, execute docker compose up -f docker-compose.schemacrawler.yml. This will create a diagram of the database schema at schemacrawler/beacons-schema.html.