commonMain.dk.cachet.carp.common.application.devices.Website.kt Maven / Gradle / Ivy
Go to download
Helper classes and base types relied upon by all subsystems. This library does not contain any domain logic.
The newest version!
@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()
{
object Sensors : DataTypeSamplingSchemeMap()
object Tasks : TaskConfigurationList()
override fun getSupportedDataTypes(): Set = Sensors.keys
override fun getDataTypeSamplingSchemes(): DataTypeSamplingSchemeMap = Sensors
override val defaultSamplingConfiguration: Map = emptyMap()
override fun createDeviceRegistrationBuilder(): WebsiteDeviceRegistrationBuilder =
WebsiteDeviceRegistrationBuilder()
override fun getRegistrationClass(): KClass = 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()
{
/**
* 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 )
}