From 02dcd01f7d4049881cc51792aea6f4c8075fd996 Mon Sep 17 00:00:00 2001 From: vishwab1 Date: Sun, 9 Aug 2026 11:22:58 +0530 Subject: [PATCH] fix(stoptb): read vanID from stoptb.van.id property instead of Redis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redis (camp:vanID) was written once at MMU login and deleted globally, unscoped, on ANY user's logout — a Redis outage or an unrelated user's logout would silently break registration on this camp. Each camp/van already runs its own dedicated backend instance, so which van this is never actually changes at runtime. registerBeneficiary() now injects vanID from the new stoptb.van.id property (no inline default, every properties file must set it explicitly, same convention as stoptb.enforce.vanid) instead of an inline Redis lookup. Removed the now-unused RedisConnection/ LettuceConnectionFactory dependency from this class. Scope: vanID only, parkingPlaceID is not part of this change. Co-Authored-By: Claude Sonnet 5 --- src/main/environment/common_ci.properties | 2 ++ src/main/environment/common_docker.properties | 2 ++ .../environment/common_example.properties | 2 ++ .../registrar/RegistrarServiceImpl.java | 35 ++++++++----------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index 8965154b..4d28e591 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -70,6 +70,8 @@ spring.redis.host=@env.REDIS_HOST@ # Stop TB: when true, beneficiary registration fails with an error if camp (vanID) is not configured stoptb.enforce.vanid=@env.STOPTB_ENFORCE_VANID@ +# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup +stoptb.van.id=@env.STOPTB_VAN_ID@ jwt.secret=@env.JWT_SECRET_KEY@ diff --git a/src/main/environment/common_docker.properties b/src/main/environment/common_docker.properties index c7f85e37..62c6e890 100644 --- a/src/main/environment/common_docker.properties +++ b/src/main/environment/common_docker.properties @@ -70,6 +70,8 @@ spring.redis.host=${REDIS_HOST} # Stop TB: when true, beneficiary registration fails with an error if camp (vanID) is not configured stoptb.enforce.vanid=${STOPTB_ENFORCE_VANID} +# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup +stoptb.van.id=${STOPTB_VAN_ID} jwt.secret=${JWT_SECRET_KEY} #ELK logging file name diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index 5f986124..c7e439a1 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -72,6 +72,8 @@ spring.redis.host=localhost # Stop TB: when true, beneficiary registration fails with an error if camp (vanID) # is not configured instead of silently registering without it stoptb.enforce.vanid=false +# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup +stoptb.van.id=0 jwt.secret=my-32-character-ultra-secure-and-ultra-long-secret logging.path=logs/ diff --git a/src/main/java/com/iemr/tm/service/registrar/RegistrarServiceImpl.java b/src/main/java/com/iemr/tm/service/registrar/RegistrarServiceImpl.java index 7dc4203e..cb1162d2 100644 --- a/src/main/java/com/iemr/tm/service/registrar/RegistrarServiceImpl.java +++ b/src/main/java/com/iemr/tm/service/registrar/RegistrarServiceImpl.java @@ -40,8 +40,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -114,8 +112,15 @@ public class RegistrarServiceImpl implements RegistrarService { @Autowired private CookieUtil cookieUtil; - @Autowired - private LettuceConnectionFactory redisConnectionFactory; + // This deployment's van/camp ID. Previously looked up from Redis ("camp:vanID"), + // written at MMU login and deleted (globally, unscoped) on ANY user's logout — a Redis + // outage or an unrelated user's logout would silently break registration on this camp. + // Each camp/van already runs its own dedicated backend instance, so which van this is + // never actually changes at runtime; reading it from properties removes the Redis + // dependency entirely. No inline default — every properties file must set this + // explicitly. Scope: vanID only, parkingPlaceID is not part of this change. + @Value("${stoptb.van.id}") + private int vanID; // When true, beneficiary registration fails loudly if camp is not configured // instead of silently registering with vanID unset. No inline default — every @@ -671,26 +676,16 @@ public String registerBeneficiary(String comingRequest, String Authorization) th Long beneficiaryID = null; Map responseMap = new HashMap<>(); - // Inject correct vanID from Redis (mobile sends vanID=0 as placeholder) - byte[] vanIDBytes = null; - byte[] ppIDBytes = null; - try { - RedisConnection conn = redisConnectionFactory.getConnection(); - vanIDBytes = conn.get("camp:vanID".getBytes()); - ppIDBytes = conn.get("camp:parkingPlaceID".getBytes()); - conn.close(); - } catch (Exception e) { - logger.warn("Camp vanID lookup failed: " + e.getMessage()); - } - if (vanIDBytes != null) { + // Inject configured vanID (mobile sends vanID=0 as placeholder). Previously looked + // up from Redis at request time; now a fixed property of this deployment (see + // vanID field javadoc above). + if (vanID > 0) { JSONObject reqJson = new JSONObject(comingRequest); - reqJson.put("vanID", Integer.parseInt(new String(vanIDBytes))); - if (ppIDBytes != null) - reqJson.put("parkingPlaceID", Integer.parseInt(new String(ppIDBytes))); + reqJson.put("vanID", vanID); comingRequest = reqJson.toString(); } else if (enforceVanID) { throw new Exception( - "Camp not configured: vanID missing. Please select van/service point in MMU before registering beneficiary."); + "Camp not configured: stoptb.van.id is 0. Set stoptb.van.id in this deployment's properties file."); } RestTemplate restTemplate = new RestTemplate();