Skip to content
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

488 include deviceregistration in devicedeploymentstatus #489

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface ClientRepositoryTest
Clock.System.now(),
deploymentId,
listOf(
DeviceDeploymentStatus.Registered( primaryDevice, true, emptySet(), emptySet() )
DeviceDeploymentStatus.Registered( primaryDevice, registration, true, emptySet(), emptySet() )
),
emptyList(),
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class StudyTest
listOf(
DeviceDeploymentStatus.Registered(
smartphone,
primaryDeviceDeployment.registration,
true,
emptySet(),
connectedDevices.map { it.roleName }.toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package dk.cachet.carp.deployments.application

import dk.cachet.carp.common.application.devices.AnyDeviceConfiguration
import dk.cachet.carp.common.application.devices.DeviceRegistration
import kotlinx.serialization.*
import kotlin.js.JsExport

Expand Down Expand Up @@ -56,6 +57,16 @@ sealed class DeviceDeploymentStatus
abstract val remainingDevicesToRegisterBeforeDeployment: Set<String>
}

/**
* A device deployment status which indicates the device has been registered.
*/
sealed interface HasDeviceRegistration
{
/**
* The last [DeviceRegistration] for this device.
*/
val deviceRegistration: DeviceRegistration
}

/**
* Device deployment status for when a device has not been registered.
Expand All @@ -74,18 +85,20 @@ sealed class DeviceDeploymentStatus
@Serializable
data class Registered(
override val device: AnyDeviceConfiguration,
override val deviceRegistration: DeviceRegistration,
override val canBeDeployed: Boolean,
override val remainingDevicesToRegisterToObtainDeployment: Set<String>,
override val remainingDevicesToRegisterBeforeDeployment: Set<String>
) : NotDeployed()
) : NotDeployed(), HasDeviceRegistration

/**
* Device deployment status when the device has retrieved its [PrimaryDeviceDeployment] and was able to load all the necessary plugins to execute the study.
*/
@Serializable
data class Deployed(
override val device: AnyDeviceConfiguration
) : DeviceDeploymentStatus()
override val device: AnyDeviceConfiguration,
override val deviceRegistration: DeviceRegistration
) : DeviceDeploymentStatus(), HasDeviceRegistration
{
// All devices that have been deployed necessarily can be deployed.
override val canBeDeployed = true
Expand All @@ -97,9 +110,10 @@ sealed class DeviceDeploymentStatus
@Serializable
data class NeedsRedeployment(
override val device: AnyDeviceConfiguration,
override val deviceRegistration: DeviceRegistration,
override val remainingDevicesToRegisterToObtainDeployment: Set<String>,
override val remainingDevicesToRegisterBeforeDeployment: Set<String>
) : NotDeployed()
) : NotDeployed(), HasDeviceRegistration
{
// All devices that have been deployed necessarily can be deployed.
override val canBeDeployed = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,25 @@ class StudyDeployment private constructor(
return when
{
needsRedeployment ->
DeviceDeploymentStatus.NeedsRedeployment( device, toObtainDeployment, beforeDeployment )
DeviceDeploymentStatus.NeedsRedeployment(
device,
_registeredDevices.getValue( device ),
toObtainDeployment,
beforeDeployment
)
isDeployed ->
DeviceDeploymentStatus.Deployed( device )
DeviceDeploymentStatus.Deployed(
device,
_registeredDevices.getValue( device )
)
isRegistered ->
DeviceDeploymentStatus.Registered( device, canBeDeployed, toObtainDeployment, beforeDeployment )
DeviceDeploymentStatus.Registered(
device,
_registeredDevices.getValue( device ),
canBeDeployed,
toObtainDeployment,
beforeDeployment
)
else ->
DeviceDeploymentStatus.Unregistered( device, canBeDeployed, toObtainDeployment, beforeDeployment )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,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 @@ -48,6 +48,25 @@ private val major1Minor1To3Migration =
}
ApiResponse( responseObject, response.ex )
}
"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.DeviceDeployed",
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.Stop" ->
{
val responseObject = response.response?.jsonObject?.migrate {
removeDeviceRegistration()
}
ApiResponse( responseObject, response.ex )
}
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.GetStudyDeploymentStatusList" ->
{
val responseObject = response.response?.jsonArray?.migrate {
objects { removeDeviceRegistration() }
}
ApiResponse( responseObject, response.ex )
}
else -> response
}

Expand All @@ -60,6 +79,15 @@ private val major1Minor1To3Migration =
json.getOrPut( "deviceDisplayName" ) { JsonNull }
}

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

override fun migrateEvent( event: JsonObject ) = event
}

Expand Down
Loading
Loading