remove the plantIds fetch

This commit is contained in:
gowthaman.b 2024-03-20 15:12:18 +05:30
parent 09bc25346d
commit 3b5a0379cb

View File

@ -75,27 +75,27 @@ object Auth {
val roles = ((jwtClaims.jwtClaims.claimsMap["realm_access"] as Map<String, Any>)["roles"]) as List<String> val roles = ((jwtClaims.jwtClaims.claimsMap["realm_access"] as Map<String, Any>)["roles"]) as List<String>
val date = Date(jwtClaims.jwtClaims.expirationTime.valueInMillis) val date = Date(jwtClaims.jwtClaims.expirationTime.valueInMillis)
try { // try {
HttpClients.createDefault().use { h -> // HttpClients.createDefault().use { h ->
//sync plant's from rmc to here, just name and id // //sync plant's from rmc to here, just name and id
for (plantId in plantIds) { // for (plantId in plantIds) {
//
val existing = Session.database.find(Plant::class.java).where().eq("plantId", plantId).findOne() // val existing = Session.database.find(Plant::class.java).where().eq("plantId", plantId).findOne()
if (existing == null) { // if (existing == null) {
h.execute(HttpGet("${appConfig.integrationRmc()}/plant?id=${plantId}")).use { r -> // h.execute(HttpGet("${appConfig.integrationRmc()}/plant?id=${plantId}")).use { r ->
if (r.statusLine.statusCode == 200) { // if (r.statusLine.statusCode == 200) {
Session.database.save(Plant().apply { // Session.database.save(Plant().apply {
this.plantId = plantId // this.plantId = plantId
this.plantName = EntityUtils.toString(r.entity) // this.plantName = EntityUtils.toString(r.entity)
}) // })
} // }
} // }
} // }
} // }
} // }
} catch (e: Exception) { // } catch (e: Exception) {
logger.warn("Exception in syncing plants", e) // logger.warn("Exception in syncing plants", e)
} // }
return AuthUser( return AuthUser(
userName = userId, userName = userId,
@ -107,23 +107,26 @@ object Auth {
) )
} }
private val userToTenant = ConcurrentHashMap<String, String>()
private fun getTenantWithCompany(userId: String, tenant: String): String { private fun getTenantWithCompany(userId: String, tenant: String): String {
try { return userToTenant.computeIfAbsent(userId) {
HttpClients.createDefault().use { h -> try {
//sync plant's from rmc to here, just name and id 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 -> h.execute(HttpGet("${appConfig.integrationRmc()}/tenant?id=${userId}")).use { r ->
if (r.statusLine.statusCode == 200) { 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) { tenant
logger.warn("Exception in syncing plants", e)
} }
return tenant
} }
fun keys(ctx: Context) { fun keys(ctx: Context) {