From f2d9576a3f94c52dcbac2cf7ef4d9c0f95a15b83 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 20 Jul 2014 21:36:38 +0200 Subject: [PATCH] =?UTF-8?q?Do=20po=C5=BEadavku=20na=20slu=C5=BEebn=C3=AD?= =?UTF-8?q?=20cestu=20byla=20p=C5=99id=C3=A1na=20chyb=C4=9Bj=C3=ADc=C3=AD?= =?UTF-8?q?=20pole,=20implementovan=C3=A1=20validace=20formul=C3=A1=C5=99e?= =?UTF-8?q?.=20Do=20BaseValidator=20byly=20p=C5=99id=C3=A1ny=20metody=20na?= =?UTF-8?q?=20obecnou=20validaci=20null/empty.=20Do=20ListViewModel=20p?= =?UTF-8?q?=C5=99id=C3=A1ny=20metody=20pro=20dota=C5=BEen=C3=AD=20lazy=20l?= =?UTF-8?q?oadovan=C3=BDch=20dat.=20closes=20#108?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukova/isspst/data/TripRequirement.java | 53 +++++++++++ .../requirement/TripRequirementService.java | 12 +-- .../TripRequirementServiceImpl.java | 7 ++ .../info/bukova/isspst/ui/ListViewModel.java | 5 + .../ui/requirement/TripRequirementForm.java | 54 ++++++++++- .../ui/requirement/TripRequirementList.java | 5 + .../isspst/validators/BaseValidator.java | 34 ++++++- .../TripRequirementFormValidator.java | 52 ++++++++++ .../WEB-INF/locales/validators.properties | 5 + .../trips/requirement/requirementsForm.zul | 95 +++++++++++++++++-- 10 files changed, 301 insertions(+), 21 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/validators/TripRequirementFormValidator.java diff --git a/src/main/java/info/bukova/isspst/data/TripRequirement.java b/src/main/java/info/bukova/isspst/data/TripRequirement.java index 2e41145b..54d4ffea 100644 --- a/src/main/java/info/bukova/isspst/data/TripRequirement.java +++ b/src/main/java/info/bukova/isspst/data/TripRequirement.java @@ -1,11 +1,21 @@ package info.bukova.isspst.data; +import java.util.ArrayList; import java.util.Date; +import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.Embedded; import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; import javax.persistence.Table; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + @Entity @Table(name = "TRIPREQUIREMENT") public class TripRequirement extends RequirementBase { @@ -16,9 +26,20 @@ public class TripRequirement extends RequirementBase { private String to; @Column(name = "TRIP_DATE") private Date tripDate; + @Column(name = "END") + private String end; + @Column(name = "END_DATE") + private Date endDate; + @ManyToMany(cascade = CascadeType.ALL) + @LazyCollection(LazyCollectionOption.TRUE) + @JoinTable(name="TRIPREQUIREMENT_PASSANGER", joinColumns={@JoinColumn(name="TRIPREQUIREMENT_ID")}, inverseJoinColumns={@JoinColumn(name="USER_ID")}) + private List passengers; + @Embedded + private Vehicle vehicle; public TripRequirement() { this.setOwnedBy(new User()); + passengers = new ArrayList(); } public String getFrom() { @@ -45,4 +66,36 @@ public class TripRequirement extends RequirementBase { this.tripDate = tripDate; } + public String getEnd() { + return end; + } + + public void setEnd(String end) { + this.end = end; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getPassengers() { + return passengers; + } + + public void setPassengers(List passengers) { + this.passengers = passengers; + } + + public Vehicle getVehicle() { + return vehicle; + } + + public void setVehicle(Vehicle vehicle) { + this.vehicle = vehicle; + } + } diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java index cf258732..89ed1331 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java @@ -1,19 +1,15 @@ package info.bukova.isspst.services.requirement; -import java.util.List; - import info.bukova.isspst.data.TripRequirement; -import info.bukova.isspst.data.User; import info.bukova.isspst.services.Service; +import java.util.List; + public interface TripRequirementService extends Service { public List getCentreReq(); public List getWorkgroupReq(); public List getFromAll(); - public void loadAuthItems(TripRequirement entity); - public List getNextApprover(TripRequirement entity); - public boolean canApprove(TripRequirement entity); - public void approve(TripRequirement entity); - + public void loadPassangers(TripRequirement entity); + } diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java index 9651933d..15496793 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -92,5 +92,12 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl { selIndex = index; } editBean = service.getById(dataBean.getId()); + loadLazyDataForEdit(editBean); showForm(); } + protected void loadLazyDataForEdit(T data) { + + } + @Command @NotifyChange("confirmDelete") public void delObject() { diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java index 60086ca3..49eb8deb 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java @@ -2,32 +2,82 @@ package info.bukova.isspst.ui.requirement; import java.util.List; +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.select.annotation.WireVariable; +import info.bukova.isspst.data.SettingsData; import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.FormViewModel; +import info.bukova.isspst.validators.TripRequirementFormValidator; public class TripRequirementForm extends FormViewModel { @WireVariable private UserService userService; - @WireVariable private WorkgroupService workgroupService; - + @WireVariable + private GlobalSettingsService settingsService; private List centres; + private List users; + private List passengers; + private User selUser; + private TripRequirementFormValidator validator; @Init(superclass = true) public void init() { centres = workgroupService.getUserCentres(userService.getCurrent()); + users = userService.getAll(); + passengers = getDataBean().getPassengers(); + validator = new TripRequirementFormValidator(); + } + + @Command + @NotifyChange("passengers") + public void addPassanger() { + getDataBean().getPassengers().add(selUser); + } + + @Command + @NotifyChange("passengers") + public void removePassanger(@BindingParam("user") User user) { + getDataBean().getPassengers().remove(user); } public List getCentres() { return centres; } + public List getUsers() { + return users; + } + + public User getSelUser() { + return selUser; + } + + public void setSelUser(User selUser) { + this.selUser = selUser; + } + + public SettingsData getSettings() { + return settingsService.getSettings(); + } + + public TripRequirementFormValidator getValidator() { + return validator; + } + + public List getPassengers() { + return passengers; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java index 3b87ca18..c570ecaf 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java @@ -76,4 +76,9 @@ public class TripRequirementList extends ListViewModel { return myCentres; } + @Override + protected void loadLazyDataForEdit(TripRequirement data) { + tripRequirementService.loadPassangers(data); + } + } diff --git a/src/main/java/info/bukova/isspst/validators/BaseValidator.java b/src/main/java/info/bukova/isspst/validators/BaseValidator.java index a92ca562..d413106c 100644 --- a/src/main/java/info/bukova/isspst/validators/BaseValidator.java +++ b/src/main/java/info/bukova/isspst/validators/BaseValidator.java @@ -3,6 +3,7 @@ package info.bukova.isspst.validators; import info.bukova.isspst.StringUtils; import org.slf4j.Logger; +import org.zkoss.bind.Property; import org.zkoss.bind.ValidationContext; import org.zkoss.bind.validator.AbstractValidator; import org.zkoss.zk.ui.Component; @@ -59,9 +60,38 @@ public abstract class BaseValidator extends AbstractValidator { this.errorMsg(ctx, msg, null); } + + protected boolean validateIsNotNull(ValidationContext ctx, String property, String errMessage, String componentId) + { + Property prop = ctx.getProperties(property)[0]; + Object value = prop.getValue(); - @Override - public void validate(ValidationContext ctx) + if (value == null) + { + this.errorMsg(ctx, StringUtils.localize(errMessage), componentId); + return false; + } + + return true; + } + + protected boolean validateIsNotNullOrNotEmpty(ValidationContext ctx, String property, String errMessage, String componentId) { + Property prop = ctx.getProperties(property)[0]; + Object value = prop.getValue(); + + if (value == null) + { + this.errorMsg(ctx, StringUtils.localize(errMessage), componentId); + return false; + } + + if ((value instanceof String) && ((String)value).isEmpty()) + { + this.errorMsg(ctx, StringUtils.localize(errMessage), componentId); + return false; + } + + return true; } } diff --git a/src/main/java/info/bukova/isspst/validators/TripRequirementFormValidator.java b/src/main/java/info/bukova/isspst/validators/TripRequirementFormValidator.java new file mode 100644 index 00000000..1d14df19 --- /dev/null +++ b/src/main/java/info/bukova/isspst/validators/TripRequirementFormValidator.java @@ -0,0 +1,52 @@ +package info.bukova.isspst.validators; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.ValidationContext; + +public class TripRequirementFormValidator extends BaseValidator { + + private final static Logger log = LoggerFactory.getLogger(TripRequirementFormValidator.class); + + @Override + protected Logger getLogger() + { + return log; + } + + @Override + public void validate(ValidationContext ctx) { + if (!this.validateIsNotNull(ctx, "centre", "RequirementCenterIsEmpty", null)) + { + return; + } + + if (!this.validateIsNotNull(ctx, "tripDate", "TripDateIsEmpty", null)) + { + return; + } + + if (!this.validateIsNotNull(ctx, "endDate", "EndDateIsEmpty", null)) + { + return; + } + + if (!this.validateIsNotNullOrNotEmpty(ctx, "from", "FromIsEmpty", null)) + { + return; + } + + if (!this.validateIsNotNullOrNotEmpty(ctx, "to", "ToIsEmpty", null)) + { + return; + } + + if (!this.validateIsNotNull(ctx, "vehicle", "VehicleIsEmpty", null)) + { + return; + } + } + + + +} diff --git a/src/main/webapp/WEB-INF/locales/validators.properties b/src/main/webapp/WEB-INF/locales/validators.properties index 2d0eee6a..8ddd11dc 100644 --- a/src/main/webapp/WEB-INF/locales/validators.properties +++ b/src/main/webapp/WEB-INF/locales/validators.properties @@ -4,3 +4,8 @@ DataTypeErr=Chybný datový typ... UserPasswordIsEmpty=Uživatelské heslo musí být zadané... UserPasswordsAreNotSame=Znovu zadané heslo není stejné... RequirementCenterIsEmpty=Musíte zadat středisko... +TripDateIsEmpty=Musíte zadat datum cesty... +EndDateIsEmpty=Musíte zadat datum konce cesty... +FromIsEmpty=Musíte zadat místo začátku cesty... +ToIsEmpty=Musíte zadat cíl cesty... +VehicleIsEmpty=Musíte zadat dopravní prostředek... diff --git a/src/main/webapp/trips/requirement/requirementsForm.zul b/src/main/webapp/trips/requirement/requirementsForm.zul index ab4984c4..cef33b0e 100644 --- a/src/main/webapp/trips/requirement/requirementsForm.zul +++ b/src/main/webapp/trips/requirement/requirementsForm.zul @@ -11,7 +11,7 @@ src="/img/reqact.png" zclass="form-caption" label="${labels.RequirementsFormTitle}" /> - + @@ -37,7 +36,7 @@ @@ -47,7 +46,7 @@ + selectedItem="@bind(fx.centre)"> @@ -60,7 +59,25 @@ + value="@bind(fx.from)" /> + + + + ${labels.RequirementsFormStartDateTime} : + + + + + + @@ -69,7 +86,7 @@ + value="@bind(fx.to)" /> @@ -78,12 +95,72 @@ + value="@bind(fx.description)" /> + + + + ${labels.RequirementsFormEndTravel} : + + + + + + ${labels.RequirementsFormEndDate} : + + - + +