Mercurial > lada > lada-server
changeset 697:8c486052264c
Refactored finding the umwelt id to be able to use it for messprogramme.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 10 Jul 2015 14:03:27 +0200 |
parents | 97ccdf45a4a3 |
children | cd22674b4673 |
files | src/main/java/de/intevation/lada/factory/ProbeFactory.java src/main/java/de/intevation/lada/rest/MessprogrammService.java src/main/java/de/intevation/lada/rest/ProbeService.java |
diffstat | 3 files changed, 34 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java Fri Jul 10 12:56:00 2015 +0200 +++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java Fri Jul 10 14:03:27 2015 +0200 @@ -287,11 +287,25 @@ } } - public LProbe findUmwelt(LProbe probe) { + public LProbe findUmweltId(LProbe probe) { String[] mediaDesk = probe.getMediaDesk().split(" "); if (mediaDesk.length <= 1) { - return null; + return probe; } + probe.setUmwId(findUmwelt(mediaDesk)); + return probe; + } + + public Messprogramm findUmweltId(Messprogramm messprogramm) { + String[] mediaDesk = messprogramm.getMediaDesk().split(" "); + if (mediaDesk.length <= 1) { + return messprogramm; + } + messprogramm.setUmwId(findUmwelt(mediaDesk)); + return messprogramm; + } + + private String findUmwelt(String[] mediaDesk) { List<Integer> mediaIds = new ArrayList<Integer>(); boolean zebs = false; Integer parent = null; @@ -325,7 +339,7 @@ @SuppressWarnings("unchecked") List<Deskriptoren> data = (List<Deskriptoren>)response.getData(); if (data.isEmpty()) { - return probe; + return ""; } hdParent = data.get(0).getId(); mediaIds.add(data.get(0).getId()); @@ -333,16 +347,16 @@ ndParent = data.get(0).getId(); } } - return getUmwelt(probe, mediaIds, zebs); + return getUmwelt(mediaIds, zebs); } - private LProbe getUmwelt(LProbe probe, List<Integer> media, boolean isZebs) { + private String getUmwelt(List<Integer> media, boolean isZebs) { QueryBuilder<DeskriptorUmwelt> builder = new QueryBuilder<DeskriptorUmwelt>( repository.entityManager("stamm"), DeskriptorUmwelt.class); if (media.size() == 0) { - return probe; + return ""; } int size = 1; @@ -360,13 +374,12 @@ @SuppressWarnings("unchecked") List<DeskriptorUmwelt> data = (List<DeskriptorUmwelt>)response.getData(); if (data.isEmpty()) { - return probe; + return ""; } boolean unique = isUnique(data); if (unique) { - probe.setUmwId(data.get(0).getUmwId()); - return probe; + return data.get(0).getUmwId(); } else { int found = -1; @@ -415,11 +428,10 @@ } } if (found >= 0) { - probe.setUmwId(data.get(found).getUmwId()); - return probe; + return data.get(found).getUmwId(); } } - return probe; + return ""; } }
--- a/src/main/java/de/intevation/lada/rest/MessprogrammService.java Fri Jul 10 12:56:00 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/MessprogrammService.java Fri Jul 10 14:03:27 2015 +0200 @@ -35,6 +35,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; +import de.intevation.lada.factory.ProbeFactory; import de.intevation.lada.model.land.Messprogramm; import de.intevation.lada.query.QueryTools; import de.intevation.lada.util.annotation.AuthorizationConfig; @@ -88,6 +89,9 @@ @AuthorizationConfig(type=AuthorizationType.OPEN_ID) private Authorization authorization; + @Inject + private ProbeFactory factory; + /** * Get all Messprogramm objects. * <p> @@ -221,6 +225,9 @@ return new Response(false, 699, null); } + if (messprogramm.getUmwId() == null || messprogramm.getUmwId().length() == 0) { + messprogramm = factory.findUmweltId(messprogramm); + } /* Persist the new messprogramm object*/ Response response = defaultRepo.create(messprogramm, "land"); Messprogramm ret = (Messprogramm)response.getData(); @@ -261,6 +268,7 @@ return new Response(false, 699, null); } messprogramm.setLetzteAenderung(new Timestamp(new Date().getTime())); + messprogramm = factory.findUmweltId(messprogramm); Response response = defaultRepo.update(messprogramm, "land"); Response updated = defaultRepo.getById( Messprogramm.class,
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java Fri Jul 10 12:56:00 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/ProbeService.java Fri Jul 10 14:03:27 2015 +0200 @@ -328,7 +328,7 @@ return response; } if (probe.getUmwId() == null || probe.getUmwId().equals("")) { - probe = factory.findUmwelt(probe); + probe = factory.findUmweltId(probe); } /* Persist the new probe object*/ Response newProbe = defaultRepo.create(probe, "land"); @@ -443,6 +443,7 @@ response.setWarnings(violation.getWarnings()); return response; } + factory.findUmweltId(probe); probe.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(probe, "land"); Response updated = defaultRepo.getById(