Indexation Feature Documentation
Overview
The indexation feature allows for the dynamic adjustment of rental prices based on changes in the Insee Index. This process involves updating rental contracts with new rent values as the index changes. Below is a detailed breakdown of the components involved and the flow of data.
Components
Database
- Indexes Collection: Stores the Insee Indexes values.
- Contracts Collection: Contains contracts with fields such as
rentAmountsandnextExpectedIndexKey.
Messaging
- MongoDB Trigger: Listens for changes in the
Indexescollection and sends a message to the AWS SQS queue when a new index is published.
Services
- adb-contracts: Processes messages from the SQS queue and updates rental contracts based on the new index values.
Process Flow
- Index Publication: A new index is published to the
Indexescollection in theadb-utilitiesdatabase. - Trigger Activation: A MongoDB trigger detects the new index and sends a message to an AWS SQS queue.
- Message Processing: The
adb-contractsservice processes the message, finds rental contracts that need updating, and calculates the new rent values. - Contract Update: The
adb-contractsservice updates therentAmounts,indexes,nextExpectedIndexKey,nextExpectedRentReviewDatefield in the relevant rental contracts.
Detailed Description
Database Level
Indexes Collection
- New indexes are added to this collection. The
effectiveDatedetermines when the index becomes active.
- New indexes are added to this collection. The
Contracts Collection
- Fields:
rentAmounts,nextExpectedIndexKey, rentAmountsis an array that stores the base rental value and additional fees.nextExpectedIndexKeyindicates which index the contract is expecting next.
- Fields:
Messaging (Trigger and Queue)
MongoDB Trigger
- Monitors the
Indexescollection for new entries. - On detecting a new index, the trigger sends a notification to an AWS SQS queue.
- Monitors the
AWS SQS Queue
- Receives messages from the MongoDB trigger.
- Messages contain details about the new index (e.g.,
indexValue,effectiveDate).
Services (adb-contracts)
Index Processing
- The
adb-contractsservice listens to the AWS SQS queue for new messages. - On receiving a message, it identifies rental contracts with
nextExpectedIndexKeymatching the new index.
- The
Rent Calculation
- For each identified contract, the service determines the qualifier of the new Index (CURRENT or FUTURE).
- The service calculates the new rent value based on the difference between the current and new index values.
- The new rent value is appended to the
rentAmountsarray in the contract.
Gherkin Features
Feature: Indexation of Rental Contracts
Scenario: Publish a new index
Given a new index is published to the "Indexes Collection" in the "adb-utilities" database
When the MongoDB trigger detects the new index
Then a message is sent to the AWS SQS queue with details about the new index
Scenario: Process new index message
Given the "adb-contracts" service listens to the AWS SQS queue for new messages
When a message about the new index is received
Then the "adb-contracts" service identifies rental contracts with "nextExpectedIndexKey" matching the new index
Scenario: Determine index qualifier
Given the "adb-contracts" service identifies rental contracts with "nextExpectedIndexKey" matching the new index
When the new index is processed
Then the qualifier of the new index is determined for the identified contracts
And the qualifier can be either "CURRENT" or "FUTURE"
Scenario: Calculate new rent value
Given the qualifier of the new index is "CURRENT"
When the "adb-contracts" service calculates the new rent value based on the difference between the current and new index values
Then the new rent value is appended to the "rentAmounts" array in the relevant rental contracts
Scenario: Update rental contracts
Given the "adb-contracts" service has calculated the new rent value
When the new rent value is appended to the "rentAmounts" array in the relevant rental contracts
Then the rental contracts are updated with the new rent values
PlantUML Diagrams
Sequence Diagram
