Fix Device renaming is not working. #442

Merged
tcdlpds merged 4 commits from nipuni/device-mgt-core:#11349 into master 3 months ago
Fixes for: http://roadmap.entgra.net/issues/11452
nipuni added 3 commits 3 months ago
fd67b39a46
Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core into #11349
tcdlpds requested changes 3 months ago
persistedDevice.setName(device.getName());
System.out.println("This is rename device");
boolean responseOfmodifyEnrollment = deviceManagementProviderService.modifyEnrollment(persistedDevice);
boolean responseOfRenameDevice = deviceManagementProviderService.updateDeviceName(persistedDevice);
Owner

Review this logic and improve it.

Review this logic and improve it.
nipuni marked this conversation as resolved
boolean response = responseOfRenameDevice && responseOfDeviceNameChanged;
return Response.status(Response.Status.CREATED).entity(response).build();
} catch (DeviceManagementException e) {
Owner

Catch BadRequestException and throw 400 response.

Catch BadRequestException and throw 400 response.
nipuni marked this conversation as resolved
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
"Therefore, not attempting method 'modifyEnrolment'");
}
return false;
Owner

Throw 'DeviceManagementException' exception.

Throw 'DeviceManagementException' exception.
nipuni marked this conversation as resolved
int tenantId = this.getTenantId();
Device currentDevice = this.getDevice(deviceIdentifier, false);
device.setId(currentDevice.getId());
if (device.getName() == null) {
Owner

Check this in the beginning of the method and throw an exception, because if this hits, it means this is a bad request.

Check this in the beginning of the method and throw an exception, because if this hits, it means this is a bad request.
nipuni marked this conversation as resolved
deviceDAO.updateDevice(device, tenantId);
DeviceManagementDAOFactory.commitTransaction();
Owner

Remove unnecessary new lines.

Remove unnecessary new lines.
nipuni marked this conversation as resolved
navodzoysa reviewed 3 months ago
(deviceId, deviceType), true);
persistedDevice.setName(device.getName());
System.out.println("This is rename device");
Collaborator

Remove unnecessary print statement.

Remove unnecessary print statement.
nipuni marked this conversation as resolved
nipuni force-pushed #11349 from d3c6c834fa to e526b271bc 3 months ago
tcdlpds requested changes 3 months ago
@Override
public Device updateDeviceName(Device device) throws DeviceManagementException {
int tenantId = this.getTenantId();
Owner

This is required in line no 5535, so move this loading into there.

This is required in line no 5535, so move this loading into there.
nipuni marked this conversation as resolved
if (device == null) {
String msg = "Required values are not set to rename device";
log.error(msg);
throw new DeviceManagementException(msg);
Owner

Throw bad request

Throw bad request
nipuni marked this conversation as resolved
DeviceManagementDAOFactory.commitTransaction();
this.removeDeviceFromCache(deviceIdentifier);
return device;
Owner

Remove unnecessary new line.

Remove unnecessary new line.
nipuni marked this conversation as resolved
return device;
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while renaming the device '" + device.getId() + "'";
Owner

rollback the transaction

rollback the transaction
nipuni marked this conversation as resolved
String msg = "Error occurred while initiating transaction to rename device: " + device.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (Exception e) {
Owner

Do we need to catch from Exception class here?

Do we need to catch from Exception class here?
nipuni marked this conversation as resolved
nipuni force-pushed #11349 from 06dc1620c8 to e4d2a0a29f 3 months ago
tcdlpds requested changes 3 months ago
Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
Owner

Move these two line also into the service method. With that improvement, we can improve the service method also.

Move these two line also into the service method. With that improvement, we can improve the service method also.
nipuni marked this conversation as resolved
tcdlpds requested changes 3 months ago
Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
(deviceId, deviceType), true);
persistedDevice.setName(device.getName());
Owner

If the name has been changed, then we need to rename and make the DAO call.

If the name has been changed, then we need to rename and make the DAO call.
nipuni marked this conversation as resolved
nipuni force-pushed #11349 from b0bdc22231 to 68c510bba1 3 months ago
nipuni force-pushed #11349 from c38e8ef484 to 61a21edb9d 3 months ago
tcdlpds merged commit d43bc1c5a4 into master 3 months ago

Reviewers

tcdlpds requested changes 3 months ago
The pull request has been merged as d43bc1c5a4.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: community/device-mgt-core#442
Loading…
There is no content yet.