Merge branch 'corrective-policy' into 'corrective-policy'

Fixes multiple device deleting issue

See merge request entgra/carbon-device-mgt!675
corrective-policy
Dharmakeerthi Lasantha 4 years ago
commit 539015fe1a

@ -150,6 +150,7 @@ import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -613,7 +614,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
try {
DeviceCacheKey deviceCacheKey; DeviceCacheKey deviceCacheKey;
for (Device device : existingDevices) { for (Device device : existingDevices) {
if (!EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())) { if (!EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())) {
@ -633,11 +633,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (deviceIdentifierMap.containsKey(device.getType())) { if (deviceIdentifierMap.containsKey(device.getType())) {
deviceIdentifierMap.get(device.getType()).add(device.getDeviceIdentifier()); deviceIdentifierMap.get(device.getType()).add(device.getDeviceIdentifier());
} else { } else {
deviceIdentifierMap.put(device.getType(), Collections.singletonList(device.getDeviceIdentifier())); deviceIdentifierMap.put(device.getType(),
new ArrayList<>(Collections.singletonList(device.getDeviceIdentifier())));
DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceManager deviceManager = this.getDeviceManager(device.getType());
if (deviceManager == null) { if (deviceManager == null) {
log.error("Device Manager associated with the device type '" + device.getType() + log.error("Device Manager associated with the device type '" + device.getType()
"' is null. Therefore, not attempting method 'deleteDevice'"); + "' is null. Therefore, not attempting method 'deleteDevice'");
return false; return false;
} }
deviceManagerMap.put(device.getType(), deviceManager); deviceManagerMap.put(device.getType(), deviceManager);
@ -651,6 +652,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Permanently deleting the details of devices : " + validDeviceIdentifiers); log.debug("Permanently deleting the details of devices : " + validDeviceIdentifiers);
} }
try {
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
//deleting device from the core //deleting device from the core
deviceDAO.deleteDevices(validDeviceIdentifiers, new ArrayList<>(deviceIds), enrollmentIds); deviceDAO.deleteDevices(validDeviceIdentifiers, new ArrayList<>(deviceIds), enrollmentIds);

Loading…
Cancel
Save