From e256628ed746bbe521c497d0ed579a1cc69c139d Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 6 Oct 2017 13:28:45 +0530 Subject: [PATCH 1/8] Add DeviceInfo event reporting --- .../impl/DeviceInformationManagerImpl.java | 96 +++++++++++++------ 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index e356802117..0a7f22dbf0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -41,6 +41,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,7 +51,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { private DeviceDetailsDAO deviceDetailsDAO; private DeviceDAO deviceDAO; private static final Log log = LogFactory.getLog(DeviceInformationManagerImpl.class); - private static final String EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream"; + private static final String LOCATION_EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream"; + private static final String DEVICE_INFO_EVENT_STREAM_DEFINITION = "org.wso2.iot.DeviceInfoStream"; + public DeviceInformationManagerImpl() { this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); @@ -70,6 +73,35 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { deviceDetailsDAO.addDeviceInformation(device.getId(), deviceInfo); deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId()); DeviceManagementDAOFactory.commitTransaction(); + + if (DeviceManagerUtil.isPublishOperationResponseEnabled()) { + Object[] metaData = {device.getDeviceIdentifier(), device.getType()}; + Object[] payload = new Object[]{ + Calendar.getInstance().getTimeInMillis(), + deviceInfo.getDeviceDetailsMap().get("IMEI"), + deviceInfo.getDeviceDetailsMap().get("IMSI"), + deviceInfo.getDeviceModel(), + deviceInfo.getVendor(), + deviceInfo.getOsVersion(), + deviceInfo.getOsBuildDate(), + deviceInfo.getBatteryLevel(), + deviceInfo.getInternalTotalMemory(), + deviceInfo.getInternalAvailableMemory(), + deviceInfo.getExternalTotalMemory(), + deviceInfo.getExternalAvailableMemory(), + deviceInfo.getOperator(), + deviceInfo.getConnectionType(), + deviceInfo.getMobileSignalStrength(), + deviceInfo.getSsid(), + deviceInfo.getCpuUsage(), + deviceInfo.getTotalRAMMemory(), + deviceInfo.getAvailableRAMMemory(), + deviceInfo.isPluggedIn() + }; + DeviceManagerUtil.getEventPublisherService().publishEvent( + DEVICE_INFO_EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload + ); + } } catch (TransactionManagementException e) { DeviceManagementDAOFactory.rollbackTransaction(); throw new DeviceDetailsMgtException("Transactional error occurred while adding the device information.", e); @@ -82,7 +114,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); throw new DeviceDetailsMgtException("Error occurred while updating the last update timestamp of the " + - "device", e); + "device", e); + } catch (DataPublisherConfigurationException e) { + DeviceManagementDAOFactory.rollbackTransaction(); + throw new DeviceDetailsMgtException("Error occurred while publishing the device location information.", e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -90,19 +125,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { @Override public DeviceInfo getDeviceInfo(DeviceIdentifier deviceId) throws DeviceDetailsMgtException { - Device device; - try { - device = DeviceManagementDataHolder.getInstance(). - getDeviceManagementProvider().getDevice(deviceId, false); - if (device == null) { - if (log.isDebugEnabled()) { - log.debug("No device is found upon the device identifier '" + deviceId.getId() + - "' and type '" + deviceId.getType() + "'. Therefore returning null"); - } - return null; - } - } catch (DeviceManagementException e) { - throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e); + Device device = getDevice(deviceId); + if (device == null) { + return null; } try { DeviceManagementDAOFactory.openConnection(); @@ -111,7 +136,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { return deviceInfo; } catch (SQLException e) { - throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e); + throw new DeviceDetailsMgtException("SQL error occurred while retrieving device " + deviceId.toString() + + "'s info from database.", e); } catch (DeviceDetailsMgtDAOException e) { throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e); } finally { @@ -166,15 +192,15 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId()); deviceDetailsDAO.addDeviceLocation(deviceLocation); - if (DeviceManagerUtil.isPublishLocationOperationResEnabled()) { - Object metaData[] = {device.getDeviceIdentifier(), device.getType()}; - Object payload[] = new Object[]{ + if (DeviceManagerUtil.isPublishOperationResponseEnabled()) { + Object[] metaData = {device.getDeviceIdentifier(), device.getType()}; + Object[] payload = new Object[]{ deviceLocation.getUpdatedTime().getTime(), deviceLocation.getLatitude(), deviceLocation.getLongitude() }; DeviceManagerUtil.getEventPublisherService().publishEvent( - EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload + LOCATION_EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload ); } DeviceManagementDAOFactory.commitTransaction(); @@ -201,29 +227,37 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { @Override public DeviceLocation getDeviceLocation(DeviceIdentifier deviceId) throws DeviceDetailsMgtException { + Device device = getDevice(deviceId); + if (device == null) { + return null; + } + try { + DeviceManagementDAOFactory.openConnection(); + return deviceDetailsDAO.getDeviceLocation(device.getId()); + } catch (SQLException e) { + throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e); + } catch (DeviceDetailsMgtDAOException e) { + throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + + private Device getDevice(DeviceIdentifier deviceId) throws DeviceDetailsMgtException { Device device; try { device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, false); if (device == null) { if (log.isDebugEnabled()) { log.debug("No device is found upon the device identifier '" + deviceId.getId() + - "' and type '" + deviceId.getType() + "'. Therefore returning null"); + "' and type '" + deviceId.getType() + "'. Therefore returning null"); } return null; } } catch (DeviceManagementException e) { throw new DeviceDetailsMgtException("Exception occurred while retrieving the device.", e); } - try { - DeviceManagementDAOFactory.openConnection(); - return deviceDetailsDAO.getDeviceLocation(device.getId()); - } catch (SQLException e) { - throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e); - } catch (DeviceDetailsMgtDAOException e) { - throw new DeviceDetailsMgtException("Exception occurred while retrieving device location.", e); - } finally { - DeviceManagementDAOFactory.closeConnection(); - } + return device; } @Override From 441017dfa7a21452f2789bbf58c16ff968b63257 Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 6 Oct 2017 13:33:03 +0530 Subject: [PATCH 2/8] Add basics feature for device management core --- .../pom.xml | 173 ++++++++++++++++++ .../src/main/resources/build.properties | 0 .../src/main/resources/conf/cdm-config.xml | 6 +- .../main/resources/conf/license-config.xml | 0 .../conf/remote-appmanager-config.xml | 0 .../src/main/resources/dbscripts/cdm/h2.sql | 0 .../main/resources/dbscripts/cdm/mssql.sql | 0 .../main/resources/dbscripts/cdm/mysql.sql | 0 .../main/resources/dbscripts/cdm/oracle.sql | 0 .../resources/dbscripts/cdm/postgresql.sql | 0 .../email/templates/user-enrollment.vm | 0 .../email/templates/user-registration.vm | 0 .../src/main/resources/p2.inf | 12 +- .../src/main/resources/rxts/license.rxt | 0 .../pom.xml | 62 +------ 15 files changed, 189 insertions(+), 64 deletions(-) create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/build.properties (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/conf/cdm-config.xml (96%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/conf/license-config.xml (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/conf/remote-appmanager-config.xml (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/dbscripts/cdm/h2.sql (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/dbscripts/cdm/mssql.sql (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/dbscripts/cdm/mysql.sql (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/dbscripts/cdm/oracle.sql (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/dbscripts/cdm/postgresql.sql (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/email/templates/user-enrollment.vm (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/email/templates/user-registration.vm (100%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/p2.inf (72%) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature => org.wso2.carbon.device.mgt.basics.feature}/src/main/resources/rxts/license.rxt (100%) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml new file mode 100644 index 0000000000..8f5826d1f2 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -0,0 +1,173 @@ + + + + + + + org.wso2.carbon.devicemgt + device-mgt-feature + 3.0.119-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.basics.feature + pom + 3.0.119-SNAPSHOT + WSO2 Carbon - Device Management Basics Feature + http://wso2.org + This feature contains the core bundles required for Basic Device Management functionality + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + + + org.wso2.carbon.registry + org.wso2.carbon.registry.indexing + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.receiver.stub + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.stub + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.publisher.stub + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.persistence.stub + + + org.wso2.orbit.org.scannotation + scannotation + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.device.mgt.basics + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.analytics.data.publisher:${carbon.device.mgt.version} + + + org.wso2.carbon.analytics-common:org.wso2.carbon.event.receiver.stub:${carbon.analytics.common.version} + + + org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.stub:${carbon.analytics.common.version} + + + org.wso2.carbon.analytics-common:org.wso2.carbon.event.publisher.stub:${carbon.analytics.common.version} + + + org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.persistence.stub:${carbon.analytics.common.version} + + + org.wso2.orbit.com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version} + + + org.wso2.orbit.org.scannotation:scannotation:${scannotation.version} + + + + + org.wso2.carbon.registry:org.wso2.carbon.registry.indexing:${carbon.registry.version} + + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + org.wso2.carbon.email.sender:${carbon.device.mgt.version} + + + + + + + + + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/build.properties b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/build.properties similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/build.properties rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/build.properties diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml similarity index 96% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml index 58ed4e6167..518edb4d8d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml @@ -87,10 +87,10 @@ true 86400 - + false - false - + false + BYOD,COPE diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/license-config.xml similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/license-config.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/remote-appmanager-config.xml similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/remote-appmanager-config.xml rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/remote-appmanager-config.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/email/templates/user-enrollment.vm b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/email/templates/user-enrollment.vm similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/email/templates/user-enrollment.vm rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/email/templates/user-enrollment.vm diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/email/templates/user-registration.vm b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/email/templates/user-registration.vm similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/email/templates/user-registration.vm rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/email/templates/user-registration.vm diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf similarity index 72% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf index 5675919164..3c343f6e31 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf @@ -1,8 +1,8 @@ instructions.configure = \ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../../repository/resources/email-templates);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\ \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/rxts/license.rxt similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/rxts/license.rxt rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/rxts/license.rxt diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 097c3ba7b7..940d8e6683 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -42,45 +42,21 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.url.printer + org.wso2.carbon.device.mgt.api.feature + zip org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common + org.wso2.carbon.device.mgt.url.printer org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.api.feature - zip + org.wso2.carbon.device.mgt.extensions.pull.notification org.wso2.orbit.org.apache.pdfbox pdfbox - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions.pull.notification - - - org.wso2.carbon.registry - org.wso2.carbon.registry.indexing - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.receiver.stub - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.stream.stub - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.publisher.stub - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.stream.persistence.stub - @@ -131,55 +107,31 @@ + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.basics.feature:${carbon.device.mgt.version} + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.api.feature:${carbon.device.mgt.version} - - org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version} - - - org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version} - org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.url.printer:${carbon.device.mgt.version} org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.pull.notification:${carbon.device.mgt.version} - - - org.wso2.carbon.identity.inbound.auth.oauth2:org.wso2.carbon.identity.oauth.stub:${identity.inbound.auth.oauth.version} - - org.wso2.orbit.com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version} - - - org.wso2.carbon.analytics-common:org.wso2.carbon.event.receiver.stub:${carbon.analytics.common.version} - - - org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.stub:${carbon.analytics.common.version} - - - org.wso2.carbon.analytics-common:org.wso2.carbon.event.publisher.stub:${carbon.analytics.common.version} - - - org.wso2.carbon.analytics-common:org.wso2.carbon.event.stream.persistence.stub:${carbon.analytics.common.version} - - org.wso2.carbon.apimgt:org.wso2.carbon.apimgt.keymgt:${carbon.api.mgt.version} org.wso2.orbit.org.apache.pdfbox:pdfbox:${orbit.version.pdfbox} - org.wso2.carbon.registry:org.wso2.carbon.registry.indexing:${carbon.registry.version} org.wso2.carbon.core.server:${carbon.kernel.version} org.wso2.carbon.device.mgt.extensions:${carbon.device.mgt.version} - org.wso2.carbon.email.sender:${carbon.device.mgt.version} From f766011f9b42850747cbc76035177d129afb793c Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 6 Oct 2017 13:36:56 +0530 Subject: [PATCH 3/8] Add isMappedToGroup method for device group service --- .../GroupManagementProviderService.java | 15 +++++-- .../GroupManagementProviderServiceImpl.java | 42 ++++++++++++++++- .../device/mgt/core/search/util/Utils.java | 7 +-- .../GroupManagementProviderServiceTest.java | 45 +++++++++++++++---- 4 files changed, 91 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index 0187e8dca6..27aa73f358 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -26,8 +26,8 @@ import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; -import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException; +import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import java.util.List; @@ -215,10 +215,19 @@ public interface GroupManagementProviderService { /** * Checks for the default group existence and create group based on device ownership. - * @param groupName - * @return + * @param groupName of the group + * @return DeviceGroup object * @throws GroupManagementException */ DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException; + /** + * Check device is belonging to a Device Group. + * + * @param groupId of Device Group. + * @param deviceIdentifier of the device. + * @throws GroupManagementException on errors. + */ + boolean isDeviceMappedToGroup(int groupId, DeviceIdentifier deviceIdentifier) throws GroupManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 69efaa107d..f55e8fb0c9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -30,7 +30,12 @@ import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.group.mgt.*; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException; +import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.core.dao.GroupDAO; import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; @@ -825,4 +830,39 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid return defaultGroup; } } + + /** + * {@inheritDoc} + */ + @Override + public boolean isDeviceMappedToGroup(int groupId, DeviceIdentifier deviceIdentifier) + throws GroupManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + Device device; + try { + device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). + getDevice(deviceIdentifier, false); + if (device == null) { + throw new GroupManagementException("Device not found for id '" + deviceIdentifier.getId() + + "' type '" + deviceIdentifier.getType() + "'"); + } + } catch (DeviceManagementException e) { + throw new GroupManagementException("Device management exception occurred when retrieving device. " + + e.getMessage(), e); + } + + try{ + GroupManagementDAOFactory.openConnection(); + return this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId); + } catch (GroupManagementDAOException e) { + throw new GroupManagementException("Error occurred when checking device, group mapping between device id '" + + deviceIdentifier.getId() + "' and group id '" + groupId + "'", e); + } catch (SQLException e) { + throw new GroupManagementException("Error occurred when opening db connection to check device, group " + + "mapping between device id '" + deviceIdentifier.getId() + + "' and group id '" + groupId + "'", e); + } finally { + GroupManagementDAOFactory.closeConnection(); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java index 58c6f621ac..9e02b3f970 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java @@ -33,10 +33,7 @@ public class Utils { DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setIMSI("e6f236ac82537a8e"); deviceInfo.setSsid("FAFDA"); - - deviceInfo.setAvailableRAMMemory(1.24); deviceInfo.setBatteryLevel(27.3); deviceInfo.setConnectionType("GSM"); @@ -44,8 +41,6 @@ public class Utils { deviceInfo.setDeviceModel("SM-T520"); deviceInfo.setExternalAvailableMemory(2.45); deviceInfo.setExternalTotalMemory(16.23); - deviceInfo.setIMEI("e6f236ac82537a8e"); - deviceInfo.setIMSI("GT-0WDA"); deviceInfo.setInternalAvailableMemory(3.56); deviceInfo.setInternalTotalMemory(7.89); deviceInfo.setMobileSignalStrength(0.67); @@ -67,6 +62,8 @@ public class Utils { propertyMap.put("MEMORY_THRESHOLD", "100663296"); propertyMap.put("CPU_IOW", "12"); propertyMap.put("CPU_IRQ", "1"); + propertyMap.put("IMEI", "e6f236ac82537a8e"); + propertyMap.put("IMSI", "432659632123654845"); deviceInfo.setDeviceDetailsMap(propertyMap); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java index 994ef33e8e..56fe67888c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java @@ -16,20 +16,26 @@ * under the License. */ - package org.wso2.carbon.device.mgt.core.service; - import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.group.mgt.*; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException; +import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; import org.wso2.carbon.device.mgt.core.TestUtils; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration; -import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; import org.wso2.carbon.user.api.Permission; @@ -65,7 +71,6 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest @Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class, TransactionManagementException.class}) public void createGroupError() throws GroupManagementException, GroupAlreadyExistException, TransactionManagementException { - GroupManagementDAOFactory.beginTransaction(); groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); } @@ -125,7 +130,6 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest @Test(dependsOnMethods = ("createGroup")) public void getGroup() throws GroupManagementException { - DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName()); Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId())); } @@ -160,8 +164,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest @Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class}) public void getGroupsByPaginationError() throws GroupManagementException { - GroupPaginationRequest request = null; - groupManagementProviderService.getGroups(request); + groupManagementProviderService.getGroups((GroupPaginationRequest) null); } @Test(dependsOnMethods = ("createGroup")) @@ -281,5 +284,29 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest groupManagementProviderService.createDefaultGroup("BYOD"); } + @Test(dependsOnMethods = {"createGroup", "addDevices", "updateGroupSecondTime"}) + public void checkDeviceBelongsToGroup() throws GroupManagementException { + List list = TestUtils.getDeviceIdentifiersList(); + boolean isMapped = groupManagementProviderService + .isDeviceMappedToGroup(groupManagementProviderService.getGroup( + TestUtils.createDeviceGroup1().getName()).getGroupId(), list.get(0)); + Assert.assertEquals(isMapped, true); + } + + @Test + public void checkDeviceBelongsToNonExistingGroup() throws GroupManagementException { + List list = TestUtils.getDeviceIdentifiersList(); + boolean isMapped = groupManagementProviderService + .isDeviceMappedToGroup(1500, list.get(0)); + Assert.assertEquals(isMapped, false); + } + + + @Test(dependsOnMethods = {"createGroup", "updateGroupSecondTime"}, expectedExceptions = {GroupManagementException.class}) + public void checkNullDeviceBelongsToGroup() throws GroupManagementException { + groupManagementProviderService.isDeviceMappedToGroup(groupManagementProviderService.getGroup( + TestUtils.createDeviceGroup1().getName()).getGroupId(), null); + } + } From 9f94f86401734f171b4bb12f1bd8247f6c200974 Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 6 Oct 2017 13:38:03 +0530 Subject: [PATCH 4/8] Rename GeoAnalyticsConfigurations to OperationAnalyticsConfiguration --- .../impl/GeoLocationBasedServiceImpl.java | 18 +++++++------- .../mgt/common/device/details/DeviceInfo.java | 24 ------------------- .../core/config/DeviceManagementConfig.java | 14 +++++------ ...a => OperationAnalyticsConfiguration.java} | 18 +++++++------- .../mgt/core/util/DeviceManagerUtil.java | 16 +++++++++++-- .../modules/business-controllers/device.js | 2 +- .../cdmf.unit.geo-dashboard/geo-dashboard.js | 2 +- features/device-mgt/pom.xml | 1 + 8 files changed, 42 insertions(+), 53 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/{GeoLocationConfiguration.java => OperationAnalyticsConfiguration.java} (65%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 04bfeff0d7..2543d1a85e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -31,15 +31,15 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.geo.service.Event; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; -import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException; +import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; -import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; -import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; @@ -76,13 +76,13 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { public Response getGeoDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, @QueryParam("from") long from, @QueryParam("to") long to) { - //First, check whether the Geo Location service has been enabled in the cdmf-config.xml file - DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance() - .getDeviceManagementConfig(); - if (deviceManagementConfig != null) { - if(!deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse()){ - return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build(); + try { + if (!DeviceManagerUtil.isPublishOperationResponseEnabled()) { + return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) + .entity("Operation publishing does not exists").build(); } + } catch (DeviceManagementException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(e.getMessage()).build(); } String tableName = "IOT_PER_DEVICE_STREAM_GEO_FUSEDSPATIALEVENT"; String fromDate = String.valueOf(from); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index b7f5a5b14c..05c8345183 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -144,30 +144,6 @@ public class DeviceInfo implements Serializable { this.location = location; } - public String getIMEI() { - if (IMEI != null) { - return IMEI; - } else { - return ""; - } - } - - public void setIMEI(String IMEI) { - this.IMEI = IMEI; - } - - public String getIMSI() { - if (IMSI != null) { - return IMSI; - } else { - return ""; - } - } - - public void setIMSI(String IMSI) { - this.IMSI = IMSI; - } - public String getDeviceModel() { if (deviceModel != null) { return deviceModel; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index 72f9944fb2..2c039b0bef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -18,7 +18,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration; -import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration; +import org.wso2.carbon.device.mgt.core.config.geo.location.OperationAnalyticsConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration; @@ -48,7 +48,7 @@ public final class DeviceManagementConfig { private DeviceStatusTaskConfig deviceStatusTaskConfig; private DeviceCacheConfiguration deviceCacheConfiguration; private CertificateCacheConfiguration certificateCacheConfiguration; - private GeoLocationConfiguration geoLocationConfiguration; + private OperationAnalyticsConfiguration operationAnalyticsConfiguration; private String defaultGroupsConfiguration; @XmlElement(name = "ManagementRepository", required = true) @@ -142,13 +142,13 @@ public final class DeviceManagementConfig { this.certificateCacheConfiguration = certificateCacheConfiguration; } - @XmlElement(name = "GeoLocationConfiguration", required = true) - public GeoLocationConfiguration getGeoLocationConfiguration() { - return geoLocationConfiguration; + @XmlElement(name = "OperationAnalyticsConfiguration", required = true) + public OperationAnalyticsConfiguration getOperationAnalyticsConfiguration() { + return operationAnalyticsConfiguration; } - public void setGeoLocationConfiguration(GeoLocationConfiguration geoLocationConfiguration) { - this.geoLocationConfiguration = geoLocationConfiguration; + public void setOperationAnalyticsConfiguration(OperationAnalyticsConfiguration operationAnalyticsConfiguration) { + this.operationAnalyticsConfiguration = operationAnalyticsConfiguration; } @XmlElement(name = "DefaultGroupsConfiguration", required = true) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/GeoLocationConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/OperationAnalyticsConfiguration.java similarity index 65% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/GeoLocationConfiguration.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/OperationAnalyticsConfiguration.java index e1aeb1a45c..8cc2053e64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/GeoLocationConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/geo/location/OperationAnalyticsConfiguration.java @@ -22,21 +22,21 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * This class represents the information related to Geo Location configuration. + * This class represents the information related to Device Operation Analytics configuration. */ -@XmlRootElement(name = "GeoLocationConfiguration") -public class GeoLocationConfiguration { +@XmlRootElement(name = "OperationAnalyticsConfiguration") +public class OperationAnalyticsConfiguration { - private boolean publishLocationOperationResponse; + private boolean publishOperationResponse; private boolean isEnabled; - public boolean getPublishLocationOperationResponse() { - return publishLocationOperationResponse; + public boolean getPublishOperationResponse() { + return publishOperationResponse; } - @XmlElement(name = "PublishLocationOperationResponse", required = true) - public void setPublishLocationOperationResponse(boolean publishLocationOperationResponse) { - this.publishLocationOperationResponse = publishLocationOperationResponse; + @XmlElement(name = "PublishOperationResponse", required = true) + public void setPublishOperationResponse(boolean publishOperationResponse) { + this.publishOperationResponse = publishOperationResponse; } public boolean getIsEnabled() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 19ab94ca8a..5d81c89e49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; @@ -415,11 +416,22 @@ public final class DeviceManagerUtil { return limit; } - public static boolean isPublishLocationOperationResEnabled() throws DeviceManagementException { + public static boolean isOperationAnalyticsEnabled() throws DeviceManagementException { DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). getDeviceManagementConfig(); if (deviceManagementConfig != null) { - return deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse(); + return deviceManagementConfig.getOperationAnalyticsConfiguration().getIsEnabled(); + } else { + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + + public static boolean isPublishOperationResponseEnabled() throws DeviceManagementException { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null && isOperationAnalyticsEnabled()) { + return deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishOperationResponse(); } else { throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + "cdm-config.xml file."); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index c83585e96b..ef6cf7357f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -73,7 +73,7 @@ deviceModule = function () { } var userName = carbonUser.username + "@" + carbonUser.domain; var locationHistory = []; - var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.isEnabled; + var geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled; if (geoServicesEnabled) { try { var fromDate = new Date(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js index f18b117259..4094fc89dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.js @@ -60,6 +60,6 @@ function onRequest(context) { } else { viewModel.lastLocation = stringify({}); } - viewModel.geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.isEnabled; + viewModel.geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled; return viewModel; } \ No newline at end of file diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index e487858393..fe682a6a8d 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -33,6 +33,7 @@ http://wso2.org + org.wso2.carbon.device.mgt.basics.feature org.wso2.carbon.device.mgt.server.feature org.wso2.carbon.device.mgt.ui.feature org.wso2.carbon.device.mgt.api.feature From b5b3647668ffd24ce8d736693a5191d9be7450ee Mon Sep 17 00:00:00 2001 From: charitha Date: Fri, 6 Oct 2017 18:51:50 +0530 Subject: [PATCH 5/8] Fixed build and test failures after upstream merge --- .../wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java | 5 +++-- .../wso2/carbon/device/mgt/core/common/TestDataHolder.java | 2 -- .../org.wso2.carbon.device.mgt.basics.feature/pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 63193ff070..87b6e70ac7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -430,8 +430,9 @@ public final class DeviceManagerUtil { public static boolean isPublishOperationResponseEnabled() throws DeviceManagementException { DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). getDeviceManagementConfig(); - if (deviceManagementConfig != null && isOperationAnalyticsEnabled()) { - return deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishOperationResponse(); + if (deviceManagementConfig != null) { + return isOperationAnalyticsEnabled() + && deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishOperationResponse(); } else { throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + "cdm-config.xml file."); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java index 355ec9a55a..dea79ea662 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java @@ -59,8 +59,6 @@ public class TestDataHolder { public static DeviceInfo generateDummyDeviceInfo() { DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setIMEI("IMEI-12345"); - deviceInfo.setIMSI("IMSI-12344"); deviceInfo.setDeviceModel("DUMMY_MODEL"); deviceInfo.setVendor("WSO2"); deviceInfo.setOsVersion("OREO"); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 8f5826d1f2..5f072d95d5 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.0.119-SNAPSHOT + 3.0.136-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.basics.feature pom - 3.0.119-SNAPSHOT + 3.0.136-SNAPSHOT WSO2 Carbon - Device Management Basics Feature http://wso2.org This feature contains the core bundles required for Basic Device Management functionality From 6e62c3d64ef3d55f68e56ea7fb8974daab8b9b01 Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 30 Oct 2017 10:14:00 +0530 Subject: [PATCH 6/8] Refactor after merging --- .../carbon/device/mgt/core/search/util/Utils.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java index ce3db26cee..ea46635116 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/util/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2017, 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 @@ -20,18 +20,11 @@ package org.wso2.carbon.device.mgt.core.search.util; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; -import org.wso2.carbon.device.mgt.common.search.Condition; -import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import static org.wso2.carbon.device.mgt.common.search.Condition.State.AND; -import static org.wso2.carbon.device.mgt.common.search.Condition.State.OR; - public class Utils { public static DeviceInfo getDeviceInfo() { @@ -75,7 +68,7 @@ public class Utils { } - public static DeviceLocation getSampleDeviceLocation(){ + private static DeviceLocation getSampleDeviceLocation(){ DeviceLocation deviceLocation = new DeviceLocation(); deviceLocation.setDeviceIdentifier(Utils.getDeviceIdentifier()); deviceLocation.setLatitude(76.2422); From 1eb2e54ae85fafa46d66af74d1d5a811efb4320b Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 30 Oct 2017 11:15:20 +0530 Subject: [PATCH 7/8] Resolve test failures and issues after merging with upstream --- .../mgt/jaxrs/service/impl/util/DeviceMgtAPITestHelper.java | 4 ---- .../resources/carbon-home/repository/conf/cdm-config.xml | 6 +++--- .../org.wso2.carbon.device.mgt.basics.feature/pom.xml | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/DeviceMgtAPITestHelper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/DeviceMgtAPITestHelper.java index 5fa279b6a0..f1f0d1628d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/DeviceMgtAPITestHelper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/DeviceMgtAPITestHelper.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.util; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; @@ -37,7 +36,6 @@ public class DeviceMgtAPITestHelper { private static final String DEVICE_TYPE_DESCRIPTION = "Dummy Description"; public static final String DEVICE_TYPE = "TEST_DEVICE_TYPE"; public static final String DEVICE_NAME = "TEST_DEVICE"; - public static final String DEVICE_IDENTIFIER = "12345"; public final static String OWNER = "admin"; /** @@ -110,8 +108,6 @@ public class DeviceMgtAPITestHelper { public static DeviceInfo generateDeviceInfo() { DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setIMEI("IMEI-12345"); - deviceInfo.setIMSI("IMSI-12344"); deviceInfo.setDeviceModel("DUMMY_MODEL"); deviceInfo.setVendor("WSO2"); deviceInfo.setOsVersion("OREO"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml index 9097a645cb..ff6b302002 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml @@ -87,10 +87,10 @@ false 86400 - + false - false - + false + BYOD,COPE diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 5f072d95d5..4f44e1cdc7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -23,14 +23,13 @@ org.wso2.carbon.devicemgt device-mgt-feature - 3.0.136-SNAPSHOT + 3.0.170-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.basics.feature pom - 3.0.136-SNAPSHOT WSO2 Carbon - Device Management Basics Feature http://wso2.org This feature contains the core bundles required for Basic Device Management functionality From 448ff20baa4da88c4130d6456686861a804ba741 Mon Sep 17 00:00:00 2001 From: Charitha Goonetilleke Date: Mon, 30 Oct 2017 12:09:12 +0530 Subject: [PATCH 8/8] Update response message --- .../mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 2543d1a85e..fc34cfba0d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -79,7 +79,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { try { if (!DeviceManagerUtil.isPublishOperationResponseEnabled()) { return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) - .entity("Operation publishing does not exists").build(); + .entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build(); } } catch (DeviceManagementException e) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(e.getMessage()).build();