Mercurial > lada > lada-server
changeset 92:197257807428
Moved validation into the LProbeRepository.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Mon, 10 Jun 2013 17:18:03 +0200 |
parents | 5471557eaf76 |
children | af8eb04a8100 |
files | src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/manage/LProbeManager.java |
diffstat | 2 files changed, 10 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java Fri Jun 07 15:23:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java Mon Jun 10 17:18:03 2013 +0200 @@ -5,6 +5,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; +import javax.inject.Named; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; import javax.persistence.TransactionRequiredException; @@ -16,6 +17,7 @@ import de.intevation.lada.manage.LProbeManager; import de.intevation.lada.model.LProbe; import de.intevation.lada.validation.ValidationException; +import de.intevation.lada.validation.Validator; /** * This Container is an interface to request, filter and select LProbe @@ -26,6 +28,10 @@ @ApplicationScoped public class LProbeRepository extends Repository{ + @Inject + @Named("lprobevalidator") + private Validator validator; + /** * The entitymanager managing the data. */ @@ -94,8 +100,9 @@ // Try to save the new LProbe. try { + validator.validate(probe); manager.create(probe); - setWarnings(manager.getWarnings()); + setWarnings(validator.getWarnings()); return true; } catch (EntityExistsException eee) { @@ -110,7 +117,7 @@ catch (ValidationException ve) { setGeneralError(604); setErrors(ve.getErrors()); - setWarnings(manager.getWarnings()); + setWarnings(validator.getWarnings()); } return false; }
--- a/src/main/java/de/intevation/lada/manage/LProbeManager.java Fri Jun 07 15:23:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/manage/LProbeManager.java Mon Jun 10 17:18:03 2013 +0200 @@ -30,10 +30,6 @@ @Inject private EntityManager em; - @Inject - @Named("lprobevalidator") - private Validator validator; - /** * Delete a LProbe object by id. * @@ -55,24 +51,12 @@ * @throws EntityExistsException * @throws IllegalArgumentException * @throws TransactionRequiredException - * @throws ValidationException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void create(LProbe probe) throws EntityExistsException, IllegalArgumentException, - TransactionRequiredException, - ValidationException { - validator.validate(probe); + TransactionRequiredException { em.persist(probe); } - - /** - * Get the warnings found while validating a LProbe object. - * - * @return Map of warnings containing field - warn code pair. - */ - public Map<String, Integer> getWarnings() { - return validator.getWarnings(); - } }