ONSdigital/rm-case-service
This microservice manages cases.
Case Service
This repository contains the Case service. This microservice is a RESTful web service implemented using Spring Boot. It manages cases, where a case represents an expected response from an sample unit such as a business or a household. Every sample unit in the survey sample must have at least one associated case. Each case can have multiple questionnaires associated with it, but it must have at least one. Each questionnaire has a question set and a Unique Access Code (UAC). Interesting things that happen during the life cycle of a case are recorded as case events. Case life cycle transitions are published as JMS messages for interested parties to subscribe to.
Inbound process
- CaseCreation message arrives from the sample service on the pubsub input channel
caseCreationChannel. - This channel is processed by the CaseCreationReceiver class which includes validation fo the message.
- The CaseCreationReceiver calls the CaseService to create the initial case.
- The CaseService then creates a Case Group based on the SampleUnit parent and saves it to the database.
- To do this it has to obtain the survey id, so it calls back to the collection exercise service with the collection
exercise id in order to swap it for a survey id - The CaseService then creates a child case for every SampleUnit child, saving each one to the database as it goes.
- All these child cases are created with a status of SAMPLED_INIT ready for the IAC scheduler.
- Finally, it sends out some case created events to the event publisher.
Outbound Process
- The CaseDistributionScheduler runs on a scheduled job every 0.5 seconds
- It retrieves all cases in SAMPLED_INIT or REPLACEMENT_INIT state
- Once it has a count of these it sends a request to the IAC service to generate IAC codes for these cases
- It then updates all Cases with a generated IAC code (unless one fails in which case its left in the database for the next run)
- Publish an event to the event publisher (unsure what this is for?)
- It adds an IAC case audit record
- Prepares a case notification to inform the action service that a new case is ready.
- The CaseNotificationPublisher publish this to action via pub sub
Improvement Process
As a part of the improvement process the outbound process will be replaced by merging action to case service.
Currently, the improvement is in progress and is feature flag off. As a part of this improvement collection exercise
service will now call /process-event endpoint in case service rather than action service to process the events.
Action Process/ Event Process
- Collection exercise service gives a call to
/process-eventendpoint which is an async call. - Which calls
ProcessCaseActionService. ProcessCaseActionServicethen calls two async services i.e.ProcessEmailActionServiceand
ProcessLetterActionService.ProcessEmailActionServiceandProcessLetterActionServicecalls back collection exercise service with the
collection exercise id in order to swap it for a survey id and then the survey service to confirm the correctness.
The services also calls party service to retried party information required for emails and letters.ProcessEmailActionServicethen usesNotifyEmailServiceto publish PubSub email messages vianotifyEmailChannel.ProcessLetterActionServiceusesUploadObjectGCSto upload the created file to the GCP and then usesNotifyLetterService
to send letter message to PubSub viaprintFileChannel./retry-eventfollows the same process to retry first fail operation for event processing which is trigger by
kubernetes cron job./action-templateis provided to create new action template.
Receipt Process
Cases are receipted by SDX-Gateway via the Case.Responses via the case-receipt-inbound flow for some reason
the inbound channel is always offline. This creates a final case event stating that the response has been received.
Report Scheduling
The ReportScheduler is driven by the report cron expression. It creates a lock on redis to ensure only
one instance can run at any given time. This scheduler executes the CaseReportService which subsequently
runs two stored procedures - generate case event reports and generate response chasing reports. These two
procedures run nightly at 11pm and populate the report table.
This service calls other service rest API
Collection Exercise - get collection exercise - used to obtain the survey id for a specific collection exercise id
IAC service - generates an IAC code for a case. This allows a respondent to enroll into the collection exercise.
Survey Service - to confirm survey associated to the collection exercise for event processing.
Party Service - to gather party information required for letters and emails event.
Micro Service Interactions
This service calls other services via Rabbit:
- action-service - Case.LifecycleEvents (aka case notifications)
The REST API is called by:
- ras-frontstage
- /cases/{case_id}
- /cases/iac/{enrolment_code}
- /cases/partyid/{party_id}
- /cases/{case_id}/events
- /categories
- action-service
- /cases/{caseid}
- /cases/{caseid}/events
- /cases/{caseid}/iac
- /casegroups/{caseGroupId}
- response-operations-ui
- /cases/{case_id}?iac=true
- /cases/{case_id}/events
- /cases/casegroupid/{case_group_id}
- /cases/partyid/{business_party_id}
- /cases/partyid/{business_party_id}
- /cases/{case_id}/iac
- /cases/{case_id}/events
- ras-party
- /cases/iac/{enrolment_code}
- /cases/{case_id}/events
- /cases/casegroupid/{case_group_id}
- /casegroups/partyid/{business_id}
- action-event
/process-event/retry-event/action-template
This service is passed messages from
- collection-exercise via the Case.CaseDelivery
- sdx-gateway via the Case.Responses queue
Improvements
Suggested improvements can be found here:
Improvements
Running
- Run
cp .maven.settings.xml ~/.m2/settings.xml # This only needs to be done once to set up mavens settings file mvn clean install mvn spring-boot:run
Code Styler
To use the code styler please goto this url (https://github.com/google/google-java-format) and follow the Intellij instructions or Eclipse depending on what you use
API
Open API spec can be found here
Integration tests
Use the command 'mvn clean install' this will run the tests in docker.
Note: You may need to a service account and key can be found locally in your environment and use the command
"export GOOGLE_APPLICATION_CREDENTIALS='/[PATH]/[NAME_OF_KEY].json'" (remove the double quotes)
To test
See curlTests.txt under /test/resources
Copyright
Copyright (C) 2017 Crown Copyright (Office for National Statistics)