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 00af11e11d..c0b4489aa9 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 @@ -65,11 +65,17 @@ javax.xml.parsers, org.w3c.dom, org.wso2.carbon.core, + org.wso2.carbon.context, org.wso2.carbon.utils.*, org.wso2.carbon.device.mgt.common.*, org.wso2.carbon.ndatasource.core, org.wso2.carbon.policy.mgt.common.*, - org.wso2.carbon.policy.mgt.core.* + org.wso2.carbon.policy.mgt.core.*, + org.wso2.carbon.registry.core, + org.wso2.carbon.registry.core.exceptions, + org.wso2.carbon.registry.core.service, + org.wso2.carbon.registry.core.session, + org.wso2.carbon.registry.api, !org.wso2.carbon.device.mgt.mobile.internal, @@ -133,6 +139,14 @@ org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.core + + org.wso2.carbon + org.wso2.carbon.registry.api + + + org.wso2.carbon + org.wso2.carbon.registry.core + org.testng testng diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobilePluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobilePluginConstants.java index 8287e60c84..b5f19808b1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobilePluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/common/MobilePluginConstants.java @@ -19,5 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.common; public class MobilePluginConstants { public static final String MOBILE_DB_SCRIPTS_FOLDER = "cdm"; + public static final String MOBILE_CONFIG_REGISTRY_ROOT = "/_system/config"; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index 321fa0222b..15c331c45e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java @@ -21,51 +21,109 @@ 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.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; 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.impl.android.dao.AndroidDAOFactory; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; +import org.wso2.carbon.registry.api.Collection; +import org.wso2.carbon.registry.api.Resource; +import org.wso2.carbon.registry.api.RegistryException; import java.util.ArrayList; import java.util.List; public class AndroidDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; - private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); - private FeatureManager featureManager = new AndroidFeatureManager(); - private License license; + private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); + private FeatureManager featureManager = new AndroidFeatureManager(); + private License license; - public AndroidDeviceManager() { - mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); - } + public AndroidDeviceManager() { + mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); + } - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } + @Override + public FeatureManager getFeatureManager() { + return featureManager; + } @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException { - return false; + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + boolean status = false; + Resource resource; + try { + if (log.isDebugEnabled()) { + log.debug("Persisting android configurations in Registry"); + } + String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( + DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + MobileDeviceManagementUtil.createRegistryCollection(resourcePath); + for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) { + resource = MobileDeviceManagementUtil.getRegistry().newResource(); + resource.setContent(configEntry.getValue()); + MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource); + } + status = true; + } catch (MobileDeviceMgtPluginException e) { + throw new DeviceManagementException( + "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); + } catch (RegistryException e) { + throw new DeviceManagementException( + "Error occurred while persisting the Registry resource : " + e.getMessage(), e); + } + return status; } @Override public TenantConfiguration getConfiguration() throws DeviceManagementException { - return null; + Collection dsCollection = null; + TenantConfiguration tenantConfiguration; + List configs = new ArrayList(); + ConfigurationEntry entry; + Resource resource; + try { + String androidRegPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + dsCollection = (Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath); + String[] dsmPaths = dsCollection.getChildren(); + for (String dsmPath : dsmPaths) { + entry = new ConfigurationEntry(); + resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath); + entry.setValue(resource.getContent()); + entry.setName(resource.getId()); + configs.add(entry); + } + tenantConfiguration = new TenantConfiguration(); + tenantConfiguration.setConfiguration(configs); + tenantConfiguration.setType(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + } catch (MobileDeviceMgtPluginException e) { + throw new DeviceManagementException( + "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); + } catch (RegistryException e) { + throw new DeviceManagementException( + "Error occurred while retrieving the Registry data : " + e.getMessage(), e); + } + return tenantConfiguration; } @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status = false; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status = false; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); + } boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); if (isEnrolled) { this.modifyEnrollment(device); @@ -75,201 +133,205 @@ public class AndroidDeviceManager implements DeviceManager { mobileDevice); AndroidDAOFactory.commitTransaction(); } - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); - log.warn(msg, mobileDAOEx); - } - String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException mobileDAOEx) { + String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); + log.warn(msg, mobileDAOEx); + } + 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"); - } - AndroidDAOFactory.beginTransaction(); - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDevice); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the update device transaction :" + device.toString(); - log.warn(msg, mobileDAOEx); - } - 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 modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Android device enrollment data"); + } + AndroidDAOFactory.beginTransaction(); + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDevice); + AndroidDAOFactory.commitTransaction(); + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException mobileDAOEx) { + String msg = "Error occurred while roll back the update device transaction :" + + device.toString(); + log.warn(msg, mobileDAOEx); + } + 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); - } - AndroidDAOFactory.beginTransaction(); - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .deleteMobileDevice(deviceId.getId()); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); - log.warn(msg, mobileDAOEx); - } - String msg = "Error while removing the Android device : " + deviceId.getId(); - 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); + } + AndroidDAOFactory.beginTransaction(); + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .deleteMobileDevice(deviceId.getId()); + AndroidDAOFactory.commitTransaction(); + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException mobileDAOEx) { + String msg = "Error occurred while roll back the device dis enrol transaction :" + + deviceId.toString(); + log.warn(msg, mobileDAOEx); + } + 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 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 isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - 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 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 setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } - @Override - public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; - } + @Override + public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } - @Override - public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, - EnrolmentInfo.Status status) throws DeviceManagementException { - return false; - } + @Override + public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, + EnrolmentInfo.Status status) throws DeviceManagementException { + return false; + } - @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { - boolean status; - Device deviceDB = this.getDevice(deviceIdentifier); - // This object holds the current persisted device object - MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB); + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) + throws DeviceManagementException { + boolean status; + Device deviceDB = this.getDevice(deviceIdentifier); + // This object holds the current persisted device object + MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB); - // This object holds the newly received device object from response - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + // This object holds the newly received device object from response + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - // Updating current object features using newer ones - mobileDeviceDB.setLatitude(mobileDevice.getLatitude()); - mobileDeviceDB.setLongitude(mobileDevice.getLongitude()); - mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties()); + // Updating current object features using newer ones + mobileDeviceDB.setLatitude(mobileDevice.getLatitude()); + mobileDeviceDB.setLongitude(mobileDevice.getLongitude()); + mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties()); - try { - if (log.isDebugEnabled()) { - log.debug( - "updating the details of Android device : " + device.getDeviceIdentifier()); - } - AndroidDAOFactory.beginTransaction(); - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() - .updateMobileDevice(mobileDeviceDB); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException mobileDAOEx) { - String msg = "Error occurred while roll back the update device info transaction :" + device.toString(); - log.warn(msg, mobileDAOEx); - } - String msg = - "Error while updating the Android device : " + device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - return status; - } + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of Android device : " + device.getDeviceIdentifier()); + } + AndroidDAOFactory.beginTransaction(); + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() + .updateMobileDevice(mobileDeviceDB); + AndroidDAOFactory.commitTransaction(); + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException mobileDAOEx) { + String msg = "Error occurred while roll back the update device info transaction :" + + device.toString(); + log.warn(msg, mobileDAOEx); + } + 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; - } + @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; + } } 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 af34ea52c5..a56c07bca4 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 @@ -21,6 +21,10 @@ 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.*; +<<<<<<< HEAD +======= +import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; +>>>>>>> d07c226dd52d29fbc7ee2993ecf0f9700aa43ece import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; @@ -29,6 +33,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.List; +import java.util.Map; public class WindowsDeviceManager implements DeviceManager { @@ -44,6 +49,7 @@ public class WindowsDeviceManager implements DeviceManager { return null; } +<<<<<<< HEAD @Override public boolean saveConfiguration(TenantConfiguration tenantConfiguration) throws DeviceManagementException { return false; @@ -55,6 +61,20 @@ public class WindowsDeviceManager implements DeviceManager { } @Override +======= + @Override + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + return false; + } + + @Override + public TenantConfiguration getConfiguration() throws DeviceManagementException { + return null; + } + + @Override +>>>>>>> d07c226dd52d29fbc7ee2993ecf0f9700aa43ece public boolean modifyEnrollment(Device device) throws DeviceManagementException { return true; } 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 0be1c46624..1951d1c0e1 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 @@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementSer import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsPolicyMonitoringService; import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; +import org.wso2.carbon.registry.core.service.RegistryService; import java.util.Map; @@ -48,6 +49,9 @@ import java.util.Map; * policy="dynamic" * bind="setDataSourceService" * unbind="unsetDataSourceService" + * @scr.reference name="registry.service" + * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="0..1" + * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService" *

* Adding reference to API Manager Configuration service is an unavoidable hack to get rid of NPEs thrown while * initializing APIMgtDAOs attempting to register APIs programmatically. APIMgtDAO needs to be proper cleaned up @@ -149,4 +153,15 @@ public class MobileDeviceManagementServiceComponent { //do nothing } + protected void setRegistryService(RegistryService registryService) { + if (log.isDebugEnabled()) { + log.debug("RegistryService acquired"); + } + MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(registryService); + } + + protected void unsetRegistryService(RegistryService registryService) { + MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(null); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceDataHolder.java new file mode 100644 index 0000000000..4ad231ebf3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceDataHolder.java @@ -0,0 +1,47 @@ +/* + * 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.internal; + +import org.wso2.carbon.registry.core.service.RegistryService; + +/** + * DataHolder class of Mobile plugins component. + */ +public class MobileDeviceManagementServiceDataHolder { + + private RegistryService registryService; + + private static MobileDeviceManagementServiceDataHolder thisInstance = new MobileDeviceManagementServiceDataHolder(); + + private MobileDeviceManagementServiceDataHolder() { + } + + public static MobileDeviceManagementServiceDataHolder getInstance() { + return thisInstance; + } + + public RegistryService getRegistryService() { + return registryService; + } + + public void setRegistryService(RegistryService registryService) { + this.registryService = registryService; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 5d7f8b35f3..82d8b68058 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -21,11 +21,19 @@ package org.wso2.carbon.device.mgt.mobile.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; +import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; import org.wso2.carbon.device.mgt.mobile.dto.*; +import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementServiceDataHolder; +import org.wso2.carbon.registry.api.RegistryException; +import org.wso2.carbon.registry.api.Resource; +import org.wso2.carbon.registry.core.Registry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -54,8 +62,9 @@ public class MobileDeviceManagementUtil { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new DeviceManagementException("Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); + throw new DeviceManagementException( + "Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage(), e); } } @@ -91,16 +100,16 @@ public class MobileDeviceManagementUtil { mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); - if (device.getProperties() != null) { - Map deviceProperties = new HashMap(); - for (Device.Property deviceProperty : device.getProperties()) { - deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue()); - } + if (device.getProperties() != null) { + Map deviceProperties = new HashMap(); + for (Device.Property deviceProperty : device.getProperties()) { + deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue()); + } - mobileDevice.setDeviceProperties(deviceProperties); - } else { - mobileDevice.setDeviceProperties(new HashMap()); - } + mobileDevice.setDeviceProperties(deviceProperties); + } else { + mobileDevice.setDeviceProperties(new HashMap()); + } } return mobileDevice; } @@ -119,13 +128,15 @@ public class MobileDeviceManagementUtil { propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial())); - if (mobileDevice.getDeviceProperties() != null) { - for (Map.Entry deviceProperty : mobileDevice.getDeviceProperties().entrySet()) { - propertyList.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue())); - } - } + if (mobileDevice.getDeviceProperties() != null) { + for (Map.Entry deviceProperty : mobileDevice.getDeviceProperties() + .entrySet()) { + propertyList + .add(getProperty(deviceProperty.getKey(), deviceProperty.getValue())); + } + } - device.setProperties(propertyList); + device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; @@ -162,27 +173,121 @@ public class MobileDeviceManagementUtil { Properties properties = new Properties(); operation.setCode(mobileOperation.getFeatureCode()); for (MobileOperationProperty mobileOperationProperty : mobileOperation.getProperties()) { - properties.put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue()); + properties + .put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue()); } operation.setProperties(properties); return operation; } - public static MobileFeature convertToMobileFeature(Feature feature) { - MobileFeature mobileFeature = new MobileFeature(); - mobileFeature.setName(feature.getName()); - mobileFeature.setCode(feature.getCode()); - mobileFeature.setDescription(feature.getDescription()); - mobileFeature.setDeviceType(feature.getDeviceType()); - return mobileFeature; - } - - public static Feature convertToFeature(MobileFeature mobileFeature) { - Feature feature = new Feature(); - feature.setDescription(mobileFeature.getDescription()); - feature.setDeviceType(mobileFeature.getDeviceType()); - feature.setCode(mobileFeature.getCode()); - feature.setName(mobileFeature.getName()); - return feature; - } + public static MobileFeature convertToMobileFeature(Feature feature) { + MobileFeature mobileFeature = new MobileFeature(); + mobileFeature.setName(feature.getName()); + mobileFeature.setCode(feature.getCode()); + mobileFeature.setDescription(feature.getDescription()); + mobileFeature.setDeviceType(feature.getDeviceType()); + return mobileFeature; + } + + public static Feature convertToFeature(MobileFeature mobileFeature) { + Feature feature = new Feature(); + feature.setDescription(mobileFeature.getDescription()); + feature.setDeviceType(mobileFeature.getDeviceType()); + feature.setCode(mobileFeature.getCode()); + feature.setName(mobileFeature.getName()); + return feature; + } + + public static Registry getRegistry() throws MobileDeviceMgtPluginException { + try { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + return MobileDeviceManagementServiceDataHolder.getInstance().getRegistryService() + .getConfigSystemRegistry( + tenantId); + } catch (RegistryException e) { + throw new MobileDeviceMgtPluginException( + "Error in retrieving conf registry instance: " + + e.getMessage(), e); + } + } + + public static Resource getRegistryResource(String path) throws MobileDeviceMgtPluginException { + try { + return MobileDeviceManagementUtil.getRegistry().get(path); + + } catch (RegistryException e) { + throw new MobileDeviceMgtPluginException("Error in retrieving registry resource : " + + e.getMessage(), e); + } + } + + public static boolean putRegistryResource(String path, + Resource resource) + throws MobileDeviceMgtPluginException { + boolean status = false; + try { + MobileDeviceManagementUtil.getRegistry().beginTransaction(); + MobileDeviceManagementUtil.getRegistry().put(path, resource); + MobileDeviceManagementUtil.getRegistry().commitTransaction(); + status = true; + } catch (RegistryException e) { + throw new MobileDeviceMgtPluginException( + "Error occurred while persisting registry resource : " + + e.getMessage(), e); + } + return status; + } + + public static String getResourcePath(String resourceName, String platform) { + String regPath = ""; + switch (platform) { + case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID: + regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" + + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID + + "/" + resourceName; + break; + case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS: + regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" + + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS + + "/" + resourceName; + break; + } + return regPath; + } + + public static String getPlatformConfigPath(String platform) { + String regPath = ""; + switch (platform) { + case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID: + regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" + + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; + break; + case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS: + regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" + + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; + break; + } + return regPath; + } + + public static boolean createRegistryCollection(String path) + throws MobileDeviceMgtPluginException { + try { + if (! MobileDeviceManagementUtil.getRegistry().resourceExists(path)) { + Resource resource = MobileDeviceManagementUtil.getRegistry().newCollection(); + MobileDeviceManagementUtil.getRegistry().beginTransaction(); + MobileDeviceManagementUtil.getRegistry().put(path, resource); + MobileDeviceManagementUtil.getRegistry().commitTransaction(); + } + return true; + } catch (MobileDeviceMgtPluginException e) { + throw new MobileDeviceMgtPluginException( + "Error occurred while creating a registry collection : " + + e.getMessage(), e); + } catch (RegistryException e) { + throw new MobileDeviceMgtPluginException( + "Error occurred while creating a registry collection : " + + e.getMessage(), e); + } + } } diff --git a/pom.xml b/pom.xml index 0e07aa8d30..1bb9c0edb1 100644 --- a/pom.xml +++ b/pom.xml @@ -419,6 +419,72 @@ + + + org.wso2.carbon + org.wso2.carbon.registry.api + ${carbon.kernel.version} + + + org.wso2.carbon + org.wso2.carbon.registry.core + ${carbon.kernel.version} + + + commons-io.wso2 + commons-io + + + net.sourceforge.findbugs + annotations + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.apache.ws.commons.schema.wso2 + XmlSchema + + + org.wso2.carbon + javax.cache.wso2 + + + org.wso2.carbon + org.wso2.carbon.registry.xboot + + + org.wso2.securevault + org.wso2.securevault + + + org.compass-project.wso2 + compass + + + org.apache.abdera.wso2 + abdera + + + org.wso2.carbon + org.wso2.carbon.ndatasource.rdbms + + + org.apache.poi.wso2 + poi-scratchpad + + + commons-httpclient.wso2 + commons-httpclient + + + commons-pool.wso2 + commons-pool + + + + @@ -521,8 +587,8 @@ 2.3.1 UTF-8 - 1.6 - 1.6 + 1.7 + 1.7