Skip to content

Commit

Permalink
CORE-18390: Allow old version of SetOwnRegistrationStatus in the comm…
Browse files Browse the repository at this point in the history
…and (corda#5114) (corda#5124)

* CORE-18357: Allow old version of SetOwnRegistrationStatus in the command

* Set to the correct version

Co-authored-by: Yiftach Kaplan <[email protected]>
Co-authored-by: Yiftach Kaplan <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2023
1 parent 8fa6856 commit 232c1a9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package net.corda.membership.impl.registration.dynamic.handler.member

import net.corda.data.identity.HoldingIdentity
import net.corda.data.membership.command.registration.member.PersistMemberRegistrationState
import net.corda.data.membership.common.RegistrationStatus as RegistrationStatusV1
import net.corda.data.membership.common.v2.RegistrationStatus as RegistrationStatusV2
import net.corda.data.membership.p2p.SetOwnRegistrationStatus as SetOwnRegistrationStatusV1
import net.corda.data.membership.p2p.v2.SetOwnRegistrationStatus as SetOwnRegistrationStatusV2
import net.corda.data.membership.state.RegistrationState
import net.corda.membership.impl.registration.dynamic.handler.RegistrationHandler
import net.corda.membership.impl.registration.dynamic.handler.RegistrationHandlerResult
Expand All @@ -17,11 +21,12 @@ internal class PersistMemberRegistrationStateHandler(
command: PersistMemberRegistrationState,
): RegistrationHandlerResult {
val member = command.member.toCorda()
val request = command.request()
val commands = membershipPersistenceClient.setRegistrationRequestStatus(
member,
command.setStatusRequest.registrationId,
command.setStatusRequest.newStatus,
command.setStatusRequest.reason
request.registrationId,
request.newStatus,
request.reason
).createAsyncCommands()
return RegistrationHandlerResult(
null,
Expand All @@ -35,4 +40,34 @@ internal class PersistMemberRegistrationStateHandler(
state: RegistrationState?,
command: PersistMemberRegistrationState
): HoldingIdentity = command.member

private fun PersistMemberRegistrationState.request(): SetOwnRegistrationStatusV2 {
val request = this.setStatusRequest
return when (request) {
is SetOwnRegistrationStatusV2 -> request
is SetOwnRegistrationStatusV1 -> SetOwnRegistrationStatusV2(
request.registrationId,
request.newStatus.toV2(),
null
)
else -> throw IllegalArgumentException("Unknown request status '${request.javaClass}' received.")
}
}

private fun RegistrationStatusV1.toV2(): RegistrationStatusV2 {
return when(this) {
RegistrationStatusV1.NEW -> RegistrationStatusV2.NEW
RegistrationStatusV1.SENT_TO_MGM -> RegistrationStatusV2.SENT_TO_MGM
RegistrationStatusV1.RECEIVED_BY_MGM -> RegistrationStatusV2.RECEIVED_BY_MGM
RegistrationStatusV1.PENDING_MEMBER_VERIFICATION -> RegistrationStatusV2.PENDING_MEMBER_VERIFICATION
RegistrationStatusV1.PENDING_MANUAL_APPROVAL -> RegistrationStatusV2.PENDING_MANUAL_APPROVAL
RegistrationStatusV1.PENDING_AUTO_APPROVAL -> RegistrationStatusV2.PENDING_AUTO_APPROVAL
RegistrationStatusV1.APPROVED -> RegistrationStatusV2.APPROVED
RegistrationStatusV1.DECLINED -> RegistrationStatusV2.DECLINED
RegistrationStatusV1.INVALID -> RegistrationStatusV2.INVALID
RegistrationStatusV1.FAILED -> RegistrationStatusV2.FAILED
else -> throw IllegalArgumentException("Unknown status '${this.name}' received.")
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ class PersistMemberRegistrationStateHandlerTest {
} doReturn operation
}
private val reason = "some reason"
val command = PersistMemberRegistrationState(
private val request = SetOwnRegistrationStatus(
UUID(1,2).toString(),
RegistrationStatus.DECLINED,
reason
)
private val command = PersistMemberRegistrationState(
HoldingIdentity("O=Alice, L=London, C=GB", "GroupId"),
SetOwnRegistrationStatus(
UUID(1,2).toString(),
RegistrationStatus.DECLINED,
reason
)
request
)

private val handler = PersistMemberRegistrationStateHandler(
Expand All @@ -66,8 +67,8 @@ class PersistMemberRegistrationStateHandlerTest {

verify(membershipPersistenceClient).setRegistrationRequestStatus(
command.member.toCorda(),
command.setStatusRequest.registrationId,
command.setStatusRequest.newStatus,
request.registrationId,
request.newStatus,
reason
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ commonsTextVersion = 1.10.0
bouncycastleVersion=1.76
# Corda API libs revision (change in 4th digit indicates a breaking change)
# Change to 5.2.0.xx-SNAPSHOT to pick up maven local published copy
cordaApiVersion=5.2.0.2-beta+
cordaApiVersion=5.2.0.3-beta+

disruptorVersion=3.4.4
felixConfigAdminVersion=1.9.26
Expand Down

0 comments on commit 232c1a9

Please sign in to comment.