|
|
|
@ -44,7 +44,8 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
private DeviceManagementConfig config;
|
|
|
|
|
private DeviceManagementRepository pluginRepository;
|
|
|
|
|
|
|
|
|
|
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
|
|
|
|
|
public DeviceManagerImpl(DeviceManagementConfig config,
|
|
|
|
|
DeviceManagementRepository pluginRepository) {
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.pluginRepository = pluginRepository;
|
|
|
|
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
@ -53,16 +54,20 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
|
try {
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
|
|
|
|
DeviceManagementDAOUtil.convertDevice(device);
|
|
|
|
|
Integer deviceTypeId =
|
|
|
|
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
|
|
|
|
deviceDto.setStatus(Status.ACTIVE);
|
|
|
|
|
deviceDto.setDeviceTypeId(deviceTypeId);
|
|
|
|
|
this.getDeviceDAO().addDevice(deviceDto);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
"Error occurred while enrolling the device '" + device.getId() + "'",
|
|
|
|
|
e);
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
@ -70,12 +75,14 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
|
try {
|
|
|
|
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'",
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
"Error occurred while modifying the device '" + device.getId() + "'",
|
|
|
|
|
e);
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
@ -83,25 +90,30 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
return dms.disenrollDevice(deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
return dms.isEnrolled(deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
return dms.setActive(deviceId, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,12 +123,14 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
List<Device> devicesList = new ArrayList<Device>();
|
|
|
|
|
try {
|
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
|
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
|
|
|
|
|
this.getDeviceDAO().getDevices(deviceTypeId);
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
|
|
|
|
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
|
|
|
|
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
|
|
|
|
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
|
|
|
|
DeviceIdentifier deviceIdentifier =
|
|
|
|
|
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
|
|
|
|
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
|
@ -125,17 +139,20 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
devicesList.add(convertedDevice);
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
"Error occurred while obtaining the device for type '" + type + "'", e);
|
|
|
|
|
}
|
|
|
|
|
return devicesList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
Device convertedDevice = null;
|
|
|
|
|
try {
|
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
|
|
|
|
Integer deviceTypeId =
|
|
|
|
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
|
|
|
|
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
|
|
|
|
if (device != null) {
|
|
|
|
@ -149,21 +166,24 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e);
|
|
|
|
|
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'",
|
|
|
|
|
e);
|
|
|
|
|
}
|
|
|
|
|
return convertedDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|