From 8620eb912f3c770c6ffa4c084d03a8d5749fef68 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 May 2016 11:59:28 +0530 Subject: [PATCH] Removing redundant implementations of android and windows plugins --- .../AndroidDeviceManagementService.java | 70 ---- .../impl/android/AndroidDeviceManager.java | 342 ------------------ .../impl/android/AndroidFeatureManager.java | 296 --------------- .../AndroidPolicyMonitoringService.java | 100 ----- .../impl/android/dao/AndroidDAOFactory.java | 117 ------ .../AndroidFeatureManagementDAOException.java | 79 ---- .../dao/impl/AndroidDeviceDAOImpl.java | 265 -------------- .../dao/impl/AndroidFeatureDAOImpl.java | 285 --------------- .../mobile/impl/android/gcm/GCMResult.java | 53 --- .../mobile/impl/android/gcm/GCMService.java | 64 ---- .../mgt/mobile/impl/android/gcm/GCMUtil.java | 199 ---------- .../android/util/AndroidPluginConstants.java | 47 --- .../impl/android/util/AndroidPluginUtils.java | 58 --- .../impl/android/util/AndroidUtils.java | 31 -- .../WindowsDeviceManagementService.java | 73 ---- .../impl/windows/WindowsDeviceManager.java | 312 ---------------- .../impl/windows/WindowsFeatureManager.java | 198 ---------- .../WindowsPolicyMonitoringService.java | 73 ---- .../impl/windows/dao/WindowsDAOFactory.java | 132 ------- .../WindowsFeatureManagementDAOException.java | 80 ---- .../dao/impl/WindowsDeviceDAOImpl.java | 238 ------------ .../dao/impl/WindowsFeatureDAOImpl.java | 267 -------------- .../windows/util/WindowsPluginConstants.java | 48 --- .../impl/windows/util/WindowsPluginUtils.java | 58 --- .../impl/windows/util/WindowsUtils.java | 50 --- .../MobileDeviceManagementDataHolder.java | 9 - ...obileDeviceManagementServiceComponent.java | 38 -- 27 files changed, 3582 deletions(-) delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java delete mode 100644 components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java deleted file mode 100644 index 5eae35cbe..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagementService.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android; - -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; -import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; - -import java.util.List; - -/** - * This represents the Android implementation of DeviceManagerService. - */ -public class AndroidDeviceManagementService implements DeviceManagementService { - - private DeviceManager deviceManager; - public static final String DEVICE_TYPE_ANDROID = "android"; - private static final String SUPER_TENANT_DOMAIN = "carbon.super"; - - @Override - public String getType() { - return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID; - } - - @Override - public void init() throws DeviceManagementException { - this.deviceManager = new AndroidDeviceManager(); - } - - @Override - public DeviceManager getDeviceManager() { - return deviceManager; - } - - @Override - public ApplicationManager getApplicationManager() { - return null; - } - - @Override - public ProvisioningConfig getProvisioningConfig() { - return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true); - } - - @Override - public PushNotificationConfig getPushNotificationConfig() { - return null; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java deleted file mode 100644 index 803af9478..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.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.PlatformConfiguration; -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.registry.RegistryBasedLicenseManager; -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.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -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.impl.android.util.AndroidPluginUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.registry.api.RegistryException; -import org.wso2.carbon.registry.api.Resource; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.util.ArrayList; -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; - - public AndroidDeviceManager() { - this.daoFactory = new AndroidDAOFactory(); - this.licenseManager = new RegistryBasedLicenseManager(); - License defaultLicense; - - try { - if (licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, - MobilePluginConstants.LANGUAGE_CODE_ENGLISH_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) { - throw new IllegalStateException("Error occurred while adding Android features to the DB."); - } - } - - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } - - @Override - public boolean saveConfiguration(PlatformConfiguration 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(PlatformConfiguration.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); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while persisting the Registry resource of Android Configuration", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration", e); - } - return status; - } - - @Override - public PlatformConfiguration 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(PlatformConfiguration.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - return (PlatformConfiguration) 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); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Android configuration", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry resource of Android Configuration", e); - } - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - boolean status = false; - boolean isEnrolled = this.isEnrolled( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - - try { - if (log.isDebugEnabled()) { - log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); - } - - if (isEnrolled) { - this.modifyEnrollment(device); - } else { - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - 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 occurred 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 occurred 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 { - //Here we don't have anything specific to do. Hence returning. - return true; - } - - @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 occurred 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 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 boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return true; - } - - @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 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 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); - // 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()); - - 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<>(mobileDevices.size()); - 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/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java deleted file mode 100644 index a408360b9..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.android; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.List; - -public class AndroidFeatureManager implements FeatureManager { - - private MobileFeatureDAO featureDAO; - private static final Log log = LogFactory.getLog(AndroidFeatureManager.class); - - public AndroidFeatureManager() { - MobileDeviceManagementDAOFactory daoFactory = new AndroidDAOFactory(); - this.featureDAO = daoFactory.getMobileFeatureDAO(); - } - - @Override - public boolean addFeature(Feature feature) throws DeviceManagementException { - try { - AndroidDAOFactory.beginTransaction(); - MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - featureDAO.addFeature(mobileFeature); - AndroidDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while adding the feature", e); - } - } - - @Override - public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(features.size()); - for (Feature feature : features) { - mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); - } - try { - AndroidDAOFactory.beginTransaction(); - featureDAO.addFeatures(mobileFeatures); - AndroidDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while adding the features", e); - } - } - - @Override - public Feature getFeature(String name) throws DeviceManagementException { - try { - MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); - return feature; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the feature", e); - } - } - - @Override - public List getFeatures() throws DeviceManagementException { - try { - List mobileFeatures = featureDAO.getAllFeatures(); - List featureList = new ArrayList(mobileFeatures.size()); - for (MobileFeature mobileFeature : mobileFeatures) { - featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); - } - return featureList; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Android platform", e); - } - } - - @Override - public boolean removeFeature(String code) throws DeviceManagementException { - boolean status; - try { - AndroidDAOFactory.beginTransaction(); - featureDAO.deleteFeatureByCode(code); - AndroidDAOFactory.commitTransaction(); - status = true; - } catch (MobileDeviceManagementDAOException e) { - try { - AndroidDAOFactory.rollbackTransaction(); - } catch (MobileDeviceManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); - } - throw new DeviceManagementException("Error occurred while removing the feature", e); - } - return status; - } - - @Override - public boolean addSupportedFeaturesToDB() throws DeviceManagementException { - synchronized (this) { - List supportedFeatures = getSupportedFeatures(); - List existingFeatures = this.getFeatures(); - List missingFeatures = MobileDeviceManagementUtil. - getMissingFeatures(supportedFeatures, existingFeatures); - if (missingFeatures.size() > 0) { - return this.addFeatures(missingFeatures); - } - return true; - } - } - - //Get the supported feature list. - private static List getSupportedFeatures() { - List supportedFeatures = new ArrayList(); - - Feature feature = new Feature(); - feature.setCode("DEVICE_LOCK"); - feature.setName("Device Lock"); - feature.setDescription("Lock the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_UNLOCK"); - feature.setName("Device Unlock"); - feature.setDescription("Unlock the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_LOCATION"); - feature.setName("Location"); - feature.setDescription("Request coordinates of device location"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("WIFI"); - feature.setName("wifi"); - feature.setDescription("Setting up wifi configuration"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CAMERA"); - feature.setName("camera"); - feature.setDescription("Enable or disable camera"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("EMAIL"); - feature.setName("Email"); - feature.setDescription("Configure email settings"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_MUTE"); - feature.setName("Mute"); - feature.setDescription("Enable mute in the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_INFO"); - feature.setName("Device info"); - feature.setDescription("Request device information"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("ENTERPRISE_WIPE"); - feature.setName("Enterprise Wipe"); - feature.setDescription("Remove enterprise applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CLEAR_PASSWORD"); - feature.setName("Clear Password"); - feature.setDescription("Clear current password"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("WIPE_DATA"); - feature.setName("Wipe Data"); - feature.setDescription("Factory reset the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("APPLICATION_LIST"); - feature.setName("Application List"); - feature.setDescription("Request list of current installed applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("CHANGE_LOCK_CODE"); - feature.setName("Change Lock-code"); - feature.setDescription("Change current lock code"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("INSTALL_APPLICATION"); - feature.setName("Install App"); - feature.setDescription("Install Enterprise or Market application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UPDATE_APPLICATION"); - feature.setName("Update App"); - feature.setDescription("Update Enterprise or Market application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UNINSTALL_APPLICATION"); - feature.setName("Uninstall App"); - feature.setDescription("Uninstall application"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("BLACKLIST_APPLICATIONS"); - feature.setName("Blacklist app"); - feature.setDescription("Blacklist applications"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("ENCRYPT_STORAGE"); - feature.setName("Encrypt storage"); - feature.setDescription("Encrypt storage"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_RING"); - feature.setName("Ring"); - feature.setDescription("Ring the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("PASSCODE_POLICY"); - feature.setName("Password Policy"); - feature.setDescription("Set passcode policy"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("NOTIFICATION"); - feature.setName("Message"); - feature.setDescription("Send message"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("DEVICE_REBOOT"); - feature.setName("Reboot"); - feature.setDescription("Reboot the device"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("UPGRADE_FIRMWARE"); - feature.setName("Upgrade Firmware"); - feature.setDescription("Upgrade Firmware"); - supportedFeatures.add(feature); - - feature = new Feature(); - feature.setCode("VPN"); - feature.setName("Configure VPN"); - feature.setDescription("Configure VPN settings"); - supportedFeatures.add(feature); - - return supportedFeatures; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java deleted file mode 100644 index ced47139f..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidPolicyMonitoringService.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.wso2.carbon.device.mgt.mobile.impl.android; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; -import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; -import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; - -import java.util.ArrayList; -import java.util.List; - -public class AndroidPolicyMonitoringService implements PolicyMonitoringService { - - private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class); - - @Override - public void notifyDevices(List list) throws PolicyComplianceException { - GCMService gcmService = MobileDeviceManagementDataHolder.getInstance().getGCMService(); - if (gcmService.isGCMEnabled() && !list.isEmpty()) { - gcmService.sendNotification("POLICY_BUNDLE", list); - } - } - - @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, - Object compliancePayload) throws PolicyComplianceException { - if (log.isDebugEnabled()) { - log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); - } - ComplianceData complianceData = new ComplianceData(); - if (compliancePayload == null || policy == null) { - return complianceData; - } - String compliancePayloadString = new Gson().toJson(compliancePayload); - // Parsing json string to get compliance features. - JsonElement jsonElement; - if (compliancePayloadString instanceof String) { - jsonElement = new JsonParser().parse(compliancePayloadString); - } else { - throw new PolicyComplianceException("Invalid policy compliance payload"); - } - - JsonArray jsonArray = jsonElement.getAsJsonArray(); - Gson gson = new Gson(); - ComplianceFeature complianceFeature; - List complianceFeatures = new ArrayList(jsonArray.size()); - List nonComplianceFeatures = new ArrayList<>(); - - for (JsonElement element : jsonArray) { - complianceFeature = gson.fromJson(element, ComplianceFeature.class); - complianceFeatures.add(complianceFeature); - } - - for (ComplianceFeature cf : complianceFeatures) { - if (!cf.isCompliant()) { - complianceData.setStatus(false); - nonComplianceFeatures.add(cf); - break; - } - } - - complianceData.setComplianceFeatures(nonComplianceFeatures); - return complianceData; - } - - @Override - public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java deleted file mode 100644 index 183a47e64..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -*/ - -package org.wso2.carbon.device.mgt.mobile.impl.android.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.*; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidDeviceDAOImpl; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.AndroidFeatureDAOImpl; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; - -public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory { - - private static final Log log = LogFactory.getLog(AndroidDAOFactory.class); - protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal<>(); - - public AndroidDAOFactory() { - this.dataSource = getDataSourceMap().get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - - @Override - public MobileDeviceDAO getMobileDeviceDAO() { - return new AndroidDeviceDAOImpl(); - } - - public MobileFeatureDAO getMobileFeatureDAO() { - return new AndroidFeatureDAOImpl(); - } - - public static void beginTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = dataSource.getConnection(); - conn.setAutoCommit(false); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); - } - } - - public static Connection getConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - try { - currentConnection.set(dataSource.getConnection()); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving data source connection", - e); - } - } - return currentConnection.get(); - } - - public static void commitTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = currentConnection.get(); - if (conn != null) { - conn.commit(); - } else { - if (log.isDebugEnabled()) { - log.debug("Datasource connection associated with the current thread is null, hence commit " + - "has not been attempted"); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e); - } - } - - public static void closeConnection() throws MobileDeviceManagementDAOException { - Connection conn = currentConnection.get(); - try { - if (conn != null) { - conn.close(); - } - } catch (SQLException e) { - log.error("Error occurred while close the connection"); - } - currentConnection.remove(); - } - - public static void rollbackTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = currentConnection.get(); - if (conn != null) { - conn.rollback(); - } else { - if (log.isDebugEnabled()) { - log.debug("Datasource connection associated with the current thread is null, hence rollback " + - "has not been attempted"); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e); - } - } - -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java deleted file mode 100644 index 68d5a17d6..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidFeatureManagementDAOException.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.android.dao; - -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; - -public class AndroidFeatureManagementDAOException extends MobileDeviceManagementDAOException { - - private String message; - private static final long serialVersionUID = 2021891706072918865L; - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message and - * nested exception. - * - * @param message error message - * @param nestedException exception - */ - public AndroidFeatureManagementDAOException(String message, Exception nestedException) { - super(message, nestedException); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message - * and cause. - * - * @param message the detail message. - * @param cause the cause of this exception. - */ - public AndroidFeatureManagementDAOException(String message, Throwable cause) { - super(message, cause); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message. - * - * @param message the detail message. - */ - public AndroidFeatureManagementDAOException(String message) { - super(message); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified and cause. - * - * @param cause the cause of this exception. - */ - public AndroidFeatureManagementDAOException(Throwable cause) { - super(cause); - } - - public String getMessage() { - return message; - } - - public void setErrorMessage(String errorMessage) { - this.message = errorMessage; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java deleted file mode 100644 index 84ad8512e..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidDeviceDAOImpl.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -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.impl.android.util.AndroidPluginConstants; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Implements MobileDeviceDAO for Android Devices. - */ -public class AndroidDeviceDAOImpl implements MobileDeviceDAO{ - - private static final Log log = LogFactory.getLog(AndroidDeviceDAOImpl.class); - - @Override - public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - MobileDevice mobileDevice = null; - ResultSet rs = null; - try { - conn = AndroidDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION" + - " FROM AD_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - rs = stmt.executeQuery(); - - if (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); - mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); - mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); - mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE)); - mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI)); - mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION)); - - Map propertyMap = new HashMap(); - propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN)); - propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO)); - propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - - if (log.isDebugEnabled()) { - log.debug("Android device " + mblDeviceId + " data has been fetched from " + - "Android database."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while fetching Android device : '" + mblDeviceId + "'"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - - return mobileDevice; - } - - @Override - public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String createDBQuery = - "INSERT INTO AD_DEVICE(DEVICE_ID, GCM_TOKEN, DEVICE_INFO, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mobileDevice.getMobileDeviceId()); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(2, properties.get(AndroidPluginConstants.GCM_TOKEN)); - stmt.setString(3, properties.get(AndroidPluginConstants.DEVICE_INFO)); - stmt.setString(4, mobileDevice.getSerial()); - stmt.setString(5, mobileDevice.getVendor()); - stmt.setString(6, mobileDevice.getMobileDeviceId()); - stmt.setString(7, properties.get(AndroidPluginConstants.DEVICE_NAME)); - stmt.setString(8, mobileDevice.getLatitude()); - stmt.setString(9, mobileDevice.getLongitude()); - stmt.setString(10, mobileDevice.getImei()); - stmt.setString(11, mobileDevice.getImsi()); - stmt.setString(12, mobileDevice.getOsVersion()); - stmt.setString(13, mobileDevice.getModel()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" + - " added to the Android database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while adding the Android device '" + - mobileDevice.getMobileDeviceId() + "' information to the Android plugin data store.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE AD_DEVICE SET GCM_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, VENDOR = ?, " + - "MAC_ADDRESS = ?, DEVICE_NAME = ?, LATITUDE = ?, LONGITUDE = ?, IMEI = ?, " + - "IMSI = ?, OS_VERSION = ?, DEVICE_MODEL = ? WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(updateDBQuery); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(1, properties.get(AndroidPluginConstants.GCM_TOKEN)); - stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO)); - stmt.setString(3, mobileDevice.getSerial()); - stmt.setString(4, mobileDevice.getVendor()); - stmt.setString(5, mobileDevice.getMobileDeviceId()); - stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME)); - stmt.setString(7, mobileDevice.getLatitude()); - stmt.setString(8, mobileDevice.getLongitude()); - stmt.setString(9, mobileDevice.getImei()); - stmt.setString(10, mobileDevice.getImsi()); - stmt.setString(11, mobileDevice.getOsVersion()); - stmt.setString(12, mobileDevice.getModel()); - stmt.setString(13, mobileDevice.getMobileDeviceId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mobileDevice.getMobileDeviceId() + " data has been" + - " modified."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while modifying the Android device '" + - mobileDevice.getMobileDeviceId() + "' data."; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDevice(String mblDeviceId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String deleteDBQuery = - "DELETE FROM AD_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, mblDeviceId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android device " + mblDeviceId + " data has deleted" + - " from the Android database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while deleting android device '" + - mblDeviceId + "'", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public List getAllMobileDevices() throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice; - List mobileDevices = new ArrayList(); - try { - conn = AndroidDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, GCM_TOKEN, DEVICE_INFO, DEVICE_MODEL, SERIAL, " + - "VENDOR, MAC_ADDRESS, DEVICE_NAME, LATITUDE, LONGITUDE, IMEI, IMSI, OS_VERSION " + - "FROM AD_DEVICE"; - stmt = conn.prepareStatement(selectDBQuery); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(AndroidPluginConstants.DEVICE_ID)); - mobileDevice.setModel(rs.getString(AndroidPluginConstants.DEVICE_MODEL)); - mobileDevice.setSerial(rs.getString(AndroidPluginConstants.SERIAL)); - mobileDevice.setVendor(rs.getString(AndroidPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(AndroidPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(AndroidPluginConstants.LONGITUDE)); - mobileDevice.setImei(rs.getString(AndroidPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(AndroidPluginConstants.IMSI)); - mobileDevice.setOsVersion(rs.getString(AndroidPluginConstants.OS_VERSION)); - - Map propertyMap = new HashMap<>(); - propertyMap.put(AndroidPluginConstants.GCM_TOKEN, rs.getString(AndroidPluginConstants.GCM_TOKEN)); - propertyMap.put(AndroidPluginConstants.DEVICE_INFO, rs.getString(AndroidPluginConstants.DEVICE_INFO)); - propertyMap.put(AndroidPluginConstants.DEVICE_NAME, rs.getString(AndroidPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - - mobileDevices.add(mobileDevice); - } - if (log.isDebugEnabled()) { - log.debug("All Android device details have fetched from Android database."); - } - return mobileDevices; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Android device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java deleted file mode 100644 index de6ec0bf6..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/AndroidFeatureDAOImpl.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidFeatureManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class AndroidFeatureDAOImpl implements MobileFeatureDAO { - - private static final Log log = LogFactory.getLog(AndroidFeatureDAOImpl.class); - - public AndroidFeatureDAOImpl() { - - } - - @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.executeUpdate(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while adding android feature '" + - mobileFeature.getName() + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - MobileFeature mobileFeature; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - stmt = conn.prepareStatement("INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); - for (int i = 0; i < mobileFeatures.size(); i++) { - mobileFeature = mobileFeatures.get(i); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.addBatch(); - } - stmt.executeBatch(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while adding android features into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = AndroidDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE AD_FEATURE SET NAME = ?, DESCRIPTION = ?" + - "WHERE CODE = ?"; - - stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mobileFeature.getName()); - stmt.setString(2, mobileFeature.getDescription()); - stmt.setString(3, mobileFeature.getCode()); - - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Android Feature " + mobileFeature.getCode() + " data has been " + - "modified."); - } - } - } catch (SQLException e) { - String msg = "Error occurred while updating the Android Feature '" + - mobileFeature.getCode() + "' to the Android db."; - log.error(msg, e); - throw new AndroidFeatureManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while deleting android feature '" + - mblFeatureId + "' from Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while deleting android feature '" + - mblFeatureCode + "' from Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - rs = stmt.executeQuery(); - - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants. - ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - return mobileFeature; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while retrieving android feature '" + - mblFeatureId + "' from the Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - - @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - rs = stmt.executeQuery(); - - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants. - ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - } - return mobileFeature; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException( - "Error occurred while retrieving android feature '" + - mblFeatureCode + "' from the Android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } - - @Override - public List getFeatureByDeviceType(String deviceType) - throws MobileDeviceManagementDAOException { - return this.getAllFeatures(); - } - - @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn = null; - List features = new ArrayList<>(); - try { - conn = AndroidDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - - while (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(AndroidPluginConstants.ANDROID_FEATURE_ID)); - mobileFeature.setCode(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_CODE)); - mobileFeature.setName(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(AndroidPluginConstants.ANDROID_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - features.add(mobileFeature); - } - return features; - } catch (SQLException e) { - throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " + - "android features from the android database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - AndroidDAOFactory.closeConnection(); - } - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java deleted file mode 100644 index c15d6d4c4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMResult.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; - -/** - * Represents model object for holding GCM response data. - */ -public class GCMResult { - - private String errorMsg; - private String msg; - private int statusCode; - - public String getErrorMsg() { - return errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getMsg() { - return msg; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public int getStatusCode() { - return statusCode; - } - - public void setStatusCode(int statusCode) { - this.statusCode = statusCode; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java deleted file mode 100644 index e49e14d32..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; - -import java.util.ArrayList; -import java.util.List; - -/** - * GCM notification service implementation for Android platform. - */ -public class GCMService { - - private static final Log log = LogFactory.getLog(GCMService.class); - private static final String NOTIFIER_TYPE = "notifierType"; - private static final String GCM_NOTIFIER_CODE = "2"; - - public boolean isGCMEnabled() { - String notifierType = GCMUtil.getConfigurationProperty(NOTIFIER_TYPE); - if (GCM_NOTIFIER_CODE.equals(notifierType)) { - return true; - } - return false; - } - - public void sendNotification(String messageData, Device device) { - List devices = new ArrayList<>(1); - devices.add(device); - GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); - if (result.getStatusCode() != 200) { - log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); - } - } - - public void sendNotification(String messageData, List devices) { - GCMResult result = GCMUtil.sendWakeUpCall(messageData, devices); - if (result.getStatusCode() != 200) { - log.error("Exception occurred while sending the GCM notification : " + result.getErrorMsg()); - } - } - - public void resetTenantConfigCache() { - GCMUtil.resetTenantConfigCache(); - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java deleted file mode 100644 index ac9d89411..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMUtil.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; - -import com.google.gson.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; -import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginConstants; -import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.ProtocolException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * Implements utility methods used by GCMService. - */ -public class GCMUtil { - - private static final Log log = LogFactory.getLog(GCMService.class); - - private final static String GCM_ENDPOINT = "https://gcm-http.googleapis.com/gcm/send"; - private static final String GCM_API_KEY = "gcmAPIKey"; - private static final int TIME_TO_LIVE = 60; - private static final int HTTP_STATUS_CODE_OK = 200; - - private static HashMap tenantConfigurationCache = new HashMap<>(); - - public static GCMResult sendWakeUpCall(String message, List devices) { - GCMResult result = new GCMResult(); - - byte[] bytes = getGCMRequest(message, getGCMTokens(devices)).getBytes(); - HttpURLConnection conn; - try { - conn = (HttpURLConnection) (new URL(GCM_ENDPOINT)).openConnection(); - conn.setDoOutput(true); - conn.setUseCaches(false); - conn.setFixedLengthStreamingMode(bytes.length); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("Authorization", "key=" + getConfigurationProperty(GCM_API_KEY)); - - OutputStream out = conn.getOutputStream(); - out.write(bytes); - out.close(); - - int status = conn.getResponseCode(); - result.setStatusCode(status); - if (status != HTTP_STATUS_CODE_OK) { - result.setErrorMsg(getString(conn.getErrorStream())); - } else { - result.setMsg(getString(conn.getInputStream())); - } - } catch (ProtocolException e) { - log.error("Exception occurred while setting the HTTP protocol.", e); - } catch (IOException ex) { - log.error("Exception occurred while sending the GCM request.", ex); - } - - return result; - } - - private static String getString(InputStream stream) throws IOException { - if (stream != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - StringBuilder content = new StringBuilder(); - - String newLine; - do { - newLine = reader.readLine(); - if (newLine != null) { - content.append(newLine).append('\n'); - } - } while (newLine != null); - - if (content.length() > 0) { - content.setLength(content.length() - 1); - } - - return content.toString(); - } - return null; - } - - private static String getGCMRequest(String message, List registrationIds) { - JsonObject gcmRequest = new JsonObject(); - gcmRequest.addProperty("delay_while_idle", false); - gcmRequest.addProperty("time_to_live", TIME_TO_LIVE); - - //Add message to GCM request - JsonObject data = new JsonObject(); - if (message != null && !message.isEmpty()) { - data.addProperty("data", message); - gcmRequest.add("data", data); - } - - //Set device reg-ids - JsonArray regIds = new JsonArray(); - for (String regId : registrationIds) { - if (regId == null || regId.isEmpty()) { - continue; - } - regIds.add(new JsonPrimitive(regId)); - } - - gcmRequest.add("registration_ids", regIds); - return gcmRequest.toString(); - } - - private static List getGCMTokens(List devices) { - List tokens = new ArrayList<>(devices.size()); - for (Device device : devices) { - tokens.add(getGCMToken(device.getProperties())); - } - return tokens; - } - - private static String getGCMToken(List properties) { - String gcmToken = null; - for (Device.Property property : properties) { - if (AndroidPluginConstants.GCM_TOKEN.equals(property.getName())) { - gcmToken = property.getValue(); - break; - } - } - return gcmToken; - } - - public static String getConfigurationProperty(String property) { - DeviceManagementService androidDMService = new AndroidDeviceManagementService(); - try { - //Get the TenantConfiguration from cache if not we'll get it from DM service - PlatformConfiguration tenantConfiguration = getTenantConfigurationFromCache(); - if (tenantConfiguration == null) { - androidDMService.init(); - tenantConfiguration = androidDMService.getDeviceManager().getConfiguration(); - if (tenantConfiguration != null) { - addTenantConfigurationToCache(tenantConfiguration); - } - } - - if (tenantConfiguration != null) { - List configs = tenantConfiguration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (property.equals(entry.getName())) { - return (String) entry.getValue(); - } - } - } - return ""; - } catch (DeviceManagementException e) { - log.error("Exception occurred while fetching the tenant-config.",e); - } - return null; - } - - public static void resetTenantConfigCache() { - tenantConfigurationCache.remove(getTenantId()); - } - - private static void addTenantConfigurationToCache(PlatformConfiguration tenantConfiguration) { - tenantConfigurationCache.put(getTenantId(), tenantConfiguration); - } - - private static PlatformConfiguration getTenantConfigurationFromCache() { - return tenantConfigurationCache.get(getTenantId()); - } - - private static int getTenantId() { - return CarbonContext.getThreadLocalCarbonContext().getTenantId(); - } -} \ No newline at end of file diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java deleted file mode 100644 index 798f5fef1..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.util; - -/** - * Defines constants used by android plugin. - */ -public class AndroidPluginConstants { - - //Properties related to AD_DEVICE table - public static final String DEVICE_ID = "DEVICE_ID"; - public static final String GCM_TOKEN = "GCM_TOKEN"; - public static final String DEVICE_INFO = "DEVICE_INFO"; - public static final String SERIAL = "SERIAL"; - public static final String DEVICE_MODEL = "DEVICE_MODEL"; - public static final String DEVICE_NAME = "DEVICE_NAME"; - public static final String LATITUDE = "LATITUDE"; - public static final String LONGITUDE = "LONGITUDE"; - public static final String IMEI = "IMEI"; - public static final String IMSI = "IMSI"; - public static final String VENDOR = "VENDOR"; - public static final String OS_VERSION = "OS_VERSION"; - public static final String MAC_ADDRESS = "MAC_ADDRESS"; - - //Properties related to AD_FEATURE table - public static final String ANDROID_FEATURE_ID = "ID"; - public static final String ANDROID_FEATURE_CODE = "CODE"; - public static final String ANDROID_FEATURE_NAME = "NAME"; - public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION"; - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java deleted file mode 100644 index ea93017c2..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidPluginUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.util; - -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; - -/** - * Contains utility methods used by Android plugin. - */ -public class AndroidPluginUtils { - - public static License getDefaultLicense() { - License license = new License(); - license.setName(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID); - license.setLanguage("en_US"); - license.setVersion("1.0.0"); - license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + - "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + - "mobile device management program, and the loading to and removal from Your Device and Your use " + - "of certain applications and any associated software and user documentation, whether provided in " + - "\"online\" or electronic format, used in connection with the operation of or provision of services " + - "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + - "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + - "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + - "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + - "\n" + - "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + - "\n" + - "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + - "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + - "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + - "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + - "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + - "the cessation of Your relationship with SoR (including termination of Your employment if You are " + - "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + - "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + - "rights not expressly granted herein."); - return license; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java deleted file mode 100644 index 48753ed4c..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/util/AndroidUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.android.util; - -import java.util.Map; - -/** - * Contains utility methods used by Android plugin. - */ -public class AndroidUtils { - - public static String getDeviceProperty(Map deviceProperties, String property) { - return deviceProperties.get(property); - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java deleted file mode 100644 index fe5372077..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagementService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows; - -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManager; -import org.wso2.carbon.device.mgt.common.ProvisioningConfig; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; -import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; - -import java.util.List; - -/** - * This represents the Windows implementation of DeviceManagerService. - */ -public class WindowsDeviceManagementService implements DeviceManagementService { - - private DeviceManager deviceManager; - public static final String DEVICE_TYPE_WINDOWS = "windows"; - private static final String SUPER_TENANT_DOMAIN = "carbon.super"; - - @Override - public String getType() { - return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS; - } - - @Override - public void init() throws DeviceManagementException { - this.deviceManager = new WindowsDeviceManager(); - } - - @Override - public DeviceManager getDeviceManager() { - return deviceManager; - } - - @Override - public ApplicationManager getApplicationManager() { - return null; - } - - @Override - public ProvisioningConfig getProvisioningConfig() { - return new ProvisioningConfig(SUPER_TENANT_DOMAIN, true); - } - - @Override - public PushNotificationConfig getPushNotificationConfig() { - return null; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java deleted file mode 100644 index dd6a2c4fb..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -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.registry.RegistryBasedLicenseManager; -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.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -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.impl.windows.util.WindowsPluginUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; -import org.wso2.carbon.registry.api.RegistryException; -import org.wso2.carbon.registry.api.Resource; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -public class WindowsDeviceManager implements DeviceManager { - - private AbstractMobileDeviceManagementDAOFactory daoFactory; - private LicenseManager licenseManager; - private FeatureManager featureManager = new WindowsFeatureManager(); - private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); - - public WindowsDeviceManager() { - this.daoFactory = new WindowsDAOFactory(); - this.licenseManager = new RegistryBasedLicenseManager(); - - License defaultLicense = WindowsPluginUtils.getDefaultLicense(); - - try { - if (licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, - MobilePluginConstants.LANGUAGE_CODE_ENGLISH_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); - } catch (DeviceManagementException e) { - throw new IllegalStateException("Error occurred while adding windows features to the DB."); - } - } - - @Override - public FeatureManager getFeatureManager() { - return featureManager; - } - - @Override - public boolean saveConfiguration(PlatformConfiguration tenantConfiguration) throws DeviceManagementException { - boolean status; - Resource resource; - try { - if (log.isDebugEnabled()) { - log.debug("Persisting windows configurations in Registry"); - } - String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - StringWriter writer = new StringWriter(); - JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(tenantConfiguration, writer); - - 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); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while persisting the Registry resource of Windows configuration", e); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Windows configuration", e); - } - return status; - } - - @Override - public PlatformConfiguration getConfiguration() throws DeviceManagementException { - Resource resource; - try { - String windowsTenantRegistryPath = MobileDeviceManagementUtil. - getPlatformConfigPath(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - resource = MobileDeviceManagementUtil.getRegistryResource(windowsTenantRegistryPath); - if (resource != null) { - JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - return (PlatformConfiguration) 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); - } catch (JAXBException e) { - throw new DeviceManagementException( - "Error occurred while parsing the Windows configuration", e); - } catch (RegistryException e) { - throw new DeviceManagementException( - "Error occurred while retrieving the Registry resource of Windows configuration", e); - } - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - boolean status = false; - MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); - try { - if (log.isDebugEnabled()) { - log.debug("Modifying the Windows device enrollment data"); - } - WindowsDAOFactory.beginTransaction(); - if (daoFactory.getMobileDeviceDAO() != null) { - status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice); - } - WindowsDAOFactory.commitTransaction(); - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while updating the enrollment of the " + - "Windows device : " + device.getDeviceIdentifier(), e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - //Here we don't have anything specific to do. Hence returning. - return true; - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - MobileDevice mobileDevice; - try { - if (log.isDebugEnabled()) { - log.debug("Checking the enrollment of Windows device : " + deviceId.getId()); - } - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); - } else { - throw new DeviceManagementException("Error occurred while getting DAO object."); - } - } catch (MobileDeviceManagementDAOException e) { - String msg = "Error occurred while checking the enrollment status of Windows device : " + deviceId.getId(); - throw new DeviceManagementException(msg, e); - } - return (mobileDevice != null); - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return true; - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return true; - } - - public List getAllDevices() throws DeviceManagementException { - List devices = null; - List mobileDevices = null; - try { - if (log.isDebugEnabled()) { - log.debug("Fetching the details of all Windows devices"); - } - WindowsDAOFactory.openConnection(); - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevices = daoFactory.getMobileDeviceDAO().getAllMobileDevices(); - } - if (mobileDevices != null) { - devices = new ArrayList<>(mobileDevices.size()); - for (MobileDevice mobileDevice : mobileDevices) { - devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); - } - } - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching all Windows devices", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return devices; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - Device device = null; - MobileDevice mobileDevice = null; - try { - if (log.isDebugEnabled()) { - log.debug("Getting the details of Windows device : '" + deviceId.getId() + "'"); - } - WindowsDAOFactory.openConnection(); - if (daoFactory.getMobileDeviceDAO() != null) { - mobileDevice = daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId()); - } - device = MobileDeviceManagementUtil.convertToDevice(mobileDevice); - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the Windows device: '" + deviceId.getId() + "'", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - return device; - } - - @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 setStatus(DeviceIdentifier deviceIdentifier, String currentUser, - EnrolmentInfo.Status status) throws DeviceManagementException { - return false; - } - - @Override - 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 requireDeviceAuthorization() { - return false; - } - - @Override - public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, - Device device) throws DeviceManagementException { - return true; - } - - @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 windows device : " + device.getDeviceIdentifier()); - } - boolean isEnrolled = this.isEnrolled( - new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - if (isEnrolled) { - this.modifyEnrollment(device); - } else { - WindowsDAOFactory.beginTransaction(); - if (daoFactory.getMobileDeviceDAO() != null) { - status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice); - } - WindowsDAOFactory.commitTransaction(); - } - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while enrolling the windows device : " - + device.getDeviceIdentifier(), e); - } - return status; - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java deleted file mode 100644 index cdca8334c..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsFeatureManager.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows; - -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import java.util.ArrayList; -import java.util.List; - -public class WindowsFeatureManager implements FeatureManager { - - private MobileFeatureDAO featureDAO; - - public WindowsFeatureManager() { - MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory(); - this.featureDAO = daoFactory.getMobileFeatureDAO(); - } - - @Override - public boolean addFeature(Feature feature) throws DeviceManagementException { - try { - WindowsDAOFactory.beginTransaction(); - MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); - featureDAO.addFeature(mobileFeature); - WindowsDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean addFeatures(List features) throws DeviceManagementException { - List mobileFeatures = new ArrayList(features.size()); - for (Feature feature : features) { - mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature)); - } - try { - WindowsDAOFactory.beginTransaction(); - featureDAO.addFeatures(mobileFeatures); - WindowsDAOFactory.commitTransaction(); - return true; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding the features", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public Feature getFeature(String name) throws DeviceManagementException { - try { - WindowsDAOFactory.openConnection(); - MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); - Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); - return feature; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public List getFeatures() throws DeviceManagementException { - - try { - WindowsDAOFactory.openConnection(); - List mobileFeatures = featureDAO.getAllFeatures(); - List featureList = new ArrayList(mobileFeatures.size()); - for (MobileFeature mobileFeature : mobileFeatures) { - featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature)); - } - return featureList; - } catch (MobileDeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + - "Windows platform", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean removeFeature(String code) throws DeviceManagementException { - boolean status; - try { - WindowsDAOFactory.beginTransaction(); - featureDAO.deleteFeatureByCode(code); - WindowsDAOFactory.commitTransaction(); - status = true; - return status; - } catch (MobileDeviceManagementDAOException e) { - WindowsDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while removing the feature", e); - } finally { - WindowsDAOFactory.closeConnection(); - } - } - - @Override - public boolean addSupportedFeaturesToDB() throws DeviceManagementException { - synchronized (this) { - List supportedFeatures = getSupportedFeatures(); - List existingFeatures = this.getFeatures(); - List missingFeatures = MobileDeviceManagementUtil. - getMissingFeatures(supportedFeatures, existingFeatures); - if (missingFeatures.size() > 0) { - return this.addFeatures(missingFeatures); - } - return true; - } - } - - /** - * Get supported Windows features. - * - * @return Supported features. - */ - public static List getSupportedFeatures() { - List supportedFeatures = new ArrayList<>(); - Feature feature; - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_LOCK"); - feature.setName("Device Lock"); - feature.setDescription("Lock the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("CAMERA"); - feature.setName("camera"); - feature.setDescription("Enable or disable camera"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_INFO"); - feature.setName("Device info"); - feature.setDescription("Request device information"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("WIPE_DATA"); - feature.setName("Wipe Data"); - feature.setDescription("Factory reset the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("ENCRYPT_STORAGE"); - feature.setName("Encrypt storage"); - feature.setDescription("Encrypt storage"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DEVICE_RING"); - feature.setName("Ring"); - feature.setDescription("Ring the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("PASSCODE_POLICY"); - feature.setName("Password Policy"); - feature.setDescription("Set passcode policy"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("DISENROLL"); - feature.setName("DisEnroll"); - feature.setDescription("DisEnroll the device"); - supportedFeatures.add(feature); - feature = WindowsUtils.getMobileFeature(); - feature.setCode("LOCK_RESET"); - feature.setName("LockReset"); - feature.setDescription("Lock Reset device"); - supportedFeatures.add(feature); - return supportedFeatures; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java deleted file mode 100644 index b4bb0bac1..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsPolicyMonitoringService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; -import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; -import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; - -import java.util.ArrayList; -import java.util.List; - -public class WindowsPolicyMonitoringService implements PolicyMonitoringService { - - private static Log log = LogFactory.getLog(WindowsPolicyMonitoringService.class); - - @Override - public void notifyDevices(List list) throws PolicyComplianceException { - - } - - @Override - public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object compliancePayload) - throws PolicyComplianceException { - if (log.isDebugEnabled()) { - log.debug("checking policy compliance status of device '" + deviceIdentifier.getId() + "'"); - } - List complianceFeatures = (List) compliancePayload; - List nonComplianceFeatures = new ArrayList<>(); - ComplianceData complianceData = new ComplianceData(); - - if (policy == null || compliancePayload == null) { - return complianceData; - } - - for (ComplianceFeature complianceFeature : complianceFeatures) { - if (!complianceFeature.isCompliant()) { - complianceData.setStatus(false); - nonComplianceFeatures.add(complianceFeature); - break; - } - } - complianceData.setComplianceFeatures(nonComplianceFeatures); - return complianceData; - } - - @Override - public String getType() { - return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java deleted file mode 100644 index 7fd0461c4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsDAOFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.dao; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; - -public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory { - - private static final Log log = LogFactory.getLog(WindowsDAOFactory.class); - protected static DataSource dataSource; - private static ThreadLocal currentConnection = new ThreadLocal<>(); - - public WindowsDAOFactory() { - this.dataSource = getDataSourceMap().get( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - - @Override - public MobileDeviceDAO getMobileDeviceDAO() { - return new WindowsDeviceDAOImpl(); - } - - @Override - public MobileFeatureDAO getMobileFeatureDAO() { - return new WindowsFeatureDAOImpl(); - } - - public static void beginTransaction() throws MobileDeviceManagementDAOException { - try { - Connection conn = dataSource.getConnection(); - conn.setAutoCommit(false); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); - } - } - - public static void openConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - Connection conn; - try { - conn = dataSource.getConnection(); - currentConnection.set(conn); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException - ("Error occurred while retrieving data source connection", e); - } - } - } - - public static Connection getConnection() throws MobileDeviceManagementDAOException { - if (currentConnection.get() == null) { - try { - currentConnection.set(dataSource.getConnection()); - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException - ("Error occurred while retrieving data source connection", e); - } - } - return currentConnection.get(); - } - - public static void commitTransaction() { - try { - Connection conn = currentConnection.get(); - if (conn != null) { - conn.commit(); - } else { - if (log.isDebugEnabled()) { - log.debug("Datasource connection associated with the current thread is null, hence commit " + - "has not been attempted"); - } - } - } catch (SQLException e) { - log.error("Error occurred while committing the transaction", e); - } - } - - public static void closeConnection() { - Connection con = currentConnection.get(); - try { - con.close(); - } catch (SQLException e) { - log.error("Error occurred while close the connection"); - } - currentConnection.remove(); - } - - public static void rollbackTransaction() { - try { - Connection conn = currentConnection.get(); - if (conn != null) { - conn.rollback(); - } else { - if (log.isDebugEnabled()) { - log.debug("Datasource connection associated with the current thread is null, hence rollback " + - "has not been attempted"); - } - } - } catch (SQLException e) { - log.warn("Error occurred while roll-backing the transaction", e); - } - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java deleted file mode 100644 index 7596b3956..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/WindowsFeatureManagementDAOException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.dao; - -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; - -/** - * This class responsible for wrapping exceptions related on Windows device features. - */ -public class WindowsFeatureManagementDAOException extends MobileDeviceManagementDAOException { - - private String message; - private static final long serialVersionUID = 2021891706072918865L; - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message and - * nested exception. - * - * @param message error message - * @param nestedException exception - */ - public WindowsFeatureManagementDAOException(String message, Exception nestedException) { - super(message, nestedException); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message - * and cause. - * - * @param message the detail message. - * @param cause the cause of this exception. - */ - public WindowsFeatureManagementDAOException(String message, Throwable cause) { - super(message, cause); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified detail message. - * - * @param message the detail message. - */ - public WindowsFeatureManagementDAOException(String message) { - super(message); - setErrorMessage(message); - } - - /** - * Constructs a new MobileDeviceManagementDAOException with the specified and cause. - * - * @param cause the cause of this exception. - */ - public WindowsFeatureManagementDAOException(Throwable cause) { - super(cause); - } - - public String getMessage() { - return message; - } - - public void setErrorMessage(String errorMessage) { - this.message = errorMessage; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java deleted file mode 100644 index d8039f67f..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsDeviceDAOImpl.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -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.impl.windows.util.WindowsPluginConstants; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsUtils; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Implements MobileDeviceDAO for Windows Devices. - */ -public class WindowsDeviceDAOImpl implements MobileDeviceDAO { - - private static final Log log = LogFactory.getLog(WindowsDeviceDAOImpl.class); - - @Override - public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice = null; - try { - conn = WindowsDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + - " OS_VERSION, DEVICE_NAME " + - "FROM WIN_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, mblDeviceId); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = WindowsUtils.loadMobileDevices(rs); - Map propertyMap = new HashMap<>(); - propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); - propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); - propertyMap.put(WindowsPluginConstants.MAC_ADDRESS, rs.getString(WindowsPluginConstants.MAC_ADDRESS)); - propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); - - mobileDevice.setDeviceProperties(propertyMap); - } - if (log.isDebugEnabled()) { - log.debug("All Windows device details have fetched from Windows database."); - } - return mobileDevice; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String createDBQuery = - "INSERT INTO WIN_DEVICE(DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, " + - "IMSI, OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, " + - "MAC_ADDRESS, DEVICE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, mobileDevice.getMobileDeviceId()); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(2, properties.get(WindowsPluginConstants.CHANNEL_URI)); - stmt.setString(3, properties.get(WindowsPluginConstants.DEVICE_INFO)); - stmt.setString(4, mobileDevice.getImei()); - stmt.setString(5, mobileDevice.getImsi()); - stmt.setString(6, mobileDevice.getOsVersion()); - stmt.setString(7, mobileDevice.getModel()); - stmt.setString(8, mobileDevice.getVendor()); - stmt.setString(9, mobileDevice.getLatitude()); - stmt.setString(10, mobileDevice.getLongitude()); - stmt.setString(11, mobileDevice.getSerial()); - stmt.setString(12, properties.get(WindowsPluginConstants.MAC_ADDRESS)); - stmt.setString(13, properties.get(WindowsPluginConstants.DEVICE_NAME)); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" + - " added to the Windows database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while adding the Windows device '" + - mobileDevice.getMobileDeviceId() + "' to the Windows db.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE WIN_DEVICE SET CHANNEL_URI = ?, DEVICE_INFO = ?, IMEI = ?, IMSI = ?, " + - "OS_VERSION = ?, DEVICE_MODEL = ?, VENDOR = ?, LATITUDE = ?, LONGITUDE = ?, " + - "SERIAL = ?, MAC_ADDRESS = ?, DEVICE_NAME = ? WHERE DEVICE_ID = ?"; - - stmt = conn.prepareStatement(updateDBQuery); - - Map properties = mobileDevice.getDeviceProperties(); - stmt.setString(1, properties.get(WindowsPluginConstants.CHANNEL_URI)); - stmt.setString(2, properties.get(WindowsPluginConstants.DEVICE_INFO)); - stmt.setString(3, mobileDevice.getImei()); - stmt.setString(4, mobileDevice.getImsi()); - stmt.setString(5, mobileDevice.getOsVersion()); - stmt.setString(6, mobileDevice.getModel()); - stmt.setString(7, mobileDevice.getVendor()); - stmt.setString(8, mobileDevice.getLatitude()); - stmt.setString(9, mobileDevice.getLongitude()); - stmt.setString(10, mobileDevice.getSerial()); - stmt.setString(11, properties.get(WindowsPluginConstants.MAC_ADDRESS)); - stmt.setString(12, properties.get(WindowsPluginConstants.DEVICE_NAME)); - stmt.setString(13, mobileDevice.getMobileDeviceId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mobileDevice.getMobileDeviceId() + " data has been" + - " modified."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while modifying the Windows device '" + - mobileDevice.getMobileDeviceId() + "' data.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String deleteDBQuery = "DELETE FROM WIN_DEVICE WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, mblDeviceId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows device " + mblDeviceId + " data has deleted" + - " from the windows database."); - } - } - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while deleting windows device '" + - mblDeviceId + "'", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public List getAllMobileDevices() throws MobileDeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - MobileDevice mobileDevice; - List mobileDevices = new ArrayList<>(); - try { - conn = WindowsDAOFactory.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, CHANNEL_URI, DEVICE_INFO, IMEI, IMSI, " + - "OS_VERSION, DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, SERIAL, MAC_ADDRESS," + - " OS_VERSION, DEVICE_NAME " + - "FROM WIN_DEVICE"; - stmt = conn.prepareStatement(selectDBQuery); - rs = stmt.executeQuery(); - - while (rs.next()) { - mobileDevice = WindowsUtils.loadMobileDevices(rs); - Map propertyMap = new HashMap<>(); - propertyMap.put(WindowsPluginConstants.CHANNEL_URI, rs.getString(WindowsPluginConstants.CHANNEL_URI)); - propertyMap.put(WindowsPluginConstants.DEVICE_INFO, rs.getString(WindowsPluginConstants.DEVICE_INFO)); - propertyMap.put(WindowsPluginConstants.DEVICE_NAME, rs.getString(WindowsPluginConstants.DEVICE_NAME)); - mobileDevice.setDeviceProperties(propertyMap); - mobileDevices.add(mobileDevice); - } - if (log.isDebugEnabled()) { - log.debug("All Windows device details have fetched from Windows database."); - } - return mobileDevices; - } catch (SQLException e) { - throw new MobileDeviceManagementDAOException("Error occurred while fetching all Windows device data", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java deleted file mode 100644 index 007eedb78..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/dao/impl/WindowsFeatureDAOImpl.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsFeatureManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.impl.windows.util.WindowsPluginConstants; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -/** - * Implement MobileFeatureDAO for Windows devices. - */ -public class WindowsFeatureDAOImpl implements MobileFeatureDAO { - - private static final Log log = LogFactory.getLog(WindowsFeatureDAOImpl.class); - - @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.executeUpdate(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while adding windows feature '" + - mobileFeature.getName() + "' into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean addFeatures(List mobileFeatures) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - stmt = conn.prepareStatement("INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"); - for (MobileFeature mobileFeature : mobileFeatures) { - stmt.setString(1, mobileFeature.getCode()); - stmt.setString(2, mobileFeature.getName()); - stmt.setString(3, mobileFeature.getDescription()); - stmt.addBatch(); - } - stmt.executeBatch(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while adding windows features into the metadata repository", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn; - PreparedStatement stmt = null; - try { - conn = WindowsDAOFactory.getConnection(); - String updateDBQuery = - "UPDATE WIN_FEATURE SET NAME = ?, DESCRIPTION = ?" + - "WHERE CODE = ?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, mobileFeature.getName()); - stmt.setString(2, mobileFeature.getDescription()); - stmt.setString(3, mobileFeature.getCode()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - if (log.isDebugEnabled()) { - log.debug("Windows Feature " + mobileFeature.getCode() + " data has been " + - "modified."); - } - } - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException("Error occurred while updating the Windows Feature '" + - mobileFeature.getCode() + "' to the Windows db.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WIN_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while deleting windows feature '" + - mblFeatureId + "' from Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - boolean status = false; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "DELETE FROM WIN_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - stmt.execute(); - status = true; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while deleting windows feature '" + - mblFeatureCode + "' from Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); - } - return status; - } - - @Override - public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, mblFeatureId); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - return mobileFeature; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while retrieving windows feature '" + - mblFeatureId + "' from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, mblFeatureCode); - rs = stmt.executeQuery(); - MobileFeature mobileFeature = null; - if (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } - return mobileFeature; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException( - "Error occurred while retrieving windows feature '" + - mblFeatureCode + "' from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public List getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException { - return this.getAllFeatures(); - } - - @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; - Connection conn; - List features = new ArrayList<>(); - try { - conn = WindowsDAOFactory.getConnection(); - String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE"; - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - MobileFeature mobileFeature; - while (rs.next()) { - mobileFeature = new MobileFeature(); - mobileFeature.setId(rs.getInt(WindowsPluginConstants.WINDOWS_FEATURE_ID)); - mobileFeature.setCode(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_CODE)); - mobileFeature.setName(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_NAME)); - mobileFeature.setDescription(rs.getString(WindowsPluginConstants.WINDOWS_FEATURE_DESCRIPTION)); - mobileFeature.setDeviceType( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - features.add(mobileFeature); - } - return features; - } catch (SQLException e) { - throw new WindowsFeatureManagementDAOException("Error occurred while retrieving all " + - "windows features from the Windows database.", e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java deleted file mode 100644 index edae380d4..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginConstants.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.util; - -/** - * Define constance used by Windows plugin. - */ -public class WindowsPluginConstants { - - //properties related to database table WINDOWS_DEVICE - public static final String DEVICE_ID = "DEVICE_ID"; - public static final String CHANNEL_URI = "CHANNEL_URI"; - public static final String DEVICE_INFO = "DEVICE_INFO"; - public static final String IMEI = "IMEI"; - public static final String IMSI = "IMSI"; - public static final String OS_VERSION = "OS_VERSION"; - public static final String DEVICE_MODEL = "DEVICE_MODEL"; - public static final String VENDOR = "VENDOR"; - public static final String LATITUDE = "LATITUDE"; - public static final String LONGITUDE = "LONGITUDE"; - public static final String SERIAL = "SERIAL"; - public static final String MAC_ADDRESS = "MAC_ADDRESS"; - public static final String DEVICE_NAME = "DEVICE_NAME"; - - //Properties related to WIN_FEATURE table - public static final String WINDOWS_FEATURE_ID = "ID"; - public static final String WINDOWS_FEATURE_CODE = "CODE"; - public static final String WINDOWS_FEATURE_NAME = "NAME"; - public static final String WINDOWS_FEATURE_DESCRIPTION = "DESCRIPTION"; - - -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java deleted file mode 100644 index a3b389c9b..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsPluginUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * / - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.util; - -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; - -/** - * Contains utility method used by Windows plugin. - */ -public class WindowsPluginUtils { - - public static License getDefaultLicense() { - License license = new License(); - license.setName(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS); - license.setLanguage("en_US"); - license.setVersion("1.0.0"); - license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " + - "and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " + - "mobile device management program, and the loading to and removal from Your Device and Your use " + - "of certain applications and any associated software and user documentation, whether provided in " + - "\"online\" or electronic format, used in connection with the operation of or provision of services " + - "to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " + - "THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " + - "DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " + - "A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" + - "\n" + - "IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" + - "\n" + - "You agree that: (1) You understand and agree to be bound by the terms and conditions contained " + - "in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " + - "into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " + - "without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " + - "Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " + - "the cessation of Your relationship with SoR (including termination of Your employment if You are " + - "an employee or expiration or termination of Your applicable franchise or supply agreement if You " + - "are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " + - "rights not expressly granted herein."); - return license; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java deleted file mode 100644 index e4ba56346..000000000 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/util/WindowsUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.impl.windows.util; - -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; - -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * Contains utility methods which are used by Windows plugin. - */ -public class WindowsUtils { - - public static MobileDevice loadMobileDevices(ResultSet rs) throws SQLException { - MobileDevice mobileDevice = new MobileDevice(); - mobileDevice.setMobileDeviceId(rs.getString(WindowsPluginConstants.DEVICE_ID)); - mobileDevice.setImei(rs.getString(WindowsPluginConstants.IMEI)); - mobileDevice.setImsi(rs.getString(WindowsPluginConstants.IMSI)); - mobileDevice.setModel(rs.getString(WindowsPluginConstants.DEVICE_MODEL)); - mobileDevice.setVendor(rs.getString(WindowsPluginConstants.VENDOR)); - mobileDevice.setLatitude(rs.getString(WindowsPluginConstants.LATITUDE)); - mobileDevice.setLongitude(rs.getString(WindowsPluginConstants.LONGITUDE)); - mobileDevice.setSerial(rs.getString(WindowsPluginConstants.SERIAL)); - mobileDevice.setOsVersion(rs.getString(WindowsPluginConstants.LATITUDE)); - return mobileDevice; - } - - public static Feature getMobileFeature() { - Feature feature = new Feature(); - return feature; - } -} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java index 869904e81..6444afd90 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementDataHolder.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.internal; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; import org.wso2.carbon.registry.core.service.RegistryService; /** @@ -29,7 +28,6 @@ public class MobileDeviceManagementDataHolder { private RegistryService registryService; private DeviceManagementService androidDeviceManagementService; - private GCMService gcmService; private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder(); @@ -57,11 +55,4 @@ public class MobileDeviceManagementDataHolder { this.androidDeviceManagementService = androidDeviceManagementService; } - public GCMService getGCMService() { - return gcmService; - } - - public void setGCMService(GCMService gcmService) { - this.gcmService = gcmService; - } } diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 92404b67a..5b7f85931 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -23,20 +23,13 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagementService; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidPolicyMonitoringService; -import org.wso2.carbon.device.mgt.mobile.impl.android.gcm.GCMService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagementService; -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; @@ -60,8 +53,6 @@ import java.util.Map; */ public class MobileDeviceManagementServiceComponent { - private ServiceRegistration androidServiceRegRef; - private ServiceRegistration windowsServiceRegRef; private ServiceRegistration gcmServiceRegRef; private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); @@ -100,30 +91,7 @@ public class MobileDeviceManagementServiceComponent { log.error("Exception occurred while initializing mobile device management database schema", e); } } - DeviceManagementService androidDeviceManagementService = new AndroidDeviceManagementService(); - GCMService gcmService = new GCMService(); - androidServiceRegRef = - bundleContext.registerService(DeviceManagementService.class.getName(), - androidDeviceManagementService, null); - windowsServiceRegRef = - bundleContext.registerService(DeviceManagementService.class.getName(), - new WindowsDeviceManagementService(), null); - - gcmServiceRegRef = - bundleContext.registerService(GCMService.class.getName(), gcmService, null); - - - // Policy management service - - bundleContext.registerService(PolicyMonitoringService.class, - new AndroidPolicyMonitoringService(), null); - bundleContext.registerService(PolicyMonitoringService.class, - new WindowsPolicyMonitoringService(), null); - - MobileDeviceManagementDataHolder.getInstance().setAndroidDeviceManagementService( - androidDeviceManagementService); - MobileDeviceManagementDataHolder.getInstance().setGCMService(gcmService); if (log.isDebugEnabled()) { log.debug("Mobile Device Management Service Component has been successfully activated"); } @@ -137,12 +105,6 @@ public class MobileDeviceManagementServiceComponent { log.debug("De-activating Mobile Device Management Service Component"); } try { - if (androidServiceRegRef != null) { - androidServiceRegRef.unregister(); - } - if (windowsServiceRegRef != null) { - windowsServiceRegRef.unregister(); - } if (gcmServiceRegRef != null) { gcmServiceRegRef.unregister(); }