Adding fixes to the device search

revert-70aa11f8
geethkokila 9 years ago
parent 73a82f743f
commit e60a383f4d

@ -238,11 +238,11 @@
</dependency> </dependency>
<!--<dependency>--> <dependency>
<!--<groupId>com.google.code.gson</groupId>--> <groupId>com.google.code.gson</groupId>
<!--<artifactId>gson</artifactId>--> <artifactId>gson</artifactId>
<!--<version>1.7.1</version>--> <version>1.7.1</version>
<!--</dependency>--> </dependency>
</dependencies> </dependencies>

@ -47,31 +47,27 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
try { try {
conn = this.getConnection(); 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, " + "VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " +
"EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, OPERATOR, CONNECTION_TYPE, " + "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " +
"MOBILE_SIGNAL_STRENGTH, SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?,? ); "); "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceInfo.getDeviceId()); stmt.setInt(1, deviceInfo.getDeviceId());
stmt.setString(2, deviceInfo.getIMEI()); stmt.setString(2, deviceInfo.getDeviceModel());
stmt.setString(3, deviceInfo.getIMSI()); stmt.setString(3, deviceInfo.getVendor());
stmt.setString(4, deviceInfo.getDeviceModel()); stmt.setString(4, deviceInfo.getOsVersion());
stmt.setString(5, deviceInfo.getVendor()); stmt.setDouble(5, deviceInfo.getBatteryLevel());
stmt.setString(6, deviceInfo.getOsVersion()); stmt.setDouble(6, deviceInfo.getInternalTotalMemory());
stmt.setDouble(7, deviceInfo.getBatteryLevel()); stmt.setDouble(7, deviceInfo.getInternalAvailableMemory());
stmt.setDouble(8, deviceInfo.getInternalTotalMemory()); stmt.setDouble(8, deviceInfo.getExternalTotalMemory());
stmt.setDouble(9, deviceInfo.getInternalAvailableMemory()); stmt.setDouble(9, deviceInfo.getExternalAvailableMemory());
stmt.setDouble(10, deviceInfo.getExternalTotalMemory()); stmt.setString(10, deviceInfo.getConnectionType());
stmt.setDouble(11, deviceInfo.getExternalAvailableMemory()); stmt.setString(11, deviceInfo.getSsid());
stmt.setString(12, deviceInfo.getOperator()); stmt.setDouble(12, deviceInfo.getCpuUsage());
stmt.setString(13, deviceInfo.getConnectionType()); stmt.setDouble(13, deviceInfo.getTotalRAMMemory());
stmt.setDouble(14, deviceInfo.getMobileSignalStrength()); stmt.setDouble(14, deviceInfo.getAvailableRAMMemory());
stmt.setString(15, deviceInfo.getSsid()); stmt.setBoolean(15, deviceInfo.isPluggedIn());
stmt.setDouble(16, deviceInfo.getCpuUsage());
stmt.setDouble(17, deviceInfo.getTotalRAMMemory());
stmt.setDouble(18, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(19, deviceInfo.isPluggedIn());
stmt.execute(); stmt.execute();
@ -128,8 +124,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
while (rs.next()) { while (rs.next()) {
deviceInfo.setDeviceId(rs.getInt("DEVICE_ID")); deviceInfo.setDeviceId(rs.getInt("DEVICE_ID"));
deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI")); // deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setVendor(rs.getString("VENDOR")); deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
@ -138,9 +134,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_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.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.setSsid(rs.getString("SSID"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));

@ -78,12 +78,12 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI")); // deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); // deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setOperator(rs.getString("OPERATOR")); // deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setSsid(rs.getString("SSID"));
@ -143,7 +143,7 @@ public class SearchDAOImpl implements SearchDAO {
Device device = new Device(); Device device = new Device();
device.setId(rs.getInt("ID")); device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION")); device.setDescription(rs.getString("DESCRIPTION"));
device.setName("NAME"); device.setName(rs.getString("NAME"));
device.setType(rs.getString("DEVICE_TYPE_NAME")); device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
@ -160,12 +160,12 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI")); // deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); // deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setOperator(rs.getString("OPERATOR")); // deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setSsid(rs.getString("SSID"));

@ -82,11 +82,19 @@ public class QueryBuilderImpl implements QueryBuilder {
} }
Map<String, List<String>> queries = new HashMap<>(); Map<String, List<String>> queries = new HashMap<>();
if ((!andColumns.isEmpty()) || (!orColumns.isEmpty())) {
queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) + queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) +
this.processOR(orColumns))); this.processOR(orColumns)));
}
if (!otherANDColumns.isEmpty()) {
queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns)); queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns));
}
if (!otherORColumns.isEmpty()) {
queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns)); queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns));
}
if (locConditon != null && locConditon.getValue() != null) {
queries.put(Constants.LOCATION, this.processLocation(locConditon)); queries.put(Constants.LOCATION, this.processLocation(locConditon));
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("General Query : " + queries.get(Constants.GENERAL)); log.debug("General Query : " + queries.get(Constants.GENERAL));
@ -164,12 +172,12 @@ public class QueryBuilderImpl implements QueryBuilder {
private String buildLocationQuery(String location) { private String buildLocationQuery(String location) {
String query = this.getGenericQueryPart(); String query = this.getGenericQueryPart();
query = query + " OR STREET1 LIKE \'%" + location + "%\'"; query = query + " AND DL.STREET1 LIKE \'%" + location + "%\'";
query = query + " OR STREET2 LIKE \'%" + location + "%\'"; query = query + " OR DL.STREET2 LIKE \'%" + location + "%\'";
query = query + " OR CITY LIKE \'%" + location + "%\'"; query = query + " OR DL.CITY LIKE \'%" + location + "%\'";
query = query + " OR STATE LIKE \'%" + location + "%\'"; query = query + " OR DL.STATE LIKE \'%" + location + "%\'";
query = query + " OR COUNTRY LIKE \'%" + location + "%\'"; query = query + " OR DL.COUNTRY LIKE \'%" + location + "%\'";
query = query + " OR ZIP LIKE \'%" + location + "%\'"; query = query + " OR DL.ZIP LIKE \'%" + location + "%\'";
return query; return query;
} }
@ -177,13 +185,13 @@ public class QueryBuilderImpl implements QueryBuilder {
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \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.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.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \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" + "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, " + "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(); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -193,14 +201,14 @@ public class QueryBuilderImpl implements QueryBuilder {
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \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.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.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \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" + "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, " + "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 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(); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} }

@ -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.Constants;
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator; import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ResultSetAggregatorImpl implements ResultSetAggregator { public class ResultSetAggregatorImpl implements ResultSetAggregator {
@ -37,24 +34,36 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND)); Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND));
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR)); Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR));
Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION)); Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION));
Map<Integer, DeviceWrapper> finalMap = new HashMap<>();
List<DeviceWrapper> finalResult = new ArrayList<>(); List<DeviceWrapper> finalResult = new ArrayList<>();
if (andMap.isEmpty()) {
finalMap = generalQueryMap;
finalResult = this.convertDeviceMapToList(generalQueryMap);
} else {
for (Integer a : andMap.keySet()) { for (Integer a : andMap.keySet()) {
if (generalQueryMap.containsKey(a)) { if (generalQueryMap.isEmpty()) {
if (!finalResult.contains(a)) {
finalResult.add(andMap.get(a)); 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()) { for (Integer a : orMap.keySet()) {
if (!finalResult.contains(a)) { if (!finalMap.containsKey(a)) {
finalResult.add(orMap.get(a)); finalResult.add(orMap.get(a));
finalMap.put(a, orMap.get(a));
} }
} }
for (Integer a : locationMap.keySet()) { for (Integer a : locationMap.keySet()) {
if (!finalResult.contains(a)) { if (!finalMap.containsKey(a)) {
finalResult.add(locationMap.get(a)); finalResult.add(locationMap.get(a));
finalMap.put(a, locationMap.get(a));
} }
} }
@ -72,4 +81,13 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
} }
return deviceWrapperMap; return deviceWrapperMap;
} }
private List<DeviceWrapper> convertDeviceMapToList(Map<Integer, DeviceWrapper> map) {
List<DeviceWrapper> list = new ArrayList<>();
for (Integer a : map.keySet()) {
list.add(map.get(a));
}
return list;
}
} }

