mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added checks for other data types.
This commit is contained in:
parent
485a0d3721
commit
26022daf03
@ -251,7 +251,7 @@ public class ProcessorImpl implements Processor {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Query : " + queryHolder.getQuery());
|
||||
}
|
||||
Connection conn;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
|
||||
@ -23,7 +23,11 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.search.Condition;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.*;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.QueryBuilder;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.QueryHolder;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.ValueType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -93,8 +97,8 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
intArr[0] = 1;
|
||||
//int x = 1;
|
||||
String query = this.getGenericQueryPart(valueTypeArray) +
|
||||
this.processAND(andColumns, valueTypeArray, intArr) +
|
||||
this.processOR(orColumns, valueTypeArray, intArr);
|
||||
this.processAND(andColumns, valueTypeArray, intArr) +
|
||||
this.processOR(orColumns, valueTypeArray, intArr);
|
||||
List<QueryHolder> queryHolders = new ArrayList<>();
|
||||
QueryHolder queryHolder = new QueryHolder();
|
||||
queryHolder.setQuery(query);
|
||||
@ -135,20 +139,13 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
+ " LIKE ? ";
|
||||
ValueType type = new ValueType();
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setStringValue("%"+con.getValue()+"%");
|
||||
type.setStringValue("%" + con.getValue() + "%");
|
||||
valueType[x] = type;
|
||||
x++;
|
||||
} else {
|
||||
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con
|
||||
.getOperator() + " ? ";
|
||||
ValueType type = new ValueType();
|
||||
if (Utils.checkColumnType(con.getKey())) {
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setStringValue(con.getValue());
|
||||
} else {
|
||||
type.setColumnType(ValueType.columnType.INTEGER);
|
||||
type.setIntValue(Integer.parseInt(con.getValue()));
|
||||
}
|
||||
ValueType type = this.getValueType(con);
|
||||
valueType[x] = type;
|
||||
x++;
|
||||
}
|
||||
@ -182,21 +179,15 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
+ " LIKE ? ";
|
||||
ValueType type = new ValueType();
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setStringValue("%"+con.getValue()+"%");
|
||||
type.setStringValue("%" + con.getValue() + "%");
|
||||
valueType[x] = type;
|
||||
x++;
|
||||
} else {
|
||||
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con
|
||||
.getOperator() + " ? ";
|
||||
|
||||
ValueType type = new ValueType();
|
||||
if (Utils.checkColumnType(con.getKey())) {
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setStringValue(con.getValue());
|
||||
} else {
|
||||
type.setColumnType(ValueType.columnType.INTEGER);
|
||||
type.setIntValue(Integer.parseInt(con.getValue()));
|
||||
}
|
||||
ValueType type = this.getValueType(con);
|
||||
|
||||
valueType[x] = type;
|
||||
x++;
|
||||
}
|
||||
@ -386,4 +377,35 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
throw new InvalidOperatorException("Error occurred while building the sql", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Value type based on the Condition data.
|
||||
*
|
||||
* @param con : The condition that passed.
|
||||
* @re
|
||||
*/
|
||||
private ValueType getValueType(Condition con) {
|
||||
ValueType type = new ValueType();
|
||||
String colValue = Utils.checkColumnType(con.getKey());
|
||||
|
||||
switch (colValue) {
|
||||
case "String":
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setStringValue(con.getValue());
|
||||
break;
|
||||
case "Double":
|
||||
type.setColumnType(ValueType.columnType.DOUBLE);
|
||||
type.setDoubleValue(Double.parseDouble(con.getValue()));
|
||||
break;
|
||||
case "Integer":
|
||||
type.setColumnType(ValueType.columnType.INTEGER);
|
||||
type.setIntValue(Integer.parseInt(con.getValue()));
|
||||
break;
|
||||
case "Long":
|
||||
type.setColumnType(ValueType.columnType.STRING);
|
||||
type.setLongValue(Long.parseLong(con.getValue()));
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@ -75,32 +75,56 @@ public class Utils {
|
||||
|
||||
}
|
||||
|
||||
public static boolean checkColumnType(String column) {
|
||||
public static String checkColumnType(String column) {
|
||||
|
||||
boolean bool = false;
|
||||
String type;
|
||||
|
||||
switch (column) {
|
||||
case "deviceModel":
|
||||
bool = true;
|
||||
type = "String";
|
||||
break;
|
||||
case "vendor":
|
||||
bool = true;
|
||||
type = "String";
|
||||
break;
|
||||
case "osVersion":
|
||||
bool = true;
|
||||
type = "String";
|
||||
break;
|
||||
case "connectionType":
|
||||
bool = true;
|
||||
type = "String";
|
||||
break;
|
||||
case "ssid":
|
||||
bool = true;
|
||||
type = "String";
|
||||
break;
|
||||
case "imei":
|
||||
type = "String";
|
||||
break;
|
||||
case "imsi":
|
||||
type = "String";
|
||||
break;
|
||||
case "batteryLevel":
|
||||
type = "Double";
|
||||
break;
|
||||
case "internalTotalMemory":
|
||||
type = "Double";
|
||||
break;
|
||||
case "internalAvailableMemory":
|
||||
type = "Double";
|
||||
break;
|
||||
case "externalAvailableMemory":
|
||||
type = "Double";
|
||||
break;
|
||||
case "externalTotalMemory":
|
||||
type = "Double";
|
||||
break;
|
||||
case "cpuUsage":
|
||||
type = "Double";
|
||||
break;
|
||||
default:
|
||||
bool = false;
|
||||
type = "String";
|
||||
break;
|
||||
}
|
||||
|
||||
return bool;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Map<String, String> getDeviceDetailsColumnNames() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user