Validace entit přes hibernate validation framework

multitenant
Josef Rokos 11 years ago
parent 7393a2d2e2
commit 5a9b8fd679

@ -13,6 +13,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
@Override @Override
@Transactional @Transactional
public void add(T entity) { public void add(T entity) {
validate(entity);
entity.setCreated(new Date()); entity.setCreated(new Date());
entity.setOwnedBy(getLoggedInUser()); entity.setOwnedBy(getLoggedInUser());
dao.add(entity); dao.add(entity);
@ -24,6 +25,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
if (entity.getCreated() == null) { if (entity.getCreated() == null) {
add(entity); add(entity);
} else { } else {
validate(entity);
entity.setModifiedBy(getLoggedInUser()); entity.setModifiedBy(getLoggedInUser());
entity.setModified(new Date()); entity.setModified(new Date());
dao.modify(entity); dao.modify(entity);

@ -28,6 +28,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
@Override @Override
@Transactional @Transactional
public void add(T entity) { public void add(T entity) {
validate(entity);
entity.setCreated(new Date()); entity.setCreated(new Date());
dao.add(entity); dao.add(entity);
} }
@ -38,6 +39,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
if (entity.getCreated() == null) { if (entity.getCreated() == null) {
add(entity); add(entity);
} else { } else {
validate(entity);
entity.setModified(new Date()); entity.setModified(new Date());
dao.modify(entity); dao.modify(entity);
} }

@ -6,7 +6,6 @@ import info.bukova.isspst.services.ValidationException;
import java.util.Map; import java.util.Map;
import org.springframework.dao.DataIntegrityViolationException;
import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ExecutionArgParam; import org.zkoss.bind.annotation.ExecutionArgParam;
@ -46,7 +45,7 @@ public class FormViewModel<T extends DataModel> {
} }
Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR);
} catch (DataIntegrityViolationException e) { } catch (Exception e) {
dataBean.setCreated(null); dataBean.setCreated(null);
e.printStackTrace(); e.printStackTrace();
Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);

Loading…
Cancel
Save