|
|
@ -17,18 +17,9 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.wso2.carbon.device.mgt.core;
|
|
|
|
package org.wso2.carbon.device.mgt.core;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.license.License;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.license.License;
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
@ -36,13 +27,18 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.Status;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.Status;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.Operation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
public class DeviceManagementServiceProviderImpl implements DeviceManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private DeviceTypeDAO deviceTypeDAO;
|
|
|
|
private DeviceTypeDAO deviceTypeDAO;
|
|
|
@ -58,57 +54,60 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
this.licenseManager = new LicenseManagerImpl();
|
|
|
|
this.licenseManager = new LicenseManagerImpl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getProviderType() {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
boolean status = dms.enrollDevice(device);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
|
|
|
DeviceManagementDAOUtil.convertDevice(device);
|
|
|
|
DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(device.getType());
|
|
|
|
Integer deviceTypeId =
|
|
|
|
|
|
|
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
|
|
|
|
|
|
|
deviceDto.setStatus(Status.ACTIVE);
|
|
|
|
deviceDto.setStatus(Status.ACTIVE);
|
|
|
|
deviceDto.setDeviceTypeId(deviceTypeId);
|
|
|
|
deviceDto.setDeviceTypeId(deviceType.getId());
|
|
|
|
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() +
|
|
|
|
throw new DeviceManagementException("Error occurred while enrolling the device " +
|
|
|
|
"'", e);
|
|
|
|
"'" + 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 =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
boolean status = dms.modifyEnrollment(device);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
|
|
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() +
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device " +
|
|
|
|
"'", e);
|
|
|
|
"'" + device.getId() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
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 =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
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 =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
return dms.isActive(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,19 +115,24 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
return dms.setActive(deviceId, status);
|
|
|
|
return dms.setActive(deviceId, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
|
|
|
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
|
|
|
DeviceManager 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);
|
|
|
|
DeviceType dt = this.getDeviceTypeDAO().getDeviceType(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(dt.getId());
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
@ -143,25 +147,25 @@ public class DeviceManagementServiceProviderImpl 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 " +
|
|
|
|
"'", e);
|
|
|
|
"'" + type + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devicesList;
|
|
|
|
return devicesList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
Device convertedDevice = null;
|
|
|
|
Device convertedDevice = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Integer deviceTypeId =
|
|
|
|
DeviceType deviceType =
|
|
|
|
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
|
|
|
this.getDeviceTypeDAO().getDeviceType(deviceId.getType());
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.Device device =
|
|
|
|
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
|
|
|
this.getDeviceDAO().getDevice(deviceId);
|
|
|
|
if (device != null) {
|
|
|
|
if (device != null) {
|
|
|
|
convertedDevice = DeviceManagementDAOUtil
|
|
|
|
convertedDevice = DeviceManagementDAOUtil
|
|
|
|
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
|
|
|
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceType.getId()));
|
|
|
|
Device dmsDevice = dms.getDevice(deviceId);
|
|
|
|
Device dmsDevice = dms.getDevice(deviceId);
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
if (dmsDevice != null) {
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
|
convertedDevice.setProperties(dmsDevice.getProperties());
|
|
|
@ -169,15 +173,15 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for id '" +
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
"'" + deviceId.getId() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return convertedDevice;
|
|
|
|
return convertedDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
return dms.updateDeviceInfo(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,7 +189,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
DeviceManagerService dms =
|
|
|
|
DeviceManager dms =
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
return dms.setOwnership(deviceId, ownershipType);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -195,24 +199,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public License getLicense(String type) throws DeviceManagementException {
|
|
|
|
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
|
|
|
try {
|
|
|
|
return licenseManager.getLicense(deviceType, languageCode);
|
|
|
|
return licenseManager.getLicense(type, Locale.ENGLISH.getLanguage());
|
|
|
|
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving license configured for " +
|
|
|
|
|
|
|
|
"device type '" + type + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addLicense(String type, License license) throws DeviceManagementException {
|
|
|
|
public boolean addLicense(String type, License license) throws LicenseManagementException {
|
|
|
|
try {
|
|
|
|
|
|
|
|
return licenseManager.addLicense(type, license);
|
|
|
|
return licenseManager.addLicense(type, license);
|
|
|
|
} catch (LicenseManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("Error occurred while adding license for device type '" +
|
|
|
|
|
|
|
|
type + "'", e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceDAO getDeviceDAO() {
|
|
|
|
public DeviceDAO getDeviceDAO() {
|
|
|
@ -227,4 +220,25 @@ public class DeviceManagementServiceProviderImpl implements DeviceManager {
|
|
|
|
return pluginRepository;
|
|
|
|
return pluginRepository;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean addOperation(Operation operation,
|
|
|
|
|
|
|
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
|
|
|
|
|
|
|
return operationManager.addOperation(operation, devices);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
|
|
|
|
return operationManager.getOperations(deviceId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
|
|
|
|
return operationManager.getPendingOperations(deviceId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
|
|
|
|
|
|
|
|
return operationManager.getFeatures(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|