From 951b9947d51665696fad7cb2ddb036b0ace979b4 Mon Sep 17 00:00:00 2001 From: Dilshan Edirisuriya Date: Mon, 30 Mar 2015 12:53:40 +0530 Subject: [PATCH] Implementing FeatureDAO for iOS --- .../mgt/mobile/impl/ios/IOSDeviceManager.java | 8 ++- .../mobile/impl/ios/IOSFeatureManager.java | 67 +++++++++++++++++-- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java index c96ede7647..6bdd521b4f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java @@ -34,8 +34,9 @@ import java.util.List; */ public class IOSDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; - private static final Log log = LogFactory.getLog(IOSDeviceManager.class); + private static final Log log = LogFactory.getLog(IOSDeviceManager.class); + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private IOSFeatureManager iosFeatureManager; @Override public String getProviderType() { @@ -45,11 +46,12 @@ public class IOSDeviceManager implements DeviceManager { public IOSDeviceManager() { mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants .MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS); + iosFeatureManager = new IOSFeatureManager(); } @Override public FeatureManager getFeatureManager() { - return null; + return iosFeatureManager; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSFeatureManager.java index e4ab47ade0..3956958484 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSFeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSFeatureManager.java @@ -18,16 +18,21 @@ */ 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.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException; import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOFactory; import java.util.List; public class IOSFeatureManager implements FeatureManager { + private static final Log log = LogFactory.getLog(IOSFeatureManager.class); + private FeatureDAO featureDAO; public IOSFeatureManager() { @@ -36,22 +41,70 @@ public class IOSFeatureManager implements FeatureManager { @Override public boolean addFeature(Feature feature) throws DeviceManagementException { - return false; + try { + FeatureManagementDAOFactory.beginTransaction(); + featureDAO.addFeature(feature); + FeatureManagementDAOFactory.commitTransaction(); + return true; + } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } + throw new DeviceManagementException("Error occurred while adding the feature", e); + } } @Override - public Feature getFeature(String s) throws DeviceManagementException { - return null; + public Feature getFeature(String name) throws DeviceManagementException { + try { + FeatureManagementDAOFactory.beginTransaction(); + Feature feature = featureDAO.getFeature(name); + FeatureManagementDAOFactory.commitTransaction(); + return feature; + } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } + throw new DeviceManagementException("Error occurred while retrieving the feature", e); + } } @Override public List getFeatures() throws DeviceManagementException { - return null; + try { + FeatureManagementDAOFactory.beginTransaction(); + List features = featureDAO.getFeatures(); + FeatureManagementDAOFactory.commitTransaction(); + return features; + } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } + throw new DeviceManagementException("Error occurred while retrieving the list of features registered " + + "for Android platform", e); + } } @Override - public boolean removeFeature(String s) throws DeviceManagementException { - return false; + public boolean removeFeature(String name) throws DeviceManagementException { + try { + FeatureManagementDAOFactory.beginTransaction(); + featureDAO.removeFeature(name); + FeatureManagementDAOFactory.commitTransaction(); + return true; + } catch (FeatureManagementDAOException e) { + try { + FeatureManagementDAOFactory.rollbackTransaction(); + } catch (FeatureManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } + throw new DeviceManagementException("Error occurred while removing the feature", e); + } } - }