Do požadavku na služební cestu byla přidána chybějící pole,
implementovaná validace formuláře. Do BaseValidator byly přidány metody na obecnou validaci null/empty. Do ListViewModel přidány metody pro dotažení lazy loadovaných dat. closes #108
This commit is contained in:
@@ -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<User> passengers;
|
||||
@Embedded
|
||||
private Vehicle vehicle;
|
||||
|
||||
public TripRequirement() {
|
||||
this.setOwnedBy(new User());
|
||||
passengers = new ArrayList<User>();
|
||||
}
|
||||
|
||||
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<User> getPassengers() {
|
||||
return passengers;
|
||||
}
|
||||
|
||||
public void setPassengers(List<User> passengers) {
|
||||
this.passengers = passengers;
|
||||
}
|
||||
|
||||
public Vehicle getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
public void setVehicle(Vehicle vehicle) {
|
||||
this.vehicle = vehicle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<TripRequirement> {
|
||||
|
||||
public List<TripRequirement> getCentreReq();
|
||||
public List<TripRequirement> getWorkgroupReq();
|
||||
public List<TripRequirement> getFromAll();
|
||||
public void loadAuthItems(TripRequirement entity);
|
||||
public List<User> getNextApprover(TripRequirement entity);
|
||||
public boolean canApprove(TripRequirement entity);
|
||||
public void approve(TripRequirement entity);
|
||||
|
||||
public void loadPassangers(TripRequirement entity);
|
||||
|
||||
}
|
||||
|
||||
@@ -92,5 +92,12 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
return super.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void loadPassangers(TripRequirement entity) {
|
||||
TripRequirement e = dao.getById(entity.getId());
|
||||
e.getPassengers().size();
|
||||
entity.setPassengers(e.getPassengers());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -159,9 +159,14 @@ public class ListViewModel<T extends DataModel> {
|
||||
selIndex = index;
|
||||
}
|
||||
editBean = service.getById(dataBean.getId());
|
||||
loadLazyDataForEdit(editBean);
|
||||
showForm();
|
||||
}
|
||||
|
||||
protected void loadLazyDataForEdit(T data) {
|
||||
|
||||
}
|
||||
|
||||
@Command
|
||||
@NotifyChange("confirmDelete")
|
||||
public void delObject() {
|
||||
|
||||
@@ -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<TripRequirement> {
|
||||
|
||||
@WireVariable
|
||||
private UserService userService;
|
||||
|
||||
@WireVariable
|
||||
private WorkgroupService workgroupService;
|
||||
|
||||
@WireVariable
|
||||
private GlobalSettingsService settingsService;
|
||||
private List<Workgroup> centres;
|
||||
private List<User> users;
|
||||
private List<User> 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<Workgroup> getCentres() {
|
||||
return centres;
|
||||
}
|
||||
|
||||
public List<User> 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<User> getPassengers() {
|
||||
return passengers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,4 +76,9 @@ public class TripRequirementList extends ListViewModel<TripRequirement> {
|
||||
return myCentres;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadLazyDataForEdit(TripRequirement data) {
|
||||
tripRequirementService.loadPassangers(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(ValidationContext ctx)
|
||||
|
||||
protected boolean validateIsNotNull(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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user