changeset 68:9e34b7e872f9

Documentation and minor code cosmetics/renamings.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 31 May 2013 14:47:54 +0200
parents 530a941dbf79
children 9409d00b9254
files src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/manage/LProbeManager.java src/main/java/de/intevation/lada/rest/LProbeService.java src/main/java/de/intevation/lada/validation/LProbeValidator.java src/main/java/de/intevation/lada/validation/ValidationException.java src/main/java/de/intevation/lada/validation/Validator.java
diffstat 6 files changed, 122 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 31 14:47:54 2013 +0200
@@ -90,14 +90,19 @@
         return em.createQuery(criteria).getResultList();
     }
 
-    public LProbe details(String probeId) {
-        return em.find(LProbe.class, probeId);
-    }
-
+    /**
+     * Validate and persist a new LProbe object.
+     *
+     * @param probe The new LProbe object
+     * @return True on success, else returns false.
+     */
     public boolean create(LProbe probe) {
+        // Make sure that no old errors and warnings remain.
         setGeneralError(200);
         setErrors(new HashMap<String, Integer>());
         setWarnings(new HashMap<String, Integer>());
+
+        // Try to save the new LProbe.
         try {
             manager.create(probe);
             setWarnings(manager.getWarnings());
@@ -120,26 +125,56 @@
         return false;
     }
 
+    /**
+     * Getter for the error code returned by the validator.
+     *
+     * @return The error code returned by the validator.
+     */
     public int getGeneralError() {
         return generalError;
     }
 
+    /**
+     * Private setter for the general error code.
+     *
+     * @param generalError
+     */
     private void setGeneralError(int generalError) {
         this.generalError = generalError;
     }
 
+    /**
+     * Getter for all errors occured while validating a LProbe object.
+     *
+     * @return Map of field - error code pairs.
+     */
     public Map<String, Integer> getErrors() {
         return errors;
     }
 
+    /**
+     * Private setter for validation errors.
+     * 
+     * @param errors
+     */
     private void setErrors(Map<String, Integer> errors) {
         this.errors = errors;
     }
 
+    /**
+     * Getter for all warnings occured while validating a LProbe object.
+     *
+     * @return Map of field - error code pairs.
+     */
     public Map<String, Integer> getWarnings() {
         return warnings;
     }
 
+    /**
+     * Private setter for validation warnings.
+     *
+     * @param warnings
+     */
     private void setWarnings(Map<String, Integer> warnings) {
         this.warnings = warnings;
     }
--- a/src/main/java/de/intevation/lada/manage/LProbeManager.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/manage/LProbeManager.java	Fri May 31 14:47:54 2013 +0200
@@ -16,6 +16,11 @@
 import de.intevation.lada.validation.ValidationException;
 import de.intevation.lada.validation.Validator;
 
+/**
+ * This Manager provides databse operations for LProbe objects.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
 @Stateless
 public class LProbeManager {
 
@@ -42,6 +47,16 @@
         em.remove(probe);
     }
 
+    /**
+     * Persist a new LProbe object in the database using the LProbeValidator.
+     *
+     * @param probe The new LProbe object.
+     *
+     * @throws EntityExistsException
+     * @throws IllegalArgumentException
+     * @throws TransactionRequiredException
+     * @throws ValidationException
+     */
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void create(LProbe probe)
     throws EntityExistsException,
@@ -52,6 +67,11 @@
         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();
     }
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 31 14:47:54 2013 +0200
@@ -49,8 +49,8 @@
     @GET
     @Path("/{id}")
     @Produces("text/json")
-    public LProbe details(@PathParam("id") String id) {
-        return repository.details(id);
+    public LProbe findById(@PathParam("id") String id) {
+        return repository.findById(LProbe.class, id);
     }
 
     /**
--- a/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Fri May 31 14:47:54 2013 +0200
@@ -5,30 +5,64 @@
 
 import javax.inject.Named;
 
+import de.intevation.lada.model.LProbe;
+
+/**
+ * Validator for LProbe objects.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
 @Named("lprobevalidator")
 public class LProbeValidator
 implements Validator
 {
 
+    /**
+     * Warnings found while validating the LProbe
+     */
     private Map<String, Integer> warnings;
 
+    /**
+     * Validate a LProbe object.
+     * 
+     * @param probe The LProbe object.
+     */
     @Override
     public void validate(Object probe)
     throws ValidationException {
         warnings = new HashMap<String, Integer>();
+        if (!(probe instanceof LProbe)) {
+            Map<String, Integer> errors = new HashMap<String, Integer>();
+            errors.put("lprobe", 610);
+            throw new ValidationException(errors);
+        }
+        // Dummy warning.
         warnings.put("entnahmeort", 612);
         validateId(probe);
     }
 
+    /**
+     * Validate the LProbe id.
+     *
+     * @param probe The LProbe object.
+     * @throws ValidationException
+     */
     private void validateId(Object probe)
     throws ValidationException{
         Map<String, Integer> errors = new HashMap<String, Integer>();
         // TODO Implement me!
+
+        // Dummy error.
         errors.put("probeid", 611);
         ValidationException ve = new ValidationException(errors);
         throw ve;
     }
 
+    /**
+     * Getter for warnings occured while validating the LProbe.
+     * 
+     * @return Map of field - warning code pairs.
+     */
     @Override
     public Map<String, Integer> getWarnings() {
         return warnings;
--- a/src/main/java/de/intevation/lada/validation/ValidationException.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/ValidationException.java	Fri May 31 14:47:54 2013 +0200
@@ -2,20 +2,40 @@
 
 import java.util.Map;
 
-
+/**
+ * Exception used for validation errors.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
 public class ValidationException
 extends Exception
 {
+    /**
+     * Errors saved in this exception.
+     */
     private Map<String, Integer> errors;
 
-    @SuppressWarnings("unused")
+    /**
+     * Do not allow an empty ValidationException object. 
+     */
     private ValidationException() {
     }
 
+    /**
+     * Create a new instance with errors.
+     *
+     * @param errors
+     */
     public ValidationException(Map<String, Integer> errors) {
+        this();
         this.errors = errors;
     }
 
+    /**
+     * Getter for the errors.
+     *
+     * @return
+     */
     public Map<String, Integer> getErrors() {
         return errors;
     }
--- a/src/main/java/de/intevation/lada/validation/Validator.java	Fri May 31 14:08:25 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/Validator.java	Fri May 31 14:47:54 2013 +0200
@@ -2,7 +2,11 @@
 
 import java.util.Map;
 
-
+/**
+ * Validator interface. Implement this interface for lada object validations.
+ * 
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
 public interface Validator
 {
     public void validate(Object object) throws ValidationException;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)