Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@ONSdigital/census-response-management
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

# What has changed
<!--- What code changes has been made -->
<!--- Has there been any refactoring -->
<!--- What tests have been written -->

# How to test?
<!--- Describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc. -->
<!--- Are there any automated tests that mean changes don't need to be manually changed -->

# Links
<!--- Add any links to issues (trello, github issues) -->
<!--- Links to any documentation -->
<!--- Links to any related PRs -->

# Screenshots (if appropriate):
24 changes: 24 additions & 0 deletions .github/workflows/check-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Label Checker
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled

jobs:

check_labels:
name: Check labels
runs-on: ubuntu-latest
permissions:
pull-requests: read
steps:
- uses: docker://onsdigital/github-pr-label-checker:v1.6.13
with:
one_of: breaking change,feature,patch
none_of: do not merge,work in progress
repo_token: ${{ secrets.GITHUB_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# MegaLinter GitHub Action configuration file
# More info at https://megalinter.io
---
name: MegaLinter

# Trigger mega-linter at every push. Action will also be visible from
# Pull Requests to main
on:
pull_request:
branches:
- main

env:
APPLY_FIXES: none
APPLY_FIXES_EVENT: pull_request

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
megalinter:
name: MegaLinter
runs-on: ubuntu-latest

# Give the default GITHUB_TOKEN write permission to comment the Megalinter output onto pull requests
# and read permission to the codebase
permissions:
contents: read
pull-requests: write

steps:
# Git Checkout
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}

# MegaLinter
- name: MegaLinter

# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors/
uses: oxsecurity/megalinter/flavors/formatters@v8

id: ml

# All available variables are described in documentation
# https://megalinter.io/latest/config-file/
env:
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/*
target/*
*.iml
.java-version
.DS_Store
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM eclipse-temurin:21-jre-alpine

ARG JAR_FILE=census-rm-case-api*.jar
CMD ["/opt/java/openjdk/bin/java", "-jar", "/opt/census-rm-case-api.jar"]

# Create a system group and user without forcing UID/GID
RUN addgroup --system case-api && \
adduser --system --ingroup case-api case-api

USER case-api

COPY target/$JAR_FILE /opt/census-rm-case-api.jar

30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Set the container runtime based on architecture, default to docker for amd64 and podman for arm64
DOCKER ?= $(shell if [ "$$(uname -m)" = "arm64" ]; then echo podman; else echo docker; fi)

install:
CONTAINER_CLI=$(DOCKER) mvn clean install

build: install docker-build

build-no-test: install-no-test docker-build

install-no-test:
CONTAINER_CLI=$(DOCKER) mvn clean install -Dmaven.test.skip=true -Dexec.skip=true -Djacoco.skip=true

format:
mvn spotless:apply

format-check:
mvn spotless:check

check:
mvn spotless:check pmd:check

test:
CONTAINER_CLI=$(DOCKER) mvn clean verify jacoco:report

docker-build:
$(DOCKER) build . --platform linux/amd64 -t census-rm-case-api:latest

rebuild-java-healthcheck:
$(MAKE) -C src/test/resources/java_healthcheck rebuild-java-healthcheck
104 changes: 103 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
# census-rm-case-api
# census-rm-case-api

# Overview
This case api service provides a range of Restful endpoints that -
* Retrieve case details by case id, case ref, UPRN or QID
* Retrieve a QID by case id
* Create and return a new Uac Qid Link

The service relies on, and makes no changes to the case schema maintained by census-rm-ddl

# Endpoints
## Case details:

* `GET /cases/uprn/<uprn>` (returns a list)
* `GET /cases/<case_id>`
* `GET /cases/qid/<qid>`
* `GET /cases/ref/<reference>`
* `GET /cases/case-details/<caseId>`
* `GET /cases/postcode/<postcode>`



All below endpoints include an optional `caseevents` boolean query parameter (default = "false"), that can be used to specify that the JSON response includes an array of associated case events. For example:
* `GET /cases/uprn/<uprn>?caseevnets=true`
* `GET /cases/<case_id>?caseevents=true`
* `GET /cases/ref/<reference>?caseevents=true`

If this query parameter is omitted these case events **will not** be returned with the case details.

### Example Case JSON Response
```json
{
"abpCode": "RD06",
"addressLevel": "U",
"addressLine1": "Flat 53 Francombe House",
"addressLine2": "Commercial Road",
"addressLine3": "",
"caseEvents": [],
"caseRef": "31283399",
"addressType": "HH",
"collectionExerciseId": "77c26716-5936-43e8-b56b-f5ca71765603",
"createdDateTime": "2019-10-25T08:34:34.680556Z",
"estabType": "Household",
"id": "040f4608-d054-4ae9-b12f-1eee7e0fa284",
"lad": "E06000023",
"latitude": "51.4463421",
"longitude": "-2.5924477",
"lsoa": "E01014542",
"msoa": "E02003043",
"oa": "E00073438",
"organisationName": "",
"postcode": "XX1 0XX",
"region": "E12000009",
"surveyType": "CENSUS",
"townName": "Windleybury",
"uprn": "10008677190",
"estabUprn": "103434302134"
}
```
## QID Get and Update:
* `GET /qids/<qid>`
* `PUT /qids/link`
### Example QIDs JSON Request
```json
{
"transactionId": "040f4608-d054-4ae9-b12f-1eee7e0fa395",
"channel": "RM",
"qidLink": {
"questionnaireId" : "Q123",
"caseId": "040f4608-d054-4ae9-b12f-1eee7e0fa173"
}
}
```

# Configuration

By default settings in src/main/resources/application.yml are used to configure [census-rm-case-api](https://github.com/ONSdigital/census-rm-case-api)

For production the configuration is overridden by the K8S apply script

# How to run
The service requires several other services to be running started from census-rm-docker-dev

# How to debug census-rm-case-api locally

## Running as a docker image
* Start census-rm-docker-dev services with the following line in section caseapi | environment in rm-services.yml
* - JAVA_OPTS=-Xmx512m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8162
* In IntelliJ, create a "Remote" configuration, set port = 8162 and run in debug mode

## Running inside IntelliJ
* Stop the census-rm-case-api service if already running
* In IntelliJ, create a SpringBoot Run configuration and run in debug mode

# Testing
## In isolation
From the project root directory, run "mvn clean install", this -
* Runs all unit tests
* Builds a new local docker image
* Brings up this image with all required services and runs all integration tests

## With Acceptance Tests
* From census-rm-acceptance-tests, run "make test"
4 changes: 4 additions & 0 deletions exclude-pmd.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO: as a team, define our own custom PMD checker so that we don't have to keep adding piecemeal
# to this file

config.uk.gov.ons.census.caseapisvc.AppConfig=AccessorMethodGeneration
1 change: 1 addition & 0 deletions healhtcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find /tmp/case-api-healthy -mmin -1 | egrep '.*'
Loading