From acb098f3ec41c4efa99cee6094c9270806389f91 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 25 Mar 2015 17:38:24 +0530 Subject: [PATCH] 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; - } - -}