changeset 67:530a941dbf79

Updated the LProbeRepository and Service, Removed LProbeDetails LProbeRepository: * Return a LProbe not LProbeDetails on single LProbe request * Added 'create' for LProbe. LProbeService: * Updated service interfaces.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 31 May 2013 14:08:25 +0200
parents 54ff6ded05b2
children 9e34b7e872f9 ccb8e93b7eca
files src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/model/LProbeDetails.java src/main/java/de/intevation/lada/rest/LProbeService.java
diffstat 3 files changed, 62 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 31 14:04:01 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 31 14:08:25 2013 +0200
@@ -1,21 +1,23 @@
 package de.intevation.lada.data;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
+import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
+import javax.persistence.TransactionRequiredException;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.LProbeManager;
-import de.intevation.lada.model.LKommentarP;
-import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
-import de.intevation.lada.model.LProbeDetails;
+import de.intevation.lada.validation.ValidationException;
 
 /**
  * This Container is an interface to request, filter and select LProbe
@@ -39,6 +41,13 @@
     private LProbeManager manager;
 
     /**
+     * Errors/Warnings occured in repository operations.
+     */
+    private int generalError;
+    private Map<String, Integer> errors;
+    private Map<String, Integer> warnings;
+
+    /**
      * Filter for LProbe objects.
      *
      * @param mstId mst_id
@@ -81,29 +90,57 @@
         return em.createQuery(criteria).getResultList();
     }
 
-    public LProbeDetails details(String probeId) {
-        LProbeDetails details = new LProbeDetails();
-        LProbe probe = em.find(LProbe.class, probeId);
-        if (probe == null) {
-            return new LProbeDetails();
-        }
-        details.setLprobe(probe);
+    public LProbe details(String probeId) {
+        return em.find(LProbe.class, probeId);
+    }
 
-        CriteriaBuilder cbLorts = em.getCriteriaBuilder();
-        CriteriaQuery<LOrt> criteriaLorts = cbLorts.createQuery(LOrt.class);
-        Root<LOrt> lo = criteriaLorts.from(LOrt.class);
-        criteriaLorts.where(cbLorts.equal(lo.get("probeId"), probe.getProbeId()));
-        List<LOrt> lorts = em.createQuery(criteriaLorts).getResultList();
-        details.setLorts(lorts);
+    public boolean create(LProbe probe) {
+        setGeneralError(200);
+        setErrors(new HashMap<String, Integer>());
+        setWarnings(new HashMap<String, Integer>());
+        try {
+            manager.create(probe);
+            setWarnings(manager.getWarnings());
+            return true;
+        }
+        catch (EntityExistsException eee) {
+            setGeneralError(601);
+        }
+        catch (IllegalArgumentException iae) {
+            setGeneralError(602);
+        }
+        catch (TransactionRequiredException tre) {
+            setGeneralError(603);
+        }
+        catch (ValidationException ve) {
+            setGeneralError(604);
+            setErrors(ve.getErrors());
+            setWarnings(manager.getWarnings());
+        }
+        return false;
+    }
 
-        CriteriaBuilder cbLKomm = em.getCriteriaBuilder();
-        CriteriaQuery<LKommentarP> criteriaLKomm =
-            cbLKomm.createQuery(LKommentarP.class);
-        Root<LKommentarP> lk = criteriaLKomm.from(LKommentarP.class);
-        criteriaLorts.where(cbLorts.equal(lk.get("probeId"), probe.getProbeId()));
-        List<LKommentarP> lkomm = em.createQuery(criteriaLKomm).getResultList();
-        details.setLkommentar(lkomm);
+    public int getGeneralError() {
+        return generalError;
+    }
 
-        return details;
+    private void setGeneralError(int generalError) {
+        this.generalError = generalError;
+    }
+
+    public Map<String, Integer> getErrors() {
+        return errors;
+    }
+
+    private void setErrors(Map<String, Integer> errors) {
+        this.errors = errors;
+    }
+
+    public Map<String, Integer> getWarnings() {
+        return warnings;
+    }
+
+    private void setWarnings(Map<String, Integer> warnings) {
+        this.warnings = warnings;
     }
 }
--- a/src/main/java/de/intevation/lada/model/LProbeDetails.java	Fri May 31 14:04:01 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-package de.intevation.lada.model;
-
-import java.io.Serializable;
-import java.util.List;
-
-
-public class LProbeDetails extends LProbe
-{
-
-    private List<LOrt> lorts;
-    private List<LKommentarP> lkommentar;
-
-    public void setLprobe(LProbe lprobe) {
-      this.setProbeId(lprobe.getProbeId());
-      this.setMstId(lprobe.getMstId());
-      this.setUmwId(lprobe.getUmwId());
-      this.setTest(lprobe.isTest());
-      this.setHauptprobenNr(lprobe.getHauptprobenNr());
-      this.setBaId(lprobe.getBaId());
-      this.setMediaDesk(lprobe.getMediaDesk());
-      this.setMedia(lprobe.getMedia());
-      this.setProbenartId(lprobe.getProbenartId());
-      this.setDatenbasisId(lprobe.getDatenbasisId());
-      this.setProbeentnahmeBeginn(lprobe.getProbeentnahmeBeginn());
-      this.setProbeentnahmeEnde(lprobe.getProbeentnahmeEnde());
-      this.setMittelungsdauer(lprobe.getMittelungsdauer());
-      this.setLetzteAenderung(lprobe.getLetzteAenderung());
-      this.setErzeugerId(lprobe.getErzeugerId());
-      this.setProbeNehmerId(lprobe.getProbeNehmerId());
-      this.setMpKat(lprobe.getMpKat());
-      this.setMplId(lprobe.getMplId());
-      this.setMprId(lprobe.getMprId());
-      this.setSolldatumBeginn(lprobe.getSolldatumBeginn());
-      this.setSolldatumEnde(lprobe.getSolldatumEnde());
-    }
-
-    public List<LOrt> getLort() {
-        return lorts;
-    }
-
-    public void setLorts(List<LOrt> lorts) {
-        this.lorts = lorts;
-    }
-
-    public List<LKommentarP> getLkommentar() {
-        return lkommentar;
-    }
-
-    public void setLkommentar(List<LKommentarP> lkommentar) {
-        this.lkommentar = lkommentar;
-    }
-}
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 31 14:04:01 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 31 14:08:25 2013 +0200
@@ -18,7 +18,6 @@
 
 import de.intevation.lada.data.LProbeRepository;
 import de.intevation.lada.model.LProbe;
-import de.intevation.lada.model.LProbeDetails;
 
 /**
  * This class produces a RESTful service to read the contents of LProbe table.
@@ -50,7 +49,7 @@
     @GET
     @Path("/{id}")
     @Produces("text/json")
-    public LProbeDetails details(@PathParam("id") String id) {
+    public LProbe details(@PathParam("id") String id) {
         return repository.details(id);
     }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)