Overview
In a spring application, we usually have three layers and each layer have a different responsibility.
- Web Layer (Controller, Exception handler, Mappers) - receive the request and send the response to the client.
- Service Layer - Business logic
- Repository Layer (Repository Interfaces & custom Repositories) - DB interaction at the lowest level
CPS have four layers of architecture and the 'Persistence Layer' was introduced to have loose coupling with DB. It gives an ability to move to another type of DB with little change.
eyJleHRTcnZJbnRlZ1R5cGUiOiIiLCJnQ2xpZW50SWQiOiIiLCJjcmVhdG9yTmFtZSI6IlJlbnUgS3VtYXJpIiwib3V0cHV0VHlwZSI6ImJsb2NrIiwibGFzdE1vZGlmaWVyTmFtZSI6IlJlbnUgS3VtYXJpIiwibGFuZ3VhZ2UiOiJlbiIsImRpYWdyYW1EaXNwbGF5TmFtZSI6IiIsInNGaWxlSWQiOiIiLCJhdHRJZCI6IjExNzc0NDIyMCIsImRpYWdyYW1OYW1lIjoiTGF5ZXJzIiwiYXNwZWN0IjoiIiwibGlua3MiOiJhdXRvIiwiY2VvTmFtZSI6IlJlZmFjdG9yaW5nIHRvIG1vdmUgYnVzaW5lc3MgbG9naWMgdG8gU2VydmljZSBMYXllciIsInRic3R5bGUiOiJ0b3AiLCJjYW5Db21tZW50IjpmYWxzZSwiZGlhZ3JhbVVybCI6IiIsImNzdkZpbGVVcmwiOiIiLCJib3JkZXIiOnRydWUsIm1heFNjYWxlIjoiMSIsIm93bmluZ1BhZ2VJZCI6MTE3NzQ0MjE4LCJlZGl0YWJsZSI6ZmFsc2UsImNlb0lkIjoxMTc3NDQyNTIsInBhZ2VJZCI6IiIsImxib3giOnRydWUsInNlcnZlckNvbmZpZyI6eyJlbWFpbHByZXZpZXciOiIxIn0sIm9kcml2ZUlkIjoiIiwicmV2aXNpb24iOjIsIm1hY3JvSWQiOiJiMmM0NmJmOC1jY2JjLTQyMTUtYTM5Mi05Nzk5YzhmNmU0MmYiLCJwcmV2aWV3TmFtZSI6IkxheWVycy5wbmciLCJsaWNlbnNlU3RhdHVzIjoiT0siLCJzZXJ2aWNlIjoiIiwiaXNUZW1wbGF0ZSI6IiIsIndpZHRoIjoiNjAwIiwic2ltcGxlVmlld2VyIjpmYWxzZSwibGFzdE1vZGlmaWVkIjoxNjQyNzY3NTI4MDAwLCJleGNlZWRQYWdlV2lkdGgiOmZhbHNlLCJvQ2xpZW50SWQiOiIifQ==
The current implementation of the Persistence Service SPI is provided in 'cps-ri' which is specific to relational DB. If we want to use another type of DB later, the Persistence and Repository layer needs to be re-written. Therefore, to achieve the original intent (use a different DB type later), it is important to keep the business logic in the 'Service' layer and have only database-specific logic in the 'Persistence' layer.
Proposed Refactoring
CPS-core has three Services (Admin, Module & Data) and each is responsible for actions on the domain objects in CPS.
ServiceName | Domain Objects | Supported Operation |
---|
CPSAdminService | Dataspace and Anchor | Create, Delete & Read |
CPSModuleService | Schema-Set | Create, Delete & Read |
CPSDataService | DataNode | Create, Delete & Read & Update |
In the existing implementation, the 'Admin Service' and 'Module Service' have the implementation to delete Data Node which is managed by 'Data Service'. This behaviour is not expected as 'Data Service' is responsible for deleting DataNode and should control how it can be done. The other services should utilize this functionality from DataService wherever required.
In this proposal, the business logic of the 'Delete SchemaSet' and 'Delete Anchor' functionality will be moved to Service Layer and domain-specific services will be used to do any operation of those domain objects.
Delete Anchor
eyJleHRTcnZJbnRlZ1R5cGUiOiIiLCJnQ2xpZW50SWQiOiIiLCJjcmVhdG9yTmFtZSI6IlJlbnUgS3VtYXJpIiwib3V0cHV0VHlwZSI6ImJsb2NrIiwibGFzdE1vZGlmaWVyTmFtZSI6IlJlbnUgS3VtYXJpIiwibGFuZ3VhZ2UiOiJlbiIsImRpYWdyYW1EaXNwbGF5TmFtZSI6IiIsInNGaWxlSWQiOiIiLCJhdHRJZCI6IjExNzc0NDIzNSIsImRpYWdyYW1OYW1lIjoiRXhpc3RpbmcgRGVsZXRlIEFuY2hvciBTZXF1ZW5jZSBEaWFncmFtIiwiYXNwZWN0IjoiIiwibGlua3MiOiJhdXRvIiwiY2VvTmFtZSI6IlJlZmFjdG9yaW5nIHRv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