Loading…
Loading…
Manages the persistence of service mappings from DataPower instances. Explains how to create, read, update, and delete service-to-backend mappings.
The DataPowerMappingRepository is a data access component responsible for managing the persistence of service mappings discovered on DataPower gateway instances. It provides a durable storage layer for DataPowerServiceMapRecord objects, which represent the link between a public-facing service endpoint and its corresponding backend implementation.
This repository is used by internal administrative services to store, retrieve, and query the inventory of services proxied by DataPower. Its primary function is to translate service discovery data into a structured, queryable format in the platform's database.
All data access is strictly partitioned by tenant. Operations performed through this repository are automatically scoped to the caller's tenant, ensuring that one tenant cannot read, modify, or delete the mappings of another.
The repository uses a JdbcTemplate to execute SQL statements against the s2r_datapower_service_map database table. It provides methods for atomic replacement of mappings, targeted deletions, and various query patterns.
Mappings are managed using a "delete-then-insert" pattern for transactional consistency.
replaceMappings: To update all mappings for a given DataPower instance, this method first deletes all existing records associated with that instanceId and then performs a batch insert of the new DataPowerServiceMapRecord objects.replaceMappingsForDomain: This method provides a more granular update, scoping the delete-and-insert operation to a specific domain within a DataPower instance.The following diagram illustrates the sequence for replacing all mappings for an instance:
sequenceDiagram
participant Caller
participant Repo as DataPowerMappingRepository
participant DB as Database
Caller->>+Repo: replaceMappings(instanceId, mappings, actor)
Repo->>DB: DELETE FROM s2r_datapower_service_map WHERE datapower_instance_id = ?
DB-->>Repo: Acknowledge delete
alt mappings is not empty
Repo->>Repo: Prepare batch INSERT arguments
Repo->>DB: batchUpdate(INSERT INTO s2r_datapower_service_map ...)
DB-->>Repo: Acknowledge insert
end
Repo-->>-Caller: voidWhen inserting records, the tenant_id is automatically populated from the current session context, and the raw_summary map is serialized into a JSONB database column.
The repository supports several deletion patterns:
deleteByInstanceId removes all mappings for a specific DataPower instance.replaceMappingsForDomain implicitly deletes by domain before inserting new records.deleteByInstanceIdAndDomainNamesNotIn removes mappings for any domains within an instance that are not in a provided list of domain names to keep. This is useful for pruning stale domains after a discovery sync.CAUTION
If an empty collection of domain names is passed to deleteByInstanceIdAndDomainNamesNotIn, the method will delete all mappings for the specified instanceId.
The repository provides several query methods to retrieve mappings:
findByInstanceId: Fetches all raw DataPowerServiceMapRecord objects for a given instance.listForDisplay: Retrieves a formatted list of mappings for display, joining with the s2r_datapower_instance table to include the instance name. It can be filtered by a specific instance ID.findAllEnabledMappings: Returns all mappings from all DataPower instances that are marked as enabled.findEnabledMappingsByServiceUris: Finds all enabled mappings that match a given set of service URIs. This method includes special logic to handle WCF service URI conventions: for each URI provided, it also searches for a variant with or without a .svc suffix. For example, a query for /MyService will also match /MyService.svc, and vice-versa. All URI comparisons are case-insensitive.findDistinctMappingsForServiceUri: Groups mappings by a service URI to find all unique backend addresses associated with it.All SQL queries executed by this repository are augmented with a clause that filters by the current tenant ID. This is a fundamental security mechanism that enforces data isolation between tenants at the database level, preventing any cross-tenant data access.
flowchart TD
subgraph "API Platform"
A[API Caller] --> B{Admin Service};
B --> C[DataPowerMappingRepository];
end
subgraph "Repository Logic"
C -- "e.g., findByInstanceId(instanceId)" --> D{Build SQL Query};
D -- "SELECT ... WHERE datapower_instance_id = ?" --> E[Append Tenant Scope];
E -- "SELECT ... WHERE ... and tenant_id = '...'" --> F[Execute via JDBC];
end
subgraph "Database"
F --> G[(s2r_datapower_service_map)];
G -- "Returns only rows for current tenant" --> F;
end
F --> C;
C -- "Returns tenant-scoped results" --> B;
B --> A;The DataPowerMappingRepository exposes the following public methods for managing service mappings.
| Method | Description |
|---|---|
replaceMappings(instanceId, mappings, actor) | Atomically replaces all mappings for a datapower_instance_id. First deletes all existing mappings for the instance, then batch-inserts the new ones. |
deleteByInstanceId(instanceId) | Deletes all mappings associated with a datapower_instance_id. |
replaceMappingsForDomain(instanceId, domainName, mappings, actor) | Atomically replaces mappings for a specific domain_name within a datapower_instance_id. Deletes existing mappings for the domain, then batch-inserts the new ones. |
deleteByInstanceIdAndDomainNamesNotIn(instanceId, domainNames) | Deletes all mappings for an instance whose domain_name is not in the provided collection. If the domainNames collection is empty, all mappings for the instance are deleted. |
findByInstanceId(instanceId) | Retrieves a list of all DataPowerServiceMapRecord objects for a given datapower_instance_id. |
findDistinctMappingsForServiceUri(serviceUri) | Finds distinct backend mappings for a given service_uri. The search is case-insensitive. Returns a list of maps, each representing a unique backend. |
listForDisplay(instanceId) | Retrieves a list of mappings formatted for display. Joins with instance data to include instance_name. If instanceId is null, it lists mappings for all instances within the tenant. |
findEnabledMappingsByServiceUris(serviceUris) | Finds all mappings from enabled instances that match one of the provided service_uri values. The search is case-insensitive and also checks for .svc variants of each URI. |
findAllEnabledMappings() | Retrieves all mappings from all enabled DataPower instances within the tenant. |
DataPowerServiceMapRecordThe s2r_datapower_service_map table stores records with the following fields. These correspond to the properties of the DataPowerServiceMapRecord object.
| Field | Type | Required | Description |
|---|---|---|---|
id | UUID | Yes | The primary key for the mapping record. |
tenant_id | UUID | Yes | The tenant that owns this record. Set automatically by the database on insert. |
datapower_instance_id | UUID | Yes | The foreign key to the s2r_datapower_instance this mapping belongs to. |
domain_name | String | Yes | The name of the DataPower domain where the service object is defined. |
object_name | String | Yes | The name of the service object in DataPower (e.g., "MyWebServiceProxy"). |
object_type | String | Yes | The type of the service object (e.g., "Web Service Proxy"). |
endpoint_rewrite_policy | String | No | The name of the endpoint rewrite policy, if any, applied to the service. |
service_uri | String | No | The public-facing URI for the service. |
frontend_url | String | No | The full frontend URL where the service is exposed. |
backend_address | String | No | The full backend address, including host and port. |
backend_host | String | No | The hostname or IP address of the backend service. |
backend_port | Integer | No | The port number of the backend service. |
backend_uri | String | No | The URI path on the backend service. |
wsdl_url | String | No | The full URL to the backend WSDL document. |
wsdl_host | String | No | The hostname or IP address of the WSDL endpoint. |
wsdl_port | Integer | No | The port number of the WSDL endpoint. |
wsdl_uri | String | No | The URI path for the WSDL document. |
route_mode | String | No | The routing mode of the service (e.g., "passthrough"). |
raw_summary | Map<String, Object> | Yes | A JSONB field containing additional, unstructured metadata from the discovery process. Defaults to {}. |
created_at | OffsetDateTime | Yes | Timestamp when the record was created. Set automatically by the database. |
updated_at | OffsetDateTime | Yes | Timestamp when the record was last updated. Set automatically by the database. |
updated_by | String | Yes | Identifier for the user or process that last updated the record. Defaults to "system" if not provided. |
When inserting or updating mappings, the raw_summary field (a Map) is serialized to a JSON string.
replaceMappings or replaceMappingsForDomain fails with an IllegalArgumentException and the message "failed to serialize DataPower mapping".raw_summary map contains an object that cannot be serialized to JSON by the underlying ObjectMapper.raw_summary map are JSON-serializable types.When retrieving mappings, the raw_summary JSON from the database is parsed back into a Map.
rawSummary field of a returned DataPowerServiceMapRecord or map is empty ({}), even though the underlying database record contains data in the raw_summary column.parseMap method catches the parsing exception and returns an empty map to prevent query failure.raw_summary column in the s2r_datapower_service_map table for the affected record to identify and correct the invalid JSON.