Mercurial > lada > lada-server
changeset 1164:84ff77bba9b0
Let the database generate id_alt and initial status for new messung objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 09 Nov 2016 12:39:08 +0100 |
parents | 315df94c679b |
children | 46db98d060ae |
files | db_schema/lada_schema.sql src/main/java/de/intevation/lada/factory/ProbeFactory.java src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java src/main/java/de/intevation/lada/rest/MessungService.java |
diffstat | 4 files changed, 34 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/db_schema/lada_schema.sql Wed Nov 09 10:18:51 2016 +0100 +++ b/db_schema/lada_schema.sql Wed Nov 09 12:39:08 2016 +0100 @@ -18,6 +18,36 @@ SET search_path = land, pg_catalog; +CREATE FUNCTION set_messung_id_alt() RETURNS trigger + LANGUAGE plpgsql + AS $$ + BEGIN + IF NEW.id_alt IS NULL THEN + NEW.id_alt = ( + SELECT count(*) + FROM land.messung + WHERE probe_id = NEW.probe_id) + 1; + END IF; + RETURN NEW; + END; +$$; + +CREATE FUNCTION set_messung_status() RETURNS trigger + LANGUAGE plpgsql + AS $$ + DECLARE status_id integer; + BEGIN + INSERT INTO land.status_protokoll + (mst_id, datum, text, messungs_id, status_kombi) + VALUES ((SELECT mst_id + FROM land.probe + WHERE id = NEW.probe_id), + now(), '', NEW.id, 1) + RETURNING id into status_id; + UPDATE land.messung SET status = status_id where id = NEW.id; + RETURN NEW; + END; +$$; CREATE FUNCTION update_letzte_aenderung() RETURNS trigger LANGUAGE plpgsql @@ -279,7 +309,7 @@ CREATE TABLE messung ( id serial PRIMARY KEY, - id_alt integer DEFAULT nextval('land.messung_messung_id_alt_seq'::regclass) NOT NULL, + id_alt integer NOT NULL, probe_id integer NOT NULL REFERENCES probe ON DELETE CASCADE, nebenproben_nr character varying(10), mmt_id character varying(2) NOT NULL REFERENCES stammdaten.mess_methode ON DELETE CASCADE, @@ -293,7 +323,8 @@ ); CREATE TRIGGER letzte_aenderung_messung BEFORE UPDATE ON messung FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung(); CREATE TRIGGER tree_modified_messung BEFORE UPDATE ON messung FOR EACH ROW EXECUTE PROCEDURE update_tree_modified_messung(); - +CREATE TRIGGER id_alt_messung BEFORE INSERT ON land.messung FOR EACH ROW EXECUTE PROCEDURE set_messung_id_alt(); +CREATE TRIGGER status_messung AFTER INSERT ON land.messung FOR EACH ROW EXECUTE PROCEDURE set_messung_status(); -- -- Name: kommentar_m; Type: TABLE; Schema: land; Owner: -; Tablespace:
--- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java Wed Nov 09 10:18:51 2016 +0100 +++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java Wed Nov 09 12:39:08 2016 +0100 @@ -366,15 +366,6 @@ messung.setProbeId(probe.getId()); repository.create(messung, "land"); - StatusProtokoll status = new StatusProtokoll(); - status.setDatum(new Timestamp(new Date().getTime())); - status.setMessungsId(messung.getId()); - status.setMstId(probe.getMstId()); - status.setStatusKombi(1); - repository.create(status, "land"); - messung.setStatus(status.getId()); - repository.update(messung, "land"); - for (int mw : mmt.getMessgroessen()) { Messwert wert = new Messwert(); wert.setMessgroesseId(mw);
--- a/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java Wed Nov 09 10:18:51 2016 +0100 +++ b/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java Wed Nov 09 12:39:08 2016 +0100 @@ -316,14 +316,6 @@ newMessung = ((Messung)created.getData()); created = repository.getById(Messung.class, newMessung.getId(), "land"); newMessung = ((Messung)created.getData()); - StatusProtokoll status = new StatusProtokoll(); - status.setDatum(new Timestamp(new Date().getTime())); - status.setMessungsId(newMessung.getId()); - status.setMstId(mstId); - status.setStatusKombi(1); - Response st = repository.create(status, "land"); - newMessung.setStatus(((StatusProtokoll)st.getData()).getId()); - repository.update(newMessung, "land"); if (object.getAttributes().containsKey("BEARBEITUNGSSTATUS")) { createStatusProtokoll(object.getAttributes().get("BEARBEITUNGSSTATUS"), newMessung, mstId); }
--- a/src/main/java/de/intevation/lada/rest/MessungService.java Wed Nov 09 10:18:51 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MessungService.java Wed Nov 09 12:39:08 2016 +0100 @@ -293,28 +293,13 @@ /* Persist the new messung object*/ Response response = repository.create(messung, "land"); - Messung ret = (Messung)response.getData(); - Messung refreshed = repository.getByIdPlain(Messung.class, ret.getId(), "land"); if(violation.hasWarnings()) { response.setWarnings(violation.getWarnings()); } - StatusProtokoll status = new StatusProtokoll(); - status.setDatum(new Timestamp(new Date().getTime())); - status.setMessungsId((ret.getId())); - Probe probe = - repository.getByIdPlain(Probe.class, ret.getProbeId(), "land"); - status.setMstId(probe.getMstId()); - status.setStatusKombi(1); - repository.create(status, "land"); - refreshed.setStatus(status.getId()); - repository.update(refreshed, "land"); - Response updated= - repository.getById(Messung.class, refreshed.getId(), "land"); - return authorization.filter( request, - updated, + response, Messung.class); }