|
|
@ -763,34 +763,23 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Device> deviceList = new ArrayList<>();
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
List<Integer> deviceIds;
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
List<Device> allDevices = service.getAllDevices();
|
|
|
|
List<Device> allDevices = service.getAllDevices();
|
|
|
|
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
|
|
//int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
|
|
|
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<Integer, Device> allDeviceMap = new HashMap<>();
|
|
|
|
HashMap<Integer, Device> allDeviceMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
if (!allDevices.isEmpty()) {
|
|
|
|
if (!allDevices.isEmpty()) {
|
|
|
|
allDeviceMap = PolicyManagerUtil.covertDeviceListToMap(allDevices);
|
|
|
|
allDeviceMap = PolicyManagerUtil.covertDeviceListToMap(allDevices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int deviceId : deviceIds) {
|
|
|
|
for (int deviceId : deviceIds) {
|
|
|
|
|
|
|
|
|
|
|
|
if (allDeviceMap.containsKey(deviceId)) {
|
|
|
|
if (allDeviceMap.containsKey(deviceId)) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Policy Applied device ids .............: " + deviceId + " - Policy Id " + policyId);
|
|
|
|
log.debug("Policy Applied device ids .............: " + deviceId + " - Policy Id " + policyId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceList.add(allDeviceMap.get(deviceId));
|
|
|
|
deviceList.add(allDeviceMap.get(deviceId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//TODO FIX ME -- This is wrong, Device id is not device identifier, so converting is wrong.
|
|
|
|
//TODO FIX ME -- This is wrong, Device id is not device identifier, so converting is wrong.
|
|
|
|
|
|
|
|
|
|
|
|
//deviceList.add(deviceDAO.getDevice(new DeviceIdentifier(Integer.toString(deviceId), ""), tenantId));
|
|
|
|
//deviceList.add(deviceDAO.getDevice(new DeviceIdentifier(Integer.toString(deviceId), ""), tenantId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
@ -804,7 +793,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return deviceList;
|
|
|
|
return deviceList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -912,6 +900,34 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void removeAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int deviceId = -1;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
Device device = service.getDevice(deviceIdentifier);
|
|
|
|
|
|
|
|
deviceId = device.getId();
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
|
|
|
|
if (policySaved != null) {
|
|
|
|
|
|
|
|
policyDAO.deleteEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while removing the applied policy to device (" +
|
|
|
|
|
|
|
|
deviceId + ")", e);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the device details (" +
|
|
|
|
|
|
|
|
deviceIdentifier.getId() + ")", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
|
|
|
|
|
|
|
|
|
|
|