From 932657c2b21ce1a391cf156ac35f55b87dc762d0 Mon Sep 17 00:00:00 2001 From: "gowthaman.b" Date: Wed, 20 Mar 2024 14:04:26 +0530 Subject: [PATCH] add plant integ --- src/main/kotlin/com/restapi/config/Auth.kt | 36 ++++++++++--------- src/main/resources/dbmigration/1.23.sql | 23 ++++++++++++ .../dbmigration/model/1.23.model.xml | 24 +++++++++++++ 3 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/dbmigration/1.23.sql create mode 100644 src/main/resources/dbmigration/model/1.23.model.xml diff --git a/src/main/kotlin/com/restapi/config/Auth.kt b/src/main/kotlin/com/restapi/config/Auth.kt index 953080b..9fcfc55 100644 --- a/src/main/kotlin/com/restapi/config/Auth.kt +++ b/src/main/kotlin/com/restapi/config/Auth.kt @@ -75,23 +75,27 @@ object Auth { val roles = ((jwtClaims.jwtClaims.claimsMap["realm_access"] as Map)["roles"]) as List 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 ) diff --git a/src/main/resources/dbmigration/1.23.sql b/src/main/resources/dbmigration/1.23.sql new file mode 100644 index 0000000..08bf2aa --- /dev/null +++ b/src/main/resources/dbmigration/1.23.sql @@ -0,0 +1,23 @@ +-- apply changes +create table plant ( + sys_pk bigint generated by default as identity not null, + deleted_on timestamp, + current_approval_level integer default 0 not null, + required_approval_levels integer default 0 not null, + deleted boolean default false not null, + version integer default 1 not null, + created_at timestamp default 'now()' not null, + modified_at timestamp default 'now()' not null, + deleted_by varchar(255), + approval_status varchar(8) default 'APPROVED' not null, + tags varchar[] default '{}' not null, + comments jsonb default '[]' not null, + plant_id varchar(255) not null, + plant_name varchar(255) not null, + created_by varchar(255) not null, + modified_by varchar(255) not null, + constraint ck_plant_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')), + constraint plantid_idx unique (plant_id), + constraint pk_plant primary key (sys_pk) +); + diff --git a/src/main/resources/dbmigration/model/1.23.model.xml b/src/main/resources/dbmigration/model/1.23.model.xml new file mode 100644 index 0000000..567cfae --- /dev/null +++ b/src/main/resources/dbmigration/model/1.23.model.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file