Skip to content

Add getDevicesByUserId() method to fetch registered devices - #300

Merged
ZiyamSanthosh merged 2 commits into
wso2:masterfrom
raviendalpatadu:feature/multiple-device-support-for-push-auth
Jul 17, 2026
Merged

Add getDevicesByUserId() method to fetch registered devices#300
ZiyamSanthosh merged 2 commits into
wso2:masterfrom
raviendalpatadu:feature/multiple-device-support-for-push-auth

Conversation

@raviendalpatadu

@raviendalpatadu raviendalpatadu commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This pull request adds a new method to retrieve devices by user ID and refactors the code to use this new method, improving clarity and maintainability. It also introduces a helper method to build lists of device DTOs from model objects.

Device retrieval improvements:

  • Added a new getDevicesByUserId method in PushDeviceManagementService to fetch all devices for the current user, with improved error handling for cases where no devices are found.
  • Updated DevicesApiServiceImpl to use the new getDevicesByUserId method instead of the old one, ensuring consistency and leveraging the improved logic.

Code modularization:

  • Added a private helper method buildListDeviceDTO in PushDeviceManagementService to convert a list of Device objects into a list of DeviceDTO objects, reducing code duplication and improving readability.

Related Issues

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@raviendalpatadu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40964db3-8bf0-4170-87ef-812da831e65d

📥 Commits

Reviewing files that changed from the base of the PR and between ec96978 and f72f919.

📒 Files selected for processing (1)
  • components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java
📝 Walkthrough

Walkthrough

The PR adds getDevicesByUserId() to retrieve all registered devices, maps them to DeviceDTO values, and preserves existing exception handling. The previous getDeviceByUserId() method remains available but is deprecated. DevicesApiServiceImpl.getDevices() now uses the multi-device retrieval method. Selected Maven dependency versions are also updated.

Sequence Diagram(s)

sequenceDiagram
  participant DevicesApiServiceImpl
  participant PushDeviceManagementService
  participant deviceHandlerService
  DevicesApiServiceImpl->>PushDeviceManagementService: getDevicesByUserId()
  PushDeviceManagementService->>deviceHandlerService: getDevicesByUserId(userId, tenantDomain)
  deviceHandlerService-->>PushDeviceManagementService: List<Device>
  PushDeviceManagementService-->>DevicesApiServiceImpl: List<DeviceDTO>
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing most required template sections, including Purpose, Goals, Approach, tests, security, and release note. Populate the full template with Purpose, Goals, Approach, User stories, Developer Checklist, Release note, Documentation, Automation tests, Security checks, and other applicable sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the main change: adding getDevicesByUserId() to fetch registered devices.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java (1)

234-246: ⚡ Quick win

Reuse the existing single-device mapper to avoid duplicated mapping logic.

Line 238-Line 243 duplicates buildDeviceDTO(Device). Reusing the existing helper keeps mapping behavior consistent and reduces drift risk.

Proposed refactor
 private List<DeviceDTO> buildListDeviceDTO(List<Device> deviceList) {

     List<DeviceDTO> deviceDTOList = new ArrayList<>();
     for (Device device : deviceList) {
-        DeviceDTO deviceDTO = new DeviceDTO();
-        deviceDTO.setDeviceId(device.getDeviceId());
-        deviceDTO.setName(device.getDeviceName());
-        deviceDTO.setModel(device.getDeviceModel());
-        deviceDTO.setProvider(device.getProvider());
-        deviceDTOList.add(deviceDTO);
+        deviceDTOList.add(buildDeviceDTO(device));
     }
     return deviceDTOList;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java`
around lines 234 - 246, The buildListDeviceDTO method is duplicating device
mapping logic that already exists in the buildDeviceDTO(Device) method. Replace
the manual field assignments (setDeviceId, setName, setModel, setProvider)
inside the for loop with a call to the existing buildDeviceDTO method for each
Device in the deviceList, capturing its result and adding it to the
deviceDTOList. This eliminates code duplication and ensures consistent mapping
behavior across both methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java`:
- Around line 234-246: The buildListDeviceDTO method is duplicating device
mapping logic that already exists in the buildDeviceDTO(Device) method. Replace
the manual field assignments (setDeviceId, setName, setModel, setProvider)
inside the for loop with a call to the existing buildDeviceDTO method for each
Device in the deviceList, capturing its result and adding it to the
deviceDTOList. This eliminates code duplication and ensures consistent mapping
behavior across both methods.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08f864dd-778e-4ee2-90e1-c4787b5c01d6

📥 Commits

Reviewing files that changed from the base of the PR and between 46396f8 and 24c6549.

📒 Files selected for processing (2)
  • components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java
  • components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DevicesApiServiceImpl.java

@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from fc241bf to 2b49aa0 Compare June 23, 2026 19:34
deviceDTOList = buildListDeviceDTO(devices);
} catch (PushDeviceHandlerException e) {
// If no device registered for the userId, the below-mentioned error is thrown.
if (!ERROR_CODE_DEVICE_NOT_FOUND_FOR_USER_ID.getCode().equals(e.getErrorCode())) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this Error doesnt come in the new getDevicesByUserId

@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from deeff5b to c618371 Compare July 16, 2026 06:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java (1)

236-243: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Ensure deviceList is not null before iteration.

If deviceHandlerService.getDevicesByUserId returns null instead of an empty list, iterating over deviceList will result in a NullPointerException. Consider adding a null check to handle potential null values safely.

♻️ Proposed refactor
     private List<DeviceDTO> buildListDeviceDTO(List<Device> deviceList) {
 
         List<DeviceDTO> deviceDTOList = new ArrayList<>();
-        for (Device device : deviceList) {
-            deviceDTOList.add(buildDeviceDTO(device));
+        if (deviceList != null) {
+            for (Device device : deviceList) {
+                deviceDTOList.add(buildDeviceDTO(device));
+            }
         }
         return deviceDTOList;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java`
around lines 236 - 243, Update buildListDeviceDTO to handle a null deviceList
before the enhanced for-loop, returning the existing empty deviceDTOList when no
devices are provided while preserving normal conversion through buildDeviceDTO
for non-null lists.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java`:
- Around line 236-243: Update buildListDeviceDTO to handle a null deviceList
before the enhanced for-loop, returning the existing empty deviceDTOList when no
devices are provided while preserving normal conversion through buildDeviceDTO
for non-null lists.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7529c624-eb96-4e01-bafa-2c5d129d8cfc

📥 Commits

Reviewing files that changed from the base of the PR and between 2b49aa0 and c618371.

📒 Files selected for processing (2)
  • components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java
  • components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DevicesApiServiceImpl.java

Adds a method to return all push-auth devices registered for the current user, supporting multiple device registration.
@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from c618371 to ec96978 Compare July 16, 2026 12:07
@jenkins-is-staging

Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/29499104047

@jenkins-is-staging

Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/29499104047
Status: failure

Adds a method to return all push-auth devices registered for the current user, supporting multiple device registration.
@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from d451e7c to f72f919 Compare July 16, 2026 13:02
@jenkins-is-staging

Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/29500960466

@jenkins-is-staging

Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/29500960466
Status: success

@jenkins-is-staging jenkins-is-staging left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/29500960466

@ZiyamSanthosh
ZiyamSanthosh merged commit c59c6f3 into wso2:master Jul 17, 2026
3 checks passed
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.

3 participants