diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 88c8973460..85093ad284 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -25,11 +25,11 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -public class DeviceManagementRepository { +public class DeviceManagementPluginRepository { private Map providers; - public DeviceManagementRepository() { + public DeviceManagementPluginRepository() { providers = new HashMap(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java index 6b74e301eb..875e2f5ee5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerFactory.java @@ -19,14 +19,14 @@ package org.wso2.carbon.device.mgt.core.app.mgt; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; -import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; public class ApplicationManagerFactory { - private static DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); + private static DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); - public DeviceManagementRepository getPluginRepository() { + public DeviceManagementPluginRepository getPluginRepository() { return pluginRepository; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java index db4a83b7c8..493ae79d37 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/RemoteApplicationManager.java @@ -30,7 +30,7 @@ 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; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; @@ -50,14 +50,14 @@ public class RemoteApplicationManager implements ApplicationManager { private ConfigurationContext configCtx; private ServiceAuthenticator authenticator; private String oAuthAdminServiceUrl; - private DeviceManagementRepository pluginRepository; + private DeviceManagementPluginRepository pluginRepository; private static final String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1"; private static final Log log = LogFactory.getLog(RemoteApplicationManager.class); public RemoteApplicationManager(AppManagementConfig appManagementConfig, - DeviceManagementRepository pluginRepository) { + DeviceManagementPluginRepository pluginRepository) { IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getIdentityConfigurations(); @@ -143,7 +143,7 @@ public class RemoteApplicationManager implements ApplicationManager { throw new ApplicationManagementException(msg, e); } - public DeviceManagementRepository getPluginRepository() { + public DeviceManagementPluginRepository getPluginRepository() { return pluginRepository; } 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 61eebebce4..2382cd1946 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 @@ -33,7 +33,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; @@ -73,8 +73,8 @@ import java.util.List; * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagementService" * cardinality="0..n" * policy="dynamic" - * bind="setDeviceManager" - * unbind="unsetDeviceManager" + * bind="setDeviceManagementService" + * unbind="unsetDeviceManagementService" * @scr.reference name="registry.service" * interface="org.wso2.carbon.registry.core.service.RegistryService" * cardinality="1..1" @@ -93,21 +93,13 @@ import java.util.List; * policy="dynamic" * bind="setDataSourceService" * unbind="unsetDataSourceService" - * @scr.reference name="org.wso2.carbon.device.mgt.user.core.usermanager" - * interface="org.wso2.carbon.device.mgt.user.core.UserManager" - * cardinality="1..1 - * policy="dynamic" - * bind="setUserManager" - * unbind="unsetUserManager" */ public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); - private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); + private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository(); private static final Object LOCK = new Object(); - private boolean isInitialized; - private List deviceManagementServices = new ArrayList(); private static List listeners = new ArrayList(); protected void activate(ComponentContext componentContext) { @@ -131,7 +123,6 @@ public class DeviceManagementServiceComponent { this.initAppManagerConnector(); OperationManagementDAOFactory.init(dsConfig); - /* If -Dsetup option enabled then create device management database schema */ String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); @@ -144,13 +135,6 @@ public class DeviceManagementServiceComponent { this.setupDefaultLicenses(DeviceManagementDataHolder.getInstance().getLicenseConfig()); } - synchronized (LOCK) { - for (DeviceManagementService deviceManagementService : deviceManagementServices) { - this.registerDeviceManagementProvider(deviceManagementService); - } - this.isInitialized = true; - } - /* Registering declarative service instances exposed by DeviceManagementServiceComponent */ this.registerServices(componentContext); @@ -244,49 +228,33 @@ public class DeviceManagementServiceComponent { } } - private void registerDeviceManagementProvider(DeviceManagementService deviceManagementService) { - try { - this.getPluginRepository().addDeviceManagementProvider(deviceManagementService); - for (PluginInitializationListener listener : listeners) { - listener.notify(deviceManagementService); - } - } catch (DeviceManagementException e) { - log.error("Error occurred while adding device management provider '" + - deviceManagementService.getProviderType() + "'"); - } - } - /** * Sets Device Manager service. * - * @param deviceManager An instance of DeviceManager + * @param deviceManagementService An instance of DeviceManagementService */ - protected void setDeviceManager(DeviceManagementService deviceManager) { + protected void setDeviceManagementService(DeviceManagementService deviceManagementService) { if (log.isDebugEnabled()) { - log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); + log.debug("Setting Device Management Service Provider: '" + + deviceManagementService.getProviderType() + "'"); } - synchronized (LOCK) { - if (isInitialized) { - this.registerDeviceManagementProvider(deviceManager); - } - deviceManagementServices.add(deviceManager); + for (PluginInitializationListener listener : listeners) { + listener.registerDeviceManagementService(deviceManagementService); } } /** * Unsets Device Management service. * - * @param deviceManager An Instance of DeviceManager + * @param deviceManagementService An Instance of DeviceManagementService */ - protected void unsetDeviceManager(DeviceManagementService deviceManager) { + protected void unsetDeviceManagementService(DeviceManagementService deviceManagementService) { if (log.isDebugEnabled()) { - log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); + log.debug("Un setting Device Management Service Provider : '" + + deviceManagementService.getProviderType() + "'"); } - try { - this.getPluginRepository().removeDeviceManagementProvider(deviceManager); - } catch (DeviceManagementException e) { - log.error("Error occurred while removing device management provider '" + - deviceManager.getProviderType() + "'"); + for (PluginInitializationListener listener : listeners) { + listener.unregisterDeviceManagementService(deviceManagementService); } } @@ -338,31 +306,7 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setRegistryService(null); } - /** - * Sets UserManager Service. - * - * @param userMgtService An instance of UserManager - */ - protected void setUserManager(UserManager userMgtService) { - if (log.isDebugEnabled()) { - log.debug("Setting UserManager Service"); - } - DeviceManagementDataHolder.getInstance().setUserManager(userMgtService); - } - - /** - * Unsets UserManager Service. - * - * @param userMgtService An instance of UserManager - */ - protected void unsetUserManager(UserManager userMgtService) { - if (log.isDebugEnabled()) { - log.debug("Unsetting UserManager Service"); - } - DeviceManagementDataHolder.getInstance().setUserManager(null); - } - - private DeviceManagementRepository getPluginRepository() { + private DeviceManagementPluginRepository getPluginRepository() { return pluginRepository; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/PluginInitializationListener.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/PluginInitializationListener.java index 2551b0fe51..35e3f80288 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/PluginInitializationListener.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/PluginInitializationListener.java @@ -22,6 +22,8 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; public interface PluginInitializationListener { - void notify(DeviceManagementService deviceManagementService); + void registerDeviceManagementService(DeviceManagementService deviceManagementService); + + void unregisterDeviceManagementService(DeviceManagementService 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 f19a23b036..32d3e61bef 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 @@ -27,18 +27,16 @@ 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.OperationManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages; import org.wso2.carbon.device.mgt.core.dao.*; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.*; import org.wso2.carbon.device.mgt.core.email.EmailConstants; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; -import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.io.IOException; import java.net.URLDecoder; @@ -52,25 +50,21 @@ public class DeviceManagementProviderServiceImpl implements private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private EnrollmentDAO enrollmentDAO; - private DeviceManagementRepository pluginRepository; + private DeviceManagementPluginRepository pluginRepository; private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); - public DeviceManagementProviderServiceImpl(DeviceManagementRepository pluginRepository) { + public DeviceManagementProviderServiceImpl() { /* Registering a listener to retrieve events when some device management service plugin is installed after * the component is done getting initialized */ DeviceManagementServiceComponent.registerPluginInitializationListener(this); - this.pluginRepository = pluginRepository; + this.pluginRepository = new DeviceManagementPluginRepository(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); } - public DeviceManagementProviderServiceImpl() { - this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); - } - @Override public String getProviderType() { return null; @@ -453,7 +447,7 @@ public class DeviceManagementProviderServiceImpl implements return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license); } - private DeviceManagementRepository getPluginRepository() { + private DeviceManagementPluginRepository getPluginRepository() { return pluginRepository; } @@ -636,7 +630,7 @@ public class DeviceManagementProviderServiceImpl implements } @Override - public void notify(DeviceManagementService deviceManagementService) { + public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { try { pluginRepository.addDeviceManagementProvider(deviceManagementService); } catch (DeviceManagementException e) { @@ -645,4 +639,14 @@ public class DeviceManagementProviderServiceImpl implements } } + @Override + public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) { + try { + pluginRepository.removeDeviceManagementProvider(deviceManagementService); + } catch (DeviceManagementException e) { + log.error("Error occurred while un-registering device management plugin '" + + deviceManagementService.getProviderType() + "'", 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 4e40a3e21b..d3cb152914 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 @@ -26,11 +26,11 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; public class DeviceManagementRepositoryTests { - private DeviceManagementRepository repository; + private DeviceManagementPluginRepository repository; @BeforeClass public void initRepository() { - this.repository = new DeviceManagementRepository(); + this.repository = new DeviceManagementPluginRepository(); } @Test @@ -59,7 +59,7 @@ public class DeviceManagementRepositoryTests { Assert.assertNull(targetProvider); } - private DeviceManagementRepository getRepository() { + private DeviceManagementPluginRepository getRepository() { return repository; }