Commit 253b4231 authored by Matija Obreza's avatar Matija Obreza Committed by Matija Obreza
Browse files

Filter by list.UUID (converts UUID to byte[])

parent d1099c48
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
package org.genesys2.server.service.impl; package org.genesys2.server.service.impl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -102,7 +105,7 @@ public class DirectMysqlQuery { ...@@ -102,7 +105,7 @@ public class DirectMysqlQuery {
protected DirectMysqlQuery join(AppliedFilters filters) { protected DirectMysqlQuery join(AppliedFilters filters) {
if (hasFilter(filters, FilterConstants.LIST)) { if (hasFilter(filters, FilterConstants.LIST)) {
innerJoin("accelistitem", "ali", "ali.acceid=a.id"); innerJoin("accelistitems", "ali", "ali.acceid=a.id");
innerJoin("accelist", "al", "al.id=ali.listid"); innerJoin("accelist", "al", "al.id=ali.listid");
} }
...@@ -422,7 +425,20 @@ public class DirectMysqlQuery { ...@@ -422,7 +425,20 @@ public class DirectMysqlQuery {
} }
private void addParam(List<Object> params, Object object) { private void addParam(List<Object> params, Object object) {
params.add(object); if (object instanceof UUID) {
params.add(toBytes((UUID) object));
} else{
params.add(object);
}
}
private byte[] toBytes(UUID uuid) {
byte[] b = new byte[16];
ByteBuffer bb = ByteBuffer.wrap(b);
bb.order(ByteOrder.BIG_ENDIAN);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return b;
} }
private void addParamLike(List<Object> params, String string) { private void addParamLike(List<Object> params, String string) {
......
...@@ -25,6 +25,7 @@ import java.util.HashSet; ...@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate; import org.apache.commons.collections4.Predicate;
...@@ -260,7 +261,16 @@ public class FilterHandler { ...@@ -260,7 +261,16 @@ public class FilterHandler {
do { do {
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) { if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
af.addFilterValue(new LiteralValueFilter(jp.getText())); if (jp.getTextLength() == 36) {
try {
af.addFilterValue(new LiteralValueFilter(UUID.fromString(jp.getText())));
} catch (IllegalArgumentException e) {
System.err.println("Not an UUID");
af.addFilterValue(new LiteralValueFilter(jp.getText()));
}
} else {
af.addFilterValue(new LiteralValueFilter(jp.getText()));
}
} else if (jp.getCurrentToken() == JsonToken.VALUE_TRUE || jp.getCurrentToken() == JsonToken.VALUE_FALSE) { } else if (jp.getCurrentToken() == JsonToken.VALUE_TRUE || jp.getCurrentToken() == JsonToken.VALUE_FALSE) {
af.addFilterValue(new LiteralValueFilter(jp.getBooleanValue())); af.addFilterValue(new LiteralValueFilter(jp.getBooleanValue()));
} else if (jp.getCurrentToken() == JsonToken.VALUE_NUMBER_FLOAT) { } else if (jp.getCurrentToken() == JsonToken.VALUE_NUMBER_FLOAT) {
...@@ -587,9 +597,9 @@ public class FilterHandler { ...@@ -587,9 +597,9 @@ public class FilterHandler {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "="+ getValue(); return getClass().getSimpleName() + "=" + getValue();
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
...@@ -670,12 +680,11 @@ public class FilterHandler { ...@@ -670,12 +680,11 @@ public class FilterHandler {
return to; return to;
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + " " + getFrom() + "<="+ getType() + "<=" + getTo(); return getClass().getSimpleName() + " " + getFrom() + "<=" + getType() + "<=" + getTo();
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment