- Notifications
You must be signed in to change notification settings - Fork6
Register the owner for a new layer by internal id#225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
coderabbitaibot commentedAug 27, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
WalkthroughAdds internalId to Layer and Collection models, introduces UserProfileClient.registerNewLayerOwner, wires UserProfileClient into LayersApiService, sets internalId during conversion, and calls the new endpoint after layer creation. Tests updated to mock UserProfileClient and verify registration call using internalId. Changes
Sequence Diagram(s)sequenceDiagram autonumber actor Caller participant LayersApiService participant LayersApiClient participant UserProfileClient Caller->>LayersApiService: createLayer(request) LayersApiService->>LayersApiClient: createCollection(request) LayersApiClient-->>LayersApiService: Collection { id, internalId, ... } note right of LayersApiService: Convert Collection -> Layer\nincluding internalId LayersApiService->>UserProfileClient: registerNewLayerOwner(layer.internalId) UserProfileClient-->>LayersApiService: 204/200 (void) LayersApiService-->>Caller: Layer { id, internalId, ... }Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from theIntegrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat withCodeRabbit:
SupportNeed help? Create a ticket on oursupport page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/test/java/io/kontur/disasterninja/service/layers/LayersApiServiceTest.java (2)
84-92:Add negative-path coverage for registration and null internalIdCover that registration is skipped on null internalId and that a registration failure does not fail createLayer (if you adopt best-effort in service).
Apply:
@@ public void createLayerTest() throws JsonProcessingException {@@ verify(layersApiClient, times(1)).createCollection(layerCreateDto); verify(userProfileClient, times(1)).registerNewLayerOwner(internalId); assertLayer(layer); }++ @Test+ public void createLayer_skipsRegistrationWhenInternalIdNull() throws JsonProcessingException {+ // given+ LayerCreateDto dto = layerCreateDto();+ Collection col = collection();+ col.setInternalId(null);+ when(layersApiClient.createCollection(any())).thenReturn(col);+ // when+ Layer layer = layersApiService.createLayer(dto);+ // then+ verify(layersApiClient, times(1)).createCollection(dto);+ verify(userProfileClient, never()).registerNewLayerOwner(any());+ assertLayer(layer);+ }++ @Test+ public void createLayer_doesNotFailOnRegistrationError() throws JsonProcessingException {+ // given+ LayerCreateDto dto = layerCreateDto();+ when(layersApiClient.createCollection(any())).thenReturn(collection());+ doThrow(new org.springframework.web.client.RestClientException("boom"))+ .when(userProfileClient).registerNewLayerOwner(internalId);+ // when+ Layer layer = layersApiService.createLayer(dto);+ // then+ assertLayer(layer);+ }
213-217:Also assert internalId mapping in helperEnsures convertToLayer propagates internalId.
Apply:
@@ private void assertLayer(Layer layer) { assertEquals(id, layer.getId()); assertEquals(title, layer.getName()); assertEquals(legend, layer.getLegend());+ assertEquals(internalId, layer.getInternalId()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
src/main/java/io/kontur/disasterninja/client/UserProfileClient.java(2 hunks)src/main/java/io/kontur/disasterninja/domain/Layer.java(1 hunks)src/main/java/io/kontur/disasterninja/dto/layerapi/Collection.java(1 hunks)src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.java(4 hunks)src/test/java/io/kontur/disasterninja/service/layers/LayersApiServiceTest.java(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{py,js,ts,java,go,cpp,c,h,cs,rb}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{py,js,ts,java,go,cpp,c,h,cs,rb}: If a file with code grows longer than 500 lines, refactor it into two or move some parts into already created libraries.
Do not mix tabs and spaces in code.
Do not break code indentation.
When adding logs, add message before starting something as long as after finishing, as it will let you find what crashed in the middle.
Write enough comments so you can deduce what was a requirement in the future and not walk in circles.
Add empty lines between logical blocks as in the rest of the codebase.
Format the code nicely and consistently.
Add enough debug logs so you can find out what's wrong but not be overwhelmed when something does not work as expected.
Files:
src/main/java/io/kontur/disasterninja/client/UserProfileClient.javasrc/main/java/io/kontur/disasterninja/domain/Layer.javasrc/main/java/io/kontur/disasterninja/dto/layerapi/Collection.javasrc/main/java/io/kontur/disasterninja/service/layers/LayersApiService.javasrc/test/java/io/kontur/disasterninja/service/layers/LayersApiServiceTest.java
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
Just ignoring exceptions is not the best fix in Java, handle them properly.
Files:
src/main/java/io/kontur/disasterninja/client/UserProfileClient.javasrc/main/java/io/kontur/disasterninja/domain/Layer.javasrc/main/java/io/kontur/disasterninja/dto/layerapi/Collection.javasrc/main/java/io/kontur/disasterninja/service/layers/LayersApiService.javasrc/test/java/io/kontur/disasterninja/service/layers/LayersApiServiceTest.java
🔇 Additional comments (3)
src/main/java/io/kontur/disasterninja/domain/Layer.java (1)
25-25:Confirm whether internalId should be exposed to API consumersIf internalId is purely backend-facing, consider excluding it from outward JSON (use a response DTO or @JsonIgnore) to avoid leaking internal identifiers.
src/main/java/io/kontur/disasterninja/dto/layerapi/Collection.java (1)
22-24:LGTM: mirrors layers-api and enables downstream owner registrationField is nullable and correctly typed.
src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.java (1)
120-123:LGTM: internalId is correctly propagated from Collection to LayerThis enables the downstream registration call.
Uh oh!
There was an error while loading.Please reload this page.
| publicResponseEntity<Void>registerNewLayerOwner(LonglayerId) { | ||
| returnuserProfileRestTemplate.exchange( | ||
| NEW_LAYER_URL, | ||
| POST, | ||
| httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null), | ||
| newParameterizedTypeReference<>() {}, | ||
| layerId); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🛠️ Refactor suggestion
Guard against null, and add start/finish logs + status check
Avoid runtime failure on null and follow logging guidelines. Also warn on non-2xx responses.
Apply:
@@- public ResponseEntity<Void> registerNewLayerOwner(Long layerId) {- return userProfileRestTemplate.exchange(- NEW_LAYER_URL,- POST,- httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null),- new ParameterizedTypeReference<>() {},- layerId);- }+ public ResponseEntity<Void> registerNewLayerOwner(Long layerId) {+ java.util.Objects.requireNonNull(layerId, "layerId (internal id) must not be null");+ LOG.info("Registering new layer owner for internalId={}", layerId);+ ResponseEntity<Void> resp = userProfileRestTemplate.exchange(+ NEW_LAYER_URL,+ POST,+ httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null),+ new ParameterizedTypeReference<>() {},+ layerId);+ if (!resp.getStatusCode().is2xxSuccessful()) {+ LOG.warn("UserProfile responded with status={} for registerNewLayerOwner, internalId={}",+ resp.getStatusCode(), layerId);+ } else {+ LOG.info("Registered new layer owner for internalId={}", layerId);+ }+ return resp;+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| publicResponseEntity<Void>registerNewLayerOwner(LonglayerId) { | |
| returnuserProfileRestTemplate.exchange( | |
| NEW_LAYER_URL, | |
| POST, | |
| httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null), | |
| newParameterizedTypeReference<>() {}, | |
| layerId); | |
| } | |
| publicResponseEntity<Void>registerNewLayerOwner(LonglayerId) { | |
| java.util.Objects.requireNonNull(layerId,"layerId (internal id) must not be null"); | |
| LOG.info("Registering new layer owner for internalId={}",layerId); | |
| ResponseEntity<Void>resp =userProfileRestTemplate.exchange( | |
| NEW_LAYER_URL, | |
| POST, | |
| httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null), | |
| newParameterizedTypeReference<>() {}, | |
| layerId); | |
| if (!resp.getStatusCode().is2xxSuccessful()) { | |
| LOG.warn("UserProfile responded with status={} for registerNewLayerOwner, internalId={}", | |
| resp.getStatusCode(),layerId); | |
| }else { | |
| LOG.info("Registered new layer owner for internalId={}",layerId); | |
| } | |
| returnresp; | |
| } |
🤖 Prompt for AI Agents
In src/main/java/io/kontur/disasterninja/client/UserProfileClient.java aroundlines 198-205, guard against a null layerId and add start/finish logs plus anon-2xx status warning: validate layerId at the top (throwIllegalArgumentException with a clear message if null), log an info messagebefore calling userProfileRestTemplate.exchange indicating the operation andlayerId, perform the exchange, then checkresponse.getStatusCode().is2xxSuccessful() and log a warning if it is not(include the status code and body/headers if helpful), log an info message onsuccessful finish with the status, and wrap the call in a try/catch to log andrethrow unexpected exceptions so errors are recorded.Uh oh!
There was an error while loading.Please reload this page.
src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.javaShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This relies on fresh PRs to
user-profile-serviceandlayers-api.Summary by CodeRabbit