Skip to content

Commit

Permalink
Make deviceDisplayName optional in DeviceRegistration
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchen233 committed Oct 11, 2024
1 parent df5affe commit 53363f8
Show file tree
Hide file tree
Showing 26 changed files with 4,043 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ data class AltBeaconDeviceRegistration(
* This value is constrained from -127 to 0.
*/
val referenceRssi: Short,
@Required
override val deviceDisplayName: String? = null, // TODO: We could map known manufacturerId's to display names.
override val additionalSpecifications: ApplicationData? = null
) : DeviceRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import kotlin.js.JsExport
@JsExport
data class BLESerialNumberDeviceRegistration(
val serialNumber: String,
@Required
override val deviceDisplayName: String? = null,
override val additionalSpecifications: ApplicationData? = null
) : DeviceRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import kotlin.js.JsExport
@Serializable
@JsExport
data class DefaultDeviceRegistration(
@Required
override val deviceDisplayName: String? = null,
override val additionalSpecifications: ApplicationData? = null,
@Required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ abstract class DeviceRegistration
* An optional concise textual representation for display purposes describing the key specifications of the device.
* E.g., device manufacturer, name, and operating system version.
*/
@Required
abstract val deviceDisplayName: String?

@Required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlin.js.JsExport
@JsExport
data class MACAddressDeviceRegistration(
val macAddress: MACAddress,
@Required
override val deviceDisplayName: String? = null,
override val additionalSpecifications: ApplicationData? = null
) : DeviceRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ data class WebsiteDeviceRegistration(
* The HTTP User-Agent header of the user agent which made the HTTP request to [url].
*/
val userAgent: String,
@Required
override val deviceDisplayName: String? = userAgent,
override val additionalSpecifications: ApplicationData? = null
) : DeviceRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ data class CustomDeviceRegistration internal constructor(
@Serializable
private data class BaseMembers(
override val deviceId: String,
override val deviceDisplayName: String?,
override val deviceDisplayName: String? = null,
override val additionalSpecifications: ApplicationData? = null
) : DeviceRegistration()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.serialization.*
*/
interface DeploymentService : ApplicationService<DeploymentService, DeploymentService.Event>
{
companion object { val API_VERSION = ApiVersion( 1, 1 ) }
companion object { val API_VERSION = ApiVersion( 1, 3 ) }

@Serializable
sealed class Event( override val aggregateId: String? ) : IntegrationEvent<DeploymentService>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package dk.cachet.carp.deployments.infrastructure.versioning

import dk.cachet.carp.common.application.services.ApiVersion
import dk.cachet.carp.common.infrastructure.versioning.ApiResponse
import dk.cachet.carp.common.infrastructure.versioning.*
import dk.cachet.carp.common.infrastructure.versioning.ApplicationServiceApiMigrator
import dk.cachet.carp.common.infrastructure.versioning.Major1Minor0To1Migration
import dk.cachet.carp.deployments.application.DeploymentService
import dk.cachet.carp.deployments.infrastructure.DeploymentServiceInvoker
import dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.*


private val major1Minor0To1Migration =
Expand All @@ -28,11 +28,58 @@ private val major1Minor0To1Migration =
}
}

/**
* - The `deviceDisplayName` field in `DeviceRegistration` is no longer required.
* This also apply to `ConnectedDeviceRegistration`.
*/
@Suppress( "MagicNumber" )
private val major1Minor1To3Migration =
object : ApiMigration( 1, 3 )
{
private val removedField = "deviceDisplayName"

@OptIn( ExperimentalSerializationApi::class )
protected fun ApiJsonObjectMigrationBuilder.addDisplayNameField( fieldName: String )
{
updateObject( fieldName ) {
json[ removedField ] ?: json.put( removedField, JsonPrimitive(null ) )
}
}

override fun migrateRequest( request: JsonObject ) = request

override fun migrateResponse( request: JsonObject, response: ApiResponse, targetVersion: ApiVersion ) =
when ( request.getType( ) )
{
"dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.GetDeviceDeploymentFor" ->
{
val responseObject = (response.response as? JsonObject)?.migrate {
addDisplayNameField( "registration" )

val connectedDevices = json[ "connectedDeviceRegistrations" ]?.jsonObject

if ( connectedDevices != null )
{
updateObject( "connectedDeviceRegistrations" )
{
for ( ( key ) in connectedDevices.entries )
{
addDisplayNameField( key )
}
}
}
}
ApiResponse( responseObject, response.ex )
}
else -> response
}
override fun migrateEvent( event: JsonObject ) = event
}

val DeploymentServiceApiMigrator = ApplicationServiceApiMigrator(
DeploymentService.API_VERSION,
DeploymentServiceInvoker,
DeploymentServiceRequest.Serializer,
DeploymentService.Event.serializer(),
listOf( major1Minor0To1Migration )
listOf( major1Minor0To1Migration, major1Minor1To3Migration )
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
[
{
"outcome": "Succeeded",
"request": {
"__type": "dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.CreateStudyDeployment",
"apiVersion": "1.3",
"id": "6a4ff16c-cafc-4392-836a-503fe0b81127",
"protocol": {
"id": "e55bf62d-56e1-4596-ad12-4868475d5398",
"createdOn": "2024-10-09T08:17:33.762380Z",
"version": 0,
"ownerId": "27879e75-ccc1-4866-9ab3-4ece1b735052",
"name": "Test protocol",
"description": "Test description",
"primaryDevices": [
{
"__type": "dk.cachet.carp.common.infrastructure.test.StubPrimaryDeviceConfiguration",
"isPrimaryDevice": true,
"roleName": "Primary"
}
],
"connectedDevices": [
{
"__type": "dk.cachet.carp.common.infrastructure.test.StubDeviceConfiguration",
"roleName": "Connected"
}
],
"connections": [
{
"roleName": "Connected",
"connectedToRoleName": "Primary"
}
]
},
"invitations": [
{
"participantId": "bc2b736f-fbc0-434d-8e07-736f56396335",
"assignedRoles": {
"__type": "dk.cachet.carp.common.application.users.AssignedTo.All"
},
"identity": {
"__type": "dk.cachet.carp.common.application.users.UsernameAccountIdentity",
"username": "Test"
},
"invitation": {
"name": "Some study"
}
}
]
},
"precedingEvents": [],
"publishedEvents": [
{
"__type": "dk.cachet.carp.deployments.application.DeploymentService.Event.StudyDeploymentCreated",
"aggregateId": "6a4ff16c-cafc-4392-836a-503fe0b81127",
"apiVersion": "1.3",
"studyDeploymentId": "6a4ff16c-cafc-4392-836a-503fe0b81127",
"protocol": {
"id": "e55bf62d-56e1-4596-ad12-4868475d5398",
"createdOn": "2024-10-09T08:17:33.762380Z",
"version": 0,
"ownerId": "27879e75-ccc1-4866-9ab3-4ece1b735052",
"name": "Test protocol",
"description": "Test description",
"primaryDevices": [
{
"__type": "dk.cachet.carp.common.infrastructure.test.StubPrimaryDeviceConfiguration",
"isPrimaryDevice": true,
"roleName": "Primary"
}
],
"connectedDevices": [
{
"__type": "dk.cachet.carp.common.infrastructure.test.StubDeviceConfiguration",
"roleName": "Connected"
}
],
"connections": [
{
"roleName": "Connected",
"connectedToRoleName": "Primary"
}
]
},
"invitations": [
{
"participantId": "bc2b736f-fbc0-434d-8e07-736f56396335",
"assignedRoles": {
"__type": "dk.cachet.carp.common.application.users.AssignedTo.All"
},
"identity": {
"__type": "dk.cachet.carp.common.application.users.UsernameAccountIdentity",
"username": "Test"
},
"invitation": {
"name": "Some study"
}
}
],
"connectedDevicePreregistrations": {}
}
],
"response": {
"__type": "dk.cachet.carp.deployments.application.StudyDeploymentStatus.Invited",
"createdOn": "1970-01-01T00:00:00Z",
"studyDeploymentId": "6a4ff16c-cafc-4392-836a-503fe0b81127",
"deviceStatusList": [
{
"__type": "dk.cachet.carp.deployments.application.DeviceDeploymentStatus.Unregistered",
"device": {
"__type": "dk.cachet.carp.common.infrastructure.test.StubPrimaryDeviceConfiguration",
"isPrimaryDevice": true,
"roleName": "Primary"
},
"canBeDeployed": true,
"remainingDevicesToRegisterToObtainDeployment": [
"Primary"
],
"remainingDevicesToRegisterBeforeDeployment": [
"Primary",
"Connected"
]
},
{
"__type": "dk.cachet.carp.deployments.application.DeviceDeploymentStatus.Unregistered",
"device": {
"__type": "dk.cachet.carp.common.infrastructure.test.StubDeviceConfiguration",
"roleName": "Connected"
},
"canBeDeployed": false,
"remainingDevicesToRegisterToObtainDeployment": [
"Connected"
],
"remainingDevicesToRegisterBeforeDeployment": [
"Connected"
]
}
],
"participantStatusList": [
{
"participantId": "bc2b736f-fbc0-434d-8e07-736f56396335",
"assignedParticipantRoles": {
"__type": "dk.cachet.carp.common.application.users.AssignedTo.All"
},
"assignedPrimaryDeviceRoleNames": [
"Primary"
]
}
],
"startedOn": null
}
},
{
"outcome": "Failed",
"request": {
"__type": "dk.cachet.carp.deployments.infrastructure.DeploymentServiceRequest.CreateStudyDeployment",
"apiVersion": "1.3",
"id": "6a4ff16c-cafc-4392-836a-503fe0b81127",
"protocol": {
"id": "d3d68082-69c7-4eda-8e60-3c134727bb84",
"createdOn": "2024-10-09T08:17:33.763129Z",
"version": 0,
"ownerId": "27879e75-ccc1-4866-9ab3-4ece1b735052",
"name": "Test protocol",
"description": "Test description",
"primaryDevices": [
{
"__type": "dk.cachet.carp.common.infrastructure.test.StubPrimaryDeviceConfiguration",
"isPrimaryDevice": true,
"roleName": "Test device"
}
]
},
"invitations": [
{
"participantId": "3528a538-279d-4871-8d03-de6b3d5722f8",
"assignedRoles": {
"__type": "dk.cachet.carp.common.application.users.AssignedTo.All"
},
"identity": {
"__type": "dk.cachet.carp.common.application.users.UsernameAccountIdentity",
"username": "User"
},
"invitation": {
"name": "Some study"
}
}
]
},
"precedingEvents": [],
"publishedEvents": [],
"exceptionType": "IllegalArgumentException"
}
]
Loading

0 comments on commit 53363f8

Please sign in to comment.