Code cleanup

revert-70aa11f8
prabathabey 10 years ago
parent a2dc916fd0
commit c0cbc59a03

@ -25,11 +25,11 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class DeviceManagementRepository { public class DeviceManagementPluginRepository {
private Map<String, DeviceManagementService> providers; private Map<String, DeviceManagementService> providers;
public DeviceManagementRepository() { public DeviceManagementPluginRepository() {
providers = new HashMap<String, DeviceManagementService>(); providers = new HashMap<String, DeviceManagementService>();
} }

@ -19,14 +19,14 @@
package org.wso2.carbon.device.mgt.core.app.mgt; 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.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; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
public class ApplicationManagerFactory { public class ApplicationManagerFactory {
private static DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); private static DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
public DeviceManagementRepository getPluginRepository() { public DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository; return pluginRepository;
} }

@ -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.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; 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.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
@ -50,14 +50,14 @@ public class RemoteApplicationManager implements ApplicationManager {
private ConfigurationContext configCtx; private ConfigurationContext configCtx;
private ServiceAuthenticator authenticator; private ServiceAuthenticator authenticator;
private String oAuthAdminServiceUrl; 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 String GET_APP_LIST_URL = "store/apis/assets/mobileapp?domain=carbon.super&page=1";
private static final Log log = LogFactory.getLog(RemoteApplicationManager.class); private static final Log log = LogFactory.getLog(RemoteApplicationManager.class);
public RemoteApplicationManager(AppManagementConfig appManagementConfig, public RemoteApplicationManager(AppManagementConfig appManagementConfig,
DeviceManagementRepository pluginRepository) { DeviceManagementPluginRepository pluginRepository) {
IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). IdentityConfigurations identityConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getIdentityConfigurations(); getDeviceManagementConfigRepository().getIdentityConfigurations();
@ -143,7 +143,7 @@ public class RemoteApplicationManager implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
public DeviceManagementRepository getPluginRepository() { public DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository; return pluginRepository;
} }

@ -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.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; 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.APIPublisherService;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; 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" * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagementService"
* cardinality="0..n" * cardinality="0..n"
* policy="dynamic" * policy="dynamic"
* bind="setDeviceManager" * bind="setDeviceManagementService"
* unbind="unsetDeviceManager" * unbind="unsetDeviceManagementService"
* @scr.reference name="registry.service" * @scr.reference name="registry.service"
* interface="org.wso2.carbon.registry.core.service.RegistryService" * interface="org.wso2.carbon.registry.core.service.RegistryService"
* cardinality="1..1" * cardinality="1..1"
@ -93,21 +93,13 @@ import java.util.List;
* policy="dynamic" * policy="dynamic"
* bind="setDataSourceService" * bind="setDataSourceService"
* unbind="unsetDataSourceService" * 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 { public class DeviceManagementServiceComponent {
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); 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 static final Object LOCK = new Object();
private boolean isInitialized;
private List<DeviceManagementService> deviceManagementServices = new ArrayList<DeviceManagementService>();
private static List<PluginInitializationListener> listeners = new ArrayList<PluginInitializationListener>(); private static List<PluginInitializationListener> listeners = new ArrayList<PluginInitializationListener>();
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
@ -130,11 +122,7 @@ public class DeviceManagementServiceComponent {
/* Initializing app manager connector */ /* Initializing app manager connector */
this.initAppManagerConnector(); this.initAppManagerConnector();
DeviceManagementProviderService deviceManagementProvider =
new DeviceManagementProviderServiceImpl(this.getPluginRepository());
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
OperationManagementDAOFactory.init(dsConfig); OperationManagementDAOFactory.init(dsConfig);
/* If -Dsetup option enabled then create device management database schema */ /* If -Dsetup option enabled then create device management database schema */
String setupOption = String setupOption =
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
@ -147,13 +135,6 @@ public class DeviceManagementServiceComponent {
this.setupDefaultLicenses(DeviceManagementDataHolder.getInstance().getLicenseConfig()); this.setupDefaultLicenses(DeviceManagementDataHolder.getInstance().getLicenseConfig());
} }
synchronized (LOCK) {
for (DeviceManagementService deviceManagementService : deviceManagementServices) {
this.registerDeviceManagementProvider(deviceManagementService);
}
this.isInitialized = true;
}
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */ /* Registering declarative service instances exposed by DeviceManagementServiceComponent */
this.registerServices(componentContext); this.registerServices(componentContext);
@ -244,49 +225,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. * 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()) { 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. * 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()) { if (log.isDebugEnabled()) {
log.debug("Un setting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); log.debug("Un setting Device Management Service Provider : '" +
deviceManagementService.getProviderType() + "'");
} }
try { for (PluginInitializationListener listener : listeners) {
this.getPluginRepository().removeDeviceManagementProvider(deviceManager); listener.unregisterDeviceManagementService(deviceManagementService);
} catch (DeviceManagementException e) {
log.error("Error occurred while removing device management provider '" +
deviceManager.getProviderType() + "'");
} }
} }
@ -338,31 +303,7 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setRegistryService(null); DeviceManagementDataHolder.getInstance().setRegistryService(null);
} }
/** private DeviceManagementPluginRepository getPluginRepository() {
* 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() {
return pluginRepository; return pluginRepository;
} }

@ -22,6 +22,8 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
public interface PluginInitializationListener { public interface PluginInitializationListener {
void notify(DeviceManagementService deviceManagementService); void registerDeviceManagementService(DeviceManagementService deviceManagementService);
void unregisterDeviceManagementService(DeviceManagementService deviceManagementService);
} }

@ -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.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; 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.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.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages; 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.*;
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.dto.*;
import org.wso2.carbon.device.mgt.core.email.EmailConstants; 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.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; 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.EmailServiceDataHolder;
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.IOException; import java.io.IOException;
import java.net.URLDecoder; import java.net.URLDecoder;
@ -52,25 +50,21 @@ public class DeviceManagementProviderServiceImpl implements
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private DeviceManagementRepository pluginRepository; private DeviceManagementPluginRepository pluginRepository;
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); 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 /* Registering a listener to retrieve events when some device management service plugin is installed after
* the component is done getting initialized */ * the component is done getting initialized */
DeviceManagementServiceComponent.registerPluginInitializationListener(this); DeviceManagementServiceComponent.registerPluginInitializationListener(this);
this.pluginRepository = pluginRepository; this.pluginRepository = new DeviceManagementPluginRepository();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
} }
public DeviceManagementProviderServiceImpl() {
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
}
@Override @Override
public String getProviderType() { public String getProviderType() {
return null; return null;
@ -453,7 +447,7 @@ public class DeviceManagementProviderServiceImpl implements
return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license); return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(type, license);
} }
private DeviceManagementRepository getPluginRepository() { private DeviceManagementPluginRepository getPluginRepository() {
return pluginRepository; return pluginRepository;
} }
@ -636,7 +630,7 @@ public class DeviceManagementProviderServiceImpl implements
} }
@Override @Override
public void notify(DeviceManagementService deviceManagementService) { public void registerDeviceManagementService(DeviceManagementService deviceManagementService) {
try { try {
pluginRepository.addDeviceManagementProvider(deviceManagementService); pluginRepository.addDeviceManagementProvider(deviceManagementService);
} catch (DeviceManagementException e) { } 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);
}
}
} }

@ -26,11 +26,11 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
public class DeviceManagementRepositoryTests { public class DeviceManagementRepositoryTests {
private DeviceManagementRepository repository; private DeviceManagementPluginRepository repository;
@BeforeClass @BeforeClass
public void initRepository() { public void initRepository() {
this.repository = new DeviceManagementRepository(); this.repository = new DeviceManagementPluginRepository();
} }
@Test @Test
@ -59,7 +59,7 @@ public class DeviceManagementRepositoryTests {
Assert.assertNull(targetProvider); Assert.assertNull(targetProvider);
} }
private DeviceManagementRepository getRepository() { private DeviceManagementPluginRepository getRepository() {
return repository; return repository;
} }

Loading…
Cancel
Save