From 3b5a0379cb0cd66da8a2d055cdcd2b4f6bfe3aed Mon Sep 17 00:00:00 2001 From: "gowthaman.b" Date: Wed, 20 Mar 2024 15:12:18 +0530 Subject: [PATCH] remove the plantIds fetch --- src/main/kotlin/com/restapi/config/Auth.kt | 65 +++++++++++----------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/main/kotlin/com/restapi/config/Auth.kt b/src/main/kotlin/com/restapi/config/Auth.kt index 6fa7400..792d279 100644 --- a/src/main/kotlin/com/restapi/config/Auth.kt +++ b/src/main/kotlin/com/restapi/config/Auth.kt @@ -75,27 +75,27 @@ object Auth { val roles = ((jwtClaims.jwtClaims.claimsMap["realm_access"] as Map)["roles"]) as List val date = Date(jwtClaims.jwtClaims.expirationTime.valueInMillis) - 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) - }) - } - } - } - } - } - } catch (e: Exception) { - logger.warn("Exception in syncing plants", e) - } +// 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) +// }) +// } +// } +// } +// } +// } +// } catch (e: Exception) { +// logger.warn("Exception in syncing plants", e) +// } return AuthUser( userName = userId, @@ -107,23 +107,26 @@ object Auth { ) } + private val userToTenant = ConcurrentHashMap() private fun getTenantWithCompany(userId: String, tenant: String): String { - try { - HttpClients.createDefault().use { h -> - //sync plant's from rmc to here, just name and id + return userToTenant.computeIfAbsent(userId) { + try { + HttpClients.createDefault().use { h -> + //sync plant's from rmc to here, just name and id - h.execute(HttpGet("${appConfig.integrationRmc()}/tenant?id=${userId}")).use { r -> - if (r.statusLine.statusCode == 200) { + h.execute(HttpGet("${appConfig.integrationRmc()}/tenant?id=${userId}")).use { r -> + if (r.statusLine.statusCode == 200) { + + "$tenant${EntityUtils.toString(r.entity)}" + } - return "$tenant${EntityUtils.toString(r.entity)}" } - } + } catch (e: Exception) { + logger.warn("Exception in syncing plants", e) } - } catch (e: Exception) { - logger.warn("Exception in syncing plants", e) + tenant } - return tenant } fun keys(ctx: Context) {