mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/geethkokila/product-cdm
This commit is contained in:
commit
137023aa8b
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl;
|
||||||
|
|
||||||
|
public interface DataSourceListener {
|
||||||
|
|
||||||
|
void notifyObserver();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceModelDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceVendorDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileOSVersionDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementBundleActivator;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
public class MobileDeviceDAOFactory implements DataSourceListener {
|
||||||
|
|
||||||
|
private static DataSource dataSource;
|
||||||
|
|
||||||
|
public MobileDeviceDAOFactory() {
|
||||||
|
MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyObserver() {
|
||||||
|
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
|
return new MobileDeviceDAOImpl(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MobileDeviceModelDAO getMobileDeviceModelDAO() {
|
||||||
|
return new MobileDeviceModelDAOImpl(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MobileDeviceVendorDAO getMobileDeviceVendorDAO() {
|
||||||
|
return new MobileDeviceVendorDAOImpl(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MobileOSVersionDAO getMobileOSVersionDAO() {
|
||||||
|
return new MobileOSVersionDAOImpl(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao.util;
|
package org.wso2.carbon.device.mgt.mobile.impl.dao.util;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
@ -35,6 +38,10 @@ import java.util.Hashtable;
|
|||||||
*/
|
*/
|
||||||
public class MobileDeviceManagementDAOUtil {
|
public class MobileDeviceManagementDAOUtil {
|
||||||
|
|
||||||
|
public static DataSource resolveDataSource() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
|
||||||
|
|
||||||
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
||||||
@ -79,4 +86,5 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
MobileDevice mobileDeviceBO = new MobileDevice();
|
MobileDevice mobileDeviceBO = new MobileDevice();
|
||||||
return mobileDeviceBO;
|
return mobileDeviceBO;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,39 +16,39 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.internal;
|
package org.wso2.carbon.device.mgt.mobile.impl.internal;
|
||||||
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.osgi.framework.BundleActivator;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.*;
|
||||||
import org.osgi.framework.ServiceRegistration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.config.MobileDeviceConfigurationManager;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.config.MobileDeviceManagementConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.MobileDataSourceConfig;
|
import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.MobileDataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.util.MobileDeviceManagementSchemaInitializer;
|
import org.wso2.carbon.device.mgt.mobile.impl.util.MobileDeviceManagementSchemaInitializer;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
||||||
|
|
||||||
public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
|
||||||
private ServiceRegistration androidServiceRegRef;
|
private ServiceRegistration androidServiceRegRef;
|
||||||
private ServiceRegistration iOSServiceRegRef;
|
private ServiceRegistration iOSServiceRegRef;
|
||||||
private ServiceRegistration windowsServiceRegRef;
|
private ServiceRegistration windowsServiceRegRef;
|
||||||
|
private static List<DataSourceListener> dataSourceListeners = new ArrayList<DataSourceListener>();
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
||||||
|
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = "org.wso2.carbon.ndatasource.core";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(BundleContext bundleContext) throws Exception {
|
public void start(BundleContext bundleContext) throws Exception {
|
||||||
try {
|
try {
|
||||||
//Initialize Mobile Device Management datasource
|
if (log.isDebugEnabled()) {
|
||||||
MobileDeviceConfigurationManager.getInstance().initConfig();
|
log.debug("Activating Mobile Device Management Service bundle");
|
||||||
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
}
|
||||||
.getMobileDeviceManagementConfig();
|
bundleContext.addBundleListener(this);
|
||||||
MobileDataSourceConfig
|
|
||||||
dsConfig = config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
|
||||||
MobileDeviceManagementDAOFactory.init(dsConfig);
|
|
||||||
|
|
||||||
/* If -Dsetup option enabled then create device management database schema */
|
/* If -Dsetup option enabled then create device management database schema */
|
||||||
String setupOption = System.getProperty("setup");
|
String setupOption = System.getProperty("setup");
|
||||||
@ -58,12 +58,12 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
|||||||
"-Dsetup is enabled. Mobile Device management repository schema initialization is about " +
|
"-Dsetup is enabled. Mobile Device management repository schema initialization is about " +
|
||||||
"to begin");
|
"to begin");
|
||||||
}
|
}
|
||||||
setupMobileDeviceManagementSchema(dsConfig);
|
setupMobileDeviceManagementSchema(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
MobileDeviceDAOFactory daoFactory = new MobileDeviceDAOFactory();
|
||||||
log.debug("Activating Mobile Device Management Service bundle");
|
//TODO Register this dao to an appropriate config file
|
||||||
}
|
|
||||||
androidServiceRegRef =
|
androidServiceRegRef =
|
||||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||||
new AndroidDeviceManagerService(), null);
|
new AndroidDeviceManagerService(), null);
|
||||||
@ -77,22 +77,7 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
|||||||
log.debug("Mobile Device Management Service bundle is activated");
|
log.debug("Mobile Device Management Service bundle is activated");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Error occurred while activating Mobile Device Management Service Component",
|
log.error("Error occurred while activating Mobile Device Management Service Component", e);
|
||||||
e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupMobileDeviceManagementSchema(MobileDataSourceConfig config) throws
|
|
||||||
DeviceManagementException {
|
|
||||||
MobileDeviceManagementSchemaInitializer initializer =
|
|
||||||
new MobileDeviceManagementSchemaInitializer(config);
|
|
||||||
log.info("Initializing mobile device management repository database schema");
|
|
||||||
try {
|
|
||||||
initializer.createRegistryDatabase();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new DeviceManagementException(
|
|
||||||
"Error occurred while initializing Mobile Device Management " +
|
|
||||||
"database schema", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +89,42 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
|||||||
androidServiceRegRef.unregister();
|
androidServiceRegRef.unregister();
|
||||||
iOSServiceRegRef.unregister();
|
iOSServiceRegRef.unregister();
|
||||||
windowsServiceRegRef.unregister();
|
windowsServiceRegRef.unregister();
|
||||||
|
|
||||||
|
bundleContext.removeBundleListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bundleChanged(BundleEvent bundleEvent) {
|
||||||
|
int eventType = bundleEvent.getType();
|
||||||
|
String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName();
|
||||||
|
if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) && eventType == BundleEvent.STARTED) {
|
||||||
|
for (DataSourceListener listener : this.getDataSourceListeners()) {
|
||||||
|
listener.notifyObserver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerDataSourceListener(DataSourceListener listener) {
|
||||||
|
dataSourceListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DataSourceListener> getDataSourceListeners() {
|
||||||
|
return dataSourceListeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupMobileDeviceManagementSchema(MobileDataSourceConfig config) throws
|
||||||
|
DeviceManagementException {
|
||||||
|
MobileDeviceManagementSchemaInitializer initializer =
|
||||||
|
new MobileDeviceManagementSchemaInitializer(config);
|
||||||
|
log.info("Initializing mobile device management repository database schema");
|
||||||
|
try {
|
||||||
|
//initializer.createRegistryDatabase();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while initializing Mobile Device Management " +
|
||||||
|
"database schema", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user