From e60a383f4d8dae092ed2f4b67e35fdea1a64f56d Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 31 Mar 2016 18:07:05 +0530 Subject: [PATCH] Adding fixes to the device search --- .../org.wso2.carbon.device.mgt.core/pom.xml | 10 +- .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 48 +++++----- .../search/mgt/dao/impl/SearchDAOImpl.java | 18 ++-- .../search/mgt/impl/QueryBuilderImpl.java | 46 +++++---- .../mgt/impl/ResultSetAggregatorImpl.java | 38 ++++++-- .../mgt/core/search/mgt/impl/Utils.java | 4 - .../device/mgt/core/Search/SearchDevice.java | 96 +++++++++++++++---- .../src/test/resources/sql/h2.sql | 16 ++-- .../src/main/resources/dbscripts/cdm/h2.sql | 16 ++-- .../main/resources/dbscripts/cdm/mssql.sql | 16 ++-- .../main/resources/dbscripts/cdm/mysql.sql | 16 ++-- .../main/resources/dbscripts/cdm/oracle.sql | 16 ++-- .../resources/dbscripts/cdm/postgresql.sql | 16 ++-- 13 files changed, 204 insertions(+), 152 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index d6de8899f0..b741f5adf1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -238,11 +238,11 @@ - - - - - + + com.google.code.gson + gson + 1.7.1 + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index a6822ce5ae..23c73b936b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -47,31 +47,27 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { try { conn = this.getConnection(); - stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, IMEI, IMSI, DEVICE_MODEL, " + + stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " + "VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " + - "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, OPERATOR, CONNECTION_TYPE, " + - "MOBILE_SIGNAL_STRENGTH, SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?,? ); "); + "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " + + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setInt(1, deviceInfo.getDeviceId()); - stmt.setString(2, deviceInfo.getIMEI()); - stmt.setString(3, deviceInfo.getIMSI()); - stmt.setString(4, deviceInfo.getDeviceModel()); - stmt.setString(5, deviceInfo.getVendor()); - stmt.setString(6, deviceInfo.getOsVersion()); - stmt.setDouble(7, deviceInfo.getBatteryLevel()); - stmt.setDouble(8, deviceInfo.getInternalTotalMemory()); - stmt.setDouble(9, deviceInfo.getInternalAvailableMemory()); - stmt.setDouble(10, deviceInfo.getExternalTotalMemory()); - stmt.setDouble(11, deviceInfo.getExternalAvailableMemory()); - stmt.setString(12, deviceInfo.getOperator()); - stmt.setString(13, deviceInfo.getConnectionType()); - stmt.setDouble(14, deviceInfo.getMobileSignalStrength()); - stmt.setString(15, deviceInfo.getSsid()); - stmt.setDouble(16, deviceInfo.getCpuUsage()); - stmt.setDouble(17, deviceInfo.getTotalRAMMemory()); - stmt.setDouble(18, deviceInfo.getAvailableRAMMemory()); - stmt.setBoolean(19, deviceInfo.isPluggedIn()); + stmt.setString(2, deviceInfo.getDeviceModel()); + stmt.setString(3, deviceInfo.getVendor()); + stmt.setString(4, deviceInfo.getOsVersion()); + stmt.setDouble(5, deviceInfo.getBatteryLevel()); + stmt.setDouble(6, deviceInfo.getInternalTotalMemory()); + stmt.setDouble(7, deviceInfo.getInternalAvailableMemory()); + stmt.setDouble(8, deviceInfo.getExternalTotalMemory()); + stmt.setDouble(9, deviceInfo.getExternalAvailableMemory()); + stmt.setString(10, deviceInfo.getConnectionType()); + stmt.setString(11, deviceInfo.getSsid()); + stmt.setDouble(12, deviceInfo.getCpuUsage()); + stmt.setDouble(13, deviceInfo.getTotalRAMMemory()); + stmt.setDouble(14, deviceInfo.getAvailableRAMMemory()); + stmt.setBoolean(15, deviceInfo.isPluggedIn()); stmt.execute(); @@ -128,8 +124,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { while (rs.next()) { deviceInfo.setDeviceId(rs.getInt("DEVICE_ID")); - deviceInfo.setIMEI(rs.getString("IMEI")); - deviceInfo.setIMSI(rs.getString("IMSI")); +// deviceInfo.setIMEI(rs.getString("IMEI")); +// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setVendor(rs.getString("VENDOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); @@ -138,9 +134,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setOperator(rs.getString("OPERATOR")); +// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); - deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); +// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java index 5409091a67..e80da38167 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java @@ -78,12 +78,12 @@ public class SearchDAOImpl implements SearchDAO { deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setIMEI(rs.getString("IMEI")); - deviceInfo.setIMSI(rs.getString("IMSI")); +// deviceInfo.setIMEI(rs.getString("IMEI")); +// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); - deviceInfo.setOperator(rs.getString("OPERATOR")); +// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); +// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setSsid(rs.getString("SSID")); @@ -143,7 +143,7 @@ public class SearchDAOImpl implements SearchDAO { Device device = new Device(); device.setId(rs.getInt("ID")); device.setDescription(rs.getString("DESCRIPTION")); - device.setName("NAME"); + device.setName(rs.getString("NAME")); device.setType(rs.getString("DEVICE_TYPE_NAME")); device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); @@ -160,12 +160,12 @@ public class SearchDAOImpl implements SearchDAO { deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setIMEI(rs.getString("IMEI")); - deviceInfo.setIMSI(rs.getString("IMSI")); +// deviceInfo.setIMEI(rs.getString("IMEI")); +// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); - deviceInfo.setOperator(rs.getString("OPERATOR")); +// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); +// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setSsid(rs.getString("SSID")); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index fcc2e26372..9dc36109c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -82,11 +82,19 @@ public class QueryBuilderImpl implements QueryBuilder { } Map> queries = new HashMap<>(); - queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) + - this.processOR(orColumns))); - queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns)); - queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns)); - queries.put(Constants.LOCATION, this.processLocation(locConditon)); + if ((!andColumns.isEmpty()) || (!orColumns.isEmpty())) { + queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) + + this.processOR(orColumns))); + } + if (!otherANDColumns.isEmpty()) { + queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns)); + } + if (!otherORColumns.isEmpty()) { + queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns)); + } + if (locConditon != null && locConditon.getValue() != null) { + queries.put(Constants.LOCATION, this.processLocation(locConditon)); + } if (log.isDebugEnabled()) { log.debug("General Query : " + queries.get(Constants.GENERAL)); @@ -164,12 +172,12 @@ public class QueryBuilderImpl implements QueryBuilder { private String buildLocationQuery(String location) { String query = this.getGenericQueryPart(); - query = query + " OR STREET1 LIKE \'%" + location + "%\'"; - query = query + " OR STREET2 LIKE \'%" + location + "%\'"; - query = query + " OR CITY LIKE \'%" + location + "%\'"; - query = query + " OR STATE LIKE \'%" + location + "%\'"; - query = query + " OR COUNTRY LIKE \'%" + location + "%\'"; - query = query + " OR ZIP LIKE \'%" + location + "%\'"; + query = query + " AND DL.STREET1 LIKE \'%" + location + "%\'"; + query = query + " OR DL.STREET2 LIKE \'%" + location + "%\'"; + query = query + " OR DL.CITY LIKE \'%" + location + "%\'"; + query = query + " OR DL.STATE LIKE \'%" + location + "%\'"; + query = query + " OR DL.COUNTRY LIKE \'%" + location + "%\'"; + query = query + " OR DL.ZIP LIKE \'%" + location + "%\'"; return query; } @@ -177,13 +185,13 @@ public class QueryBuilderImpl implements QueryBuilder { return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + " D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + - "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" + + "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + - "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" + - "DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + "DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + - "DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " + + "DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -193,14 +201,14 @@ public class QueryBuilderImpl implements QueryBuilder { return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + " D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" + - "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" + + "DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" + "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + - "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" + - "DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + "DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + "DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" + - "DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " + + "DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java index 069b1630ac..dc33400b6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java @@ -23,10 +23,7 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.core.search.mgt.Constants; import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ResultSetAggregatorImpl implements ResultSetAggregator { @@ -37,24 +34,36 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator { Map andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND)); Map orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR)); Map locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION)); - + Map finalMap = new HashMap<>(); List finalResult = new ArrayList<>(); - for (Integer a : andMap.keySet()) { - if (generalQueryMap.containsKey(a)) { - if (!finalResult.contains(a)) { + + if (andMap.isEmpty()) { + finalMap = generalQueryMap; + finalResult = this.convertDeviceMapToList(generalQueryMap); + } else { + for (Integer a : andMap.keySet()) { + if (generalQueryMap.isEmpty()) { finalResult.add(andMap.get(a)); + finalMap.put(a, andMap.get(a)); + } else if (generalQueryMap.containsKey(a)) { + if (!finalMap.containsKey(a)) { + finalResult.add(andMap.get(a)); + finalMap.put(a, andMap.get(a)); + } } } } for (Integer a : orMap.keySet()) { - if (!finalResult.contains(a)) { + if (!finalMap.containsKey(a)) { finalResult.add(orMap.get(a)); + finalMap.put(a, orMap.get(a)); } } for (Integer a : locationMap.keySet()) { - if (!finalResult.contains(a)) { + if (!finalMap.containsKey(a)) { finalResult.add(locationMap.get(a)); + finalMap.put(a, locationMap.get(a)); } } @@ -72,4 +81,13 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator { } return deviceWrapperMap; } + + private List convertDeviceMapToList(Map map) { + List list = new ArrayList<>(); + + for (Integer a : map.keySet()) { + list.add(map.get(a)); + } + return list; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java index bd0b7a816a..cef647d727 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java @@ -32,8 +32,6 @@ public class Utils { Map colonmsMap = new HashMap<>(); - colonmsMap.put("IMEI", "IMEI"); - colonmsMap.put("IMSI", "IMSI"); colonmsMap.put("deviceModel", "DEVICE_MODEL"); colonmsMap.put("vendor", "VENDOR"); colonmsMap.put("osVersion", "OS_VERSION"); @@ -42,9 +40,7 @@ public class Utils { colonmsMap.put("internalAvailableMemory", "INTERNAL_AVAILABLE_MEMORY"); colonmsMap.put("externalTotalMemory", "EXTERNAL_TOTAL_MEMORY"); colonmsMap.put("externalAvailableMemory", "EXTERNAL_AVAILABLE_MEMORY"); - colonmsMap.put("operator", "OPERATOR"); colonmsMap.put("connectionType", "CONNECTION_TYPE"); - colonmsMap.put("mobileSignalStrength", "MOBILE_SIGNAL_STRENGTH"); colonmsMap.put("ssid", "SSID"); colonmsMap.put("cpuUsage", "CPU_USAGE"); colonmsMap.put("totalRAMMemory", "TOTAL_RAM_MEMORY"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java index bab5f5b228..88acffe514 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.search; +import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.testng.annotations.BeforeClass; @@ -61,36 +62,93 @@ public class SearchDevice extends BaseDeviceManagementTest { cond.setState(Condition.State.AND); conditions.add(cond); - Condition cond2 = new Condition(); - cond2.setKey("CPU_USAGE"); - cond2.setOperator(">"); - cond2.setValue("40"); - cond2.setState(Condition.State.OR); - conditions.add(cond2); - - Condition cond3 = new Condition(); - cond3.setKey("LOCATION"); - cond3.setOperator("="); - cond3.setValue("Colombo"); - cond3.setState(Condition.State.AND); - conditions.add(cond3); +// Condition cond2 = new Condition(); +// cond2.setKey("CPU_USAGE"); +// cond2.setOperator(">"); +// cond2.setValue("40"); +// cond2.setState(Condition.State.OR); +// conditions.add(cond2); +// +// Condition cond3 = new Condition(); +// cond3.setKey("LOCATION"); +// cond3.setOperator("="); +// cond3.setValue("Colombo"); +// cond3.setState(Condition.State.AND); +// conditions.add(cond3); context.setConditions(conditions); -// Gson gson = new Gson(); -// -// String aaa = gson.toJson(context); -// -// log.info(aaa); - SearchManagerService service = new SearchManagerServiceImpl(); List deviceWrappers = service.search(context); + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info(bbbb); + + for (DeviceWrapper dw : deviceWrappers) { log.debug(dw.getDevice().getDescription()); log.debug(dw.getDevice().getDeviceIdentifier()); } } + +// @Test +// public void doValidLocationSearch() throws Exception{ +// +// SearchContext context = new SearchContext(); +// List conditions = new ArrayList<>(); +// +// Condition cond = new Condition(); +// cond.setKey("LOCATION"); +// cond.setOperator("="); +// cond.setValue("Karan"); +// cond.setState(Condition.State.AND); +// conditions.add(cond); +// +// context.setConditions(conditions); +// +// SearchManagerService service = new SearchManagerServiceImpl(); +// List deviceWrappers = service.search(context); +// +// Gson gson = new Gson(); +// String bbbb = gson.toJson(deviceWrappers); +// log.info("Valid Search " + bbbb); +// +// +// for (DeviceWrapper dw : deviceWrappers) { +// log.debug(dw.getDevice().getDescription()); +// log.debug(dw.getDevice().getDeviceIdentifier()); +// } +// } +// +// @Test +// public void doInvalidLocationSearch() throws Exception{ +// +// SearchContext context = new SearchContext(); +// List conditions = new ArrayList<>(); +// +// Condition cond = new Condition(); +// cond.setKey("LOCATION"); +// cond.setOperator("="); +// cond.setValue("Colombo"); +// cond.setState(Condition.State.AND); +// conditions.add(cond); +// +// context.setConditions(conditions); +// +// SearchManagerService service = new SearchManagerServiceImpl(); +// List deviceWrappers = service.search(context); +// +// Gson gson = new Gson(); +// String bbbb = gson.toJson(deviceWrappers); +// log.info("Invalid Search " + bbbb); +// +// +// for (DeviceWrapper dw : deviceWrappers) { +// log.debug(dw.getDevice().getDescription()); +// log.debug(dw.getDevice().getDeviceIdentifier()); +// } +// } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index ebacfbfd90..d61153d30f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -460,23 +460,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - IMEI VARCHAR(100) NULL, - IMSI VARCHAR(100) NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, BATTERY_LEVEL DECIMAL(4) NULL, - INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - OPERATOR VARCHAR(45) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, CONNECTION_TYPE VARCHAR(10) NULL, - MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, SSID VARCHAR(45) NULL, CPU_USAGE DECIMAL(5) NULL, - TOTAL_RAM_MEMORY DECIMAL(5) NULL, - AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE 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.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 3dfaa9e13b..e77513b350 100644 --- 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.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -461,23 +461,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - IMEI VARCHAR(100) NULL, - IMSI VARCHAR(100) NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, BATTERY_LEVEL DECIMAL(4) NULL, - INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - OPERATOR VARCHAR(45) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, CONNECTION_TYPE VARCHAR(10) NULL, - MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, SSID VARCHAR(45) NULL, CPU_USAGE DECIMAL(5) NULL, - TOTAL_RAM_MEMORY DECIMAL(5) NULL, - AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE 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.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index bae7db4986..d46cfdf5fd 100644 --- 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.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -432,23 +432,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ; CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - IMEI VARCHAR(100) NULL, - IMSI VARCHAR(100) NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, BATTERY_LEVEL DECIMAL(4) NULL, - INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - OPERATOR VARCHAR(45) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, CONNECTION_TYPE VARCHAR(10) NULL, - MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, SSID VARCHAR(45) NULL, CPU_USAGE DECIMAL(5) NULL, - TOTAL_RAM_MEMORY DECIMAL(5) NULL, - AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, PRIMARY KEY (ID), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), 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.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index b7431857ec..485c954c4c 100644 --- 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.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -445,23 +445,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ; CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - IMEI VARCHAR(100) NULL, - IMSI VARCHAR(100) NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, BATTERY_LEVEL DECIMAL(4) NULL, - INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - OPERATOR VARCHAR(45) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, CONNECTION_TYPE VARCHAR(10) NULL, - MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, SSID VARCHAR(45) NULL, CPU_USAGE DECIMAL(5) NULL, - TOTAL_RAM_MEMORY DECIMAL(5) NULL, - AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, PRIMARY KEY (ID), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), 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.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index f7a68e3ee1..4ec9750cbe 100644 --- 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.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -745,23 +745,19 @@ END; CREATE TABLE DM_DEVICE_DETAIL ( ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) NOT NULL, - IMEI VARCHAR2(100) NULL, - IMSI VARCHAR2(100) NULL, DEVICE_MODEL VARCHAR2(45) NULL, VENDOR VARCHAR2(45) NULL, OS_VERSION VARCHAR2(45) NULL, BATTERY_LEVEL NUMBER(4) NULL, - INTERNAL_TOTAL_MEMORY NUMBER(5) NULL, - INTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, - EXTERNAL_TOTAL_MEMORY NUMBER(5) NULL, - EXTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, - OPERATOR VARCHAR2(45) NULL, + INTERNAL_TOTAL_MEMORY NUMBER(30) NULL, + INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, + EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL, + EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, CONNECTION_TYPE VARCHAR2(10) NULL, - MOBILE_SIGNAL_STRENGTH NUMBER(5) NULL, SSID VARCHAR2(45) NULL, CPU_USAGE NUMBER(5) NULL, - TOTAL_RAM_MEMORY NUMBER(5) NULL, - AVAILABLE_RAM_MEMORY NUMBER(5) NULL, + TOTAL_RAM_MEMORY NUMBER(30) NULL, + AVAILABLE_RAM_MEMORY NUMBER(30) NULL, PLUGGED_IN NUMBER(10) NULL, PRIMARY KEY (ID) , 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.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 40e2a47540..c608b4930e 100644 --- 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.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -391,23 +391,19 @@ CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC) CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), DEVICE_ID INT NOT NULL, - IMEI VARCHAR(100) NULL, - IMSI VARCHAR(100) NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, BATTERY_LEVEL DECIMAL(4) NULL, - INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, - EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, - OPERATOR VARCHAR(45) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, CONNECTION_TYPE VARCHAR(10) NULL, - MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, SSID VARCHAR(45) NULL, CPU_USAGE DECIMAL(5) NULL, - TOTAL_RAM_MEMORY DECIMAL(5) NULL, - AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT NULL, PRIMARY KEY (ID) , CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE