From a41f3143f2bcac72695f049d14f479a82cfc0b57 Mon Sep 17 00:00:00 2001 From: Franta Pribyl Date: Fri, 23 May 2014 09:25:40 +0200 Subject: [PATCH] =?UTF-8?q?=C3=9Aprava=20agendy=20Budovy=20-=20odd=C4=9Ble?= =?UTF-8?q?n=C3=AD=20chybov=C3=BDch=20hl=C3=A1=C5=A1en=C3=AD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/data/Building.java | 29 +++++----- .../bukova/isspst/filters/BuildingFilter.java | 56 +++++++++++++++++++ .../resources/ValidationMessages.properties | 1 + src/main/webapp/WEB-INF/zk-label.properties | 1 - 4 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/filters/BuildingFilter.java create mode 100644 src/main/resources/ValidationMessages.properties diff --git a/src/main/java/info/bukova/isspst/data/Building.java b/src/main/java/info/bukova/isspst/data/Building.java index e3be3304..7730055e 100644 --- a/src/main/java/info/bukova/isspst/data/Building.java +++ b/src/main/java/info/bukova/isspst/data/Building.java @@ -3,38 +3,33 @@ package info.bukova.isspst.data; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotBlank; -import org.hibernate.validator.constraints.NotEmpty; @Entity -@Table(name="BUILDING") +@Table(name = "BUILDING") public class Building extends BaseData implements DataModel { - - @Column(name="CODE", unique=true) + @Column(name = "CODE", unique = true) private String code; - - @Column(name="NAME") + + @Column(name = "NAME") private String name; - - @Column(name="DESCRIPTION") + + @Column(name = "DESCRIPTION") private String description; - /** * @return the code */ - @NotBlank(message = "${labels.BuildingsFormCodeConstr}") - @NotNull(message = "${labels.BuildingsFormCodeConstr}") - @NotEmpty(message = "${labels.BuildingsFormCodeConstr}") + @NotBlank(message = "{BuildingsFormCodeConstr}") public String getCode() { return code; } /** - * @param code the code to set + * @param code + * the code to set */ public void setCode(String code) { this.code = code; @@ -48,7 +43,8 @@ public class Building extends BaseData implements DataModel { } /** - * @param name the name to set + * @param name + * the name to set */ public void setName(String name) { this.name = name; @@ -62,7 +58,8 @@ public class Building extends BaseData implements DataModel { } /** - * @param description the description to set + * @param description + * the description to set */ public void setDescription(String description) { this.description = description; diff --git a/src/main/java/info/bukova/isspst/filters/BuildingFilter.java b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java new file mode 100644 index 00000000..787c6a22 --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java @@ -0,0 +1,56 @@ +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Building; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class BuildingFilter implements Filter { + + private Building condBuilding; + + public BuildingFilter(Building condBuilding) { + this.condBuilding = condBuilding; + } + + private static class BuildingMatcher extends TypeSafeMatcher { + + private Building condBuilding; + + public BuildingMatcher(Building cond) { + this.condBuilding = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("buildings matches"); + } + + @Override + public boolean matchesSafely(Building item) { + return nullStr(item.getCode()).toLowerCase().contains(nullStr(condBuilding.getCode()).toLowerCase()) + && nullStr(item.getName()).toLowerCase().contains(nullStr(condBuilding.getName()).toLowerCase()) + && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condBuilding.getDescription()).toLowerCase()); + } + + @Factory + public static Matcher matchBuilding(Building building) { + return new BuildingMatcher(building); + } + } + + @Override + public BuildingMatcher matcher() { + return new BuildingMatcher(condBuilding); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/resources/ValidationMessages.properties b/src/main/resources/ValidationMessages.properties new file mode 100644 index 00000000..ebe76fac --- /dev/null +++ b/src/main/resources/ValidationMessages.properties @@ -0,0 +1 @@ +BuildingsFormCodeConstr=Zadejte k\u00f3d budovy... \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/zk-label.properties b/src/main/webapp/WEB-INF/zk-label.properties index a072d70c..e8f09376 100644 --- a/src/main/webapp/WEB-INF/zk-label.properties +++ b/src/main/webapp/WEB-INF/zk-label.properties @@ -2,7 +2,6 @@ AgendaBuildings=Budovy BuildingsFormCode=Kód -BuildingsFormCodeConstr=Zadejte kód budovy... BuildingsFormName=Název BuildingsFormDescription=Popis