-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Move Sharing State Transition Logic to the Sharing State Service #513
Feat: Move Sharing State Transition Logic to the Sharing State Service #513
Conversation
b0c119b
to
637bd3d
Compare
53bab1b
to
cc62eac
Compare
@@ -92,6 +91,9 @@ class BusinessPartnerService( | |||
|
|||
saveChangelog(resolutionResults) | |||
|
|||
val partners = resolutionResults.map { it.businessPartner } | |||
sharingStateService.setInitial(partners.map { it.externalId }, BusinessPartnerType.ADDRESS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing this with AddressPersistenceService, would it make sense to call sharingStateService.setSuccess(..)
instead?
But setting which of the 3 BPNs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it via a simple logic to map from business partner types to the relevant BPN.
Later on, we should move from setting BPN and business partner type explicitely in the sharing state and rather inferring it from the business partner stages. But this can only happen after we integrated the L/S/A endpoints to the generic model, made the external identifiers unique and the business partner type optional in the sharing state.
|
||
return page.toDto(page.content.map { | ||
return sharingStatePage.toDto(sharingStatePage.content.map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use .toPageDto { SharingStateDto(...) }
from CommonMappings.kt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, used that mapping instead
|
||
fun setSuccess(externalIdBpnDto: Collection<ExternalIdBpnDto>, businessPartnerType: BusinessPartnerType): Collection<SharingState> { | ||
val sharingStates = getOrCreate(externalIdBpnDto.map { it.externalId }, businessPartnerType) | ||
val externalIdByBpn = externalIdBpnDto.associateBy { it.externalId } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name is confusing.
val externalIdByBpn = externalIdBpnDto.associateBy { it.externalId } | |
val bpnByExternalId = externalIdBpnDto.associateBy { it.externalId }.mapValues { it.value.bpn } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, makes sense
cc62eac
to
08fce18
Compare
Wait until #519 is merged before this should be merged |
08fce18
to
b39f15e
Compare
- moved service logic for handling state transitions from other services to the sharing state service - added validation for logic when passing transition requests - added and adapted tests
b39f15e
to
259e740
Compare
Description
Currently, the sharing state service is somewhat of a glorified repository. It just takes a DTO, maps it to the entity and saves whatever is inside. This means the logic of managing sharing state transitions is left to the invoking services.
The goal of this pull request is to move such sharing state transition logic to the sharing state, by this capsulating responsibitilies between the services better.
In addition I added some validation logic for transitioning to shring states making sure essential information for that state is given. At the same time, information that is irrelevant for the transitioned sharing state is being ignored (such as error information for any other state than Error).
Pre-review checks
Please ensure to do as many of the following checks as possible, before asking for committer review: