From 29a6f0706af15f00e971c2892830e3bbe5f237a5 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 24 Jul 2015 12:09:01 +0530 Subject: [PATCH] Adapting LicenseManager changes introduced in org.wso2.carbon.device.mgt.core and org.wso2.carbon.device.mgt.extensions --- .../pom.xml | 5 + .../AndroidDeviceManagementService.java | 3 +- .../impl/android/AndroidDeviceManager.java | 566 +++++++++--------- .../WindowsDeviceManagementService.java | 3 +- .../impl/windows/WindowsDeviceManager.java | 44 +- ... => MobileDeviceManagementDataHolder.java} | 8 +- ...obileDeviceManagementServiceComponent.java | 4 +- .../util/MobileDeviceManagementUtil.java | 5 +- pom.xml | 5 + 9 files changed, 351 insertions(+), 292 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/{MobileDeviceManagementServiceDataHolder.java => MobileDeviceManagementDataHolder.java} (78%) 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 c0b4489aa..64d5d4aa6 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 @@ -76,6 +76,7 @@ org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.api, + org.wso2.carbon.device.mgt.extensions.license.mgt !org.wso2.carbon.device.mgt.mobile.internal, @@ -127,6 +128,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + org.wso2.carbon org.wso2.carbon.ndatasource.core diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java index 416a7cef5..ffac64dec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java @@ -43,10 +43,11 @@ import java.util.List; public class AndroidDeviceManagementService implements DeviceManagementService { private DeviceManager deviceManager; + public static final String DEVICE_TYPE_ANDROID = "android"; @Override public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; + return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID; } @Override 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 20692e5e6..eb4d116cd 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 @@ -24,13 +24,18 @@ 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.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.extensions.license.mgt.RegistryBasedLicenseManager; 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.internal.MobileDeviceManagementDataHolder; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.registry.api.Collection; +import org.wso2.carbon.registry.api.Registry; import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.api.RegistryException; @@ -39,295 +44,314 @@ 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 LicenseManager licenseManager; - public AndroidDeviceManager() { - mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); - } + public AndroidDeviceManager() { + this.mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); + try { + Registry registry = + MobileDeviceManagementDataHolder.getInstance().getRegistryService().getConfigSystemRegistry(); + this.licenseManager = new RegistryBasedLicenseManager(registry); + } catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) { + throw new IllegalStateException("Error occurred while retrieving config system registry of the tenant, " + + "which in turns fails the initialization of Android Device Manager", e); + } + } - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } + @Override + public FeatureManager getFeatureManager() { + return featureManager; + } - @Override - 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 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 { - 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 TenantConfiguration getConfiguration() throws DeviceManagementException { + 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; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - AndroidDAOFactory.beginTransaction(); - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( - 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; - } + @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()); + } + AndroidDAOFactory.beginTransaction(); + status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( + 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; + } - @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 License getLicense(String languageCode) throws LicenseManagementException { + return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode); + } - // This object holds the newly received device object from response - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); + @Override + public void addLicense(License license) throws LicenseManagementException { + licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license); + } - // Updating current object features using newer ones - mobileDeviceDB.setLatitude(mobileDevice.getLatitude()); - mobileDeviceDB.setLongitude(mobileDevice.getLongitude()); - mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties()); + @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); - 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; - } + // This object holds the newly received device object from response + MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - @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; - } + // 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; + } + + @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/WindowsDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java index f38589605..08f686ad2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java @@ -40,10 +40,11 @@ import java.util.List; public class WindowsDeviceManagementService implements DeviceManagementService { private DeviceManager deviceManager; + public static final String DEVICE_TYPE_WINDOWS = "windows"; @Override public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; + return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS; } @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/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 467c5fa5b..25d8c2bac 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,24 +21,38 @@ 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.*; -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.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.extensions.license.mgt.RegistryBasedLicenseManager; 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.windows.dao.WindowsDAOFactory; +import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; +import org.wso2.carbon.registry.api.Registry; import java.util.List; -import java.util.Map; public class WindowsDeviceManager implements DeviceManager { - private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; + private MobileDeviceManagementDAOFactory daoFactory; + private LicenseManager licenseManager; + private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); public WindowsDeviceManager() { - mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); + daoFactory = new WindowsDAOFactory(); + try { + Registry registry = + MobileDeviceManagementDataHolder.getInstance().getRegistryService().getConfigSystemRegistry(); + this.licenseManager = new RegistryBasedLicenseManager(registry); + } catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) { + throw new IllegalStateException("Error occurred while retrieving config system registry of the tenant, " + + "which in turns fails the initialization of Android Device Manager", e); + } } @Override @@ -110,7 +124,18 @@ public class WindowsDeviceManager implements DeviceManager { } @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { + public License getLicense(String languageCode) throws LicenseManagementException { + return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); + } + + @Override + public void addLicense(License license) throws LicenseManagementException { + licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, license); + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, + Device device) throws DeviceManagementException { return true; } @@ -119,13 +144,10 @@ public class WindowsDeviceManager implements DeviceManager { boolean status; MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); try { - status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( - mobileDevice); + status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice); } catch (MobileDeviceManagementDAOException e) { - String msg = "Error while enrolling the Windows device : " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); + throw new DeviceManagementException("Error while enrolling the Windows device '" + + device.getDeviceIdentifier() + "'", e); } return status; } 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/MobileDeviceManagementDataHolder.java similarity index 78% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceDataHolder.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java index 4ad231ebf..40c661009 100644 --- 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/MobileDeviceManagementDataHolder.java @@ -23,16 +23,16 @@ import org.wso2.carbon.registry.core.service.RegistryService; /** * DataHolder class of Mobile plugins component. */ -public class MobileDeviceManagementServiceDataHolder { +public class MobileDeviceManagementDataHolder { private RegistryService registryService; - private static MobileDeviceManagementServiceDataHolder thisInstance = new MobileDeviceManagementServiceDataHolder(); + private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder(); - private MobileDeviceManagementServiceDataHolder() { + private MobileDeviceManagementDataHolder() { } - public static MobileDeviceManagementServiceDataHolder getInstance() { + public static MobileDeviceManagementDataHolder getInstance() { return thisInstance; } 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 1951d1c0e..a35d8df1a 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 @@ -157,11 +157,11 @@ public class MobileDeviceManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("RegistryService acquired"); } - MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(registryService); + MobileDeviceManagementDataHolder.getInstance().setRegistryService(registryService); } protected void unsetRegistryService(RegistryService registryService) { - MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(null); + MobileDeviceManagementDataHolder.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/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 82d8b6805..52cef6eab 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 @@ -30,7 +30,8 @@ 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.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; +import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.core.Registry; @@ -201,7 +202,7 @@ public class MobileDeviceManagementUtil { public static Registry getRegistry() throws MobileDeviceMgtPluginException { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - return MobileDeviceManagementServiceDataHolder.getInstance().getRegistryService() + return MobileDeviceManagementDataHolder.getInstance().getRegistryService() .getConfigSystemRegistry( tenantId); } catch (RegistryException e) { diff --git a/pom.xml b/pom.xml index 1bb9c0edb..dd66c8eb0 100644 --- a/pom.xml +++ b/pom.xml @@ -214,6 +214,11 @@ org.wso2.carbon.device.mgt.common ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common