|
|
|
@ -23,6 +23,7 @@ import org.osgi.framework.BundleContext;
|
|
|
|
|
import org.osgi.service.component.ComponentContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
|
|
|
|
@ -51,12 +52,14 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
|
*/
|
|
|
|
|
public class DeviceManagementServiceComponent {
|
|
|
|
|
|
|
|
|
|
public static final String SETUP_OPTION = "setup";
|
|
|
|
|
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
|
|
|
|
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
|
|
|
|
|
|
|
|
|
|
protected void activate(ComponentContext componentContext) {
|
|
|
|
|
try {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Initializing device management core bundle");
|
|
|
|
|
}
|
|
|
|
|
/* Initializing Device Management Configuration */
|
|
|
|
|
DeviceConfigurationManager.getInstance().initConfig();
|
|
|
|
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
@ -68,19 +71,24 @@ public class DeviceManagementServiceComponent {
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
|
|
|
|
|
|
|
|
|
|
/* If -Dsetup option enabled then create device management database schema */
|
|
|
|
|
String setupOption = System.getProperty(SETUP_OPTION);
|
|
|
|
|
String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
|
|
|
|
if (setupOption != null) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
|
|
|
|
|
"to begin");
|
|
|
|
|
}
|
|
|
|
|
setupDeviceManagementSchema(dsConfig);
|
|
|
|
|
this.setupDeviceManagementSchema(dsConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Registering OSGi service DeviceManagementService");
|
|
|
|
|
}
|
|
|
|
|
BundleContext bundleContext = componentContext.getBundleContext();
|
|
|
|
|
bundleContext.registerService(DeviceManagementService.class.getName(),
|
|
|
|
|
new DeviceManagementService(), null);
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Device management core bundle has been successfully initialized");
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
String msg = "Error occurred while initializing device management core bundle";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -91,38 +99,43 @@ public class DeviceManagementServiceComponent {
|
|
|
|
|
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
|
|
|
|
log.info("Initializing device management repository database schema");
|
|
|
|
|
|
|
|
|
|
// catch generic exception. If any error occurs wrap and throw DeviceManagementException
|
|
|
|
|
try {
|
|
|
|
|
initializer.createRegistryDatabase();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initializing Device Management " +
|
|
|
|
|
"database schema", e);
|
|
|
|
|
}
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Device management metadata repository schema has been successfully initialized");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets Device Manager services
|
|
|
|
|
* @param deviceManager An instance of DeviceManagerService
|
|
|
|
|
* Sets Device Manager service.
|
|
|
|
|
* @param deviceManagerService An instance of DeviceManagerService
|
|
|
|
|
*/
|
|
|
|
|
protected void setDeviceManagerService(DeviceManagerService deviceManager) {
|
|
|
|
|
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Setting Device Management Service");
|
|
|
|
|
log.debug("Setting Device Management Service Provider : '" +
|
|
|
|
|
deviceManagerService.getProviderType() + "'");
|
|
|
|
|
}
|
|
|
|
|
this.getPluginRepository().addDeviceManagementProvider(deviceManager);
|
|
|
|
|
this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unsets Device Management services
|
|
|
|
|
* @param deviceManager An instance of DeviceManagerService
|
|
|
|
|
* Unsets Device Management service.
|
|
|
|
|
* @param deviceManagerService An Instance of DeviceManagerService
|
|
|
|
|
*/
|
|
|
|
|
protected void unsetDeviceManagerService(DeviceManagerService deviceManager) {
|
|
|
|
|
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Unsetting Device Management Service");
|
|
|
|
|
log.debug("Unsetting Device Management Service Provider : '" +
|
|
|
|
|
deviceManagerService.getProviderType() + "'");
|
|
|
|
|
}
|
|
|
|
|
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets Realm Service
|
|
|
|
|
* Sets Realm Service.
|
|
|
|
|
* @param realmService An instance of RealmService
|
|
|
|
|
*/
|
|
|
|
|
protected void setRealmService(RealmService realmService) {
|
|
|
|
@ -133,7 +146,7 @@ public class DeviceManagementServiceComponent {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unsets Realm Service
|
|
|
|
|
* Unsets Realm Service.
|
|
|
|
|
* @param realmService An instance of RealmService
|
|
|
|
|
*/
|
|
|
|
|
protected void unsetRealmService(RealmService realmService) {
|
|
|
|
|