Open-sourced generic, dynamic POC, RESTful alerting API
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.poc.alerting.persistence
|
||||
|
||||
import org.h2.tools.Server
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories("com.poc.alerting.persistence.repositories")
|
||||
@EntityScan("com.poc.alerting.persistence.dto")
|
||||
@EnableAutoConfiguration
|
||||
open class H2Config {
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
@Profile("persistence")
|
||||
open fun inMemoryH2DatabaseServer(): Server {
|
||||
return Server.createTcpServer(
|
||||
"-tcp", "-tcpAllowOthers", "-tcpPort", "9091"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.poc.alerting.persistence
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
|
||||
@SpringBootApplication(scanBasePackages = ["com.poc.alerting.persistence"])
|
||||
open class Persistence
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<Persistence>(*args)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.poc.alerting.persistence.dto
|
||||
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.Id
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.Size
|
||||
|
||||
@Entity
|
||||
data class Account(
|
||||
@Id
|
||||
@GeneratedValue
|
||||
val id: Long,
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 255)
|
||||
val name: String,
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 255)
|
||||
val extId: String
|
||||
)
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.poc.alerting.persistence.dto
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp
|
||||
import org.hibernate.annotations.UpdateTimestamp
|
||||
import java.util.Date
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.ManyToOne
|
||||
import javax.persistence.Temporal
|
||||
import javax.persistence.TemporalType
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.NotNull
|
||||
import javax.validation.constraints.Size
|
||||
|
||||
@Entity
|
||||
data class Alert(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
val id: Long,
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 255)
|
||||
val extId: String,
|
||||
|
||||
@Size(max = 255)
|
||||
var threshold: String,
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
val type: AlertTypeEnum,
|
||||
|
||||
@Size(max = 255)
|
||||
var frequency: String = "",
|
||||
|
||||
var enabled: String = "",
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
var lastTriggerTimestamp: Date,
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
var notificationSentTimestamp: Date,
|
||||
|
||||
var isTriggered: Boolean,
|
||||
|
||||
@Size(max = 255)
|
||||
var referenceTimePeriod: String,
|
||||
|
||||
@CreationTimestamp
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
val created: Date,
|
||||
|
||||
@UpdateTimestamp
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
var updated: Date,
|
||||
|
||||
@Size(max = 255)
|
||||
var updatedBy: String,
|
||||
|
||||
@ManyToOne
|
||||
var account: Account
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.poc.alerting.persistence.dto
|
||||
|
||||
import kotlin.random.Random
|
||||
|
||||
enum class AlertTypeEnum(val query: () -> Int) {
|
||||
HARDCODED_ALERT_1({ Random.nextInt(0,1000) }),
|
||||
HARDCODED_ALERT_2({ Random.nextInt(0,1000) })
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.poc.alerting.persistence.dto
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp
|
||||
import org.hibernate.annotations.UpdateTimestamp
|
||||
import java.util.Date
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.EnumType
|
||||
import javax.persistence.Enumerated
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.ManyToOne
|
||||
import javax.persistence.Temporal
|
||||
import javax.persistence.TemporalType
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.NotNull
|
||||
import javax.validation.constraints.Size
|
||||
|
||||
@Entity
|
||||
data class Recipient(
|
||||
@Id
|
||||
@GeneratedValue
|
||||
val id: Long,
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 255)
|
||||
val extId: String,
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 255)
|
||||
val recipient: String,
|
||||
|
||||
@NotNull
|
||||
@Enumerated(EnumType.STRING)
|
||||
val type: RecipientTypeEnum,
|
||||
|
||||
@Size(max = 255)
|
||||
val username: String,
|
||||
|
||||
@Size(max = 255)
|
||||
val password: String,
|
||||
|
||||
@CreationTimestamp
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
val created: Date,
|
||||
|
||||
@UpdateTimestamp
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
val updated: Date,
|
||||
|
||||
@Size(max = 255)
|
||||
val updatedBy: String,
|
||||
|
||||
@ManyToOne
|
||||
val alert: Alert,
|
||||
|
||||
@ManyToOne
|
||||
val account: Account
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.poc.alerting.persistence.dto
|
||||
|
||||
enum class RecipientTypeEnum {
|
||||
EMAIL,
|
||||
SMS,
|
||||
HTTP
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.poc.alerting.persistence.repositories
|
||||
|
||||
import com.poc.alerting.persistence.dto.Account
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface AccountRepository : JpaRepository<Account, Long> {
|
||||
fun findByExtId(accountExtId: String): Account
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.poc.alerting.persistence.repositories
|
||||
|
||||
import com.poc.alerting.persistence.dto.Alert
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
import org.springframework.data.repository.PagingAndSortingRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface AlertRepository : CrudRepository<Alert, Long>, PagingAndSortingRepository<Alert, Long> {
|
||||
fun findByExtIdAndAccount_ExtId(alertId: String, accountExtId: String): Alert
|
||||
|
||||
fun findAllByAccount_ExtId(accountExtId: String): List<Alert>
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.poc.alerting.persistence.repositories
|
||||
|
||||
import com.poc.alerting.persistence.dto.Recipient
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface RecipientRepository : CrudRepository<Recipient, Long> {
|
||||
fun findByExtIdAndAlert_ExtIdAndAccount_ExtId(recipientId: String, alertId: String, accountExtId: String): Recipient
|
||||
|
||||
fun findAllByAccount_ExtId(accountExtId: String): List<Recipient>
|
||||
|
||||
fun findAllByAlert_ExtIdAndAccount_ExtId(alertId: String, accountExtId: String): List<Recipient>
|
||||
}
|
||||
Reference in New Issue
Block a user