Skip to content

Commit

Permalink
fixup! Include DeviceRegistration in DeviceDeploymentStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Whathecode committed Oct 25, 2024
1 parent 570ac77 commit 10da0cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ sealed class DeviceDeploymentStatus
sealed interface HasDeviceRegistration
{
/**
* The registration information of the device, if available.
* The last [DeviceRegistration] for this device.
*/
val deviceRegistration: DeviceRegistration
}


/**
* Device deployment status for when a device has not been registered.
*/
Expand All @@ -77,7 +76,7 @@ sealed class DeviceDeploymentStatus
override val device: AnyDeviceConfiguration,
override val canBeDeployed: Boolean,
override val remainingDevicesToRegisterToObtainDeployment: Set<String>,
override val remainingDevicesToRegisterBeforeDeployment: Set<String>,
override val remainingDevicesToRegisterBeforeDeployment: Set<String>
) : NotDeployed()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class StudyDeployment private constructor(
isRegistered ->
DeviceDeploymentStatus.Registered(
device,
_registeredDevices.getValue(device ),
_registeredDevices.getValue( device ),
canBeDeployed,
toObtainDeployment,
beforeDeployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private val major1Minor0To1Migration =
}
}


private val major1Minor1To3Migration =
@Suppress( "MagicNumber" )
object : ApiMigration( 1, 3 )
Expand All @@ -37,7 +38,7 @@ private val major1Minor1To3Migration =
{
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.GetDeviceDeploymentFor" ->
{
val responseObject = (response.response as? JsonObject)?.migrate {
val responseObject = response.response?.jsonObject?.migrate {
requiredDeviceDisplayName( "registration" )

updateOptionalObject( "connectedDeviceRegistrations" )
Expand All @@ -49,30 +50,20 @@ private val major1Minor1To3Migration =
}
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.CreateStudyDeployment",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.GetStudyDeploymentStatus",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.RegisterDevice",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.UnregisterDevice",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.DeployDevice",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.Stop",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.RegisterDevice" ->
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.DeviceDeployed",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.Stop" ->
{
val responseObject = response.response?.jsonObject?.migrate {
updateArray( "deviceStatusList" ) {
objects {
removeDeviceRegistration()
}
}
removeDeviceRegistration()
}
ApiResponse( responseObject, response.ex )
}
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.GetStudyDeploymentStatusList" ->
{
val responseObject = (response.response as? JsonArray)?.migrate {
objects {
updateArray( "deviceStatusList" ) {
objects {
removeDeviceRegistration()
}
}
}
val responseObject = response.response?.jsonArray?.migrate {
objects { removeDeviceRegistration() }
}
ApiResponse( responseObject, response.ex )
}
Expand All @@ -89,14 +80,18 @@ private val major1Minor1To3Migration =
}

/**
* The `deviceRegistration` field was added to the `DeviceStatus` object.
* Remove the newly added `deviceRegistration` field from `DeviceDeploymentStatus` objects contained within
* `StudyDeploymentStatus`.
*/
private fun ApiJsonObjectMigrationBuilder.removeDeviceRegistration() =
json.remove( "deviceRegistration" )
updateArray( "deviceStatusList" ) {
objects { json.remove( "deviceRegistration" ) }
}

override fun migrateEvent( event: JsonObject ) = event
}


val DeploymentServiceApiMigrator = ApplicationServiceApiMigrator(
DeploymentService.API_VERSION,
DeploymentServiceInvoker,
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/deployments/DeviceDeploymentStatus.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"properties": {
"deviceRegistration": { "$ref": "../common/devices/DeviceRegistration.json" }
},
"required": [ "registration" ]
"required": [ "deviceRegistration" ]
},
"Unregistered": {
"$anchor": "Unregistered",
Expand Down

0 comments on commit 10da0cc

Please sign in to comment.