diff --git a/src/main/environment/1097_ci.properties b/src/main/environment/1097_ci.properties index 514f675d..8a1835aa 100644 --- a/src/main/environment/1097_ci.properties +++ b/src/main/environment/1097_ci.properties @@ -34,3 +34,8 @@ elasticsearch.index.beneficiary=@env.ELASTICSEARCH_INDEX_BENEFICIARY@ # Enable/Disable ES (for gradual rollout) elasticsearch.enabled=@env.ELASTICSEARCH_ENABLED@ +# Van/local-laptop deployments only. The 1097 service is not a van deployment, so this +# stays false — but must still be set explicitly, since IdentityService.java (shared with +# the common_* build) now requires this property with no inline default. +stoptb.enforce.vanid=false + diff --git a/src/main/environment/1097_docker.properties b/src/main/environment/1097_docker.properties index 88df0354..afe4177c 100644 --- a/src/main/environment/1097_docker.properties +++ b/src/main/environment/1097_docker.properties @@ -34,3 +34,8 @@ elasticsearch.index.beneficiary=${ELASTICSEARCH_INDEX_BENEFICIARY} # Enable/Disable ES (for gradual rollout) elasticsearch.enabled=${ELASTICSEARCH_ENABLED} +# Van/local-laptop deployments only. The 1097 service is not a van deployment, so this +# stays false — but must still be set explicitly, since IdentityService.java (shared with +# the common_* build) now requires this property with no inline default. +stoptb.enforce.vanid=false + diff --git a/src/main/environment/1097_example.properties b/src/main/environment/1097_example.properties index ba2f3211..3e9f808a 100644 --- a/src/main/environment/1097_example.properties +++ b/src/main/environment/1097_example.properties @@ -31,3 +31,8 @@ elasticsearch.index.beneficiary=beneficiary_index # Enable/Disable ES (for gradual rollout) elasticsearch.enabled=true +# Van/local-laptop deployments only. The 1097 service is not a van deployment, so this +# stays false — but must still be set explicitly, since IdentityService.java (shared with +# the common_* build) now requires this property with no inline default. +stoptb.enforce.vanid=false + diff --git a/src/main/java/com/iemr/common/identity/service/IdentityService.java b/src/main/java/com/iemr/common/identity/service/IdentityService.java index 06a921b2..88cb26bb 100644 --- a/src/main/java/com/iemr/common/identity/service/IdentityService.java +++ b/src/main/java/com/iemr/common/identity/service/IdentityService.java @@ -169,6 +169,14 @@ private JdbcTemplate getJdbcTemplate() { @Value("${elasticsearch.enabled}") private boolean esEnabled; + // Van/local-laptop deployments only — see RmnchDataSyncServiceImpl and FLW-API's + // CampConfigService for the same flag. createIdentity() previously had no enforcement + // check at all, so a missing vanID here would silently save VanID=NULL instead of failing. + // No inline default: every properties file must set this explicitly, so a forgotten + // config fails loudly at startup instead of silently running fail-open. + @Value("${stoptb.enforce.vanid}") + private boolean enforceVanID; + public void getBenAdress() { logger.debug("Address count: " + addressRepo.count()); logger.debug( @@ -1385,6 +1393,11 @@ private MBeneficiarydetail convertIdentityEditDTOToMBeneficiarydetail(IdentityEd public BeneficiaryCreateResp createIdentity(IdentityDTO identity) { logger.info("IdentityService.createIdentity - start"); + if (identity.getVanID() == null && enforceVanID) { + throw new IllegalStateException( + "Camp not configured: vanID missing. Please select van/service point in MMU before registering beneficiary."); + } + // Atomically claim the next available ID using SELECT … FOR UPDATE SKIP LOCKED. // This is safe across multiple app servers sharing the same database — each server // locks and reserves a distinct row, so duplicate BenRegId inserts cannot occur. @@ -1764,8 +1777,8 @@ private MBeneficiaryImage identityDTOToMBeneficiaryImage(IdentityDTO identity) { beneficiaryImage.setCreatedDate(identity.getCreatedDate()); if (identity.getVanID() != null) { beneficiaryImage.setVanID(identity.getVanID()); - } - if (identity.getBenFamilyDTOs() != null) { + } else if (identity.getBenFamilyDTOs() != null && !identity.getBenFamilyDTOs().isEmpty() + && identity.getBenFamilyDTOs().get(0).getVanID() != null) { beneficiaryImage.setVanID(identity.getBenFamilyDTOs().get(0).getVanID()); } diff --git a/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java b/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java index aeb3f912..27bc3cbf 100644 --- a/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java +++ b/src/main/java/com/iemr/common/identity/service/rmnch/RmnchDataSyncServiceImpl.java @@ -126,8 +126,9 @@ public class RmnchDataSyncServiceImpl implements RmnchDataSyncService { private String fhirUrl; // When true, sync fails loudly if camp is not configured instead of silently - // skipping vanID stamping - @Value("${stoptb.enforce.vanid:false}") + // skipping vanID stamping. No inline default — every properties file must set this + // explicitly, so a forgotten config fails loudly at startup instead of running fail-open. + @Value("${stoptb.enforce.vanid}") private boolean enforceVanID; @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Override @@ -401,6 +402,10 @@ public String syncDataToAmrit(String requestOBJ, String authorization) throws Ex if (hhTimestampMap.containsKey(obj.getHouseoldId())) obj.setGpsTimestamp(new Timestamp(hhTimestampMap.get(obj.getHouseoldId()))); } + // Set VanID/ParkingPlaceID for both NEW and existing households — this must + // stay OUTSIDE the "household already exists" block above (it's regressed + // back inside there twice already via merges), otherwise a brand-new + // household never gets VanID stamped, breaking van-scoped sync. if (obj.getVanID() == null && vanID != null) { obj.setVanID(vanID); obj.setParkingPlaceID(parkingPlaceID);