# HG changeset patch # User Raimund Renkert # Date 1485526201 -3600 # Node ID 9dfb52db6a0fc1871388c850567a653ae59e2973 # Parent dc7dde59bb54fd555b59b6863084db46ab4a8bdf Make use of the ort factory in ort service. diff -r dc7dde59bb54 -r 9dfb52db6a0f db_schema/lada_schema.sql --- a/db_schema/lada_schema.sql Fri Jan 27 15:00:31 2017 +0100 +++ b/db_schema/lada_schema.sql Fri Jan 27 15:10:01 2017 +0100 @@ -151,7 +151,6 @@ datenbasis_id integer NOT NULL REFERENCES stammdaten.datenbasis, ba_id integer DEFAULT 1 REFERENCES stammdaten.betriebsart, gem_id character varying(8) REFERENCES stammdaten.verwaltungseinheit, - ort_id integer NOT NULL REFERENCES stammdaten.ort, media_desk character varying(100) CHECK(media_desk LIKE '% %'), umw_id character varying(3) REFERENCES stammdaten.umwelt, probenart_id integer NOT NULL REFERENCES stammdaten.probenart, @@ -285,6 +284,21 @@ CREATE TRIGGER letzte_aenderung_ortszuordnung BEFORE UPDATE ON ortszuordnung FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); CREATE TRIGGER tree_modified_ortszuordnung BEFORE UPDATE ON ortszuordnung FOR EACH ROW EXECUTE PROCEDURE update_tree_modified(); +-- +-- Name: ortszuordnung_mp; Type: TABLE; Schema: land; Owner: -; Tablespace: +-- + +CREATE TABLE ortszuordnung_mp ( + id serial PRIMARY KEY, + messprogramm_id integer NOT NULL REFERENCES messprogramm ON DELETE CASCADE, + ort_id integer NOT NULL REFERENCES stammdaten.ort, + ortszuordnung_typ character varying(1) REFERENCES stammdaten.ortszuordnung_typ, + ortszusatztext character varying(100), + letzte_aenderung timestamp without time zone DEFAULT now(), + tree_modified timestamp without time zone DEFAULT now(), + EXCLUDE (messprogramm_id WITH =) WHERE (ortszuordnung_typ = 'E') +); +CREATE TRIGGER letzte_aenderung_ortszuordnung_mp BEFORE UPDATE ON ortszuordnung_mp FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); -- -- Name: zusatz_wert; Type: TABLE; Schema: land; Owner: -; Tablespace: @@ -362,7 +376,6 @@ CREATE TRIGGER letzte_aenderung_messwert BEFORE UPDATE ON messwert FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); CREATE TRIGGER tree_modified_messwert BEFORE UPDATE ON messwert FOR EACH ROW EXECUTE PROCEDURE update_tree_modified(); - -- -- Name: status_protokoll; Type: TABLE; Schema: land; Owner: -; Tablespace: -- diff -r dc7dde59bb54 -r 9dfb52db6a0f src/main/java/de/intevation/lada/factory/ProbeFactory.java --- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java Fri Jan 27 15:00:31 2017 +0100 +++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java Fri Jan 27 15:10:01 2017 +0100 @@ -25,6 +25,7 @@ import de.intevation.lada.model.land.Messung; import de.intevation.lada.model.land.Messwert; import de.intevation.lada.model.land.Ortszuordnung; +import de.intevation.lada.model.land.OrtszuordnungMp; import de.intevation.lada.model.land.StatusProtokoll; import de.intevation.lada.model.stammdaten.DeskriptorUmwelt; import de.intevation.lada.model.stammdaten.Deskriptoren; @@ -60,16 +61,16 @@ int[] J = { Calendar.YEAR, Calendar.DAY_OF_YEAR, 1 }; - this.fieldsTable = new Hashtable(); + fieldsTable = new Hashtable(); - this.fieldsTable.put("T", T); - this.fieldsTable.put("W", W); - this.fieldsTable.put("W2", W2); - this.fieldsTable.put("W4", W4); - this.fieldsTable.put("M", M); - this.fieldsTable.put("Q", Q); - this.fieldsTable.put("H", H); - this.fieldsTable.put("J", J); + fieldsTable.put("T", T); + fieldsTable.put("W", W); + fieldsTable.put("W2", W2); + fieldsTable.put("W4", W4); + fieldsTable.put("M", M); + fieldsTable.put("Q", Q); + fieldsTable.put("H", H); + fieldsTable.put("J", J); } private class Intervall { @@ -356,7 +357,8 @@ Response response = repository.filter(builder.getQuery(), "land"); @SuppressWarnings("unchecked") List mmts = (List)response.getData(); - for (MessprogrammMmt mmt : mmts) { + for (int i = 0; i < mmts.size(); i++) { + MessprogrammMmt mmt = mmts.get(i); Messung messung = new Messung(); messung.setFertig(false); messung.setGeplant(true); @@ -375,22 +377,19 @@ repository.create(wert, "land"); } } - if (messprogramm.getOrtId() != null && - !messprogramm.getOrtId().equals("")) { - Ortszuordnung ort = new Ortszuordnung(); - ort.setOrtszuordnungTyp("E"); - ort.setProbeId(probe.getId()); - QueryBuilder ortBuilder = new QueryBuilder( - repository.entityManager("stamm"), Ort.class); - ortBuilder.and("id", messprogramm.getOrtId()); - Response ortResponse = repository.filter( - ortBuilder.getQuery(), "stamm"); - @SuppressWarnings("unchecked") - List orte = (List) ortResponse.getData(); - if (orte != null && !orte.isEmpty()) { - ort.setOrtId(orte.get(0).getId()); - } - repository.create(ort, "land"); + QueryBuilder builderOrt = + new QueryBuilder( + repository.entityManager("land"), + OrtszuordnungMp.class); + List orte = + repository.filterPlain(builderOrt.getQuery(), "land"); + for (OrtszuordnungMp ort : orte) { + Ortszuordnung ortP = new Ortszuordnung(); + ortP.setOrtszuordnungTyp(ort.getOrtszuordnungTyp()); + ortP.setProbeId(probe.getId()); + ortP.setOrtId(ort.getOrtId()); + ortP.setOrtszusatztext(ort.getOrtszusatztext()); + repository.create(ortP, "land"); } // Reolad the probe to have the old id probe = (Probe)repository.getById( diff -r dc7dde59bb54 -r 9dfb52db6a0f src/main/java/de/intevation/lada/rest/stamm/OrtService.java --- a/src/main/java/de/intevation/lada/rest/stamm/OrtService.java Fri Jan 27 15:00:31 2017 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java Fri Jan 27 15:10:01 2017 +0100 @@ -271,7 +271,7 @@ return new Response(false, 699, ort); } - ortFactory.transformCoordinates(ort); + ort = ortFactory.completeOrt(ort); if (ortFactory.hasErrors()) { Violation factoryErrs = new Violation(); for (ReportItem err : ortFactory.getErrors()) { @@ -290,7 +290,10 @@ return response; } - Response response = repository.create(ort, "stamm"); + Response response = new Response(true, 201, ort); + if (ort.getId() == null) { + response = repository.create(ort, "stamm"); + } if(violation.hasWarnings()) { response.setWarnings(violation.getWarnings()); }