Sjednoceno porovnávání textů během filtrování záznamů.

Hledání probíhá podle počátečních znaků...

closes #134
multitenant
František Přibyl 10 years ago
parent aa8a0ebd2a
commit 4047418fba

@ -2,55 +2,74 @@ package info.bukova.isspst;
import org.zkoss.util.resource.Labels; import org.zkoss.util.resource.Labels;
public class StringUtils { public class StringUtils
{
public static String nullStr(String str) { private static String nullStr(String str)
{
return str == null ? "" : str; return str == null ? "" : str;
} }
public static String not0ToStr(long i) { private static String not0ToStr(long i)
{
return i == 0 ? "" : String.valueOf(i); return i == 0 ? "" : String.valueOf(i);
} }
public static String localizeDbErr(String sqlError) { public static String localizeDbErr(String sqlError)
{
String splitMessage[] = sqlError.split("'"); String splitMessage[] = sqlError.split("'");
String message = ""; String message = "";
for (int i = 0; i < splitMessage.length; i++) { for (int i = 0; i < splitMessage.length; i++)
if (i % 2 == 0) { {
if (i % 2 == 0)
{
message += getLocalized(splitMessage[i]); message += getLocalized(splitMessage[i]);
} else { }
else
{
message += " '" + splitMessage[i] + "' "; message += " '" + splitMessage[i] + "' ";
} }
} }
return message; return message;
} }
public static String localize(String key) { public static String localize(String key)
{
return Labels.getLabel(key) == null ? key : Labels.getLabel(key); return Labels.getLabel(key) == null ? key : Labels.getLabel(key);
} }
private static String getLocalized(String str) { private static String getLocalized(String str)
{
String words[] = str.split(" "); String words[] = str.split(" ");
String key = ""; String key = "";
for (String word: words) { for (String word : words)
if (!word.isEmpty()) { {
if (!word.isEmpty())
{
key += word.substring(0, 1).toUpperCase() + word.substring(1); key += word.substring(0, 1).toUpperCase() + word.substring(1);
} }
} }
return Labels.getLabel("Db" + key); return Labels.getLabel("Db" + key);
} }
public static boolean isEqualForFilter(String value, String search) public static boolean isEqualForFilter(String value, String search)
{ {
value = StringUtils.nullStr(value).toLowerCase(); value = StringUtils.nullStr(value).toLowerCase();
search = StringUtils.nullStr(search).toLowerCase(); search = StringUtils.nullStr(search).toLowerCase();
return value.contains(search); return value.startsWith(search);
} }
public static boolean isIcEqualForFilter(long value, long search)
{
String compareValue = StringUtils.not0ToStr(value);
String searchValue = StringUtils.not0ToStr(search);
return compareValue.startsWith(searchValue);
}
public static String encodeSpecialChars(String value) public static String encodeSpecialChars(String value)
{ {
if (value != null) if (value != null)
@ -58,7 +77,7 @@ public class StringUtils {
value = value.replace("²", "[up]2[/up]"); value = value.replace("²", "[up]2[/up]");
value = value.replace("³", "[up]3[/up]"); value = value.replace("³", "[up]3[/up]");
} }
return value; return value;
} }
@ -69,7 +88,7 @@ public class StringUtils {
value = value.replace("[up]2[/up]", "²"); value = value.replace("[up]2[/up]", "²");
value = value.replace("[up]3[/up]", "³"); value = value.replace("[up]3[/up]", "³");
} }
return value; return value;
} }
} }

@ -1,7 +1,6 @@
package info.bukova.isspst.filters; package info.bukova.isspst.filters;
import static info.bukova.isspst.StringUtils.not0ToStr; import info.bukova.isspst.StringUtils;
import static info.bukova.isspst.StringUtils.nullStr;
import info.bukova.isspst.data.Address; import info.bukova.isspst.data.Address;
import org.hamcrest.Description; import org.hamcrest.Description;
@ -31,13 +30,15 @@ public class AddressFilter implements Filter<Address> {
} }
@Override @Override
public boolean matchesSafely(Address item) { public boolean matchesSafely(Address item)
return nullStr(item.getCompany()).toLowerCase().contains(nullStr(condAddress.getCompany()).toLowerCase()) {
&& nullStr(item.getCity()).toLowerCase().contains(nullStr(condAddress.getCity()).toLowerCase()) boolean companyIsEqual = StringUtils.isEqualForFilter(item.getCompany(), condAddress.getCompany());
&& nullStr(item.getContactName()).toLowerCase().contains(nullStr(condAddress.getContactName()).toLowerCase()) boolean cityIsEqual = StringUtils.isEqualForFilter(item.getCity(), condAddress.getCity());
&& nullStr(item.getStreet()).toLowerCase().contains(nullStr(condAddress.getStreet()).toLowerCase()) boolean contactNameIsEqual = StringUtils.isEqualForFilter(item.getContactName(), condAddress.getContactName());
&& not0ToStr(item.getIc()).startsWith(not0ToStr(condAddress.getIc())) boolean streetIsEqual = StringUtils.isEqualForFilter(item.getStreet(), condAddress.getStreet());
&& nullStr(item.getHouseNumber()).startsWith(nullStr(condAddress.getHouseNumber())); boolean icIsEqual = StringUtils.isIcEqualForFilter(item.getIc(), condAddress.getIc());
boolean houseNumberIsEqual = StringUtils.isEqualForFilter(item.getHouseNumber(), condAddress.getHouseNumber());
return (companyIsEqual && cityIsEqual && contactNameIsEqual && streetIsEqual && icIsEqual && houseNumberIsEqual);
} }
@Factory @Factory

