From e60a383f4d8dae092ed2f4b67e35fdea1a64f56d Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 31 Mar 2016 18:07:05 +0530 Subject: [PATCH 1/6] 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 From 7cd1722829aa140452135ff13214dd5dde7e7a8e Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Thu, 31 Mar 2016 18:15:15 +0530 Subject: [PATCH 2/6] making certificates searchable --- .../mgt/core/dao/CertificateDAO.java | 2 + .../dao/impl/GenericCertificateDAOImpl.java | 38 +++++++++++++++++++ .../service/CertificateManagementService.java | 2 + .../CertificateManagementServiceImpl.java | 14 +++++++ 4 files changed, 56 insertions(+) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java index ca9310a97f..5916148c22 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java @@ -72,4 +72,6 @@ public interface CertificateDAO { * @return whether the certificate was removed or not. */ boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException; + + public List searchCertificate(String serialNumber) throws CertificateManagementDAOException; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java index 018d5bbbe8..221000dd40 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java @@ -116,6 +116,44 @@ public class GenericCertificateDAOImpl implements CertificateDAO { return certificateResponse; } + @Override + public List searchCertificate(String serialNumber) + throws CertificateManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + CertificateResponse certificateResponse = null; + List certificates = new ArrayList<>(); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + conn = this.getConnection(); + String query = + "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID FROM DM_DEVICE_CERTIFICATE WHERE SERIAL_NUMBER LIKE ?" + + " AND TENANT_ID = ? "; + stmt = conn.prepareStatement(query); + stmt.setString(1, "%" + serialNumber + "%"); + stmt.setInt(2, tenantId); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + certificateResponse = new CertificateResponse(); + byte [] certificateBytes = resultSet.getBytes("CERTIFICATE"); + certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER")); + certificateResponse.setTenantId(resultSet.getInt("TENANT_ID")); + CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse); + certificates.add(certificateResponse); + } + } catch (SQLException e) { + String errorMsg = + "Unable to get the read the certificate with serial" + serialNumber; + log.error(errorMsg, e); + throw new CertificateManagementDAOException(errorMsg, e); + } finally { + CertificateManagementDAOUtil.cleanupResources(stmt, resultSet); + } + return certificates; + } + @Override public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException { PreparedStatement stmt = null; diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java index 59a8e98b5a..c91f0f34d6 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementService.java @@ -76,4 +76,6 @@ public interface CertificateManagementService { boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException; public List getCertificates() throws CertificateManagementDAOException; + + public List searchCertificates(String serialNumber) throws CertificateManagementDAOException; } diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index f4548337fa..a69cde8079 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -192,4 +192,18 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe } } + @Override public List searchCertificates(String serialNumber) throws CertificateManagementDAOException { + try { + CertificateManagementDAOFactory.openConnection(); + CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO(); + return certificateDAO.searchCertificate(serialNumber); + } catch (SQLException e) { + String errorMsg = "Error when opening connection"; + log.error(errorMsg, e); + throw new CertificateManagementDAOException(errorMsg, e); + } finally { + CertificateManagementDAOFactory.closeConnection(); + } + } + } From 72591eff4462daa8bc6d7bddad727cc84137907f Mon Sep 17 00:00:00 2001 From: mharindu Date: Thu, 31 Mar 2016 18:44:55 +0530 Subject: [PATCH 3/6] Fixed modify enrollment bug --- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index f70eb5dca5..672c02642c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -215,6 +215,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { DeviceManager deviceManager = this.getDeviceManager(device.getType()); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " + @@ -227,6 +228,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int tenantId = this.getTenantId(); DeviceManagementDAOFactory.beginTransaction(); DeviceType type = deviceTypeDAO.getDeviceType(device.getType()); + Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId); + device.setId(currentDevice.getId()); + device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId()); deviceDAO.updateDevice(type.getId(), device, tenantId); enrollmentDAO.updateEnrollment(device.getEnrolmentInfo()); DeviceManagementDAOFactory.commitTransaction(); From afbfaf4c1def34b437b4a75e5bd7082dcd9dd17a Mon Sep 17 00:00:00 2001 From: mharindu Date: Thu, 31 Mar 2016 19:33:19 +0530 Subject: [PATCH 4/6] Fixed for EMM-1305 --- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 2e77a9b25c..91dd6de9dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -227,7 +227,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv try { int tenantId = this.getTenantId(); DeviceManagementDAOFactory.beginTransaction(); - DeviceType type = deviceTypeDAO.getDeviceType(device.getType()); + + DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId); Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId); device.setId(currentDevice.getId()); device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId()); From 9661502524d209015af9591ef370939fff482115 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Thu, 31 Mar 2016 20:08:20 +0530 Subject: [PATCH 5/6] fixing issue with certificate delete --- .../service/CertificateManagementServiceImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index a69cde8079..7157d08e6b 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -17,6 +17,7 @@ */ package org.wso2.carbon.certificate.mgt.core.service; +import com.sun.org.apache.xpath.internal.operations.Bool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.bouncycastle.pkcs.PKCS10CertificationRequest; @@ -31,6 +32,7 @@ import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader; import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import java.io.InputStream; @@ -165,11 +167,13 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe @Override public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException { try { - CertificateManagementDAOFactory.openConnection(); + CertificateManagementDAOFactory.beginTransaction(); CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO(); - return certificateDAO.removeCertificate(serialNumber); - } catch (SQLException e) { - String errorMsg = "Error when opening connection"; + Boolean status = certificateDAO.removeCertificate(serialNumber); + CertificateManagementDAOFactory.commitTransaction(); + return status; + } catch (TransactionManagementException e) { + String errorMsg = "Error when deleting"; log.error(errorMsg, e); throw new CertificateManagementDAOException(errorMsg, e); } finally { From d6923a1343e7ac9a239756acc683e7e68882237c Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 1 Apr 2016 00:25:09 +0530 Subject: [PATCH 6/6] Fixing the issue in single condition --- .../device/mgt/core/search/mgt/impl/QueryBuilderImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9dc36109c4..cf4d2a03d6 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 @@ -50,8 +50,8 @@ public class QueryBuilderImpl implements QueryBuilder { if (conditions.get(0).getKey().equalsIgnoreCase(Constants.LOCATION)) { locConditon = conditions.get(0); - } else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) || - Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0))) { + } else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0).getKey()) || + Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0).getKey())) { andColumns.add(conditions.get(0)); } else { otherANDColumns.add(conditions.get(0));