Skip to content

Fix TL enrichment null safety in plain search - #425

Open
priyanshu-egov wants to merge 2 commits into
egovernments:masterfrom
priyanshu-egov:fix/tl-plainsearch-enrichment
Open

Fix TL enrichment null safety in plain search#425
priyanshu-egov wants to merge 2 commits into
egovernments:masterfrom
priyanshu-egov:fix/tl-plainsearch-enrichment

Conversation

@priyanshu-egov

@priyanshu-egov priyanshu-egov commented Jan 21, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Processing now tolerates missing address/locality data and skips licenses without locality codes instead of failing.
    • Avoids unnecessary location calls when no localities are present.
    • Owner enrichment no longer fails on missing user data; missing owners are logged as warnings and processing continues.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Replaced strict null checks with tolerant extraction for locality data in BoundaryService and added guards to skip licenses lacking locality codes. EnrichmentService now logs missing user entries during owner enrichment instead of throwing exceptions and checks for null/empty owner lists before iterating.

Changes

Cohort / File(s) Summary
Boundary / Locality enrichment
tradelicense/tl-services/src/main/java/org/egov/tl/service/BoundaryService.java
Compute localityCode only when tradeLicenseDetail → address → locality are non-null; build localities list with non-empty codes; early return when localities empty; skip licenses without locality-derived jsonPath during enrichment; validate boundary object type before mapping.
Owner enrichment & logging
tradelicense/tl-services/src/main/java/org/egov/tl/service/EnrichmentService.java
Added @Slf4j and logging import; enrichOwner now returns early if license/owners null or empty; when a user is not found in user search, log a warning instead of throwing a CustomException.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I hopped through code where nulls once made a fray,

Skipped the empty lanes and logged the stray,
Boundaries found when locality spoke true,
Owners missing — a gentle warn, not rue,
A rabbit's nibble of resilient glue.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix TL enrichment null safety in plain search' clearly describes the main changes: addressing null safety issues in the TL (Trade License) enrichment service during plain search operations, which matches the modifications to BoundaryService and EnrichmentService that add null checks and tolerant handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In
`@tradelicense/tl-services/src/main/java/org/egov/tl/service/BoundaryService.java`:
- Around line 90-100: In BoundaryService where you iterate
request.getLicenses(), you read context.read(jsonPath) into boundaryObject and
then call context.read(jsonPath) again for boundaryResponse; change the code to
reuse the already-read boundaryObject by casting it to the expected type (e.g.,
ArrayList) and assign that to boundaryResponse (e.g., ArrayList boundaryResponse
= (ArrayList) boundaryObject) after your instanceof and emptiness checks,
removing the second context.read(jsonPath) call; keep the existing checks using
boundaryObject and preserve variable names propertyIdToJsonPath, jsonPath,
context.read, boundaryObject, and boundaryResponse.
- Around line 53-62: Collecting localityCode into the localities set should be
followed by an early return when localities is empty to avoid calling the
location-service unnecessarily; in BoundaryService, after the block that adds
localityCode to localities (variables: localityCode, localities), check if
localities.isEmpty() and return the appropriate empty result for that method
(e.g., empty map/list) so the downstream location-service call is skipped.

In
`@tradelicense/tl-services/src/main/java/org/egov/tl/service/EnrichmentService.java`:
- Around line 316-326: The block in EnrichmentService that iterates owners can
NPE because license.getTradeLicenseDetail() may be null; update the logic in the
method containing this block to first null-check TradeLicenseDetail (e.g.,
assign TradeLicenseDetail detail = license.getTradeLicenseDetail()) and only if
detail != null and CollectionUtils.isNotEmpty(detail.getOwners()) iterate
owners, using detail.getId() for logging; ensure you never call getOwners() or
getId() on a null TradeLicenseDetail.

Comment thread tradelicense/tl-services/src/main/java/org/egov/tl/service/BoundaryService.java Outdated
Comment thread tradelicense/tl-services/src/main/java/org/egov/tl/service/EnrichmentService.java Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tradelicense/tl-services/src/main/java/org/egov/tl/service/BoundaryService.java (1)

77-84: Redundant empty check after early return.

The condition if(!CollectionUtils.isEmpty(localities)) is now always true because the method returns early at line 66-68 when localities is empty. Consider removing the redundant check for clarity.

♻️ Suggested cleanup
-        if(!CollectionUtils.isEmpty(localities)) {
-            uri.append("&").append("codes=");
-            for (int i = 0; i < localities.size(); i++) {
-                uri.append(localities.get(i));
-                if(i!=localities.size()-1)
-                    uri.append(",");
-            }
+        uri.append("&").append("codes=");
+        for (int i = 0; i < localities.size(); i++) {
+            uri.append(localities.get(i));
+            if(i!=localities.size()-1)
+                uri.append(",");
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant