Merge branch 'fix-enrollment-issue' into 'master'

Fix device enrollment failure

See merge request entgra/carbon-device-mgt!856
feature/traccar-sync
Charitha Goonetilleke 3 years ago
commit 777392e36c

@ -994,16 +994,19 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Group devices to the group: " + groupId); log.debug("Group devices to the group: " + groupId);
} }
Device device;
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
List<String> deviceIdentifierList = deviceIdentifiers.stream()
.map(DeviceIdentifier::getId)
.collect(Collectors.toCollection(ArrayList::new));
List<Device> devicesList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getDeviceByIdList(deviceIdentifierList);
if (devicesList == null || devicesList.isEmpty()) {
throw new DeviceNotFoundException("Couldn't find any devices for the given deviceIdentifiers '" + deviceIdentifiers + "'");
}
GroupManagementDAOFactory.beginTransaction(); GroupManagementDAOFactory.beginTransaction();
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for (Device device : devicesList) {
device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(deviceIdentifier, false);
if (device == null) {
throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'");
}
if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)) { if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)) {
this.groupDAO.addDevice(groupId, device.getId(), tenantId); this.groupDAO.addDevice(groupId, device.getId(), tenantId);
} }

Loading…
Cancel
Save