Fixing device management API structure

4.x.x
prabathabey 10 years ago
parent 8073d46f58
commit fd6793a9af

@ -24,13 +24,6 @@ import java.util.List;
* device type plugin implementation intended to be managed through CDM. * device type plugin implementation intended to be managed through CDM.
*/ */
public interface DeviceManager { public interface DeviceManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getProviderType();
/** /**
* Method to return feature manager implementation associated with a particular platform-specific plugin. * Method to return feature manager implementation associated with a particular platform-specific plugin.
* *

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.common.spi; package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
@ -25,6 +26,19 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
* Composite interface that acts as the SPI exposing all device management as well as application management * Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities * functionalities
*/ */
public interface DeviceManagementService extends DeviceManager, ApplicationManager { public interface DeviceManagementService extends ApplicationManager {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getType();
void init() throws DeviceManagementException;
DeviceManager getDeviceManager();
ApplicationManager getApplicationManager();
} }

@ -34,7 +34,7 @@ public class DeviceManagementPluginRepository {
} }
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getType();
try { try {
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -45,7 +45,7 @@ public class DeviceManagementPluginRepository {
} }
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getProviderType(); String deviceType = provider.getType();
providers.remove(deviceType); providers.remove(deviceType);
} }

@ -203,7 +203,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" + log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
@ -213,7 +213,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
pluginRepository.removeDeviceManagementProvider(deviceManagementService); pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" + log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
} }

@ -242,7 +242,7 @@ public class DeviceManagementServiceComponent {
protected void setDeviceManagementService(DeviceManagementService deviceManagementService) { protected void setDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" + log.debug("Setting Device Management Service Provider: '" +
deviceManagementService.getProviderType() + "'"); deviceManagementService.getType() + "'");
} }
synchronized (LOCK) { synchronized (LOCK) {
deviceManagers.add(deviceManagementService); deviceManagers.add(deviceManagementService);
@ -260,7 +260,7 @@ public class DeviceManagementServiceComponent {
protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) { protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Un setting Device Management Service Provider : '" + log.debug("Un setting Device Management Service Provider : '" +
deviceManagementService.getProviderType() + "'"); deviceManagementService.getType() + "'");
} }
for (PluginInitializationListener listener : listeners) { for (PluginInitializationListener listener : listeners) {
listener.unregisterDeviceManagementService(deviceManagementService); listener.unregisterDeviceManagementService(deviceManagementService);

@ -21,7 +21,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
@ -68,11 +67,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementServiceComponent.registerPluginInitializationListener(this); DeviceManagementServiceComponent.registerPluginInitializationListener(this);
} }
@Override
public String getProviderType() {
return null;
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {
return null; return null;
@ -81,14 +75,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public FeatureManager getFeatureManager(String type) { public FeatureManager getFeatureManager(String type) {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(type); this.getPluginRepository().getDeviceManagementService(type).getDeviceManager();
return dms.getFeatureManager(); return dms.getFeatureManager();
} }
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.enrollDevice(device); boolean status = dms.enrollDevice(device);
try { try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) { if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {
@ -134,7 +128,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.modifyEnrollment(device); boolean status = dms.modifyEnrollment(device);
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -167,7 +161,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
try { try {
Device device = deviceDAO.getDevice(deviceId,tenantId); Device device = deviceDAO.getDevice(deviceId,tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType()); DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
@ -188,14 +182,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isEnrolled(deviceId); return dms.isEnrolled(deviceId);
} }
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isActive(deviceId); return dms.isActive(deviceId);
} }
@ -203,7 +197,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setActive(DeviceIdentifier deviceId, boolean status) public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException { throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setActive(deviceId, status); return dms.setActive(deviceId, status);
} }
@ -227,7 +221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -257,7 +252,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -407,7 +403,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
if (device != null) { if (device != null) {
DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType()); DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
Device pluginSpecificInfo = dms.getDevice(deviceId); Device pluginSpecificInfo = dms.getDevice(deviceId);
device.setProperties(pluginSpecificInfo.getProperties()); device.setProperties(pluginSpecificInfo.getProperties());
device.setFeatures(pluginSpecificInfo.getFeatures()); device.setFeatures(pluginSpecificInfo.getFeatures());
@ -418,7 +415,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
return dms.updateDeviceInfo(deviceIdentifier, device); return dms.updateDeviceInfo(deviceIdentifier, device);
} }
@ -426,14 +423,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException { throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.setOwnership(deviceId, ownershipType); return dms.setOwnership(deviceId, ownershipType);
} }
@Override @Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
return dms.isClaimable(deviceId); return dms.isClaimable(deviceId);
} }
@ -552,7 +549,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
for (Device device : userDevices) { for (Device device : userDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -594,7 +592,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : userDevices) { for (Device device : userDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -641,7 +640,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -673,7 +673,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while registering device management plugin '" + log.error("Error occurred while registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }
@ -683,7 +683,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
pluginRepository.removeDeviceManagementProvider(deviceManagementService); pluginRepository.removeDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while un-registering device management plugin '" + log.error("Error occurred while un-registering device management plugin '" +
deviceManagementService.getProviderType() + "'", e); deviceManagementService.getType() + "'", e);
} }
} }

@ -41,9 +41,9 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e); Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e);
} }
DeviceManager targetProvider = DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType()); Assert.assertEquals(targetProvider.getType(), sourceProvider.getType());
} }
@Test(dependsOnMethods = "testAddDeviceManagementService") @Test(dependsOnMethods = "testAddDeviceManagementService")
@ -54,7 +54,7 @@ public class DeviceManagementRepositoryTests {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e); Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e);
} }
DeviceManager targetProvider = DeviceManagementService targetProvider =
this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST);
Assert.assertNull(targetProvider); Assert.assertNull(targetProvider);
} }

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
@ -29,98 +30,49 @@ public class TestDeviceManagementService implements DeviceManagementService {
public static final String DEVICE_TYPE_TEST = "Test"; public static final String DEVICE_TYPE_TEST = "Test";
@Override
public String getProviderType() {
return TestDeviceManagementService.DEVICE_TYPE_TEST;
}
@Override
public FeatureManager getFeatureManager() {
return null;
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
}
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public String getType() {
return false; return TestDeviceManagementService.DEVICE_TYPE_TEST;
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
return false;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
return null;
}
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return null;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
return false;
} }
@Override @Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { public void init() throws DeviceManagementException {
return false;
} }
@Override @Override
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { public DeviceManager getDeviceManager() {
return false; return null;
} }
@Override @Override
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, public ApplicationManager getApplicationManager() {
EnrolmentInfo.Status status) throws DeviceManagementException { return null;
return false;
} }
@Override @Override
public Application[] getApplications(String domain, int pageNumber, public Application[] getApplications(String domain, int pageNumber,
int size) throws ApplicationManagementException { int size) throws ApplicationManagementException {
return new Application[0]; return new Application[0];
} }
@Override @Override
public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
String status) throws ApplicationManagementException { String status) throws ApplicationManagementException {
} }
@Override @Override
public String getApplicationStatus(DeviceIdentifier deviceId, public String getApplicationStatus(DeviceIdentifier deviceId,
Application application) throws ApplicationManagementException { Application application) throws ApplicationManagementException {
return null; return null;
} }
@Override @Override
public void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers) public void installApplication(Operation operation,
throws ApplicationManagementException { List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
} }
} }

@ -48,4 +48,5 @@ public class UnregistrationProfile {
public void setUserId(String userId) { public void setUserId(String userId) {
this.userId = userId; this.userId = userId;
} }
} }

Loading…
Cancel
Save