Alert models represent system alerts and notifications generated by monitoring conditions in sectors. The system includes a comprehensive catalog of alert types and severities.
Alert
Domain model representing an alert in the system.
data class Alert(
val id: Long,
val code: String,
val tenantId: Long,
val sectorId: Long,
val sectorCode: String?,
val alertTypeId: Short?,
val alertTypeName: String?,
val severityId: Short?,
val severityName: String?,
val severityLevel: Short?,
val message: String?,
val description: String?,
val isResolved: Boolean,
val resolvedAt: String?,
val resolvedByUserName: String?,
val createdAt: String
)
Fields
Unique identifier for the alert
Unique code assigned to the alert
ID of the tenant/client that owns this alert
ID of the sector where the alert was triggered
Code of the sector (for display purposes)
ID of the alert type from catalog
Name of the alert type (e.g., “Temperature”, “Humidity”)
ID of the alert severity from catalog
Name of the severity level (e.g., “Critical”, “Warning”)
Numeric severity level for sorting/prioritization
Detailed alert description
Whether the alert has been resolved
ISO 8601 timestamp when the alert was resolved
Username of the user who resolved the alert
ISO 8601 timestamp when the alert was created
Computed Properties
Returns the first two letters of the message or description in uppercase for avatar display.val initials: String
get() = (message ?: description)?.take(2)?.uppercase() ?: "AL"
Example: “Temperature too high” → “TE”, null → “AL”
Returns the display text (message or description).val displayText: String
get() = message ?: description ?: ""
AlertType
Domain model for alert type catalog.
data class AlertType(
val id: Short,
val name: String,
val description: String?
)
Unique identifier for the alert type
Name of the alert type (e.g., “Temperature”, “Humidity”, “Equipment Failure”)
Detailed description of the alert type
AlertSeverityCatalog
Domain model for alert severity catalog.
data class AlertSeverityCatalog(
val id: Short,
val name: String,
val level: Short,
val description: String?,
val color: String?,
val requiresAction: Boolean
)
Unique identifier for the severity
Name of the severity level (e.g., “Critical”, “Warning”, “Info”)
Numeric level for prioritization (higher = more severe)
Detailed description of the severity level
Color code for UI display (e.g., “#FF0000” for critical)
Whether alerts with this severity require immediate action
API DTOs
AlertResponse
Response DTO for alerts from /tenants/{tenantId}/alerts endpoint.
@Serializable
data class AlertResponse(
val id: Long,
val code: String,
val tenantId: Long,
val sectorId: Long,
val sectorCode: String? = null,
val alertTypeId: Short? = null,
val alertTypeName: String? = null,
val severityId: Short? = null,
val severityName: String? = null,
val severityLevel: Short? = null,
val message: String? = null,
val description: String? = null,
val isResolved: Boolean = false,
val resolvedAt: String? = null,
val resolvedByUserId: Long? = null,
val resolvedByUserName: String? = null,
val createdAt: String,
val updatedAt: String? = null
)
Converts AlertResponse to Alert domain model.fun AlertResponse.toDomain() = Alert(
id = id,
code = code,
tenantId = tenantId,
sectorId = sectorId,
sectorCode = sectorCode,
alertTypeId = alertTypeId,
alertTypeName = alertTypeName,
severityId = severityId,
severityName = severityName,
severityLevel = severityLevel,
message = message,
description = description,
isResolved = isResolved,
resolvedAt = resolvedAt,
resolvedByUserName = resolvedByUserName,
createdAt = createdAt
)
AlertCreateRequest
Request DTO for creating a new alert.
@Serializable
data class AlertCreateRequest(
val sectorId: Long,
val alertTypeId: Short? = null,
val severityId: Short? = null,
val message: String? = null,
val description: String? = null
)
ID of the sector where the alert occurred
ID of the alert type from catalog
ID of the severity level from catalog
Detailed alert description
AlertUpdateRequest
Request DTO for updating an alert. All fields are optional for partial updates.
@Serializable
data class AlertUpdateRequest(
val sectorId: Long? = null,
val alertTypeId: Short? = null,
val severityId: Short? = null,
val message: String? = null,
val description: String? = null
)
AlertResolveRequest
Request DTO for resolving an alert.
@Serializable
data class AlertResolveRequest(
val resolvedByUserId: Long? = null
)
ID of the user resolving the alert (optional, may be derived from session)
Catalog API DTOs
AlertTypeResponse
Response DTO for alert types from /catalog/alert-types endpoint.
@Serializable
data class AlertTypeResponse(
val id: Short,
val name: String,
val description: String? = null
)
Converts AlertTypeResponse to AlertType domain model.fun AlertTypeResponse.toDomain() = AlertType(
id = id,
name = name,
description = description
)
AlertSeverityResponse
Response DTO for alert severities from /catalog/alert-severities endpoint.
@Serializable
data class AlertSeverityResponse(
val id: Short,
val name: String,
val level: Short,
val description: String? = null,
val color: String? = null,
val requiresAction: Boolean = false,
val notificationDelayMinutes: Int = 0
)
Delay in minutes before sending notifications for this severity level
toDomain
() -> AlertSeverityCatalog
Converts AlertSeverityResponse to AlertSeverityCatalog domain model.fun AlertSeverityResponse.toDomain() = AlertSeverityCatalog(
id = id,
name = name,
level = level,
description = description,
color = color,
requiresAction = requiresAction
)
Catalog Request DTOs
AlertTypeCreateRequest
@Serializable
data class AlertTypeCreateRequest(
val name: String,
val description: String? = null
)
AlertTypeUpdateRequest
@Serializable
data class AlertTypeUpdateRequest(
val name: String? = null,
val description: String? = null
)
AlertSeverityCreateRequest
@Serializable
data class AlertSeverityCreateRequest(
val name: String,
val level: Short,
val description: String? = null,
val color: String? = null,
val requiresAction: Boolean = false,
val notificationDelayMinutes: Int = 0
)
AlertSeverityUpdateRequest
@Serializable
data class AlertSeverityUpdateRequest(
val name: String? = null,
val level: Short? = null,
val description: String? = null,
val color: String? = null,
val requiresAction: Boolean? = null,
val notificationDelayMinutes: Int? = null
)
Usage Examples
Creating an Alert
val alert = Alert(
id = 1L,
code = "ALT001",
tenantId = 1L,
sectorId = 1L,
sectorCode = "SEC001",
alertTypeId = 1,
alertTypeName = "Temperature",
severityId = 1,
severityName = "Critical",
severityLevel = 5,
message = "Temperature too high",
description = "Temperature exceeded 35°C threshold",
isResolved = false,
resolvedAt = null,
resolvedByUserName = null,
createdAt = "2024-03-01T14:30:00Z"
)
println(alert.initials) // "TE"
println(alert.displayText) // "Temperature too high"
Creating an Alert via API
val createRequest = AlertCreateRequest(
sectorId = 1L,
alertTypeId = 1,
severityId = 1,
message = "Humidity too low",
description = "Humidity dropped below 40% threshold"
)
val response: AlertResponse = apiClient.createAlert(
tenantId = 1L,
request = createRequest
)
val alert: Alert = response.toDomain()
Resolving an Alert
val resolveRequest = AlertResolveRequest(
resolvedByUserId = 1L
)
val response: AlertResponse = apiClient.resolveAlert(
tenantId = 1L,
alertId = 1L,
request = resolveRequest
)
println("Alert resolved by: ${response.resolvedByUserName}")
println("Resolved at: ${response.resolvedAt}")
Filtering Alerts by Severity
val alerts = getAlerts(tenantId = 1L)
val criticalAlerts = alerts.filter { it.severityLevel != null && it.severityLevel!! >= 4 }
val unresolvedAlerts = alerts.filter { !it.isResolved }
println("Critical alerts: ${criticalAlerts.size}")
println("Unresolved alerts: ${unresolvedAlerts.size}")
Working with Alert Catalog
// Fetch alert types
val types = apiClient.getAlertTypes()
val temperatureType = types.find { it.name == "Temperature" }
// Fetch severities
val severities = apiClient.getAlertSeverities()
val criticalSeverity = severities.find { it.name == "Critical" }
println("Critical severity level: ${criticalSeverity?.level}")
println("Requires action: ${criticalSeverity?.requiresAction}")
println("Color: ${criticalSeverity?.color}")
Sorting Alerts by Severity
val alerts = getAlerts(tenantId = 1L)
val sortedAlerts = alerts.sortedByDescending { it.severityLevel ?: 0 }
sortedAlerts.forEach { alert ->
println("[${alert.severityName}] ${alert.displayText}")
}
Creating Custom Alert Type
val createTypeRequest = AlertTypeCreateRequest(
name = "Equipment Failure",
description = "Triggered when equipment malfunctions or fails"
)
val typeResponse = apiClient.createAlertType(createTypeRequest)
val createSeverityRequest = AlertSeverityCreateRequest(
name = "Emergency",
level = 10,
description = "Immediate action required",
color = "#FF0000",
requiresAction = true,
notificationDelayMinutes = 0
)
val severityResponse = apiClient.createAlertSeverity(createSeverityRequest)