From b96d561ef0c138980219532207c68b1e796ea0e9 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 11:02:25 +0530 Subject: [PATCH 01/11] License Manaproduct/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.javagement --- .../java/org/wso2/cdmserver/mobileservices/android/Device.java | 1 + .../org/wso2/cdmserver/mobileservices/android/Operation.java | 2 ++ .../cdmserver/mobileservices/android/util/AndroidAPIUtils.java | 2 ++ 3 files changed, 5 insertions(+) diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java index 037d5cf30..84a514f2a 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java @@ -137,6 +137,7 @@ public class Device { @Produces("text/plain") public String getLicense() { //TODO: need to implement fetch license from core + // AndroidAPIUtils.getDeviceManagementService().updateDeviceInfo(device); return "License Agreement"; } } diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java index 425536497..9136e9f47 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java @@ -79,6 +79,8 @@ public class Operation { Message responseMsg = new Message(); try { dmService = AndroidAPIUtils.getDeviceManagementService(); + + //TODO: need to complete getOperation logic boolean result = dmService.getOperationManager("").addOperation(null, null); if (result) { Response.status(HttpStatus.SC_OK); diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java index 9ac3ec057..9696a1470 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.core.LicenseManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -56,4 +57,5 @@ public class AndroidAPIUtils { PrivilegedCarbonContext.endTenantFlow(); return dmService; } + } From dcf222d2c16bcb3002899afa81968ee473b53f67 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:29:33 +0530 Subject: [PATCH 02/11] Reverted changes back to the list implementation. The Map conversion is not properly supported in CFX --- .../util/MobileDeviceManagementUtil.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 78b120e48..482136f08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -59,20 +59,38 @@ public class MobileDeviceManagementUtil { "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { + for (Device.Property prop : device.getProperties()) { + if (property.equals(prop.getName())) { + return prop.getValue(); + } + } + return null; + } + private static Device.Property getProperty(String property, String value) { + Device.Property prop = null; + if (property != null) { + prop = new Device.Property(); + prop.setName(property); + prop.setValue(value); + return prop; + } + return prop; + } public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); - mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI)); - mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI)); - mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID)); - mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL)); - mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION)); - mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); + mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); + mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID)); + mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); + mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); + mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -81,16 +99,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - Map propertyMap = new HashMap(); - propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei()); - propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()); - propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()); - propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel()); - propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()); - propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()); - propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()); - propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()); - device.setProperties(propertyMap); + List propertyList = new ArrayList(); + propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); + propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); + propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); + propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); + propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); + propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); + device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; From 24184b48a7ebe31a0b98835c12753b144e9db707 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 11:29:33 +0530 Subject: [PATCH 03/11] Reverted changes back to the list implementation. The Map conversion is not properly supported in CXF --- .../util/MobileDeviceManagementUtil.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 78b120e48..482136f08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -59,20 +59,38 @@ public class MobileDeviceManagementUtil { "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { + for (Device.Property prop : device.getProperties()) { + if (property.equals(prop.getName())) { + return prop.getValue(); + } + } + return null; + } + private static Device.Property getProperty(String property, String value) { + Device.Property prop = null; + if (property != null) { + prop = new Device.Property(); + prop.setName(property); + prop.setValue(value); + return prop; + } + return prop; + } public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); - mobileDevice.setImei(device.getProperties().get(MOBILE_DEVICE_IMEI)); - mobileDevice.setImsi(device.getProperties().get(MOBILE_DEVICE_IMSI)); - mobileDevice.setRegId(device.getProperties().get(MOBILE_DEVICE_REG_ID)); - mobileDevice.setModel(device.getProperties().get(MOBILE_DEVICE_MODEL)); - mobileDevice.setOsVersion(device.getProperties().get(MOBILE_DEVICE_OS_VERSION)); - mobileDevice.setVendor(device.getProperties().get(MOBILE_DEVICE_VENDOR)); - mobileDevice.setLatitude(device.getProperties().get(MOBILE_DEVICE_LATITUDE)); - mobileDevice.setLongitude(device.getProperties().get(MOBILE_DEVICE_LONGITUDE)); + mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); + mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); + mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID)); + mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); + mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); + mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -81,16 +99,16 @@ public class MobileDeviceManagementUtil { Device device = null; if (mobileDevice != null) { device = new Device(); - Map propertyMap = new HashMap(); - propertyMap.put(MOBILE_DEVICE_IMEI, mobileDevice.getImei()); - propertyMap.put(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()); - propertyMap.put(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId()); - propertyMap.put(MOBILE_DEVICE_MODEL, mobileDevice.getModel()); - propertyMap.put(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()); - propertyMap.put(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()); - propertyMap.put(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()); - propertyMap.put(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()); - device.setProperties(propertyMap); + List propertyList = new ArrayList(); + propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); + propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); + propertyList.add(getProperty(MOBILE_DEVICE_REG_ID, mobileDevice.getRegId())); + propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); + propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); + propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); + device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } return device; From 20a228992fe5690883cf31df2c623501c50c1339 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 23 Jan 2015 12:29:17 +0530 Subject: [PATCH 04/11] Adding org.wso2.carbon.identity.self.registration.server.feature to p2 profile gen --- product/modules/distribution/pom.xml | 21 ++++--- product/modules/p2-profile-gen/pom.xml | 84 +++++++++++++++++++------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/product/modules/distribution/pom.xml b/product/modules/distribution/pom.xml index 6db365a13..18a8de391 100644 --- a/product/modules/distribution/pom.xml +++ b/product/modules/distribution/pom.xml @@ -35,10 +35,10 @@ WSO2 Mobile Device Manager (MDM) Distribution - - com.h2database.wso2 + + com.h2database.wso2 h2-database-engine - + @@ -98,7 +98,7 @@ maven-antrun-plugin - + create-device-mgt-schema package @@ -125,14 +125,15 @@ - + - + create-idp-mgt-schema package @@ -159,14 +160,15 @@ - + - + create-api-mgt-schema package @@ -193,7 +195,8 @@ - + diff --git a/product/modules/p2-profile-gen/pom.xml b/product/modules/p2-profile-gen/pom.xml index 1697bf450..0329734c5 100644 --- a/product/modules/p2-profile-gen/pom.xml +++ b/product/modules/p2-profile-gen/pom.xml @@ -214,25 +214,59 @@ org.wso2.carbon:org.wso2.carbon.identity.authenticator.saml2.sso.server.feature:${carbon.platform.version} - - org.wso2.carbon:org.wso2.carbon.um.ws.service.client.feature:${carbon.platform.version} - + + org.wso2.carbon:org.wso2.carbon.um.ws.service.client.feature:${carbon.platform.version} + - org.wso2.carbon:org.wso2.carbon.registry.core.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.core.server.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.ui.menu.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.resource.properties.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.associations.dependencies.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.community.features.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.community.features.server.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.extensions.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.ws.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.ui.menu.governance.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.registry.contentsearch.feature:${carbon.platform.version} + + org.wso2.carbon:org.wso2.carbon.registry.core.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.core.server.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.ui.menu.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.resource.properties.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.associations.dependencies.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.community.features.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.community.features.server.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.extensions.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.ws.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.ui.menu.governance.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.registry.contentsearch.feature:${carbon.platform.version} + - org.wso2.carbon:org.wso2.carbon.governance.metadata.feature:${carbon.platform.version} - org.wso2.carbon:org.wso2.carbon.governance.lifecycle.management.feature:${carbon.platform.version} + + org.wso2.carbon:org.wso2.carbon.governance.metadata.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.governance.lifecycle.management.feature:${carbon.platform.version} + + + + + org.wso2.carbon:org.wso2.carbon.identity.self.registration.server.feature:${carbon.platform.version} + + + + @@ -369,7 +403,9 @@ ${carbon.platform.version} - org.wso2.carbon.identity.application.authentication.framework.server.feature.group + + org.wso2.carbon.identity.application.authentication.framework.server.feature.group + ${carbon.platform.version} @@ -393,6 +429,12 @@ ${carbon.platform.version} + + + org.wso2.carbon.identity.self.registration.server.feature.group + ${carbon.platform.version} + + @@ -448,10 +490,10 @@ org.wso2.carbon.governance.lifecycle.management.feature.group ${carbon.platform.version} - - org.wso2.carbon.um.ws.service.client.feature.group - ${carbon.platform.version} - + + org.wso2.carbon.um.ws.service.client.feature.group + ${carbon.platform.version} + From f1193b56472193ae6c3e1d5391610be3eb0a8cb2 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Fri, 23 Jan 2015 12:47:25 +0530 Subject: [PATCH 05/11] Fixed indentation. UI module changes --- .../util/MobileDeviceManagementUtil.java | 18 +++++++-------- .../jaggeryapps/cdm/modules/device.js | 23 ++++++++++++------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 482136f08..7bd38fee9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -54,11 +54,11 @@ public class MobileDeviceManagementUtil { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new DeviceManagementException( - "Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); + throw new DeviceManagementException("Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage(), e); } } + private static String getPropertyValue(Device device, String property) { for (Device.Property prop : device.getProperties()) { if (property.equals(prop.getName())) { @@ -78,6 +78,7 @@ public class MobileDeviceManagementUtil { } return prop; } + public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { @@ -114,8 +115,7 @@ public class MobileDeviceManagementUtil { return device; } - public static MobileOperation convertToMobileOperation( - org.wso2.carbon.device.mgt.common.Operation operation) { + public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) { MobileOperation mobileOperation = new MobileOperation(); MobileOperationProperty operationProperty = null; List properties = new LinkedList(); @@ -135,18 +135,18 @@ public class MobileDeviceManagementUtil { public static List getMobileOperationIdsFromMobileDeviceOperations( List mobileDeviceOperationMappings) { List mobileOperationIds = new ArrayList(); - for(MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings){ + for (MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings) { mobileOperationIds.add(mobileDeviceOperationMapping.getOperationId()); } return mobileOperationIds; } - public static Operation convertMobileOperationToOperation(MobileOperation mobileOperation){ + public static Operation convertMobileOperationToOperation(MobileOperation mobileOperation) { Operation operation = new Operation(); Properties properties = new Properties(); operation.setCode(mobileOperation.getFeatureCode()); - for(MobileOperationProperty mobileOperationProperty:mobileOperation.getProperties()){ - properties.put(mobileOperationProperty.getProperty(),mobileOperationProperty.getValue()); + for (MobileOperationProperty mobileOperationProperty : mobileOperation.getProperties()) { + properties.put(mobileOperationProperty.getProperty(), mobileOperationProperty.getValue()); } operation.setProperties(properties); return operation; diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js index c208c91a4..13d77bc29 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/device.js @@ -18,25 +18,30 @@ var utility = require("/modules/utility.js"); var DeviceIdentifier = Packages.org.wso2.carbon.device.mgt.common.DeviceIdentifier; +var DeviceManagerUtil = Packages.org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; var log = new Log(); - var deviceManagementService = utility.getDeviceManagementService(); var listDevices = function () { + var devices = deviceManagementService.getAllDevices("android"); + var deviceList = []; + for (i = 0; i < devices.size(); i++) { var device = devices.get(i); + + var propertiesList = DeviceManagerUtil.convertPropertiesToMap(device.getProperties()); deviceList.push({ "identifier": device.getDeviceIdentifier(), "name": device.getName(), "ownership": device.getOwnership(), "owner": device.getOwner(), "deviceType": device.getType(), - "vendor": device.getProperties().get("vendor"), - "model": device.getProperties().get("model"), - "osVersion": device.getProperties().get("osVersion") + "vendor": propertiesList.get("vendor"), + "model": propertiesList.get("model"), + "osVersion": propertiesList.get("osVersion") }); } return deviceList; @@ -50,9 +55,11 @@ var getDevice = function(type, deviceId){ } var viewDevice = function(type, deviceId){ + var device = this.getDevice(type, deviceId); - var entries = device.getProperties().entrySet(); + var propertiesList = DeviceManagerUtil.convertPropertiesToMap(device.getProperties()); + var entries = propertiesList.entrySet(); var iterator = entries.iterator(); var properties = {}; while(iterator.hasNext()){ @@ -67,9 +74,9 @@ var viewDevice = function(type, deviceId){ "ownership": device.getOwnership(), "owner": device.getOwner(), "deviceType": device.getType(), - "vendor": device.getProperties().get("vendor"), - "model": device.getProperties().get("model"), - "osVersion": device.getProperties().get("osVersion"), + "vendor": propertiesList.get("vendor"), + "model": propertiesList.get("model"), + "osVersion": propertiesList.get("osVersion"), "properties": properties }; } \ No newline at end of file From 4974d49320232d391b45ac8cb7ec4ded16d46856 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 13:49:27 +0530 Subject: [PATCH 06/11] License Management --- .../mobileservices/android/Device.java | 24 +++++++++++++------ .../android/util/AndroidAPIUtils.java | 21 +++++++++++++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java index 84a514f2a..0a9e01ffc 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java @@ -17,15 +17,13 @@ */ package org.wso2.cdmserver.mobileservices.android; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException; import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils; import org.wso2.cdmserver.mobileservices.android.util.Message; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException; + import javax.ws.rs.*; import javax.ws.rs.core.Response; import java.util.List; @@ -132,12 +130,24 @@ public class Device { } } - @POST + @GET @Path("/device/license") @Produces("text/plain") public String getLicense() { //TODO: need to implement fetch license from core - // AndroidAPIUtils.getDeviceManagementService().updateDeviceInfo(device); - return "License Agreement"; + License license = null; + try { + try { + license = AndroidAPIUtils.getLicenseManagerService().getLicense(DeviceManagementConstants + .MobileDeviceTypes + .MOBILE_DEVICE_TYPE_ANDROID, DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); + } catch (LicenseManagementException e) { + e.printStackTrace(); + } + }catch(DeviceManagementServiceException deviceMgtEx){ + deviceMgtEx.printStackTrace(); + } + + return license.getLicenseText(); } } diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java index 9696a1470..39ee771de 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/util/AndroidAPIUtils.java @@ -20,7 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.core.LicenseManager; +import org.wso2.carbon.device.mgt.core.service.LicenseManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -58,4 +58,23 @@ public class AndroidAPIUtils { return dmService; } + public static LicenseManagementService getLicenseManagerService() throws DeviceManagementServiceException{ + + //TODO: complete login change super tenent context + LicenseManagementService licenseManagementService; + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + licenseManagementService = (LicenseManagementService) ctx.getOSGiService(LicenseManagementService.class, null); + + if (licenseManagementService == null){ + String msg = "License management service not initialized"; + log.error(msg); + throw new DeviceManagementServiceException(msg); + } + PrivilegedCarbonContext.endTenantFlow(); + return licenseManagementService; + } + } From f4a40a2fd1bf2161244e7266ecc515e3169f054b Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 23 Jan 2015 14:43:45 +0530 Subject: [PATCH 07/11] changing the read me file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0789eca2b..6482d5081 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -product-cdm +product-mdm =========== WSO2 MOBILE DEVICE MANAGER From 845c9f89981b2a36819113aa87c98ec8093684df Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 23 Jan 2015 14:45:14 +0530 Subject: [PATCH 08/11] changing the read me file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6482d5081..4a8a0a7a7 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ WSO2 MOBILE DEVICE MANAGER WSO2 Mobile Device Manager (WSO2 MDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program. -Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 EMM offers a single enterprise-grade platform. +Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 MDM offers a single enterprise-grade platform. From 54e827ce689a012e2407801005b790656e4a71de Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 23 Jan 2015 15:58:06 +0530 Subject: [PATCH 09/11] Added unit-tests & refactored the code --- .../pom.xml | 11 + .../dao/MobileDeviceOperationMappingDAO.java | 16 +- .../mgt/mobile/dao/MobileFeatureDAO.java | 14 +- .../mobile/dao/MobileFeaturePropertyDAO.java | 8 +- .../mobile/dao/impl/MobileDeviceDAOImpl.java | 2 +- .../MobileDeviceOperationMappingDAOImpl.java | 21 +- .../mobile/dao/impl/MobileFeatureDAOImpl.java | 18 +- .../impl/MobileFeaturePropertyDAOImpl.java | 8 +- .../AndroidMobileOperationManager.java | 8 +- ...obileDeviceManagementServiceComponent.java | 3 +- .../mobile/impl/dao/FeatureDAOTestSuite.java | 139 --------- .../impl/dao/MobileFeatureDAOTestSuite.java | 275 ++++++++++++++++++ ...=> MobileFeaturePropertyDAOTestSuite.java} | 2 +- ...alformed-mobile-config-no-jndi-config.xml} | 0 .../src/test/resources/sql/CreateH2TestDB.sql | 1 + .../src/test/resources/testng.xml | 12 +- 16 files changed, 349 insertions(+), 189 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/{FeaturePropertyDAOTestSuite.java => MobileFeaturePropertyDAOTestSuite.java} (93%) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/{malformed-mobile-config-no-jndi.config.xml => malformed-mobile-config-no-jndi-config.xml} (100%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index 8bec5af48..cdad607b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -67,6 +67,17 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + src/test/resources/testng.xml + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java index 4f8c79802..52de3c928 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java @@ -32,7 +32,7 @@ public interface MobileDeviceOperationMappingDAO { * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation) throws MobileDeviceManagementDAOException; /** @@ -42,7 +42,7 @@ public interface MobileDeviceOperationMappingDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation) throws MobileDeviceManagementDAOException; /** @@ -53,7 +53,7 @@ public interface MobileDeviceOperationMappingDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId) + boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -64,7 +64,7 @@ public interface MobileDeviceOperationMappingDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateMobileDeviceOperationToCompleted(String deviceId, int operationId) + boolean updateMobileDeviceOperationMappingToCompleted(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -75,7 +75,7 @@ public interface MobileDeviceOperationMappingDAO { * @return The status of the operation. If the deletion was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean deleteMobileDeviceOperation(String deviceId, int operationId) + boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -87,7 +87,7 @@ public interface MobileDeviceOperationMappingDAO { * deviceId and operationId. * @throws MobileDeviceManagementDAOException */ - MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId) + MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, int operationId) throws MobileDeviceManagementDAOException; /** @@ -96,7 +96,7 @@ public interface MobileDeviceOperationMappingDAO { * @return Device operation mapping object list. * @throws MobileDeviceManagementDAOException */ - List getAllMobileDeviceOperationsOfDevice(String deviceId) + List getAllMobileDeviceOperationNappingsOfDevice(String deviceId) throws MobileDeviceManagementDAOException; /** @@ -105,6 +105,6 @@ public interface MobileDeviceOperationMappingDAO { * @return Device operation mapping object list. * @throws MobileDeviceManagementDAOException */ - List getAllPendingOperationsOfMobileDevice(String deviceId) + List getAllPendingOperationMappingsOfMobileDevice(String deviceId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java index 8b516443a..b820c40d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java @@ -33,7 +33,7 @@ public interface MobileFeatureDAO { * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; + boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; /** * Update a feature in the feature table. @@ -42,7 +42,7 @@ public interface MobileFeatureDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; + boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; /** * Delete a feature from feature table when the feature id is given. @@ -51,7 +51,7 @@ public interface MobileFeatureDAO { * @return The status of the operation. If the operationId was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean deleteFeatureById(String featureId) throws MobileDeviceManagementDAOException; + boolean deleteMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException; /** * Delete a feature from feature table when the feature code is given. @@ -60,7 +60,7 @@ public interface MobileFeatureDAO { * @return The status of the operation. If the operationId was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean deleteFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; + boolean deleteMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; /** * Retrieve a given feature from feature table when the feature id is given. @@ -69,7 +69,7 @@ public interface MobileFeatureDAO { * @return Feature object that holds data of the feature represented by featureId. * @throws MobileDeviceManagementDAOException */ - MobileFeature getFeatureById(String featureId) throws MobileDeviceManagementDAOException; + MobileFeature getMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException; /** * Retrieve a given feature from feature table when the feature code is given. @@ -78,7 +78,7 @@ public interface MobileFeatureDAO { * @return Feature object that holds data of the feature represented by featureCode. * @throws MobileDeviceManagementDAOException */ - MobileFeature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; + MobileFeature getMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; /** * Retrieve all the features from plugin specific database. @@ -86,5 +86,5 @@ public interface MobileFeatureDAO { * @return Feature object list. * @throws MobileDeviceManagementDAOException */ - List getAllFeatures() throws MobileDeviceManagementDAOException; + List getAllMobileFeatures() throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java index a61a598a9..5faf3b964 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java @@ -32,7 +32,7 @@ public interface MobileFeaturePropertyDAO { * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty) + boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException; /** @@ -42,7 +42,7 @@ public interface MobileFeaturePropertyDAO { * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty) + boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException; /** @@ -52,7 +52,7 @@ public interface MobileFeaturePropertyDAO { * @return The status of the operation. If the operationId was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean deleteFeatureProperty(String property) throws MobileDeviceManagementDAOException; + boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException; /** * Retrieve a given feature property from feature property table. @@ -61,7 +61,7 @@ public interface MobileFeaturePropertyDAO { * @return Feature property object that holds data of the feature property represented by propertyId. * @throws MobileDeviceManagementDAOException */ - MobileFeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException; + MobileFeatureProperty getMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException; /** * Retrieve a list of feature property corresponds to a feature id . diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java index ef75ac0b0..ef899886a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java @@ -100,7 +100,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { stmt.setString(6, mobileDevice.getModel()); stmt.setString(7, mobileDevice.getVendor()); stmt.setString(8, mobileDevice.getLatitude()); - stmt.setString(8, mobileDevice.getLongitude()); + stmt.setString(9, mobileDevice.getLongitude()); int rows = stmt.executeUpdate(); if(rows>0){ status = true; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java index 387b09d17..678815cfa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java @@ -45,7 +45,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + public boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -81,7 +81,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -114,7 +114,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId) + public boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -147,8 +147,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public boolean updateMobileDeviceOperationToCompleted(String deviceId, - int operationId) + public boolean updateMobileDeviceOperationMappingToCompleted(String deviceId, + int operationId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -181,7 +181,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public boolean deleteMobileDeviceOperation(String deviceId, int operationId) + public boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -210,7 +210,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId) + public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, + int operationId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -246,7 +247,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public List getAllMobileDeviceOperationsOfDevice(String deviceId) + public List getAllMobileDeviceOperationNappingsOfDevice( + String deviceId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -282,7 +284,8 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio } @Override - public List getAllPendingOperationsOfMobileDevice(String deviceId) + public List getAllPendingOperationMappingsOfMobileDevice( + String deviceId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 6f983089d..30dc4db14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -44,7 +44,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { + public boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; PreparedStatement stmt = null; @@ -73,7 +73,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public boolean updateFeature(MobileFeature mobileFeature) + public boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -103,7 +103,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public boolean deleteFeatureByCode(String featureCode) + public boolean deleteMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -129,7 +129,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public boolean deleteFeatureById(String featureId) + public boolean deleteMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -139,7 +139,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { String deleteDBQuery = "DELETE FROM MBL_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, featureId); + stmt.setInt(1, featureId); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; @@ -155,7 +155,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public MobileFeature getFeatureByCode(String featureCode) + public MobileFeature getMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -187,7 +187,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public MobileFeature getFeatureById(String featureID) + public MobileFeature getMobileFeatureById(int featureID) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -197,7 +197,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { String selectDBQuery = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, featureID); + stmt.setInt(1, featureID); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { mobileFeature = new MobileFeature(); @@ -219,7 +219,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO { } @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { + public List getAllMobileFeatures() throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; MobileFeature mobileFeature; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java index f99a2c7f0..766c6aca6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java @@ -44,7 +44,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { } @Override - public boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty) + public boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -73,7 +73,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { } @Override - public boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty) + public boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -101,7 +101,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { } @Override - public boolean deleteFeatureProperty(String property) + public boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -128,7 +128,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { } @Override - public MobileFeatureProperty getFeatureProperty(String property) + public MobileFeatureProperty getMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index aeb22ba7b..af3622e9c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -59,7 +59,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId()); mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .addMobileDeviceOperation( + .addMobileDeviceOperationMapping( mobileDeviceOperationMapping); } } @@ -81,7 +81,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage MobileOperation mobileOperation = null; try { mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllMobileDeviceOperationsOfDevice( + .getAllMobileDeviceOperationNappingsOfDevice( deviceIdentifier .getId()); if (mobileDeviceOperationMappings.size() > 0) { @@ -121,7 +121,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage try { //Get the list of pending operations for the given device mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .getAllPendingOperationsOfMobileDevice( + .getAllPendingOperationMappingsOfMobileDevice( deviceIdentifier .getId()); //Go through each operation mapping for retrieving the data corresponding to each operation @@ -142,7 +142,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS); operation.setSentDate(new Date().getTime()); MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() - .updateMobileDeviceOperationToInProgress( + .updateMobileDeviceOperationMappingToInProgress( operation.getDeviceId(), operation.getOperationId()); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index 28606783d..2d4a5fae6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -55,6 +55,7 @@ import java.util.List; */ public class MobileDeviceManagementServiceComponent { + private static final String SETUP_COMMAND = "setup"; private ServiceRegistration androidServiceRegRef; private ServiceRegistration iOSServiceRegRef; private ServiceRegistration windowsServiceRegRef; @@ -77,7 +78,7 @@ public class MobileDeviceManagementServiceComponent { MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); MobileDeviceManagementDAOFactory.init(); - String setupOption = System.getProperty("setup"); + String setupOption = System.getProperty(SETUP_COMMAND); if (setupOption != null) { if (log.isDebugEnabled()) { log.debug( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java deleted file mode 100644 index 620127c5a..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2014, 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.dao; - -import org.apache.commons.dbcp.BasicDataSource; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations; -import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.Statement; -import java.util.Iterator; - -public class FeatureDAOTestSuite { - - private TestDBConfiguration testDBConfiguration; - private Connection conn = null; - private Statement stmt = null; - private MobileFeatureDAOImpl featureDAO; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - createH2DB(testDBConfiguration); - BasicDataSource testDataSource = new BasicDataSource(); - testDataSource.setDriverClassName(testDBConfiguration.getDriverClass()); - testDataSource.setUrl(testDBConfiguration.getConnectionUrl()); - testDataSource.setUsername(testDBConfiguration.getUserName()); - testDataSource.setPassword(testDBConfiguration.getPwd()); - featureDAO = new MobileFeatureDAOImpl(testDataSource); - default: - } - } - - private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws - MobileDeviceManagementDAOException, - DeviceManagementException { - - File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); - Document doc = null; - testDBConfiguration = null; - TestDBConfigurations testDBConfigurations = null; - - doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig); - JAXBContext testDBContext = null; - - try { - testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); - Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); - testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc); - } catch (JAXBException e) { - throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e); - } - - Iterator itrDBConfigs = - testDBConfigurations.getDbTypesList().iterator(); - while (itrDBConfigs.hasNext()) { - testDBConfiguration = itrDBConfigs.next(); - if (testDBConfiguration.getDbType().equals(dbType.toString())) { - break; - } - } - - return testDBConfiguration; - } - - private void createH2DB(TestDBConfiguration testDBConf) throws Exception { - Class.forName(testDBConf.getDriverClass()); - conn = DriverManager.getConnection(testDBConf.getConnectionUrl()); - stmt = conn.createStatement(); - stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); - stmt.close(); - conn.close(); - } - - @Test - public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException { - - MobileFeature mobileFeature = new MobileFeature(); - mobileFeature.setCode("Camera"); - mobileFeature.setDescription("Camera enable or disable"); - mobileFeature.setName("Camera"); - boolean added = featureDAO.addFeature(mobileFeature); - // Long deviceId = null; - // try { - // conn = DeviceManagementDAOFactory.getDataSource().getConnection(); - // stmt = conn.createStatement(); - // ResultSet resultSet = stmt - // .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); - // - // while (resultSet.next()) { - // deviceId = resultSet.getLong(1); - // } - // conn.close(); - // } catch (SQLException sqlEx) { - // throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx); - // } - - Assert.assertTrue(added, "Device Id is null"); - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java new file mode 100644 index 000000000..de81ff5a6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2014, 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.dao; + +import org.apache.commons.dbcp.BasicDataSource; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; +import org.wso2.carbon.device.mgt.mobile.impl.TestUtils; +import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; +import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; +import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations; +import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.sql.*; +import java.util.Iterator; +import java.util.List; + +public class MobileFeatureDAOTestSuite { + + public static final String MBL_FEATURE_NAME = "Camera"; + private static final String MBL_FEATURE_CODE = "500A"; + public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable"; + public static final String MBL_FEATURE_UPDATED_CODE = "501B"; + private TestDBConfiguration testDBConfiguration; + private Connection conn = null; + private Statement stmt = null; + private MobileFeatureDAOImpl mblFeatureDAO; + private int mblFeatureId; + + @BeforeClass + @Parameters("dbType") + public void setUpDB(String dbTypeStr) throws Exception { + + DBTypes dbType = DBTypes.valueOf(dbTypeStr); + testDBConfiguration = getTestDBConfiguration(dbType); + + switch (dbType) { + case H2: + createH2DB(testDBConfiguration); + BasicDataSource testDataSource = new BasicDataSource(); + testDataSource.setDriverClassName(testDBConfiguration.getDriverClass()); + testDataSource.setUrl(testDBConfiguration.getConnectionUrl()); + testDataSource.setUsername(testDBConfiguration.getUserName()); + testDataSource.setPassword(testDBConfiguration.getPwd()); + mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource); + default: + } + } + + private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws + MobileDeviceManagementDAOException, + DeviceManagementException { + + File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); + Document doc = null; + testDBConfiguration = null; + TestDBConfigurations testDBConfigurations = null; + + doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig); + JAXBContext testDBContext = null; + + try { + testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e); + } + + Iterator itrDBConfigs = + testDBConfigurations.getDbTypesList().iterator(); + while (itrDBConfigs.hasNext()) { + testDBConfiguration = itrDBConfigs.next(); + if (testDBConfiguration.getDbType().equals(dbType.toString())) { + break; + } + } + + return testDBConfiguration; + } + + private void createH2DB(TestDBConfiguration testDBConf) throws Exception { + Class.forName(testDBConf.getDriverClass()); + conn = DriverManager.getConnection(testDBConf.getConnectionUrl()); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); + stmt.close(); + conn.close(); + } + + @Test + public void addMobileFeatureTest() + throws MobileDeviceManagementDAOException { + + MobileFeature mobileFeature = new MobileFeature(); + MobileFeature testMblFeature = new MobileFeature(); + mobileFeature.setCode(MBL_FEATURE_CODE); + mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); + mobileFeature.setName(MBL_FEATURE_NAME); + boolean added = mblFeatureDAO.addMobileFeature(mobileFeature); + try { + conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl()); + stmt = conn.createStatement(); + ResultSet resultSet = stmt + .executeQuery( + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '500A'"); + while (resultSet.next()) { + testMblFeature.setId(resultSet.getInt(1)); + testMblFeature.setCode(resultSet.getString(2)); + testMblFeature.setName(resultSet.getString(3)); + testMblFeature.setDescription(resultSet.getString(4)); + } + conn.close(); + } catch (SQLException e) { + throw new MobileDeviceManagementDAOException("Error in retrieving Mobile Feature data ", + e); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + mblFeatureId = testMblFeature.getId(); + Assert.assertTrue(added, "MobileFeature is added"); + Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(), + "MobileFeature code has persisted successfully"); + Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(), + "MobileFeature name has persisted successfully"); + Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(), + "MobileFeature description has persisted successfully"); + } + + @Test(dependsOnMethods = { "addMobileFeatureTest" }) + public void getMobileFeatureByCodeTest() + throws MobileDeviceManagementDAOException { + + MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureByCode(MBL_FEATURE_CODE); + Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(), + "MobileFeature code has retrieved successfully"); + Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(), + "MobileFeature name has retrieved successfully"); + Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(), + "MobileFeature description has retrieved successfully"); + } + + @Test(dependsOnMethods = { "addMobileFeatureTest" }) + public void deleteMobileFeatureByCodeTest() + throws MobileDeviceManagementDAOException { + boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE); + try { + conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl()); + stmt = conn.createStatement(); + ResultSet resultSet = stmt + .executeQuery( + "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE CODE = '500A'"); + while (resultSet.next()) { + status = false; + } + conn.close(); + } catch (SQLException e) { + throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", + e); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + Assert.assertTrue(status, "MobileFeature has deleted successfully"); + } + + @Test(dependsOnMethods = { "addMobileFeatureTest" }) + public void getMobileFeatureByIdTest() + throws MobileDeviceManagementDAOException { + + MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureById(mblFeatureId); + Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(), + "MobileFeature code has retrieved successfully"); + Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(), + "MobileFeature name has retrieved successfully"); + Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(), + "MobileFeature description has retrieved successfully"); + } + + @Test(dependsOnMethods = { "addMobileFeatureTest" }) + public void getAllMobileFeaturesTest() + throws MobileDeviceManagementDAOException { + + List mobileFeatures = mblFeatureDAO.getAllMobileFeatures(); + Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null"); + Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature"); + } + + @Test(dependsOnMethods = { "addMobileFeatureTest" }) + public void deleteMobileFeatureByIdTest() + throws MobileDeviceManagementDAOException { + boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId); + try { + conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl()); + stmt = conn.createStatement(); + ResultSet resultSet = stmt + .executeQuery( + "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE FEATURE_ID = " + + mblFeatureId); + while (resultSet.next()) { + status = false; + } + conn.close(); + } catch (SQLException e) { + throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", + e); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + Assert.assertTrue(status, "MobileFeature has deleted successfully"); + } + + @Test(dependsOnMethods = { "deleteMobileFeatureByCodeTest", "addMobileFeatureTest" }) + public void updateMobileFeatureTest() + throws MobileDeviceManagementDAOException { + + MobileFeature mobileFeature = new MobileFeature(); + MobileFeature testMblFeature = new MobileFeature(); + mobileFeature.setCode(MBL_FEATURE_UPDATED_CODE); + mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION); + mobileFeature.setName(MBL_FEATURE_NAME); + mobileFeature.setId(mblFeatureId); + boolean updated = mblFeatureDAO.updateMobileFeature(mobileFeature); + try { + conn = DriverManager.getConnection(testDBConfiguration.getConnectionUrl()); + stmt = conn.createStatement(); + ResultSet resultSet = stmt + .executeQuery( + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = " + + MBL_FEATURE_UPDATED_CODE); + while (resultSet.next()) { + testMblFeature.setId(resultSet.getInt(1)); + testMblFeature.setCode(resultSet.getString(2)); + testMblFeature.setName(resultSet.getString(3)); + testMblFeature.setDescription(resultSet.getString(4)); + } + conn.close(); + } catch (SQLException e) { + throw new MobileDeviceManagementDAOException("Error in updating Mobile Feature data ", + e); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + Assert.assertTrue(updated, "MobileFeature has updated"); + Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(), + "MobileFeature data has updated successfully"); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java similarity index 93% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java index 193749368..227fc4f01 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeaturePropertyDAOTestSuite.java @@ -16,5 +16,5 @@ package org.wso2.carbon.device.mgt.mobile.impl.dao; -public class FeaturePropertyDAOTestSuite { +public class MobileFeaturePropertyDAOTestSuite { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi.config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi-config.xml similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi.config.xml rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi-config.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql index 39610edd9..aab99bd14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql @@ -42,6 +42,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( `OPERATION_ID` INT NOT NULL , `SENT_DATE` BIGINT NULL , `RECEIVED_DATE` BIGINT NULL , + `STATUS` VARCHAR(10) NOT NULL , PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` FOREIGN KEY (`DEVICE_ID` ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml index 204866688..0c639fea3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml @@ -18,10 +18,18 @@ - + - + + + + \ No newline at end of file From 329f956f3d612d07feb8429de91bdfbc3704fb02 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 23 Jan 2015 18:19:21 +0530 Subject: [PATCH 10/11] License Management --- .../src/repository/resources/rxts/license.rxt | 15 ++++++++++++--- .../cdmserver/mobileservices/android/Device.java | 4 +--- .../impl/CertificateEnrollmentServiceImpl.java | 15 +++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/product/modules/distribution/src/repository/resources/rxts/license.rxt b/product/modules/distribution/src/repository/resources/rxts/license.rxt index 72f5c2618..2fc84c6db 100644 --- a/product/modules/distribution/src/repository/resources/rxts/license.rxt +++ b/product/modules/distribution/src/repository/resources/rxts/license.rxt @@ -1,16 +1,19 @@ - /license/@{overview_provider}/@{overview_name}/@{overview_version} + /license/@{overview_provider}/@{overview_name}/@{overview_language}/@{overview_version} overview_name - + + + + @@ -24,11 +27,17 @@ Name + + Language + Version - Createdtime + Validity From + + + Validity To License diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java index 0a9e01ffc..20af913ff 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Device.java @@ -131,10 +131,9 @@ public class Device { } @GET - @Path("/device/license") + @Path("/license") @Produces("text/plain") public String getLicense() { - //TODO: need to implement fetch license from core License license = null; try { try { @@ -147,7 +146,6 @@ public class Device { }catch(DeviceManagementServiceException deviceMgtEx){ deviceMgtEx.printStackTrace(); } - return license.getLicenseText(); } } diff --git a/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/impl/CertificateEnrollmentServiceImpl.java b/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/impl/CertificateEnrollmentServiceImpl.java index 32f8c35dc..ca41e7394 100644 --- a/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/impl/CertificateEnrollmentServiceImpl.java +++ b/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/impl/CertificateEnrollmentServiceImpl.java @@ -69,7 +69,8 @@ public class CertificateEnrollmentServiceImpl implements CertificateEnrollmentSe String wapProvisioningXmlFile; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); - @Override public void RequestSecurityToken(String TokenType, String RequestType, + //@Override + public void RequestSecurityToken(String TokenType, String RequestType, String BinarySecurityToken, AdditionalContext AdditionalContext, Holder response) { @@ -109,18 +110,20 @@ public class CertificateEnrollmentServiceImpl implements CertificateEnrollmentSe NodeList wapParm = dDoc.getElementsByTagName("parm"); ///////// - wapParm.item(0).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf( + /* wapParm.item(0).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf( DigestUtils.sha1Hex(rooCACertificate.getEncoded()))); - ///////// + */ ///////// NamedNodeMap rootCertAttributes = wapParm.item(0).getAttributes(); Node b64Encoded = rootCertAttributes.getNamedItem("value"); rootCertEncodedString=rootCertEncodedString.replaceAll("\n",""); b64Encoded.setTextContent(rootCertEncodedString); System.out.println("COPY_ROOT_CERT:"+rootCertEncodedString); - ///////// - wapParm.item(1).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf(DigestUtils.sha1Hex(signedCert.getEncoded()))); - ///////// + ///////// + ///////// +/* + wapParm.item(1).getParentNode().getAttributes().getNamedItem("type").setTextContent(String.valueOf(DigestUtils.sha1Hex(signedCert.getEncoded()))); +*/ From e40424c7583f3f4e3ebc3b60ecfda3bf7b97a1e2 Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 23 Jan 2015 19:44:16 +0530 Subject: [PATCH 11/11] Added copying mobile db scripts to bin.xml & refactored code --- .../impl/dao/MobileFeatureDAOTestSuite.java | 11 ++++- .../modules/distribution/src/assembly/bin.xml | 2 +- .../jax-rs/src/main/java/Licenses.java | 45 ------------------- .../mobileservices/android/Test.java | 35 --------------- 4 files changed, 10 insertions(+), 83 deletions(-) delete mode 100644 product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java delete mode 100644 product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java index de81ff5a6..0f94b06a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileFeatureDAOTestSuite.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.dao; import org.apache.commons.dbcp.BasicDataSource; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; @@ -44,6 +46,7 @@ import java.util.List; public class MobileFeatureDAOTestSuite { + private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class); public static final String MBL_FEATURE_NAME = "Camera"; private static final String MBL_FEATURE_CODE = "500A"; public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable"; @@ -139,6 +142,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in retrieving Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in retrieving Mobile Feature data ", e); } finally { @@ -182,6 +186,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in deleting Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", e); } finally { @@ -228,6 +233,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in deleting Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ", e); } finally { @@ -252,8 +258,8 @@ public class MobileFeatureDAOTestSuite { stmt = conn.createStatement(); ResultSet resultSet = stmt .executeQuery( - "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = " + - MBL_FEATURE_UPDATED_CODE); + "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '" + + MBL_FEATURE_UPDATED_CODE + "'"); while (resultSet.next()) { testMblFeature.setId(resultSet.getInt(1)); testMblFeature.setCode(resultSet.getString(2)); @@ -262,6 +268,7 @@ public class MobileFeatureDAOTestSuite { } conn.close(); } catch (SQLException e) { + log.error("Error in updating Mobile Feature data ", e); throw new MobileDeviceManagementDAOException("Error in updating Mobile Feature data ", e); } finally { diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 7420ae1f6..0a4cbc57a 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -210,7 +210,7 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/dbscripts/cdm + ../distribution/src/repository/dbscripts/cdm wso2mdm-${project.version}/dbscripts/cdm */** diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java deleted file mode 100644 index aa49c5939..000000000 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/Licenses.java +++ /dev/null @@ -1,45 +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. - * / - */ - -import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.License; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Produces; - -/** - * License Management related JAX RS APIs - */ - -@Produces({ "application/json", "application/xml" }) -@Consumes({ "application/json", "application/xml" }) -public class Licenses { - - private static Log log = LogFactory.getLog(Licenses.class); - - @GET - public License getLicense(String deviceType) throws AndroidAgentException { - return null; - } - -} diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java deleted file mode 100644 index ee9e56212..000000000 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Test.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.wso2.cdmserver.mobileservices.android; - -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.Device; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; - -/** - * This is a Test class - */ -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class Test { - - @GET - public List getAllDevices() throws DeviceManagementException{ - - Device dev = new Device(); - dev.setName("test1"); - dev.setDateOfEnrolment(11111111L); - dev.setDateOfLastUpdate(992093209L); - dev.setDescription("sassasaas"); - - ArrayList listdevices = new ArrayList(); - listdevices.add(dev); - throw new DeviceManagementException("test ex"); - - } -}