Merge pull request #672 from harshanL/cloud-3.1.0

Fix for Advanced Search Issue #670
Kamidu Sachith Punchihewa 8 years ago committed by GitHub
commit 75bcc720d6

@ -35,6 +35,7 @@ public class QueryBuilderImpl implements QueryBuilder {
private static final Log log = LogFactory.getLog(QueryBuilderImpl.class); private static final Log log = LogFactory.getLog(QueryBuilderImpl.class);
private final String WILDCARD_OPERATOR = "%"; private final String WILDCARD_OPERATOR = "%";
private final String OR_OPERATOR = "OR";
private String current_username; private String current_username;
private boolean isDeviceAdminUser; private boolean isDeviceAdminUser;
@ -131,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) { for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (Utils.checkDeviceDetailsColumns(con.getKey())) {
if (con.operator.equals(WILDCARD_OPERATOR)) { if (con.operator.equals(WILDCARD_OPERATOR)) {
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey())
+ " LIKE ? "; + " LIKE ? ";
ValueType type = new ValueType(); ValueType type = new ValueType();
type.setColumnType(ValueType.columnType.STRING); type.setColumnType(ValueType.columnType.STRING);
@ -215,6 +216,11 @@ public class QueryBuilderImpl implements QueryBuilder {
} catch (Exception e) { } catch (Exception e) {
throw new InvalidOperatorException("Error occurred while building the sql", e); throw new InvalidOperatorException("Error occurred while building the sql", e);
} }
if (!querySuffix.isEmpty()) {
//Replacing the first OR operator as it's unnecessary
querySuffix = querySuffix.replaceFirst(OR_OPERATOR, "");
querySuffix = " AND (" + querySuffix + ")";
}
return querySuffix; return querySuffix;
} }

Loading…
Cancel
Save