Adding the changes for device search

revert-70aa11f8
geethkokila 9 years ago
parent e4b400a5e7
commit e2d67fc92c

@ -34,7 +34,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SearchDAOImpl implements SearchDAO {
@ -52,12 +54,13 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery();
while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
@ -105,6 +108,8 @@ public class SearchDAOImpl implements SearchDAO {
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId());
}
}
} catch (SQLException e) {
@ -132,12 +137,13 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery();
while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
@ -184,7 +190,10 @@ public class SearchDAOImpl implements SearchDAO {
wrapper.setDeviceInfo(deviceInfo);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId());
}
}
} catch (SQLException e) {

@ -114,7 +114,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
@ -132,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();

@ -60,6 +60,41 @@ public class Utils {
}
public static boolean checkColumnType(String column) {
boolean bool = false;
switch (column) {
case "deviceModel":
bool = true;
break;
case "vendor":
bool = true;
break;
case "osVersion":
bool = true;
break;
case "connectionType":
bool = true;
break;
case "ssid":
bool = true;
break;
default: bool =false;
break;
}
return bool;
}
public static String getConvertedValue(String column, String value) {
if(checkColumnType(column)){
return "\'" + value + "\'";
} else return value;
}
public static Map<String, String> getDeviceDetailsColumnNames() {
return genericColumnsMap;
}

@ -93,62 +93,91 @@ public class SearchDevice extends BaseDeviceManagementTest {
}
// @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());
// }
// }
@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());
}
}
@Test
public void doStringSearch() throws Exception{
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
Condition cond = new Condition();
cond.setKey("deviceModel");
cond.setOperator("=");
cond.setValue("SM-T520");
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());
}
}
}

Loading…
Cancel
Save