ADORSYS-GIS / ADORSYS-GIS/webank-UserApp
Implement Product Functionality using AOP Filter Chains and Property Bag (Product & Customer Specific)
- Lingua principale
- TypeScript
- Stelle
- 5
- Fork
- 0
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### Description
**Objective:**
To introduce a highly flexible and extensible mechanism for adding product-specific functionality to the core banking system, specifically for the `webank-BankAccount` module. This solution must accommodate **product-specific** and **customer-specific** customizations of business rules and properties, allowing for diverse bank account types without core module modifications.
**Proposed Solution:**
We will implement product functionality using a combination of Aspect-Oriented Programming (AOP) based filter chains and a property bag data model extension. Filter chains will be dynamically loaded and applied based on both the **bank product** and the **customer** context.
**1. AOP-Based Filter Chain for Business Method Interception (Product & Customer Specific):**
* **Concept:** We will use Spring AOP to intercept the execution of business methods within the `webank-BankAccount` module (and potentially other core modules). The filter chain applied will be dynamic, determined at runtime based on the bank product and customer.
* **Filter Chain Handler (Product & Customer Aware):** An AOP Aspect will act as a central handler. This handler will:
* **Infer Bank Product:** From the incoming request context, the handler must be able to reliably infer the **bank product** associated with the operation. This might involve inspecting request parameters, headers, or utilizing a context object established earlier in the request processing pipeline. We need to define a clear strategy for product identification from the request.
* **Determine Customer Context:** Similarly, the handler needs to identify the **customer** associated with the request. This is likely to be available from the security context or session.
* **Load Product & Customer Specific Filter Chain:** Based on the identified **bank product** and **customer**, the handler will load the appropriate filter chain. This implies a multi-level configuration or lookup mechanism. We need a strategy to manage and store these filter chain configurations (see "Filter Chain Configuration and Customization" below).
* **Forward to Filter Chain:** Forward the method invocation to the dynamically loaded filter chain.
* **Filter Chain Implementation:** Each filter chain will be a sequence of individual filter components (likely Spring Beans implementing a defined `Filter` interface).
* **Filter Responsibilities:** Filters within a chain can perform various pre and post-processing tasks specific to the product and potentially customer, such as:
* **Validation:** Product and customer-specific data validation.
* **Authorization:** Product and customer-specific authorization rules.
* **Business Logic:** Applying product and customer-specific business rules and calculations.
* **Auditing:** Product and customer-specific auditing.
* **Data Enrichment/Transformation:** Modifying request or response data based on product and customer logic.
**2. Product-Specific Persistent Properties (Property Bag):**
* **Data Model Extension:** To accommodate product-specific data that needs to be persisted, we will extend the `bank_account` data model with a "property bag" column.
* **Property Bag Type:** This column will be a JSON blob (or similar serialized object type, depending on the database) to store additional properties as key-value pairs.
* **Benefits:**
* **Schema Flexibility:** Avoids database schema changes for each new product type.
* **Simplified Data Model:** Keeps the core `bank_account` table relatively stable.
* **Product Customization:** Allows for storing product-specific configurations and data directly with the account.
* **Implementation Details:**
* We will define a clear structure for the JSON blob to ensure data consistency and facilitate querying (if necessary).
* Spring modules (plugins) for specific product types will be responsible for interpreting and utilizing the properties within the bag.
**3. Exception Handling within the Filter Chain:**
* **Data Model Extension:** We need a robust mechanism to handle exceptions that may occur during filter chain processing.
* **AOP Handler Responsibility:** The AOP filter chain handler will be responsible for catching exceptions thrown by filters within the chain.
* **Exception Handling Strategy:**
* **Centralized Exception Handling:** The handler can implement a centralized exception handling strategy. This could involve:
* Logging the exception with relevant context (product type, customer, filter name, method name).
* Returning a standardized error response to the caller.
* Potentially triggering rollback mechanisms if the operation is transactional.
* **Filter-Specific Exception Handling (Optional):** We could potentially allow individual filters to handle specific exceptions themselves, but a centralized handler is recommended for consistency and control.
**4. Stopping Filter Chain Processing:**
* **Data Model Extension:** Filters need the ability to halt further processing within the chain based on business rules or validation failures.
* **Mechanism:** Filters can signal a "stop" condition by:
* **Returning a specific value:** Filters can return a designated value (e.g., `false`, `null`, or a specific status object) to indicate that processing should stop.
* **Throwing an Exception:** Filters can throw a specific exception type to signal a critical error or a condition that requires immediate termination of the chain.
* **AOP Handler Action:** The AOP filter chain handler will check for the "stop" signal from filters. If a stop is indicated, the handler will:
* Prevent further filters in the chain from being executed.
* Return an appropriate response (e.g., error response, or a specific "stopped" status) back to the original method caller.
**5. Filter Chain Configuration and Customization (Product & Customer Specific):**
* **Configuration Strategy:** We need to define how filter chains are configured and associated with bank products and customers. Possible options include:
* **Configuration Files (e.g., YAML, JSON):** Define filter chains in configuration files, mapping product types and potentially customer identifiers to specific filter chain definitions (list of filter bean names and order).
* **Database Configuration:** Store filter chain configurations in the database, allowing for dynamic updates and management through a UI or API. This offers greater flexibility for customer-specific customizations.
* **Convention-Based Configuration:** Establish naming conventions for filter chains and filters based on product types and customer identifiers. The handler can then dynamically discover and load beans based on these conventions.
* **Customer-Specific Overrides:** We need a mechanism to allow for customer-specific customizations of filter chains. This could involve:
* **Extending Product Filter Chains:** Customer-specific configurations could *extend* the base filter chain defined for a product, adding or modifying filters.
* **Replacing Product Filter Chains:** In more extreme cases, customers might require completely *replacing* the standard product filter chain with their own custom chain.
* **Priority/Precedence:** If both product-level and customer-level configurations exist, we need to define a clear priority or precedence rule to determine the effective filter chain.
**Benefits of this Approach (Product & Customer Specific):**
* **Extensibility & Customization:** Highly flexible and adaptable to diverse product requirements and customer-specific needs.
* **Granular Control:** Allows for fine-grained control over business logic at both the product and customer level.
* **Maintainability & Modularity:** Keeps core logic separate and promotes modular development of product and customer-specific features.
**Next Steps:**
* **Detailed Design (Product & Customer Context):** Elaborate on how bank product and customer context will be inferred from requests. Design the filter chain configuration and customization strategy, considering configuration files, database, or conventions.
* **Implementation (Product & Customer Specific Chains):** Develop the AOP handler to dynamically load filter chains based on product and customer. Implement configuration loading and customization mechanisms.
* **Testing (Customer Specific Configurations):** Thoroughly test customer-specific filter chain overrides and ensure proper precedence rules are enforced.
* **Documentation:** Document how to configure product and customer-specific filter chains and properties.
**Open Questions/Discussion Points:**
* **How to reliably and efficiently infer the bank product and customer context from each request?**
* **What is the best strategy for configuring and storing product and customer-specific filter chains? (Files, DB, Conventions?)**
* **How to manage customer-specific overrides and ensure proper precedence of filter chains?**
* **What specific exception types should filters throw to signal different error conditions or processing stops, considering product and customer context?**
* **How should we manage transactions across potentially complex, customer-specific filter chains?**
* **Performance implications of dynamic filter chain loading and customer-specific configurations?**
### Discussion
_No response_
### Motivation
_No response_
### Details
_No response_
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.