From 9ef3aea603459b6acfd4b15ac30e4fccf38b2203 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 17 Nov 2015 20:39:06 +0530 Subject: [PATCH 1/3] refactored device info --- .../mgt/mobile/impl/windows/util/WindowsPluginConstants.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java index edae380d4..6e93b4f38 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java @@ -37,6 +37,7 @@ public class WindowsPluginConstants { public static final String SERIAL = "SERIAL"; public static final String MAC_ADDRESS = "MAC_ADDRESS"; public static final String DEVICE_NAME = "DEVICE_NAME"; + public static final String RESOLUTION = "RESOLUTION"; //Properties related to WIN_FEATURE table public static final String WINDOWS_FEATURE_ID = "ID"; From 75d35dadca6f1872be6746724a5f98ecb61ec3df Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 4 Dec 2015 11:02:40 +0530 Subject: [PATCH 2/3] fixed default license issue --- .../impl/android/AndroidDeviceManager.java | 572 +++++++++--------- .../impl/windows/WindowsDeviceManager.java | 12 +- 2 files changed, 294 insertions(+), 290 deletions(-) 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 11442785c..b16305836 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 @@ -49,317 +49,319 @@ import java.util.List; public class AndroidDeviceManager implements DeviceManager { - private AbstractMobileDeviceManagementDAOFactory daoFactory; - private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); - private FeatureManager featureManager = new AndroidFeatureManager(); - private LicenseManager licenseManager; + private AbstractMobileDeviceManagementDAOFactory daoFactory; + private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); + private FeatureManager featureManager = new AndroidFeatureManager(); + private LicenseManager licenseManager; - public AndroidDeviceManager() { - this.daoFactory = new AndroidDAOFactory(); - this.licenseManager = new RegistryBasedLicenseManager(); + public AndroidDeviceManager() { + this.daoFactory = new AndroidDAOFactory(); + this.licenseManager = new RegistryBasedLicenseManager(); + License defaultLicense; - License defaultLicense = AndroidPluginUtils.getDefaultLicense(); - try { - licenseManager - .addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); - featureManager.addSupportedFeaturesToDB(); - } catch (LicenseManagementException e) { - log.error("Error occurred while adding default license for Android devices", e); - } catch (DeviceManagementException e) { + try { + if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, "en_US") == null) { + defaultLicense = AndroidPluginUtils.getDefaultLicense(); + licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); + } + featureManager.addSupportedFeaturesToDB(); + } catch (LicenseManagementException e) { + log.error("Error occurred while adding default license for Android devices", e); + } catch (DeviceManagementException e) { log.error("Error occurred while adding supported device features for Android platform", e); } } - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } + @Override + public FeatureManager getFeatureManager() { + return featureManager; + } - @Override - public boolean saveConfiguration(TenantConfiguration tenantConfiguration) - throws DeviceManagementException { - boolean status; - try { - if (log.isDebugEnabled()) { - log.debug("Persisting android configurations in Registry"); - } - String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( - DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(tenantConfiguration, writer); + @Override + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Persisting android configurations in Registry"); + } + String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( + DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + StringWriter writer = new StringWriter(); + JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.marshal(tenantConfiguration, writer); - Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource(); - resource.setContent(writer.toString()); - resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); - MobileDeviceManagementUtil.putRegistryResource(resourcePath, 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 of Android Configuration : " + e.getMessage(), e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration : " + e.getMessage(), e); - } - return status; - } + Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newResource(); + resource.setContent(writer.toString()); + resource.setMediaType(MobilePluginConstants.MEDIA_TYPE_XML); + MobileDeviceManagementUtil.putRegistryResource(resourcePath, 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 of Android Configuration : " + e.getMessage(), e); + } catch (JAXBException e) { + throw new DeviceManagementException( + "Error occurred while parsing the Android configuration : " + e.getMessage(), e); + } + return status; + } - @Override - public TenantConfiguration getConfiguration() throws DeviceManagementException { - Resource resource; - try { - String androidRegPath = - MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); - if(resource != null){ - JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - return (TenantConfiguration) unmarshaller.unmarshal( - new StringReader(new String((byte[]) resource.getContent(), Charset. - forName(MobilePluginConstants.CHARSET_UTF8)))); - } - return null; - } catch (MobileDeviceMgtPluginException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration : " + e.getMessage(), e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry resource of Android Configuration : " + e.getMessage(), e); - } - } + @Override + public TenantConfiguration getConfiguration() throws DeviceManagementException { + Resource resource; + try { + String androidRegPath = + MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath); + if (resource != null) { + JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return (TenantConfiguration) unmarshaller.unmarshal( + new StringReader(new String((byte[]) resource.getContent(), Charset. + forName(MobilePluginConstants.CHARSET_UTF8)))); + } + return null; + } catch (MobileDeviceMgtPluginException e) { + throw new DeviceManagementException( + "Error occurred while retrieving the Registry instance : " + e.getMessage(), e); + } catch (JAXBException e) { + throw new DeviceManagementException( + "Error occurred while parsing the Android configuration : " + e.getMessage(), e); + } catch (RegistryException e) { + throw new DeviceManagementException( + "Error occurred while retrieving the Registry resource of Android Configuration : " + e.getMessage(), e); + } + } - @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()); - } - boolean isEnrolled = this.isEnrolled( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - if (isEnrolled) { - this.modifyEnrollment(device); - } else { - AndroidDAOFactory.beginTransaction(); - status = daoFactory.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(); - throw new DeviceManagementException(msg, e); - } - return status; - } + @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()); + } + boolean isEnrolled = this.isEnrolled( + new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + if (isEnrolled) { + this.modifyEnrollment(device); + } else { + AndroidDAOFactory.beginTransaction(); + status = daoFactory.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(); + 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 = daoFactory.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(); - 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 = daoFactory.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(); + 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 = daoFactory.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(); - 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 = daoFactory.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(); + 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 = - daoFactory.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(); - 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 = + daoFactory.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(); + 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 = daoFactory.getMobileDeviceDAO(). - getMobileDevice(deviceId.getId()); - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the Android device: '" + - deviceId.getId() + "'", 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 = daoFactory.getMobileDeviceDAO(). + getMobileDevice(deviceId.getId()); + device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); + } catch (MobileDeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while fetching the Android device: '" + + deviceId.getId() + "'", 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 License getLicense(String languageCode) throws LicenseManagementException { - return licenseManager. - getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode); - } + @Override + public License getLicense(String languageCode) throws LicenseManagementException { + return licenseManager. + getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode); + } - @Override - public void addLicense(License license) throws LicenseManagementException { - licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license); - } + @Override + public void addLicense(License license) throws LicenseManagementException { + licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license); + } - @Override - public boolean requireDeviceAuthorization() { - return true; - } + @Override + public boolean requireDeviceAuthorization() { + return true; + } - @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) - throws DeviceManagementException { - boolean status; - Device existingDevice = this.getDevice(deviceIdentifier); - // This object holds the current persisted device object - MobileDevice existingMobileDevice = - MobileDeviceManagementUtil.convertToMobileDevice(existingDevice); + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) + throws DeviceManagementException { + boolean status; + Device existingDevice = this.getDevice(deviceIdentifier); + // This object holds the current persisted device object + MobileDevice existingMobileDevice = + MobileDeviceManagementUtil.convertToMobileDevice(existingDevice); - // 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 - existingMobileDevice.setLatitude(mobileDevice.getLatitude()); - existingMobileDevice.setLongitude(mobileDevice.getLongitude()); - existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties()); + // Updating current object features using newer ones + existingMobileDevice.setLatitude(mobileDevice.getLatitude()); + existingMobileDevice.setLongitude(mobileDevice.getLongitude()); + existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties()); - try { - if (log.isDebugEnabled()) { - log.debug( - "updating the details of Android device : " + device.getDeviceIdentifier()); - } - AndroidDAOFactory.beginTransaction(); - status = daoFactory.getMobileDeviceDAO().updateMobileDevice(existingMobileDevice); - AndroidDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll back the update device info transaction : '" + - device.toString() + "'", e1); - } - throw new DeviceManagementException( - "Error occurred while updating the Android device: '" + - device.getDeviceIdentifier() + "'", e); - } - return status; - } + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of Android device : " + device.getDeviceIdentifier()); + } + AndroidDAOFactory.beginTransaction(); + status = daoFactory.getMobileDeviceDAO().updateMobileDevice(existingMobileDevice); + AndroidDAOFactory.commitTransaction(); + } catch (MobileDeviceManagementDAOException e) { + try { + AndroidDAOFactory.rollbackTransaction(); + } catch (MobileDeviceManagementDAOException e1) { + log.warn("Error occurred while roll back the update device info transaction : '" + + device.toString() + "'", e1); + } + throw new DeviceManagementException( + "Error occurred while updating the Android device: '" + + device.getDeviceIdentifier() + "'", 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 = - daoFactory.getMobileDeviceDAO().getAllMobileDevices(); - if (mobileDevices != null) { - devices = new ArrayList<>(); - for (MobileDevice mobileDevice : mobileDevices) { - devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching all Android devices", - 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 = + daoFactory.getMobileDeviceDAO().getAllMobileDevices(); + if (mobileDevices != null) { + devices = new ArrayList<>(); + for (MobileDevice mobileDevice : mobileDevices) { + devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); + } + } + } catch (MobileDeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while fetching all Android devices", + 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 fabfe1ac2..d83a4585b 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 @@ -51,7 +51,7 @@ public class WindowsDeviceManager implements DeviceManager { private AbstractMobileDeviceManagementDAOFactory daoFactory; private LicenseManager licenseManager; - private FeatureManager featureManager = new WindowsFeatureManager(); + private FeatureManager featureManager = new WindowsFeatureManager(); private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); public WindowsDeviceManager() { @@ -61,7 +61,9 @@ public class WindowsDeviceManager implements DeviceManager { License defaultLicense = WindowsPluginUtils.getDefaultLicense(); try { - licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); + if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, "en_US") == null) { + licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); + } featureManager.addSupportedFeaturesToDB(); } catch (LicenseManagementException e) { log.error("Error occurred while adding default license for Windows devices", e); @@ -118,12 +120,12 @@ public class WindowsDeviceManager implements DeviceManager { MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath); - if(resource != null){ + if (resource != null) { JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); return (TenantConfiguration) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset. - forName(MobilePluginConstants.CHARSET_UTF8)))); + forName(MobilePluginConstants.CHARSET_UTF8)))); } return null; } catch (MobileDeviceMgtPluginException e) { @@ -255,7 +257,7 @@ public class WindowsDeviceManager implements DeviceManager { @Override public License getLicense(String languageCode) throws LicenseManagementException { - return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); + return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode); } @Override From 665a46a65a35764e9b6f297ed429cca4df82ef8b Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 4 Dec 2015 15:32:43 +0530 Subject: [PATCH 3/3] add Language type constant --- .../carbon/device/mgt/mobile/common/MobilePluginConstants.java | 2 ++ .../device/mgt/mobile/impl/android/AndroidDeviceManager.java | 3 ++- .../device/mgt/mobile/impl/windows/WindowsDeviceManager.java | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) 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 66420e82d..67e793fa5 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 @@ -23,5 +23,7 @@ public class MobilePluginConstants { public static final String MEDIA_TYPE_XML = "application/xml"; public static final String CHARSET_UTF8 = "UTF8"; + public static final String LANGUAGE_CODE_ENGLISH_US = "en_US"; + public static final String LANGUAGE_CODE_ENGLISH_UK = "en_UK"; } 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 b16305836..6c8f220bb 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 @@ -60,7 +60,8 @@ public class AndroidDeviceManager implements DeviceManager { License defaultLicense; try { - if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, "en_US") == null) { + if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, + MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) { defaultLicense = AndroidPluginUtils.getDefaultLicense(); licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); } 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 d83a4585b..792c7e745 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 @@ -61,7 +61,8 @@ public class WindowsDeviceManager implements DeviceManager { License defaultLicense = WindowsPluginUtils.getDefaultLicense(); try { - if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, "en_US") == null) { + if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, + MobilePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) { licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); } featureManager.addSupportedFeaturesToDB();