@ -32,8 +32,6 @@ public class Utils {
Map<String, String> colonmsMap = new HashMap<>(); Map<String, String> colonmsMap = new HashMap<>();
colonmsMap.put("IMEI", "IMEI");
colonmsMap.put("IMSI", "IMSI");
colonmsMap.put("deviceModel", "DEVICE_MODEL"); colonmsMap.put("deviceModel", "DEVICE_MODEL");
colonmsMap.put("vendor", "VENDOR"); colonmsMap.put("vendor", "VENDOR");
colonmsMap.put("osVersion", "OS_VERSION"); colonmsMap.put("osVersion", "OS_VERSION");
@ -42,9 +40,7 @@ public class Utils {
colonmsMap.put("internalAvailableMemory", "INTERNAL_AVAILABLE_MEMORY"); colonmsMap.put("internalAvailableMemory", "INTERNAL_AVAILABLE_MEMORY");
colonmsMap.put("externalTotalMemory", "EXTERNAL_TOTAL_MEMORY"); colonmsMap.put("externalTotalMemory", "EXTERNAL_TOTAL_MEMORY");
colonmsMap.put("externalAvailableMemory", "EXTERNAL_AVAILABLE_MEMORY"); colonmsMap.put("externalAvailableMemory", "EXTERNAL_AVAILABLE_MEMORY");
colonmsMap.put("operator", "OPERATOR");
colonmsMap.put("connectionType", "CONNECTION_TYPE"); colonmsMap.put("connectionType", "CONNECTION_TYPE");
colonmsMap.put("mobileSignalStrength", "MOBILE_SIGNAL_STRENGTH");
colonmsMap.put("ssid", "SSID"); colonmsMap.put("ssid", "SSID");
colonmsMap.put("cpuUsage", "CPU_USAGE"); colonmsMap.put("cpuUsage", "CPU_USAGE");
colonmsMap.put("totalRAMMemory", "TOTAL_RAM_MEMORY"); colonmsMap.put("totalRAMMemory", "TOTAL_RAM_MEMORY");

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.core.search; package org.wso2.carbon.device.mgt.core.search;
import com.google.gson.Gson;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -61,36 +62,93 @@ public class SearchDevice extends BaseDeviceManagementTest {
cond.setState(Condition.State.AND); cond.setState(Condition.State.AND);
conditions.add(cond); conditions.add(cond);
Condition cond2 = new Condition(); // Condition cond2 = new Condition();
cond2.setKey("CPU_USAGE"); // cond2.setKey("CPU_USAGE");
cond2.setOperator(">"); // cond2.setOperator(">");
cond2.setValue("40"); // cond2.setValue("40");
cond2.setState(Condition.State.OR); // cond2.setState(Condition.State.OR);
conditions.add(cond2); // conditions.add(cond2);
//
Condition cond3 = new Condition(); // Condition cond3 = new Condition();
cond3.setKey("LOCATION"); // cond3.setKey("LOCATION");
cond3.setOperator("="); // cond3.setOperator("=");
cond3.setValue("Colombo"); // cond3.setValue("Colombo");
cond3.setState(Condition.State.AND); // cond3.setState(Condition.State.AND);
conditions.add(cond3); // conditions.add(cond3);
context.setConditions(conditions); context.setConditions(conditions);
// Gson gson = new Gson();
//
// String aaa = gson.toJson(context);
//
// log.info(aaa);
SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context); List<DeviceWrapper> deviceWrappers = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
log.info(bbbb);
for (DeviceWrapper dw : deviceWrappers) { for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription()); log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(dw.getDevice().getDeviceIdentifier());
} }
} }
// @Test
// public void doValidLocationSearch() throws Exception{
//
// SearchContext context = new SearchContext();
// List<Condition> 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<DeviceWrapper> 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<Condition> 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<DeviceWrapper> 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());
// }
// }
} }

