From acb098f3ec41c4efa99cee6094c9270806389f91 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 25 Mar 2015 17:38:24 +0530 Subject: [PATCH 1/5] Create plugin level database --- .../datasource/DataSourceConfigAdapter.java | 51 +++++ .../MobileDataSourceConfigurations.java | 38 ++++ .../AndroidMobileOperationManager.java | 182 ------------------ .../impl/ios/IOSMobileOperationManager.java | 126 ------------ 4 files changed, 89 insertions(+), 308 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java new file mode 100644 index 0000000000..71675785c1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/DataSourceConfigAdapter.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.config.datasource; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DataSourceConfigAdapter + extends XmlAdapter> { + + @Override + public Map unmarshal(MobileDataSourceConfigurations mobileDataSourceConfigurations) + throws Exception { + + Map mobileDataSourceConfigMap = new HashMap(); + for (MobileDataSourceConfig mobileDataSourceConfig : mobileDataSourceConfigurations + .getMobileDataSourceConfigs()) { + mobileDataSourceConfigMap.put(mobileDataSourceConfig.getType(), mobileDataSourceConfig); + } + return mobileDataSourceConfigMap; + } + + @Override + public MobileDataSourceConfigurations marshal(Map mobileDataSourceConfigMap) + throws Exception { + + MobileDataSourceConfigurations mobileDataSourceConfigurations = new MobileDataSourceConfigurations(); + mobileDataSourceConfigurations.setMobileDataSourceConfigs( + (List) mobileDataSourceConfigMap.values()); + + return mobileDataSourceConfigurations; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java new file mode 100644 index 0000000000..7c4afa9a4a --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java @@ -0,0 +1,38 @@ +package org.wso2.carbon.device.mgt.mobile.config.datasource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ +@XmlRootElement(name = "DataSourceConfigurations") +public class MobileDataSourceConfigurations { + + @XmlElement(name = "DataSourceConfigurations", nillable = true) + private List mobileDataSourceConfigs; + + public List getMobileDataSourceConfigs() { + return mobileDataSourceConfigs; + } + + public void setMobileDataSourceConfigs(List mobileDataSourceConfigs) { + this.mobileDataSourceConfigs = mobileDataSourceConfigs; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java deleted file mode 100644 index 683bf7868b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.android; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManagementException; -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.mobile.AbstractMobileOperationManager; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; -import org.wso2.carbon.device.mgt.mobile.dto.*; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class AndroidMobileOperationManager extends AbstractMobileOperationManager { - - private static final Log log = LogFactory.getLog(AndroidMobileOperationManager.class); - - @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { - boolean status = false; - try { - MobileDeviceOperationMapping mobileDeviceOperationMapping; - MobileOperation mobileOperation = - MobileDeviceManagementUtil.convertToMobileOperation(operation); - int operationId = - MobileDeviceManagementDAOFactory.getMobileOperationDAO().addMobileOperation(mobileOperation); - if (operationId > 0) { - for (MobileOperationProperty operationProperty : mobileOperation.getProperties()) { - operationProperty.setOperationId(operationId); - status = - MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO().addMobileOperationProperty( - operationProperty); - } - for (DeviceIdentifier deviceIdentifier : devices) { - mobileDeviceOperationMapping = new MobileDeviceOperationMapping(); - mobileDeviceOperationMapping.setOperationId(operationId); - mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId()); - mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); - status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .addMobileDeviceOperationMapping(mobileDeviceOperationMapping); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new OperationManagementException("Error while adding an operation " + operation.getCode() + - "to Android devices", e); - } - return status; - } - - @Override - public List getOperations(DeviceIdentifier deviceIdentifier) - throws OperationManagementException { - List operations = new ArrayList(); - List mobileDeviceOperationMappings; - List operationProperties; - MobileOperation mobileOperation; - try { - mobileDeviceOperationMappings = - MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllMobileDeviceOperationMappingsOfDevice(deviceIdentifier.getId()); - if (mobileDeviceOperationMappings.size() > 0) { - List operationIds = - MobileDeviceManagementUtil.getMobileOperationIdsFromMobileDeviceOperations( - mobileDeviceOperationMappings); - for (Integer operationId : operationIds) { - mobileOperation = - MobileDeviceManagementDAOFactory.getMobileOperationDAO().getMobileOperation(operationId); - operationProperties = - MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO() - .getAllMobileOperationPropertiesOfOperation(operationId); - mobileOperation.setProperties(operationProperties); - operations.add(MobileDeviceManagementUtil.convertMobileOperationToOperation(mobileOperation)); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new OperationManagementException("Error while fetching the operations for the android device '" + - deviceIdentifier.getId() + "'", e); - } - return operations; - } - - @Override - public List getPendingOperations(DeviceIdentifier deviceIdentifier) - throws OperationManagementException { - List operations = new ArrayList(); - List mobileDeviceOperationMappings; - List operationProperties; - MobileOperation mobileOperation; - try { - //Get the list of pending operations for the given device - mobileDeviceOperationMappings = - MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllPendingOperationMappingsOfMobileDevice(deviceIdentifier.getId()); - //Go through each operation mapping for retrieving the data corresponding to each operation - for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) { - //Get the MobileOperation data - mobileOperation = - MobileDeviceManagementDAOFactory.getMobileOperationDAO().getMobileOperation( - operation.getOperationId()); - //Get properties of the operation - operationProperties = - MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO(). - getAllMobileOperationPropertiesOfOperation(operation.getOperationId()); - mobileOperation.setProperties(operationProperties); - operations.add(MobileDeviceManagementUtil.convertMobileOperationToOperation(mobileOperation)); - //Update the MobileDeviceOperationMapping data to the In-Progress state - operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS); - operation.setSentDate(new Date().getTime()); - MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .updateMobileDeviceOperationMappingToInProgress(operation.getDeviceId(), - operation.getOperationId()); - } - } catch (MobileDeviceManagementDAOException e) { - throw new OperationManagementException("Error while fetching the operations for the android device '" + - deviceIdentifier.getId() + "'", e); - } - return operations; - } - - @Override - public List getFeatures(String deviceType) throws FeatureManagementException { - MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO(); - MobileFeaturePropertyDAO featurePropertyDAO = - MobileDeviceManagementDAOFactory.getFeaturePropertyDAO(); - List features = new ArrayList(); - try { - List mobileFeatures = - featureDAO.getMobileFeatureByDeviceType(deviceType); - for (MobileFeature mobileFeature : mobileFeatures) { - Feature feature = new Feature(); - feature.setId(mobileFeature.getId()); - feature.setDeviceType(mobileFeature.getDeviceType()); - feature.setName(mobileFeature.getName()); - feature.setDescription(mobileFeature.getDescription()); - List metadataEntries = - new ArrayList(); - List properties = - featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId()); - for (MobileFeatureProperty property : properties) { - Feature.MetadataEntry metaEntry = new Feature.MetadataEntry(); - metaEntry.setId(property.getFeatureID()); - metaEntry.setValue(property.getProperty()); - metadataEntries.add(metaEntry); - } - feature.setMetadataEntries(metadataEntries); - features.add(feature); - } - } catch (MobileDeviceManagementDAOException e) { - throw new FeatureManagementException("Error while fetching the features for the device type '" + - deviceType + "'", e); - } - return features; - } - -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java deleted file mode 100644 index cbc7411be9..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.ios; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManagementException; -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.mobile.AbstractMobileOperationManager; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; -import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class IOSMobileOperationManager extends AbstractMobileOperationManager { - - private static final Log log = LogFactory.getLog(IOSMobileOperationManager.class); - @Override - public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { - return null; - } - - @Override - public boolean addOperation(Operation operation, List devices) - throws OperationManagementException { - - boolean status = false; - - try { - MobileDeviceOperationMapping mobileDeviceOperationMapping; - MobileOperation mobileOperation = MobileDeviceManagementUtil.convertToMobileOperation(operation); - int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO(). - addMobileOperation(mobileOperation); - - if (operationId > 0) { - - for (MobileOperationProperty operationProperty : mobileOperation.getProperties()) { - operationProperty.setOperationId(operationId); - status = MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO(). - addMobileOperationProperty(operationProperty); - } - - for (DeviceIdentifier deviceIdentifier : devices) { - mobileDeviceOperationMapping = new MobileDeviceOperationMapping(); - mobileDeviceOperationMapping.setOperationId(operationId); - mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId()); - mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); - status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO(). - addMobileDeviceOperationMapping(mobileDeviceOperationMapping); - } - - } - } catch (MobileDeviceManagementDAOException e) { - String msg = String.format("Error while adding operation %s to iOS device", operation.getCode()); - log.error(msg, e); - throw new OperationManagementException(msg, e); - } - - return status; - } - - @Override - public List getPendingOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { - - List operations = new ArrayList(); - List mobileDeviceOperationMappings; - List operationProperties ; - MobileOperation mobileOperation; - - try { - mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO(). - getAllPendingOperationMappingsOfMobileDevice(deviceIdentifier.getId()); - - for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) { - - mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO(). - getMobileOperation(operation.getOperationId()); - operationProperties = MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO(). - getAllMobileOperationPropertiesOfOperation(operation.getOperationId()); - mobileOperation.setProperties(operationProperties); - operations.add(MobileDeviceManagementUtil.convertMobileOperationToOperation(mobileOperation)); - operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS); - operation.setSentDate(new Date().getTime()); - - MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO(). - updateMobileDeviceOperationMappingToInProgress(operation.getDeviceId(), - operation.getOperationId()); - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error occurred when retrieving pending operations in iOS device " + deviceIdentifier.getId(); - log.error(msg, e); - throw new OperationManagementException(msg, e); - } - return operations; - } - - @Override - public List getFeatures(String type) throws FeatureManagementException { - return null; - } - -} From b796dee2e585cbc93e50904f66ebebf675dfe4e7 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 25 Mar 2015 17:38:46 +0530 Subject: [PATCH 2/5] Create plugin level database --- .../MobileDeviceManagementRepository.java | 22 +- .../datasource/MobileDataSourceConfig.java | 10 + .../dao/MobileDeviceManagementDAOFactory.java | 59 ++-- .../android/AndroidDeviceManagerService.java | 316 +++++++++--------- .../impl/ios/IOSDeviceManagerService.java | 14 +- .../windows/WindowsDeviceManagerService.java | 8 +- ...MobileDeviceManagementBundleActivator.java | 9 +- ...obileDeviceManagementServiceComponent.java | 17 +- .../src/main/resources/conf/mobile-config.xml | 18 +- 9 files changed, 271 insertions(+), 202 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java index 96b6644b2d..1d7b6560c9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java @@ -18,10 +18,14 @@ package org.wso2.carbon.device.mgt.mobile.config; +import org.wso2.carbon.device.mgt.mobile.common.PluginTypeEnum; +import org.wso2.carbon.device.mgt.mobile.config.datasource.DataSourceConfigAdapter; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Map; /** * Class for holding management repository data. @@ -29,15 +33,19 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "ManagementRepository") public class MobileDeviceManagementRepository { - private MobileDataSourceConfig mobileDataSourceConfig; + private Map mobileDataSourceConfigMap; - @XmlElement(name = "DataSourceConfiguration", nillable = false) - public MobileDataSourceConfig getMobileDataSourceConfig() { - return mobileDataSourceConfig; + public MobileDataSourceConfig getMobileDataSourceConfig(PluginTypeEnum type) { + return mobileDataSourceConfigMap.get(type.toString()); } - public void setMobileDataSourceConfig(MobileDataSourceConfig mobileDataSourceConfig) { - this.mobileDataSourceConfig = mobileDataSourceConfig; - } + @XmlElement(name="DataSourceConfigurations") + @XmlJavaTypeAdapter(DataSourceConfigAdapter.class) + public Map getMobileDataSourceConfigMap() { + return mobileDataSourceConfigMap; + } + public void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { + this.mobileDataSourceConfigMap = mobileDataSourceConfigMap; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java index 53eced08ea..99fa93fe83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.mobile.config.datasource; +import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -27,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "DataSourceConfiguration") public class MobileDataSourceConfig { private JNDILookupDefinition jndiLookupDefinition; + private String type; @XmlElement(name = "JndiLookupDefinition", nillable = true) public JNDILookupDefinition getJndiLookupDefinition() { @@ -37,4 +39,12 @@ import javax.xml.bind.annotation.XmlRootElement; this.jndiLookupDefinition = jndiLookupDefinition; } + @XmlAttribute(name = "type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index 925b35fa84..34348e046a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -29,25 +29,34 @@ import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import javax.sql.DataSource; import java.util.Hashtable; import java.util.List; +import java.util.Map; /** * Factory class used to create MobileDeviceManagement related DAO objects. */ public class MobileDeviceManagementDAOFactory { - private static DataSource dataSource; - private static MobileDataSourceConfig mobileDataSourceConfig; private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class); - - public MobileDeviceManagementDAOFactory() { - + private static Map mobileDataSourceConfigMap; + private static Map dataSourceMap; + private String pluginProvider; + private DataSource dataSource; + + public MobileDeviceManagementDAOFactory(String pluginProvider) { + this.pluginProvider = pluginProvider; + this.dataSource = dataSourceMap.get(pluginProvider); } public static void init() { try { - dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig); + DataSource dataSource; + for(String pluginType:mobileDataSourceConfigMap.keySet()){ + dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get + (pluginType)); + dataSourceMap.put(pluginType,dataSource); + } } catch (DeviceManagementException e) { - log.error("Exception occurred while initializing the mobile datasource.",e); + log.error("Exception occurred while initializing the mobile data source.",e); } } @@ -88,41 +97,47 @@ public class MobileDeviceManagementDAOFactory { return dataSource; } - public static MobileDeviceDAO getMobileDeviceDAO() { + public MobileDeviceDAO getMobileDeviceDAO() { return new MobileDeviceDAOImpl(dataSource); } - public static MobileOperationDAO getMobileOperationDAO() { + public MobileOperationDAO getMobileOperationDAO() { return new MobileOperationDAOImpl(dataSource); } - public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() { + public MobileOperationPropertyDAO getMobileOperationPropertyDAO() { return new MobileOperationPropertyDAOImpl(dataSource); } - public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { + public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { return new MobileDeviceOperationMappingDAOImpl(dataSource); } - public static MobileFeatureDAO getFeatureDAO() { + public MobileFeatureDAO getFeatureDAO() { return new MobileFeatureDAOImpl(dataSource); } - public static MobileFeaturePropertyDAO getFeaturePropertyDAO() { + public MobileFeaturePropertyDAO getFeaturePropertyDAO() { return new MobileFeaturePropertyDAOImpl(dataSource); } - public static MobileDataSourceConfig getMobileDeviceManagementConfig() { - return mobileDataSourceConfig; + public MobileDataSourceConfig getMobileDeviceManagementConfig(String pluginType) { + return mobileDataSourceConfigMap.get(pluginType); } - public static void setMobileDataSourceConfig( - MobileDataSourceConfig mobileDataSourceConfig) { - MobileDeviceManagementDAOFactory.mobileDataSourceConfig = - mobileDataSourceConfig; - } + public static Map getMobileDataSourceConfigMap() { + return mobileDataSourceConfigMap; + } - public static DataSource getDataSource() { - return dataSource; + public static void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { + MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap; + } + + public DataSource getDataSource(String type) { + return dataSourceMap.get(type); } + + public static Map getDataSourceMap() { + return dataSourceMap; + } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java index cffd4d882f..c7f62709d3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java @@ -20,12 +20,12 @@ package org.wso2.carbon.device.mgt.mobile.impl.android; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.device.mgt.common.*; import java.util.ArrayList; import java.util.List; @@ -35,12 +35,18 @@ import java.util.List; */ public class AndroidDeviceManagerService implements DeviceManager { - private static final Log log = LogFactory.getLog(AndroidDeviceManagerService.class); + private static final Log log = LogFactory.getLog(AndroidDeviceManagerService.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; - @Override - public String getProviderType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; - } + public AndroidDeviceManagerService() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + } + + @Override + public String getProviderType() { + return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; + } @Override public FeatureManager getFeatureManager() { @@ -48,157 +54,157 @@ public class AndroidDeviceManagerService implements DeviceManager { } @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( - mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while enrolling the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Android device enrollment data"); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the enrollment of the Android device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean status; - try { - if (log.isDebugEnabled()) { - log.debug("Dis-enrolling Android device : " + deviceId); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .deleteMobileDevice(deviceId.getId()); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while removing the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - boolean isEnrolled = false; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( - deviceId.getId()); - if (mobileDevice != null) { - isEnrolled = true; - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while checking the enrollment status of Android device : " + - deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return isEnrolled; - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return true; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - Device device; - try { - if (log.isDebugEnabled()) { - log.debug("Getting the details of Android device : " + deviceId.getId()); - } - MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getMobileDevice(deviceId.getId()); - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching the Android device : " + deviceId.getId(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return device; - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - boolean status; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); - } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } - - @Override - public List getAllDevices() throws DeviceManagementException { - List devices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Android devices"); - } - List mobileDevices = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). - getAllMobileDevices(); - if (mobileDevices != null) { - devices = new ArrayList(); + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while enrolling the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Android device enrollment data"); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while updating the enrollment of the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling Android device : " + deviceId); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .deleteMobileDevice(deviceId.getId()); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while removing the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( + deviceId.getId()); + if (mobileDevice != null) { + isEnrolled = true; + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of Android device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of Android device : " + deviceId.getId()); + } + MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getMobileDevice(deviceId.getId()); + device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("updating the details of Android device : " + device.getDeviceIdentifier()); + } + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while updating the Android device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all Android devices"); + } + List mobileDevices = + mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + getAllMobileDevices(); + if (mobileDevices != null) { + devices = new ArrayList(); for (MobileDevice mobileDevice : mobileDevices) { devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); } - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while fetching all Android devices."; - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return devices; - } + } + } catch (MobileDeviceManagementDAOException e) { + String msg = "Error while fetching all Android devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java index 29168335b1..fed37b4fa5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java @@ -35,12 +35,18 @@ import java.util.List; public class IOSDeviceManagerService implements DeviceManager { private static final Log log = LogFactory.getLog(IOSDeviceManagerService.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; @Override public String getProviderType() { return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS; } + public IOSDeviceManagerService() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants + .MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS); + } + @Override public FeatureManager getFeatureManager() { return null; @@ -51,7 +57,7 @@ public class IOSDeviceManagerService implements DeviceManager { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while enrolling the iOS device : " + @@ -70,7 +76,7 @@ public class IOSDeviceManagerService implements DeviceManager { if (log.isDebugEnabled()) { log.debug("Modifying the iOS device enrollment data"); } - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO() + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() .updateMobileDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while updating the enrollment of the iOS device : " + @@ -94,7 +100,7 @@ public class IOSDeviceManagerService implements DeviceManager { log.debug("Checking the enrollment of iOS device : " + deviceId.getId()); } MobileDevice mobileDevice = - MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( + mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( deviceId.getId()); if (mobileDevice != null) { isEnrolled = true; @@ -131,7 +137,7 @@ public class IOSDeviceManagerService implements DeviceManager { if (log.isDebugEnabled()) { log.debug("Getting the details of iOS device : " + deviceId.getId()); } - MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO(). + MobileDevice mobileDevice = mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). getMobileDevice(deviceId.getId()); device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java index 6fca617162..a2fc29b6cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java @@ -35,6 +35,12 @@ import java.util.List; public class WindowsDeviceManagerService implements DeviceManager { private static final Log log = LogFactory.getLog(WindowsDeviceManagerService.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + + public WindowsDeviceManagerService() { + mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants + .MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + } @Override public String getProviderType() { @@ -97,7 +103,7 @@ public class WindowsDeviceManagerService implements DeviceManager { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( mobileDevice); } catch (MobileDeviceManagementDAOException e) { String msg = "Error while enrolling the Windows device : " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java index 8b851a83d8..1d228d1fd4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java @@ -39,6 +39,7 @@ import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * BundleActivator of MobileDeviceManagement component. @@ -64,14 +65,14 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B } bundleContext.addBundleListener(this); - /* Initialize the datasource configuration */ + /* Initialize the data source configuration */ MobileDeviceConfigurationManager.getInstance().initConfig(); MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); + Map mobileDataSourceConfigMap = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap(); - MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); + MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(mobileDataSourceConfigMap); androidServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index f68765bfa3..8d7d0cdfbb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -39,7 +39,9 @@ import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; +import javax.sql.DataSource; import java.util.List; +import java.util.Map; /** * @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent" @@ -71,14 +73,14 @@ public class MobileDeviceManagementServiceComponent { try { BundleContext bundleContext = ctx.getBundleContext(); - /* Initialize the datasource configuration */ + /* Initialize the data source configuration */ MobileDeviceConfigurationManager.getInstance().initConfig(); MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); + Map dsConfigMap = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap(); - MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); + MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap); MobileDeviceManagementDAOFactory.init(); String setupOption = System.getProperty("setup"); if (setupOption != null) { @@ -88,8 +90,11 @@ public class MobileDeviceManagementServiceComponent { "to begin"); } try { - MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( - MobileDeviceManagementDAOFactory.getDataSource()); + Map dataSourceMap = MobileDeviceManagementDAOFactory.getDataSourceMap(); + for(DataSource dataSource:dataSourceMap.values()) { + MobileDeviceManagementDAOUtil + .setupMobileDeviceManagementSchema(dataSource); + } } catch (DeviceManagementException e) { log.error("Exception occurred while initializing mobile device management database schema", e); } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml index 9ed6b8af08..e0f632213a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml @@ -19,13 +19,25 @@ - + + + + + jdbc/MobileIOSDM_DS + + + - jdbc/MobileDM_DS + jdbc/MobileAndroidDM_DS + + + jdbc/MobileWindowsDM_DS + + + - From 1c13180e568efb2b3ff464cffb79cc29f761c06d Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 26 Mar 2015 17:22:24 +0530 Subject: [PATCH 3/5] Create pluin level databases --- .../pom.xml | 2 +- .../AbstractMobileOperationManager.java | 4 +-- .../MobileDeviceConfigurationManager.java | 3 -- .../MobileDeviceManagementRepository.java | 16 ++++++--- .../datasource/MobileDataSourceConfig.java | 3 +- .../MobileDataSourceConfigurations.java | 17 +++++---- .../impl/windows/WindowsDeviceManager.java | 8 ++--- .../malformed-mobile-config-no-api-config.xml | 35 +++++++++---------- .../src/main/resources/conf/mobile-config.xml | 1 - 9 files changed, 45 insertions(+), 44 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index d3d4069a47..e6974c9192 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -60,7 +60,7 @@ javax.xml.bind.*, javax.naming, javax.sql, - javax.xml.bind.annotation, + javax.xml.bind.annotation.*, javax.xml.parsers, org.w3c.dom, org.wso2.carbon.core, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java index 5a63eef8ba..1b369bb169 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java @@ -33,8 +33,8 @@ public abstract class AbstractMobileOperationManager implements OperationManager } @Override - public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + public boolean addOperation(Operation operation, List devices) throws + OperationManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java index 755e71f90a..07123434d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceConfigurationManager.java @@ -75,8 +75,5 @@ public class MobileDeviceConfigurationManager { return currentMobileDeviceConfig; } - public MobileDataSourceConfig getMobileDataSourceConfig() { - return currentMobileDeviceConfig.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java index 1d7b6560c9..88369dd842 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/MobileDeviceManagementRepository.java @@ -18,13 +18,13 @@ package org.wso2.carbon.device.mgt.mobile.config; -import org.wso2.carbon.device.mgt.mobile.common.PluginTypeEnum; import org.wso2.carbon.device.mgt.mobile.config.datasource.DataSourceConfigAdapter; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.List; import java.util.Map; /** @@ -34,12 +34,13 @@ import java.util.Map; public class MobileDeviceManagementRepository { private Map mobileDataSourceConfigMap; + private List mobileDataSourceConfigs; - public MobileDataSourceConfig getMobileDataSourceConfig(PluginTypeEnum type) { - return mobileDataSourceConfigMap.get(type.toString()); - } + public MobileDataSourceConfig getMobileDataSourceConfig(String provider) { + return mobileDataSourceConfigMap.get(provider); + } - @XmlElement(name="DataSourceConfigurations") + @XmlElement(name = "DataSourceConfigurations") @XmlJavaTypeAdapter(DataSourceConfigAdapter.class) public Map getMobileDataSourceConfigMap() { return mobileDataSourceConfigMap; @@ -48,4 +49,9 @@ public class MobileDeviceManagementRepository { public void setMobileDataSourceConfigMap(Map mobileDataSourceConfigMap) { this.mobileDataSourceConfigMap = mobileDataSourceConfigMap; } + + public List getMobileDataSourceConfigs() { + return (List) mobileDataSourceConfigMap.values(); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java index 99fa93fe83..869aaf12e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java @@ -25,7 +25,8 @@ import javax.xml.bind.annotation.XmlRootElement; /** * Class for holding data source configuration in mobile-config.xml at parsing with JAXB. */ -@XmlRootElement(name = "DataSourceConfiguration") public class MobileDataSourceConfig { +@XmlRootElement(name = "DataSourceConfiguration") +public class MobileDataSourceConfig { private JNDILookupDefinition jndiLookupDefinition; private String type; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java index 7c4afa9a4a..17e80f5bf3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfigurations.java @@ -1,9 +1,3 @@ -package org.wso2.carbon.device.mgt.mobile.config.datasource; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.List; - /* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * @@ -21,10 +15,19 @@ import java.util.List; * specific language governing permissions and limitations * under the License. */ +package org.wso2.carbon.device.mgt.mobile.config.datasource; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + @XmlRootElement(name = "DataSourceConfigurations") +@XmlAccessorType(XmlAccessType.FIELD) public class MobileDataSourceConfigurations { - @XmlElement(name = "DataSourceConfigurations", nillable = true) + @XmlElement(name = "DataSourceConfiguration", nillable = true) private List mobileDataSourceConfigs; public List getMobileDataSourceConfigs() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 920d61296e..054e1eab8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -34,17 +34,13 @@ import java.util.List; */ public class WindowsDeviceManager implements DeviceManager { -<<<<<<< HEAD:components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java - private static final Log log = LogFactory.getLog(WindowsDeviceManagerService.class); - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; - public WindowsDeviceManagerService() { + public WindowsDeviceManager() { mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants .MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); } -======= private static final Log log = LogFactory.getLog(WindowsDeviceManager.class); ->>>>>>> 2c5cc4c28de5586b7450887d02c49a4c9973b40a:components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @Override public String getProviderType() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml index 69f2044ec5..3fad2eceb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml @@ -19,24 +19,23 @@ - - - jdbc/MobileDM_DS - - + + + + jdbc/MobileIOSDM_DS + + + + + jdbc/MobileAndroidDM_DS + + + + + jdbc/MobileWindowsDM_DS + + + - - - - - enrollment - admin - enrollment - 1.0.0 - http://localhost:9763/ - http,https - - - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml index e0f632213a..9daf68724d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/src/main/resources/conf/mobile-config.xml @@ -19,7 +19,6 @@ - From ef1b304b142e1c6f01f0851e34553831e10c6705 Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 26 Mar 2015 20:34:40 +0530 Subject: [PATCH 4/5] Create databases in plugin level --- .../dao/MobileDeviceManagementDAOFactory.java | 2 ++ .../MobileDeviceManagementServiceComponent.java | 15 ++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index 0dc2d7fbd0..c1eebf9139 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.impl.*; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import javax.sql.DataSource; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -51,6 +52,7 @@ public class MobileDeviceManagementDAOFactory { public static void init() throws DeviceManagementException { + dataSourceMap = new HashMap(); DataSource dataSource; for (String pluginType : mobileDataSourceConfigMap.keySet()) { dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 4798236c37..96d1bb95f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -25,7 +25,6 @@ import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; -import org.wso2.carbon.device.mgt.mobile.DataSourceListener; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; @@ -56,9 +55,9 @@ import java.util.Map; public class MobileDeviceManagementServiceComponent { private ServiceRegistration serverStartupObserverRef; - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration iOSServiceRegRef; - private ServiceRegistration windowsServiceRegRef; + private ServiceRegistration androidServiceRegRef; + private ServiceRegistration iOSServiceRegRef; + private ServiceRegistration windowsServiceRegRef; private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); @@ -136,11 +135,9 @@ public class MobileDeviceManagementServiceComponent { protected void setDataSourceService(DataSourceService dataSourceService) { /* This is to avoid mobile device management component getting initialized before the underlying datasources are registered */ - try { - MobileDeviceManagementDAOFactory.init(); - } catch (DeviceManagementException e) { - log.error("Error occurred while initializing mobile device management repository datasource", e); - } + if (log.isDebugEnabled()){ + log.debug("Data source service set to mobile service component"); + } } protected void unsetDataSourceService(DataSourceService dataSourceService) { From 1798fabc01f01d8a7c4419bee5abe755627f807d Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 26 Mar 2015 22:22:59 +0530 Subject: [PATCH 5/5] Create plugin level database --- .../mobile/internal/MobileDeviceManagementServiceComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 94d1039a60..5e5d87c341 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -140,7 +140,7 @@ public class MobileDeviceManagementServiceComponent { log.debug("Data source service set to mobile service component"); } } - + protected void unsetDataSourceService(DataSourceService dataSourceService) { //do nothing }