Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
gabriel-fallen wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromregister-new-layer-owner

Conversation

@gabriel-fallen
Copy link
Contributor

@gabriel-fallengabriel-fallen commentedAug 27, 2025
edited by coderabbitaibot
Loading

This relies on fresh PRs touser-profile-service andlayers-api.

Summary by CodeRabbit

  • New Features
    • Automatically assigns the creator as the owner when a new layer is created, ensuring immediate and consistent access management.
  • Tests
    • Added test coverage to verify owner registration occurs during layer creation.

@coderabbitai
Copy link
Contributor

coderabbitaibot commentedAug 27, 2025
edited
Loading

Walkthrough

Adds 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

Cohort / File(s)Summary of changes
User profile client API
src/main/java/io/kontur/disasterninja/client/UserProfileClient.java
Added NEW_LAYER_URL ("/access/new_layer/{layerId}") and methodpublic ResponseEntity<Void> registerNewLayerOwner(Long layerId) performing POST with bearer auth and path param.
Domain and DTO internalId support
src/main/java/io/kontur/disasterninja/domain/Layer.java,src/main/java/io/kontur/disasterninja/dto/layerapi/Collection.java
Layer: addedprivate final Long internalId (builder/exposure implied by service use). Collection DTO: added@JsonProperty("internalId") private Long internalId.
Layers service integration
src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.java
InjectedUserProfileClient. During createLayer, after building Layer (now includes internalId from Collection), callsuserProfileClient.registerNewLayerOwner(layer.getInternalId()). Minor finals on locals.
Tests updated for new flow
src/test/java/io/kontur/disasterninja/service/layers/LayersApiServiceTest.java
Mocked/injected UserProfileClient. SetinternalId on test Collection. VerifiedregisterNewLayerOwner(internalId) is called after create.

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, ... }
Loading

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branchregister-new-layer-owner

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
🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on oursupport page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type@coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a.coderabbit.yaml file to the root of your repository.
  • Please see theconfiguration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit ourStatus Page to check the current availability of CodeRabbit.
  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitaicoderabbitaibot left a 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 internalId

Cover 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 helper

Ensures 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.

📥 Commits

Reviewing files that changed from the base of the PR and betweend5cac94 andf04a205.

📒 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.java
  • src/main/java/io/kontur/disasterninja/domain/Layer.java
  • src/main/java/io/kontur/disasterninja/dto/layerapi/Collection.java
  • src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.java
  • src/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.java
  • src/main/java/io/kontur/disasterninja/domain/Layer.java
  • src/main/java/io/kontur/disasterninja/dto/layerapi/Collection.java
  • src/main/java/io/kontur/disasterninja/service/layers/LayersApiService.java
  • src/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 consumers

If 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 registration

Field 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 Layer

This enables the downstream registration call.

Comment on lines +198 to +205
publicResponseEntity<Void>registerNewLayerOwner(LonglayerId) {
returnuserProfileRestTemplate.exchange(
NEW_LAYER_URL,
POST,
httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null),
newParameterizedTypeReference<>() {},
layerId);
}
Copy link
Contributor

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.

Suggested change
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.

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

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

@KomzpaKomzpaAwaiting requested review from Komzpa

@dqunbpdqunbpAwaiting requested review from dqunbp

@sleeping-hsleeping-hAwaiting requested review from sleeping-h

@froluifroluiAwaiting requested review from frolui

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

enhancementNew feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@gabriel-fallen

[8]ページ先頭

©2009-2025 Movatter.jp