@ -460,23 +460,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL, BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
OPERATOR VARCHAR(45) NULL,
CONNECTION_TYPE VARCHAR(10) NULL, CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL, SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -461,23 +461,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL, BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
OPERATOR VARCHAR(45) NULL,
CONNECTION_TYPE VARCHAR(10) NULL, CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL, SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -432,23 +432,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL, BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
OPERATOR VARCHAR(45) NULL,
CONNECTION_TYPE VARCHAR(10) NULL, CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL, SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),

@ -445,23 +445,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL, BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
OPERATOR VARCHAR(45) NULL,
CONNECTION_TYPE VARCHAR(10) NULL, CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL, SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),

@ -745,23 +745,19 @@ END;
CREATE TABLE DM_DEVICE_DETAIL ( CREATE TABLE DM_DEVICE_DETAIL (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) NOT NULL,
IMEI VARCHAR2(100) NULL,
IMSI VARCHAR2(100) NULL,
DEVICE_MODEL VARCHAR2(45) NULL, DEVICE_MODEL VARCHAR2(45) NULL,
VENDOR VARCHAR2(45) NULL, VENDOR VARCHAR2(45) NULL,
OS_VERSION VARCHAR2(45) NULL, OS_VERSION VARCHAR2(45) NULL,
BATTERY_LEVEL NUMBER(4) NULL, BATTERY_LEVEL NUMBER(4) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(5) NULL, INTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(5) NULL, EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
OPERATOR VARCHAR2(45) NULL,
CONNECTION_TYPE VARCHAR2(10) NULL, CONNECTION_TYPE VARCHAR2(10) NULL,
MOBILE_SIGNAL_STRENGTH NUMBER(5) NULL,
SSID VARCHAR2(45) NULL, SSID VARCHAR2(45) NULL,
CPU_USAGE NUMBER(5) NULL, CPU_USAGE NUMBER(5) NULL,
TOTAL_RAM_MEMORY NUMBER(5) NULL, TOTAL_RAM_MEMORY NUMBER(30) NULL,
AVAILABLE_RAM_MEMORY NUMBER(5) NULL, AVAILABLE_RAM_MEMORY NUMBER(30) NULL,
PLUGGED_IN NUMBER(10) NULL, PLUGGED_IN NUMBER(10) NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
, ,

@ -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 ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'),
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL, BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
OPERATOR VARCHAR(45) NULL,
CONNECTION_TYPE VARCHAR(10) NULL, CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL, SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL, PLUGGED_IN INT NULL,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

Loading…
Cancel
Save