Skip to content

Add getDevicesByUserId() method to fetch registered devices#300

Open
raviendalpatadu wants to merge 3 commits into
wso2:masterfrom
raviendalpatadu:feature/multiple-device-support-for-push-auth
Open

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

Conversation

@raviendalpatadu

@raviendalpatadu raviendalpatadu commented Jun 17, 2026

Copy link
Copy Markdown

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d595fd90-174b-4a4c-92f1-b9d5a42c1759

📥 Commits

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

📒 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

Summary

This pull request enhances device management functionality by introducing a new method for retrieving all devices registered to a user.

Key Changes

New getDevicesByUserId() Method: A public method has been added to the PushDeviceManagementService class to retrieve all devices registered for the current user. The method:

  • Calls deviceHandlerService.getDevicesByUserId(userId, tenantDomain) to fetch all user devices
  • Converts the returned Device objects to DeviceDTO objects using a new helper method
  • Gracefully handles scenarios where no devices are found for the user by catching the ERROR_CODE_DEVICE_NOT_FOUND_FOR_USER_ID exception and returning an empty list
  • Propagates other exceptions for proper error handling

Helper Method Addition: A new private buildListDeviceDTO() method centralizes the conversion of Device model objects to DeviceDTO transfer objects. This reduces code duplication by reusing the existing buildDeviceDTO() method for each device in the list.

Deprecation of Existing Method: The existing single-device getDeviceByUserId() method is now marked as @Deprecated with updated Javadoc directing callers to use getDevicesByUserId() instead.

Service Implementation Update: The DevicesApiServiceImpl.getDevices() method now calls the new getDevicesByUserId() instead of getDeviceByUserId(), enabling retrieval of all user devices while maintaining the same API response structure.

Impact

These changes improve the API's capability to handle multi-device scenarios while enhancing code maintainability through better separation of concerns and centralized DTO conversion logic.

Walkthrough

The PR replaces the single-device retrieval method getDeviceByUserId() in PushDeviceManagementService with a new public method getDevicesByUserId() that queries the DeviceHandlerService for all registered devices belonging to the current user. A new private helper buildListDeviceDTO(List<Device>) is added to map the resulting device list to List<DeviceDTO>. The existing "device not found" error-code handling is preserved. DevicesApiServiceImpl.getDevices() is updated to call the renamed method.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. While it describes the technical changes, it lacks most required sections from the template: Goals, Approach, User stories, Developer Checklist, Release notes, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, and Test environment are all missing or unfilled. Complete the required template sections, including Goals, Approach, Release notes, Documentation, Automation tests, and Security checks to meet repository standards for pull request documentation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely summarizes the main change: adding a new getDevicesByUserId() method for fetching multiple 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.

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

✨ 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
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