@ -1,6 +1,6 @@
package info.bukova.isspst.filters; package info.bukova.isspst.filters;
import static info.bukova.isspst.StringUtils.nullStr; import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Building; import info.bukova.isspst.data.Building;
import org.hamcrest.Description; import org.hamcrest.Description;
@ -30,10 +30,12 @@ public class BuildingFilter implements Filter<Building> {
} }
@Override @Override
public boolean matchesSafely(Building item) { public boolean matchesSafely(Building item)
return nullStr(item.getCode()).toLowerCase().contains(nullStr(condBuilding.getCode()).toLowerCase()) {
&& nullStr(item.getName()).toLowerCase().contains(nullStr(condBuilding.getName()).toLowerCase()) boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condBuilding.getCode());
&& nullStr(item.getDescription()).toLowerCase().contains(nullStr(condBuilding.getDescription()).toLowerCase()); boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condBuilding.getName());
boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condBuilding.getDescription());
return (codeIsEqual && nameIsEqual && descriptionIsEqual);
} }
@Factory @Factory

@ -1,6 +1,6 @@
package info.bukova.isspst.filters; package info.bukova.isspst.filters;
import static info.bukova.isspst.StringUtils.nullStr; import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.ServiceItem; import info.bukova.isspst.data.ServiceItem;
import org.hamcrest.Description; import org.hamcrest.Description;
@ -30,10 +30,12 @@ public class ServiceItemFilter implements Filter<ServiceItem> {
} }
@Override @Override
public boolean matchesSafely(ServiceItem item) { public boolean matchesSafely(ServiceItem item)
return nullStr(item.getCode()).toLowerCase().contains(nullStr(condServiceItem.getCode()).toLowerCase()) {
&& nullStr(item.getName()).toLowerCase().contains(nullStr(condServiceItem.getName()).toLowerCase()) boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condServiceItem.getCode());
&& nullStr(item.getDescription()).toLowerCase().contains(nullStr(condServiceItem.getDescription()).toLowerCase()); boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condServiceItem.getName());
boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condServiceItem.getDescription());
return (codeIsEqual && nameIsEqual && descriptionIsEqual);
} }
@Factory @Factory

@ -1,13 +1,12 @@
package info.bukova.isspst.filters; package info.bukova.isspst.filters;
import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Factory; import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher; import org.hamcrest.TypeSafeMatcher;
import static info.bukova.isspst.StringUtils.nullStr;
public class UserFilter implements Filter<User> { public class UserFilter implements Filter<User> {
private User condUser; private User condUser;
@ -30,11 +29,13 @@ public class UserFilter implements Filter<User> {
} }
@Override @Override
public boolean matchesSafely(User item) { public boolean matchesSafely(User item)
return nullStr(item.getUsername()).toLowerCase().contains(nullStr(condUser.getUsername()).toLowerCase()) {
&& nullStr(item.getFirstName()).toLowerCase().contains(nullStr(condUser.getFirstName()).toLowerCase()) boolean userNameIsEqual = StringUtils.isEqualForFilter(item.getUsername(), condUser.getUsername());
&& nullStr(item.getLastName()).toLowerCase().contains(nullStr(condUser.getLastName()).toLowerCase()) boolean firstNameIsEqual = StringUtils.isEqualForFilter(item.getFirstName(), condUser.getFirstName());
&& nullStr(item.getPersonalNumber()).toLowerCase().contains(nullStr(condUser.getPersonalNumber()).toLowerCase()); boolean lastNameIsEqual = StringUtils.isEqualForFilter(item.getLastName(), condUser.getLastName());
boolean personalNumberIsEqual = StringUtils.isEqualForFilter(item.getPersonalNumber(), condUser.getPersonalNumber());
return (userNameIsEqual && firstNameIsEqual && lastNameIsEqual && personalNumberIsEqual);
} }
@Factory @Factory

@ -1,6 +1,6 @@
package info.bukova.isspst.filters; package info.bukova.isspst.filters;
import static info.bukova.isspst.StringUtils.nullStr; import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.data.Workgroup;
import org.hamcrest.Description; import org.hamcrest.Description;
@ -30,10 +30,12 @@ public class WorkgroupFilter implements Filter<Workgroup> {
} }
@Override @Override
public boolean matchesSafely(Workgroup item) { public boolean matchesSafely(Workgroup item)
return nullStr(item.getCode()).toLowerCase().contains(nullStr(condWorkgroup.getCode()).toLowerCase()) {
&& nullStr(item.getName()).toLowerCase().contains(nullStr(condWorkgroup.getName()).toLowerCase()) boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condWorkgroup.getCode());
&& item.isCentre() == condWorkgroup.isCentre(); boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condWorkgroup.getName());
boolean centerIsEqual = (item.isCentre() == condWorkgroup.isCentre());
return (codeIsEqual && nameIsEqual && centerIsEqual);
} }
@Factory @Factory

Loading…
Cancel
Save