From 647998c7d08f31f98a06dec802dc2b738c2441b9 Mon Sep 17 00:00:00 2001 From: Kasun Delgolla Date: Tue, 20 Oct 2015 01:39:03 +0530 Subject: [PATCH] Committing windows feature manager --- .../impl/windows/WindowsDeviceManager.java | 4 +- .../impl/windows/WindowsFeatureManager.java | 104 ++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java 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 82f398901..e69350034 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 @@ -50,7 +50,7 @@ public class WindowsDeviceManager implements DeviceManager { private MobileDeviceManagementDAOFactory daoFactory; private LicenseManager licenseManager; - + private FeatureManager featureManager = new WindowsFeatureManager(); private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); public WindowsDeviceManager() { @@ -60,7 +60,7 @@ public class WindowsDeviceManager implements DeviceManager { @Override public FeatureManager getFeatureManager() { - return null; + return featureManager; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java new file mode 100644 index 000000000..99067b7eb --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java @@ -0,0 +1,104 @@ +/* + * 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.windows; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManager; +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.dto.MobileFeature; +import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; +import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; + +import java.util.ArrayList; +import java.util.List; + +public class WindowsFeatureManager implements FeatureManager { + + private MobileFeatureDAO featureDAO; + private static final Log log = LogFactory.getLog(WindowsFeatureManager.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + + public WindowsFeatureManager() { + mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); + this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); + } + + @Override + public boolean addFeature(Feature feature) throws DeviceManagementException { + + try { + WindowsDAOFactory.beginTransaction(); + MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); + featureDAO.addFeature(mobileFeature); + WindowsDAOFactory.commitTransaction(); + return true; + } catch (MobileDeviceManagementDAOException e) { + WindowsDAOFactory.rollbackTransaction(); + throw new DeviceManagementException("Error occurred while adding the feature", e); + } + } + + @Override + public Feature getFeature(String name) throws DeviceManagementException { + try { + MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); + Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); + return feature; + } catch (MobileDeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the feature", e); + } + } + + @Override + public List getFeatures() throws DeviceManagementException { + + List featureList = new ArrayList(); + try { + List mobileFeatures = featureDAO.getAllFeatures(); + for (MobileFeature mobileFeature : mobileFeatures) { + featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); + } + return featureList; + } catch (MobileDeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + + "Android platform", e); + } + } + + @Override + public boolean removeFeature(String code) throws DeviceManagementException { + boolean status = false; + try { + WindowsDAOFactory.beginTransaction(); + featureDAO.deleteFeatureByCode(code); + WindowsDAOFactory.commitTransaction(); + status = true; + } catch (MobileDeviceManagementDAOException e) { + WindowsDAOFactory.rollbackTransaction(); + throw new DeviceManagementException("Error occurred while removing the feature", e); + } + return status; + } + +} \ No newline at end of file