|
|
@ -47,8 +47,7 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
|
|
|
|
|
|
|
@ -59,13 +58,13 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
this.getDeviceDAO().addDevice(deviceDto);
|
|
|
|
this.getDeviceDAO().addDevice(deviceDto);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e);
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
|
|
|
|
|
|
|
e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -77,47 +76,37 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
return dms.disenrollDevice(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
return dms.isEnrolled(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
|
|
|
|
return dms.setActive(deviceId, status);
|
|
|
|
return dms.setActive(deviceId, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
|
|
|
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
|
|
|
DeviceManagerService dms =
|
|
|
|
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(type);
|
|
|
|
|
|
|
|
List<Device> devicesList = new ArrayList<Device>();
|
|
|
|
List<Device> devicesList = new ArrayList<Device>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
|
|
|
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
|
|
|
|
this.getDeviceDAO().getDevices(deviceTypeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
|
|
|
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
|
|
|
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
|
|
|
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
|
|
|
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
|
|
|
DeviceIdentifier deviceIdentifier =
|
|
|
|
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
|
|
|
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
|
|
|
|
|
|
|
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
|
|
|
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
@ -126,26 +115,41 @@ public class DeviceManagerImpl implements DeviceManager {
|
|
|
|
devicesList.add(convertedDevice);
|
|
|
|
devicesList.add(convertedDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'",
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
|
|
|
|
e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devicesList;
|
|
|
|
return devicesList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
return dms.getDevice(deviceId);
|
|
|
|
Device convertedDevice = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
convertedDevice = DeviceManagementDAOUtil
|
|
|
|
|
|
|
|
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
|
|
|
|
|
|
|
Device dmsDevice = dms.getDevice(deviceId);
|
|
|
|
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
|
|
|
|
|
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return convertedDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
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);
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|