[Lada-commits] [PATCH 1 of 2] Refactored finding the umwelt id to be able to use it for messprogramme
Wald Commits
scm-commit at wald.intevation.org
Fri Jul 10 14:04:02 CEST 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1436529807 -7200
# Node ID 8c486052264ca8d42d6b61d4c06a599440afbf9c
# Parent 97ccdf45a4a3ce01e69d3b3847478c30ebf2363a
Refactored finding the umwelt id to be able to use it for messprogramme.
diff -r 97ccdf45a4a3 -r 8c486052264c src/main/java/de/intevation/lada/factory/ProbeFactory.java
--- 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 "";
}
}
diff -r 97ccdf45a4a3 -r 8c486052264c src/main/java/de/intevation/lada/rest/MessprogrammService.java
--- 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,
diff -r 97ccdf45a4a3 -r 8c486052264c src/main/java/de/intevation/lada/rest/ProbeService.java
--- 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(
More information about the Lada-commits
mailing list