add plant integ
This commit is contained in:
@@ -75,23 +75,27 @@ object Auth {
|
||||
val roles = ((jwtClaims.jwtClaims.claimsMap["realm_access"] as Map<String, Any>)["roles"]) as List<String>
|
||||
val date = Date(jwtClaims.jwtClaims.expirationTime.valueInMillis)
|
||||
|
||||
HttpClients.createDefault().use { h ->
|
||||
//sync plant's from rmc to here, just name and id
|
||||
for (plantId in plantIds) {
|
||||
try {
|
||||
HttpClients.createDefault().use { h ->
|
||||
//sync plant's from rmc to here, just name and id
|
||||
for (plantId in plantIds) {
|
||||
|
||||
val existing = Session.database.find(Plant::class.java).where().eq("plantId", plantId).findOne()
|
||||
if (existing == null) {
|
||||
h.execute(HttpGet("${appConfig.integrationRmc()}/plant?id=${plantId}")).use { r ->
|
||||
if (r.statusLine.statusCode == 200) {
|
||||
Session.database.save(Plant().apply {
|
||||
this.plantId = plantId
|
||||
this.plantName = EntityUtils.toString(r.entity)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val existing = Session.database.find(Plant::class.java).where().eq("plantId", plantId).findOne()
|
||||
if (existing == null) {
|
||||
h.execute(HttpGet("${appConfig.integrationRmc()}/plant?id=${plantId}")).use { r ->
|
||||
if (r.statusLine.statusCode == 200) {
|
||||
Session.database.save(Plant().apply {
|
||||
this.plantId = plantId
|
||||
this.plantName = EntityUtils.toString(r.entity)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (e: Exception){
|
||||
logger.warn("Exception in syncing plants", e)
|
||||
}
|
||||
return AuthUser(
|
||||
userName = userId, tenant = tenant, roles = roles, token = authToken, expiry = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault())), plantIds = plantIds
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user