-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d3ee7c
commit 8bc4e40
Showing
9 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/Website.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
@file:Suppress( "NON_EXPORTABLE_TYPE" ) | ||
|
||
package dk.cachet.carp.common.application.devices | ||
|
||
import dk.cachet.carp.common.application.Trilean | ||
import dk.cachet.carp.common.application.data.DataType | ||
import dk.cachet.carp.common.application.sampling.DataTypeSamplingSchemeMap | ||
import dk.cachet.carp.common.application.sampling.SamplingConfiguration | ||
import dk.cachet.carp.common.application.tasks.TaskConfigurationList | ||
import dk.cachet.carp.common.infrastructure.serialization.NotSerializable | ||
import kotlinx.serialization.Required | ||
import kotlinx.serialization.Serializable | ||
import kotlin.js.JsExport | ||
import kotlin.reflect.KClass | ||
|
||
|
||
/** | ||
* A website which participates in a study as a primary device. | ||
*/ | ||
@Serializable | ||
@JsExport | ||
data class Website( | ||
override val roleName: String, | ||
override val isOptional: Boolean = false | ||
) : PrimaryDeviceConfiguration<WebsiteDeviceRegistration, WebsiteDeviceRegistrationBuilder>() | ||
{ | ||
object Sensors : DataTypeSamplingSchemeMap() | ||
object Tasks : TaskConfigurationList() | ||
|
||
override fun getSupportedDataTypes(): Set<DataType> = Sensors.keys | ||
override fun getDataTypeSamplingSchemes(): DataTypeSamplingSchemeMap = Sensors | ||
|
||
override val defaultSamplingConfiguration: Map<DataType, SamplingConfiguration> = emptyMap() | ||
|
||
override fun createDeviceRegistrationBuilder(): WebsiteDeviceRegistrationBuilder = | ||
WebsiteDeviceRegistrationBuilder() | ||
override fun getRegistrationClass(): KClass<WebsiteDeviceRegistration> = WebsiteDeviceRegistration::class | ||
override fun isValidRegistration( registration: WebsiteDeviceRegistration ): Trilean = Trilean.TRUE | ||
} | ||
|
||
|
||
/** | ||
* A [DeviceRegistration] for a [Website], specifying the [url] where the study runs. | ||
*/ | ||
@Serializable | ||
@JsExport | ||
data class WebsiteDeviceRegistration( | ||
val url: String, | ||
/** | ||
* 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 | ||
) : DeviceRegistration() | ||
{ | ||
@Required | ||
override val deviceId: String = url | ||
} | ||
|
||
|
||
@Suppress( "SERIALIZER_TYPE_INCOMPATIBLE" ) | ||
@Serializable( NotSerializable::class ) | ||
@JsExport | ||
class WebsiteDeviceRegistrationBuilder : DeviceRegistrationBuilder<WebsiteDeviceRegistration>() | ||
{ | ||
/** | ||
* The web URL from which the [Website] is accessed. | ||
*/ | ||
var url: String = "" | ||
|
||
/** | ||
* The HTTP User-Agent header of the user agent which made the HTTP request to [url]. | ||
*/ | ||
var userAgent: String = "" | ||
|
||
override fun build(): WebsiteDeviceRegistration = WebsiteDeviceRegistration( url, userAgent, deviceDisplayName ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
carp.common/src/commonTest/kotlin/dk/cachet/carp/common/application/devices/WebsiteTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dk.cachet.carp.common.application.devices | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
|
||
class WebsiteTest | ||
{ | ||
@Test | ||
fun registration_builder_sets_properties() | ||
{ | ||
val expectedUrl = "https://www.example.com" | ||
val expectedUserAgent = | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" | ||
|
||
val registration = WebsiteDeviceRegistrationBuilder().apply { | ||
url = expectedUrl | ||
userAgent = expectedUserAgent | ||
}.build() | ||
|
||
assertEquals( expectedUrl, registration.url ) | ||
assertEquals( expectedUserAgent, registration.userAgent ) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"type": "object", | ||
"allOf": [ { "$ref": "PrimaryDeviceConfiguration.json#PrimaryDeviceConfiguration" } ], | ||
"properties": { | ||
"__type": { "const": "dk.cachet.carp.common.application.devices.Website" } | ||
}, | ||
"unevaluatedProperties": false, | ||
"$defs": { | ||
"DeviceRegistration": { | ||
"$anchor": "DeviceRegistration", | ||
"$ref": "WebsiteDeviceRegistration.json" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"type": "object", | ||
"allOf": [ { "$ref": "DeviceRegistration.json#DeviceRegistration" } ], | ||
"properties": { | ||
"url": { "type": "string", "format": "uri" }, | ||
"userAgent": { "type": "string" } | ||
}, | ||
"required": [ "url", "userAgent" ], | ||
"unevaluatedProperties": false | ||
} |