From fd6793a9afa8eac11cec1fbd82d63790901329f7 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 9 Jul 2015 22:07:15 +0530 Subject: [PATCH] Fixing device management API structure --- .../device/mgt/common/DeviceManager.java | 7 -- .../common/spi/DeviceManagementService.java | 16 +++- .../DeviceManagementPluginRepository.java | 4 +- ...ApplicationManagerProviderServiceImpl.java | 4 +- .../DeviceManagementServiceComponent.java | 4 +- .../DeviceManagementProviderServiceImpl.java | 48 +++++------ .../core/DeviceManagementRepositoryTests.java | 6 +- .../mgt/core/TestDeviceManagementService.java | 80 ++++--------------- .../profile/UnregistrationProfile.java | 1 + 9 files changed, 65 insertions(+), 105 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java index 3c872467131..111b7a3be2f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java @@ -24,13 +24,6 @@ import java.util.List; * device type plugin implementation intended to be managed through CDM. */ 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. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index df97aede203..941d51c4731 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -18,6 +18,7 @@ */ 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.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 * 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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 85093ad284b..488f2f98667 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -34,7 +34,7 @@ public class DeviceManagementPluginRepository { } public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceType = provider.getProviderType(); + String deviceType = provider.getType(); try { DeviceManagerUtil.registerDeviceType(deviceType); } catch (DeviceManagementException e) { @@ -45,7 +45,7 @@ public class DeviceManagementPluginRepository { } public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceType = provider.getProviderType(); + String deviceType = provider.getType(); providers.remove(deviceType); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 69a7e8eb8a3..c2ec4f8d7f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -203,7 +203,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem pluginRepository.addDeviceManagementProvider(deviceManagementService); } catch (DeviceManagementException e) { 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); } catch (DeviceManagementException e) { log.error("Error occurred while un-registering device management plugin '" + - deviceManagementService.getProviderType() + "'", e); + deviceManagementService.getType() + "'", e); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 48b695f2e96..2d480dfbc64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -242,7 +242,7 @@ public class DeviceManagementServiceComponent { protected void setDeviceManagementService(DeviceManagementService deviceManagementService) { if (log.isDebugEnabled()) { log.debug("Setting Device Management Service Provider: '" + - deviceManagementService.getProviderType() + "'"); + deviceManagementService.getType() + "'"); } synchronized (LOCK) { deviceManagers.add(deviceManagementService); @@ -260,7 +260,7 @@ public class DeviceManagementServiceComponent { protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) { if (log.isDebugEnabled()) { log.debug("Un setting Device Management Service Provider : '" + - deviceManagementService.getProviderType() + "'"); + deviceManagementService.getType() + "'"); } for (PluginInitializationListener listener : listeners) { listener.unregisterDeviceManagementService(deviceManagementService); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 150287fdbda..c10541362ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -21,7 +21,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; 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.LicenseManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -68,11 +67,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementServiceComponent.registerPluginInitializationListener(this); } - @Override - public String getProviderType() { - return null; - } - @Override public FeatureManager getFeatureManager() { return null; @@ -81,14 +75,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public FeatureManager getFeatureManager(String type) { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(type); + this.getPluginRepository().getDeviceManagementService(type).getDeviceManager(); return dms.getFeatureManager(); } @Override public boolean enrollDevice(Device device) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(device.getType()); + this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager(); boolean status = dms.enrollDevice(device); try { if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) { @@ -134,7 +128,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(device.getType()); + this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager(); boolean status = dms.modifyEnrollment(device); try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -167,7 +161,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); try { Device device = deviceDAO.getDevice(deviceId,tenantId); DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType()); @@ -188,14 +182,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); return dms.isEnrolled(deviceId); } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); return dms.isActive(deviceId); } @@ -203,7 +197,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); return dms.setActive(deviceId, status); } @@ -227,7 +221,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } for (Device device : allDevices) { Device dmsDevice = - this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -257,7 +252,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv for (Device device : allDevices) { Device dmsDevice = - this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -407,7 +403,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } if (device != null) { - DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + DeviceManager dms = + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); Device pluginSpecificInfo = dms.getDevice(deviceId); device.setProperties(pluginSpecificInfo.getProperties()); device.setFeatures(pluginSpecificInfo.getFeatures()); @@ -418,7 +415,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(device.getType()); + this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager(); return dms.updateDeviceInfo(deviceIdentifier, device); } @@ -426,14 +423,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); return dms.setOwnership(deviceId, ownershipType); } @Override public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManager dms = - this.getPluginRepository().getDeviceManagementService(deviceId.getType()); + this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); return dms.isClaimable(deviceId); } @@ -552,7 +549,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv for (Device device : userDevices) { Device dmsDevice = - this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -594,7 +592,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } for (Device device : userDevices) { Device dmsDevice = - this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -641,7 +640,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } for (Device device : allDevices) { Device dmsDevice = - this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); device.setFeatures(dmsDevice.getFeatures()); device.setProperties(dmsDevice.getProperties()); @@ -673,7 +673,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv pluginRepository.addDeviceManagementProvider(deviceManagementService); } catch (DeviceManagementException e) { 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); } catch (DeviceManagementException e) { log.error("Error occurred while un-registering device management plugin '" + - deviceManagementService.getProviderType() + "'", e); + deviceManagementService.getType() + "'", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java index 26e40ca524f..d4d54b6a628 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java @@ -41,9 +41,9 @@ public class DeviceManagementRepositoryTests { } catch (DeviceManagementException e) { Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e); } - DeviceManager targetProvider = + DeviceManagementService targetProvider = this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); - Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType()); + Assert.assertEquals(targetProvider.getType(), sourceProvider.getType()); } @Test(dependsOnMethods = "testAddDeviceManagementService") @@ -54,7 +54,7 @@ public class DeviceManagementRepositoryTests { } catch (DeviceManagementException e) { Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e); } - DeviceManager targetProvider = + DeviceManagementService targetProvider = this.getRepository().getDeviceManagementService(TestDeviceManagementService.DEVICE_TYPE_TEST); Assert.assertNull(targetProvider); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index f074adc2e50..58f583edee7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -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.app.mgt.Application; 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.spi.DeviceManagementService; @@ -29,98 +30,49 @@ public class TestDeviceManagementService implements DeviceManagementService { 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 - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - return false; - } - - @Override - public List 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; + public String getType() { + return TestDeviceManagementService.DEVICE_TYPE_TEST; } @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - return false; + public void init() throws DeviceManagementException { + } @Override - public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { - return false; + public DeviceManager getDeviceManager() { + return null; } @Override - public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, - EnrolmentInfo.Status status) throws DeviceManagementException { - return false; + public ApplicationManager getApplicationManager() { + return null; } @Override public Application[] getApplications(String domain, int pageNumber, int size) throws ApplicationManagementException { - return new Application[0]; + return new Application[0]; } @Override public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, String status) throws ApplicationManagementException { - + } @Override public String getApplicationStatus(DeviceIdentifier deviceId, Application application) throws ApplicationManagementException { - return null; + return null; } @Override - public void installApplication(Operation operation, List deviceIdentifiers) - throws ApplicationManagementException { - + public void installApplication(Operation operation, + List deviceIdentifiers) throws ApplicationManagementException { + } + } diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/UnregistrationProfile.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/UnregistrationProfile.java index a7959a7dedf..4f3930f5d08 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/UnregistrationProfile.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/profile/UnregistrationProfile.java @@ -48,4 +48,5 @@ public class UnregistrationProfile { public void setUserId(String userId) { this.userId = userId; } + }