# HG changeset patch # User Raimund Renkert # Date 1453363317 -3600 # Node ID 2fe625c91ab3ffee85955c0bc53c95e6f9b08cc7 # Parent 9dd9a3de7a6178d9cc5c022bb5b7f0e2a0ab43ba# Parent 2203e5d76071eff40e210c9310ffe13aaf2ee12d Merged branches. diff -r 2203e5d76071 -r 2fe625c91ab3 .hgignore --- a/.hgignore Thu Jan 14 10:22:14 2016 +0100 +++ b/.hgignore Thu Jan 21 09:01:57 2016 +0100 @@ -8,6 +8,8 @@ .factorypath .gitignore .project +*.swp +*.swo *~ # intellij support - ignore *.iml, .idea @@ -18,4 +20,3 @@ syntax: regexp ^target/ ^.settings - diff -r 2203e5d76071 -r 2fe625c91ab3 db_schema/lada_schema.sql --- a/db_schema/lada_schema.sql Thu Jan 14 10:22:14 2016 +0100 +++ b/db_schema/lada_schema.sql Thu Jan 21 09:01:57 2016 +0100 @@ -152,7 +152,7 @@ NEW.tree_modified = now(); RAISE NOTICE 'updating other rows'; UPDATE land.messung SET tree_modified = now() WHERE probe_id = NEW.id; - UPDATE land.ort SET tree_modified = now() WHERE probe_id = NEW.id; + UPDATE land.ortszuordnung SET tree_modified = now() WHERE probe_id = NEW.id; UPDATE land.zusatz_wert SET tree_modified = now() WHERE probe_id = NEW.id; RETURN NEW; END; @@ -430,24 +430,24 @@ -- --- Name: ort; Type: TABLE; Schema: bund; Owner: -; Tablespace: --- - -CREATE TABLE ort ( +-- Name: ortszuordnung; Type: TABLE; Schema: bund; Owner: -; Tablespace: +-- + +CREATE TABLE ortszuordnung ( id integer DEFAULT nextval('ort_id_seq'::regclass) NOT NULL, probe_id integer NOT NULL, ort_id bigint NOT NULL, - orts_typ character varying(1), + ortszuordnung_typ character varying(1), ortszusatztext character varying(100), letzte_aenderung timestamp without time zone DEFAULT now() ); -- --- Name: COLUMN ort.orts_typ; Type: COMMENT; Schema: bund; Owner: - --- - -COMMENT ON COLUMN ort.orts_typ IS 'E = Entnahmeport, U = Ursprungsort, Z = Ortszusatz'; +-- Name: COLUMN ortszuordnung.ortszuordnung_typ; Type: COMMENT; Schema: bund; Owner: - +-- + +COMMENT ON COLUMN ortszuordnung.ortszuordnung_typ IS 'E = Entnahmeport, U = Ursprungsort, Z = Ortszusatz'; -- @@ -766,13 +766,13 @@ -- --- Name: ort; Type: TABLE; Schema: land; Owner: -; Tablespace: --- - -CREATE TABLE ort ( +-- Name: ortszuordnung; Type: TABLE; Schema: land; Owner: -; Tablespace: +-- + +CREATE TABLE ortszuordnung ( tree_modified timestamp without time zone DEFAULT now() ) -INHERITS (bund.ort); +INHERITS (bund.ortszuordnung); -- @@ -966,6 +966,39 @@ -- +-- Name: datensatz_erzeuger; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: +-- + +CREATE TABLE datensatz_erzeuger ( + id integer NOT NULL, + netzbetreiber_id character varying(2), + da_erzeuger_id character varying(2), + mst_id character varying(5), + bezeichnung character varying(120), + letzte_aenderung timestamp without time zone +); + + +-- +-- Name: datensatz_erzeuger_id_seq; Type: SEQUENCE; Schema: stammdaten; Owner: - +-- + +CREATE SEQUENCE datensatz_erzeuger_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: datensatz_erzeuger_id_seq; Type: SEQUENCE OWNED BY; Schema: stammdaten; Owner: - +-- + +ALTER SEQUENCE datensatz_erzeuger_id_seq OWNED BY datensatz_erzeuger.id; + + +-- -- Name: de_vg; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: -- @@ -1219,6 +1252,38 @@ -- +-- Name: messprogramm_kategorie; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: +-- + +CREATE TABLE messprogramm_kategorie ( + id integer NOT NULL, + netzbetreiber_id character varying(2), + mpl_id character varying(3), + bezeichnung character varying(120), + letzte_aenderung timestamp without time zone +); + + +-- +-- Name: messprogramm_kategorie_id_seq; Type: SEQUENCE; Schema: stammdaten; Owner: - +-- + +CREATE SEQUENCE messprogramm_kategorie_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: messprogramm_kategorie_id_seq; Type: SEQUENCE OWNED BY; Schema: stammdaten; Owner: - +-- + +ALTER SEQUENCE messprogramm_kategorie_id_seq OWNED BY messprogramm_kategorie.id; + + +-- -- Name: mg_grp; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: -- @@ -1271,10 +1336,9 @@ CREATE TABLE ort ( id integer NOT NULL, - o_typ character varying(1), netzbetreiber_id character varying(2), - bezeichnung character varying(10), - beschreibung character varying(100), + ort_id character varying(10), + langtext character varying(100), staat_id smallint, gem_id character varying(8), unscharf character(1) DEFAULT NULL::bpchar, @@ -1287,22 +1351,21 @@ latitude double precision, longitude double precision, geom public.geometry(Point,4326), - shape public.geometry(MultiPolygon,4326) + shape public.geometry(MultiPolygon,4326), + ort_typ smallint, + kurztext character varying(15), + berichtstext character varying(70), + zone character varying(1), + sektor character varying(2), + zustaendigkeit character varying(10), + mp_art character varying(10), + aktiv character(1), + anlage_id integer, + oz_id integer ); -- --- Name: COLUMN ort.o_typ; Type: COMMENT; Schema: stammdaten; Owner: - --- - -COMMENT ON COLUMN ort.o_typ IS 'D = dynamischer Messpunkt (nicht vordefiniert) -V = vordefinierter Messpunkt -R = REI-Messpunkt -S = Station -Z = Ortzszusatz'; - - --- -- Name: ort_id_seq; Type: SEQUENCE; Schema: stammdaten; Owner: - -- @@ -1322,6 +1385,26 @@ -- +-- Name: ort_typ; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: +-- + +CREATE TABLE ort_typ ( + id smallint NOT NULL, + ort_typ character varying(60) +); + + +-- +-- Name: ortszuordnung_typ; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: +-- + +CREATE TABLE ortszuordnung_typ ( + id character(1) NOT NULL, + ortstyp character varying(60) +); + + +-- -- Name: pflicht_messgroesse; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: -- @@ -1398,6 +1481,48 @@ -- +-- Name: probenehmer; Type: TABLE; Schema: stammdaten; Owner: -; Tablespace: +-- + +CREATE TABLE probenehmer ( + id integer NOT NULL, + netzbetreiber_id character varying(2), + prn_id character varying(9), + bearbeiter character varying(25), + bemerkung character varying(60), + betrieb character varying(80), + bezeichnung character varying(80), + kurz_bezeichnung character varying(10), + ort character varying(20), + plz character varying(5), + strasse character varying(30), + telefon character varying(20), + tp character varying(3), + typ character(1), + letzte_aenderung timestamp without time zone +); + + +-- +-- Name: probenehmer_id_seq; Type: SEQUENCE; Schema: stammdaten; Owner: - +-- + +CREATE SEQUENCE probenehmer_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: probenehmer_id_seq; Type: SEQUENCE OWNED BY; Schema: stammdaten; Owner: - +-- + +ALTER SEQUENCE probenehmer_id_seq OWNED BY probenehmer.id; + + +-- -- Name: s_00_view; Type: VIEW; Schema: stammdaten; Owner: - -- @@ -1991,14 +2116,14 @@ -- Name: id; Type: DEFAULT; Schema: land; Owner: - -- -ALTER TABLE ONLY ort ALTER COLUMN id SET DEFAULT nextval('bund.ort_id_seq'::regclass); +ALTER TABLE ONLY ortszuordnung ALTER COLUMN id SET DEFAULT nextval('bund.ort_id_seq'::regclass); -- -- Name: letzte_aenderung; Type: DEFAULT; Schema: land; Owner: - -- -ALTER TABLE ONLY ort ALTER COLUMN letzte_aenderung SET DEFAULT now(); +ALTER TABLE ONLY ortszuordnung ALTER COLUMN letzte_aenderung SET DEFAULT now(); -- @@ -2084,6 +2209,13 @@ -- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - -- +ALTER TABLE ONLY datensatz_erzeuger ALTER COLUMN id SET DEFAULT nextval('datensatz_erzeuger_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - +-- + ALTER TABLE ONLY de_vg ALTER COLUMN id SET DEFAULT nextval('de_vg_id_seq'::regclass); @@ -2126,6 +2258,13 @@ -- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - -- +ALTER TABLE ONLY messprogramm_kategorie ALTER COLUMN id SET DEFAULT nextval('messprogramm_kategorie_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - +-- + ALTER TABLE ONLY ort ALTER COLUMN id SET DEFAULT nextval('ort_id_seq'::regclass); @@ -2147,6 +2286,13 @@ -- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - -- +ALTER TABLE ONLY probenehmer ALTER COLUMN id SET DEFAULT nextval('probenehmer_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: stammdaten; Owner: - +-- + ALTER TABLE ONLY staat ALTER COLUMN id SET DEFAULT nextval('staat_id_seq'::regclass); @@ -2193,11 +2339,11 @@ -- --- Name: ort_pkey; Type: CONSTRAINT; Schema: bund; Owner: -; Tablespace: --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_pkey PRIMARY KEY (id); +-- Name: ortszuordnung_pkey; Type: CONSTRAINT; Schema: bund; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_pkey PRIMARY KEY (id); -- @@ -2307,11 +2453,11 @@ -- --- Name: ort_pkey; Type: CONSTRAINT; Schema: land; Owner: -; Tablespace: --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_pkey PRIMARY KEY (id); +-- Name: ortszuordnung_pkey; Type: CONSTRAINT; Schema: land; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_pkey PRIMARY KEY (id); -- @@ -2397,6 +2543,14 @@ -- +-- Name: datensatz_erzeuger_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY datensatz_erzeuger + ADD CONSTRAINT datensatz_erzeuger_pkey PRIMARY KEY (id); + + +-- -- Name: de_vg_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: -- @@ -2461,6 +2615,14 @@ -- +-- Name: messprogramm_kategorie_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY messprogramm_kategorie + ADD CONSTRAINT messprogramm_kategorie_pkey PRIMARY KEY (id); + + +-- -- Name: mg_grp_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: -- @@ -2493,6 +2655,22 @@ -- +-- Name: ort_typ_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY ort_typ + ADD CONSTRAINT ort_typ_pkey PRIMARY KEY (id); + + +-- +-- Name: ortszuordnung_typ_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY ortszuordnung_typ + ADD CONSTRAINT ortszuordnung_typ_pkey PRIMARY KEY (id); + + +-- -- Name: pflicht_messgroesse_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: -- @@ -2533,6 +2711,14 @@ -- +-- Name: probenehmer_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY probenehmer + ADD CONSTRAINT probenehmer_pkey PRIMARY KEY (id); + + +-- -- Name: staat_pkey; Type: CONSTRAINT; Schema: stammdaten; Owner: -; Tablespace: -- @@ -2694,7 +2880,7 @@ -- Name: tree_timestamp_ort; Type: TRIGGER; Schema: land; Owner: - -- -CREATE TRIGGER tree_timestamp_ort BEFORE UPDATE ON ort FOR EACH ROW EXECUTE PROCEDURE update_time_ort(); +CREATE TRIGGER tree_timestamp_ort BEFORE UPDATE ON ortszuordnung FOR EACH ROW EXECUTE PROCEDURE update_time_ort(); -- @@ -2778,19 +2964,27 @@ -- --- Name: ort_ort_id_fkey; Type: FK CONSTRAINT; Schema: bund; Owner: - --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_ort_id_fkey FOREIGN KEY (ort_id) REFERENCES stammdaten.ort(id); - - --- --- Name: ort_probe_id_fkey; Type: FK CONSTRAINT; Schema: bund; Owner: - --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_probe_id_fkey FOREIGN KEY (probe_id) REFERENCES probe(id); +-- Name: ortszuordnung_ort_id_fkey; Type: FK CONSTRAINT; Schema: bund; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_ort_id_fkey FOREIGN KEY (ort_id) REFERENCES stammdaten.ort(id); + + +-- +-- Name: ortszuordnung_ortszuordnung_typ_fkey; Type: FK CONSTRAINT; Schema: bund; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_ortszuordnung_typ_fkey FOREIGN KEY (ortszuordnung_typ) REFERENCES stammdaten.ortszuordnung_typ(id); + + +-- +-- Name: ortszuordnung_probe_id_fkey; Type: FK CONSTRAINT; Schema: bund; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_probe_id_fkey FOREIGN KEY (probe_id) REFERENCES probe(id); -- @@ -3012,19 +3206,27 @@ -- --- Name: ort_ort_id_fkey; Type: FK CONSTRAINT; Schema: land; Owner: - --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_ort_id_fkey FOREIGN KEY (ort_id) REFERENCES stammdaten.ort(id); - - --- --- Name: ort_probe_id_fkey; Type: FK CONSTRAINT; Schema: land; Owner: - --- - -ALTER TABLE ONLY ort - ADD CONSTRAINT ort_probe_id_fkey FOREIGN KEY (probe_id) REFERENCES probe(id) ON DELETE CASCADE; +-- Name: ortszuordnung_ort_id_fkey; Type: FK CONSTRAINT; Schema: land; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_ort_id_fkey FOREIGN KEY (ort_id) REFERENCES stammdaten.ort(id); + + +-- +-- Name: ortszuordnung_ortszuordnung_typ_fkey; Type: FK CONSTRAINT; Schema: land; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_ortszuordnung_typ_fkey FOREIGN KEY (ortszuordnung_typ) REFERENCES stammdaten.ortszuordnung_typ(id); + + +-- +-- Name: ortszuordnung_probe_id_fkey; Type: FK CONSTRAINT; Schema: land; Owner: - +-- + +ALTER TABLE ONLY ortszuordnung + ADD CONSTRAINT ortszuordnung_probe_id_fkey FOREIGN KEY (probe_id) REFERENCES probe(id) ON DELETE CASCADE; -- @@ -3150,6 +3352,22 @@ -- +-- Name: datensatz_erzeuger_mst_id_fkey1; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY datensatz_erzeuger + ADD CONSTRAINT datensatz_erzeuger_mst_id_fkey1 FOREIGN KEY (mst_id) REFERENCES mess_stelle(id); + + +-- +-- Name: datensatz_erzeuger_netzbetreiber_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY datensatz_erzeuger + ADD CONSTRAINT datensatz_erzeuger_netzbetreiber_id_fkey FOREIGN KEY (netzbetreiber_id) REFERENCES netz_betreiber(id); + + +-- -- Name: fk_deskriptoren_vorgaenger; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - -- @@ -3158,6 +3376,22 @@ -- +-- Name: messprogramm_kategorie_netzbetreiber_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY messprogramm_kategorie + ADD CONSTRAINT messprogramm_kategorie_netzbetreiber_id_fkey FOREIGN KEY (netzbetreiber_id) REFERENCES netz_betreiber(id); + + +-- +-- Name: ort_anlage_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY ort + ADD CONSTRAINT ort_anlage_fkey FOREIGN KEY (anlage_id) REFERENCES ort(id); + + +-- -- Name: ort_gem_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - -- @@ -3182,6 +3416,22 @@ -- +-- Name: ort_ort_typ_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY ort + ADD CONSTRAINT ort_ort_typ_fkey FOREIGN KEY (ort_typ) REFERENCES ort_typ(id); + + +-- +-- Name: ort_oz_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY ort + ADD CONSTRAINT ort_oz_fkey FOREIGN KEY (oz_id) REFERENCES ort(id); + + +-- -- Name: ort_staat_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - -- @@ -3222,6 +3472,14 @@ -- +-- Name: probenehmer_netzbetreiber_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - +-- + +ALTER TABLE ONLY probenehmer + ADD CONSTRAINT probenehmer_netzbetreiber_id_fkey FOREIGN KEY (netzbetreiber_id) REFERENCES netz_betreiber(id); + + +-- -- Name: staat_kda_id_fkey; Type: FK CONSTRAINT; Schema: stammdaten; Owner: - -- diff -r 2203e5d76071 -r 2fe625c91ab3 pom.xml --- a/pom.xml Thu Jan 14 10:22:14 2016 +0100 +++ b/pom.xml Thu Jan 21 09:01:57 2016 +0100 @@ -123,7 +123,7 @@ junit junit - 4.12 + 4.11 test @@ -154,6 +154,12 @@ 3.0.11.Final test + + org.jboss.arquillian.extension + arquillian-persistence-dbunit + 1.0.0.Alpha7 + test + diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/exporter/laf/LafCreator.java --- a/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java Thu Jan 21 09:01:57 2016 +0100 @@ -19,7 +19,7 @@ import de.intevation.lada.model.land.LKommentarP; import de.intevation.lada.model.land.LMessung; import de.intevation.lada.model.land.LMesswert; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.LZusatzWert; import de.intevation.lada.model.land.ProbeTranslation; @@ -27,7 +27,7 @@ import de.intevation.lada.model.stamm.Messgroesse; import de.intevation.lada.model.stamm.ProbenZusatz; import de.intevation.lada.model.stamm.Probenart; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Ort; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; import de.intevation.lada.util.data.Repository; @@ -197,30 +197,31 @@ */ @SuppressWarnings("unchecked") private String writeOrt(LProbe probe) { - QueryBuilder builder = - new QueryBuilder( + QueryBuilder builder = + new QueryBuilder( repository.entityManager("land"), - LOrt.class); + LOrtszuordnung.class); builder.and("probeId", probe.getId()); Response objects = repository.filter(builder.getQuery(), "land"); - List orte = (List)objects.getData(); + List orte = + (List)objects.getData(); String laf = ""; - for(LOrt o : orte) { + for(LOrtszuordnung o : orte) { laf += "%ORT%\n"; - QueryBuilder oBuilder = - new QueryBuilder( + QueryBuilder oBuilder = + new QueryBuilder( repository.entityManager("stamm"), - SOrt.class); - oBuilder.and("id", o.getOrt()); - List sOrte= - (List)repository.filter( + Ort.class); + oBuilder.and("id", o.getOrtId()); + List sOrte= + (List)repository.filter( oBuilder.getQuery(), "stamm").getData(); laf += lafLine("ORT_CODE", - "\"" + sOrte.get(0).getBezeichnung() + "\""); - laf += lafLine("ORT_TYP", "\"" + o.getOrtsTyp() + "\""); + "\"" + sOrte.get(0).getAnlageId() + "\""); + laf += lafLine("ORT_TYP", "\"" + o.getOrtszuordnungTyp() + "\""); laf += o.getOrtszusatztext() == null ? "": lafLine("ORT_ZUSATZTEXT", "\"" + o.getOrtszusatztext() + "\""); laf += lafLine("ORT_LAND_S", String.valueOf(sOrte.get(0).getStaatId())); @@ -230,7 +231,7 @@ koord += sOrte.get(0).getLatitude(); //TODO: use table koordinatenart and koord*extern! laf += lafLine("ORT_KOORDINATEN_S", koord); - laf += lafLine("ORT_GEMEINDESCHLUESSEL", sOrte.get(0).getVerwaltungseinheitId()); + laf += lafLine("ORT_GEMEINDESCHLUESSEL", sOrte.get(0).getOrtId()); } return laf; } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/factory/ProbeFactory.java --- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java Thu Jan 21 09:01:57 2016 +0100 @@ -19,7 +19,7 @@ import de.intevation.lada.model.land.LKommentarP; import de.intevation.lada.model.land.LMessung; import de.intevation.lada.model.land.LMesswert; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.Messprogramm; import de.intevation.lada.model.land.MessprogrammMmt; @@ -27,7 +27,7 @@ import de.intevation.lada.model.land.ProbeTranslation; import de.intevation.lada.model.stamm.DeskriptorUmwelt; import de.intevation.lada.model.stamm.Deskriptoren; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Ort; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; import de.intevation.lada.util.data.Repository; @@ -208,17 +208,17 @@ } if (messprogramm.getOrtId() != null && !messprogramm.getOrtId().equals("")) { - LOrt ort = new LOrt(); - ort.setOrtsTyp("E"); + LOrtszuordnung ort = new LOrtszuordnung(); + ort.setOrtszuordnungTyp("E"); ort.setProbeId(probe.getId()); - QueryBuilder ortBuilder = new QueryBuilder( - repository.entityManager("stamm"), SOrt.class); + 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(); + List orte = (List) ortResponse.getData(); if (orte != null && !orte.isEmpty()) { - ort.setOrt(BigInteger.valueOf(orte.get(0).getId())); + ort.setOrtId(Long.valueOf(orte.get(0).getId())); } repository.create(ort, "land"); } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/importer/laf/LafParser.java --- a/src/main/java/de/intevation/lada/importer/laf/LafParser.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/importer/laf/LafParser.java Thu Jan 21 09:01:57 2016 +0100 @@ -18,7 +18,7 @@ import de.intevation.lada.importer.ReportItem; import de.intevation.lada.model.land.LMessung; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.util.auth.UserInfo; import de.intevation.lada.validation.Validator; @@ -215,7 +215,7 @@ } } writer.writeOrte(userInfo, producer.getOrte()); - for (LOrt ort: producer.getLOrte()) { + for (LOrtszuordnung ort: producer.getLOrte()) { Violation oViolation = ortValidator.validate(ort); if (oViolation.hasErrors()) { ReportItem oErr = new ReportItem("validation", oViolation.getErrors(), null); diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/importer/laf/LafProducer.java --- a/src/main/java/de/intevation/lada/importer/laf/LafProducer.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/importer/laf/LafProducer.java Thu Jan 21 09:01:57 2016 +0100 @@ -15,17 +15,16 @@ import javax.inject.Inject; import de.intevation.lada.importer.ReportItem; -import de.intevation.lada.model.Ort; import de.intevation.lada.model.land.LKommentarM; import de.intevation.lada.model.land.LKommentarP; import de.intevation.lada.model.land.LMessung; import de.intevation.lada.model.land.LMesswert; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.LZusatzWert; import de.intevation.lada.model.land.MessungTranslation; import de.intevation.lada.model.land.ProbeTranslation; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Ort; /** * The LAFProducer creates entity objects form key-value pairs using the @@ -79,12 +78,12 @@ /** * Orte created by this producer. */ - private List lorte; + private List lorte; /** * SOrte created by this producer. */ - private List orte; + private List orte; /** * Messwerte created by this producer. @@ -139,7 +138,7 @@ this.pKommentare = new ArrayList(); this.mKommentare = new HashMap>(); this.messungen = new HashMap(); - this.lorte = new ArrayList(); + this.lorte = new ArrayList(); this.messwerte = new HashMap>(); String fileName = "/import.json"; LafFormat format = new LafFormat(); @@ -333,14 +332,14 @@ /** * @return List of {@link Ort} entities. */ - public List getOrte() { + public List getOrte() { return this.orte; } /** * @return List of {@link LOrt} entities. */ - public List getLOrte() { + public List getLOrte() { return this.lorte; } @@ -381,8 +380,8 @@ this.probe = new LProbe(); this.messungen = new HashMap(); this.messung = null; - this.lorte = new ArrayList(); - this.orte = new ArrayList(); + this.lorte = new ArrayList(); + this.orte = new ArrayList(); this.ort.reset(); this.messwerte = new HashMap>(); this.mKommentare = new HashMap>(); @@ -413,11 +412,11 @@ */ public void newOrt() { if (this.ort != null) { - SOrt o = this.ort.toOrt(); + Ort o = this.ort.toOrt(); if (o != null) { this.orte.add(o); } - LOrt lo = this.ort.toLOrt(); + LOrtszuordnung lo = this.ort.toLOrt(); if (lo != null) { this.lorte.add(lo); } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/importer/laf/LafWriter.java --- a/src/main/java/de/intevation/lada/importer/laf/LafWriter.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/importer/laf/LafWriter.java Thu Jan 21 09:01:57 2016 +0100 @@ -19,11 +19,11 @@ import de.intevation.lada.model.land.LKommentarP; import de.intevation.lada.model.land.LMessung; import de.intevation.lada.model.land.LMesswert; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.MessungTranslation; import de.intevation.lada.model.land.ProbeTranslation; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Ort; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.auth.Authorization; @@ -85,7 +85,7 @@ * @return success */ public boolean writeProbe(UserInfo userInfo, LProbe probe, ProbeTranslation probeTranslation) { - if (!authorization.isAuthorized(userInfo, probe)) { + if (!authorization.isAuthorized(userInfo, probe, LProbe.class)) { errors.add(new ReportItem("auth", "not authorized", 699)); return false; } @@ -133,7 +133,7 @@ * @param orte List of {@link SOrt} objects. * @return success */ - public boolean writeOrte(UserInfo userInfo, List orte) { + public boolean writeOrte(UserInfo userInfo, List orte) { return true; } @@ -144,7 +144,7 @@ * @param orte List of {@link LOrt} objects. * @return success */ - public boolean writeLOrte(UserInfo userInfo, LOrt ort) { + public boolean writeLOrte(UserInfo userInfo, LOrtszuordnung ort) { ort.setProbeId(this.currentProbeId); repository.create(ort, "land"); return true; diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/importer/laf/OrtCreator.java --- a/src/main/java/de/intevation/lada/importer/laf/OrtCreator.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/importer/laf/OrtCreator.java Thu Jan 21 09:01:57 2016 +0100 @@ -16,8 +16,8 @@ import org.apache.log4j.Logger; import de.intevation.lada.importer.ReportItem; -import de.intevation.lada.model.land.LOrt; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.land.LOrtszuordnung; +import de.intevation.lada.model.stamm.Ort; import de.intevation.lada.model.stamm.Staat; import de.intevation.lada.model.stamm.Verwaltungseinheit; import de.intevation.lada.util.annotation.RepositoryConfig; @@ -401,12 +401,12 @@ * * @return The new Ort. */ - public SOrt toOrt() { + public Ort toOrt() { if (this.ortCode != null && this.ortCode.length() > 0) { return null; } logger.debug("create a new ort"); - SOrt ort = new SOrt(); + Ort ort = new Ort(); repository.create(ort, "stamm"); this.ortId = ort.getId(); boolean koord = true; @@ -460,14 +460,14 @@ if (this.nuts != null && this.nuts.length() > 0) { ort.setNutsCode(nuts); } - else if (ort.getVerwaltungseinheitId() != null && - ort.getVerwaltungseinheitId().length() > 0) + else if (ort.getGemId() != null && + ort.getGemId().length() > 0) { QueryBuilder builder = new QueryBuilder( repository.entityManager("stamm"), Verwaltungseinheit.class); - builder.and("id", ort.getVerwaltungseinheitId()); + builder.and("id", ort.getGemId()); @SuppressWarnings("unchecked") List einheit = (List)repository.filter( @@ -478,7 +478,7 @@ ort.setNutsCode(einheit.get(0).getNuts()); } } - ort.setBeschreibung(beschreibung); + ort.setLangtext(beschreibung); if (this.hoehe != null) { ort.setHoeheLand(Float.valueOf(hoehe)); } @@ -494,7 +494,7 @@ * @param koord Set the coordinates or not. * @return The Ort object. */ - private SOrt setLandLang(SOrt ort, boolean koord) { + private Ort setLandLang(Ort ort, boolean koord) { QueryBuilder builder = new QueryBuilder( repository.entityManager("stamm"), @@ -526,7 +526,7 @@ * @param koord Set the coordinates or not. * @return The Ort object. */ - private SOrt setLandKurz(SOrt ort, boolean koord) { + private Ort setLandKurz(Ort ort, boolean koord) { QueryBuilder builder = new QueryBuilder( repository.entityManager("stamm"), @@ -558,7 +558,7 @@ * @param koord Set the coordinates or not. * @return The Ort object. */ - private SOrt setLandS(SOrt ort, boolean koord) { + private Ort setLandS(Ort ort, boolean koord) { ort.setStaatId(Integer.valueOf(this.landS)); if (koord) { QueryBuilder builder = @@ -592,7 +592,7 @@ * @param koord Set the coordinates or not. * @return The Ort object. */ - private SOrt setGemeinde(SOrt ort, boolean koord) { + private Ort setGemeinde(Ort ort, boolean koord) { QueryBuilder builder = new QueryBuilder( repository.entityManager("stamm"), @@ -607,7 +607,7 @@ this.warnings.add(new ReportItem("verwaltungseinheit", null, 631)); return ort; } - ort.setVerwaltungseinheitId(einheit.get(0).getId()); + ort.setGemId(einheit.get(0).getId()); if (koord) { ort.setKoordXExtern(einheit.get(0).getKoordXExtern()); ort.setKoordYExtern(einheit.get(0).getKoordYExtern()); @@ -623,8 +623,8 @@ * @param koord Set the coordinates or not. * @return The Ort object. */ - private SOrt setGemeindeS(SOrt ort, boolean koord) { - ort.setVerwaltungseinheitId(this.gemSchluessel); + private Ort setGemeindeS(Ort ort, boolean koord) { + ort.setGemId(this.gemSchluessel); if (koord) { QueryBuilder builder = new QueryBuilder( @@ -652,7 +652,7 @@ * @param ort The ort object. * @return The Ort object. */ - private SOrt setKoordinaten(SOrt ort) { + private Ort setKoordinaten(Ort ort) { String art = ""; String x = ""; String y = ""; @@ -685,7 +685,7 @@ } ort.setKoordXExtern(x); ort.setKoordYExtern(y); - ort.setKoordinatenartId(Integer.valueOf(art)); + ort.setKdaId(Integer.valueOf(art)); return ort; } @@ -695,7 +695,7 @@ * @param ort The ort object. * @return The Ort object. */ - private SOrt setKoordinatenS(SOrt ort) { + private Ort setKoordinatenS(Ort ort) { String art = ""; String x = ""; String y = ""; @@ -730,7 +730,7 @@ ort.setLongitude(Double.valueOf(x)); ort.setKoordYExtern(y); ort.setLatitude(Double.valueOf(y)); - ort.setKoordinatenartId(Integer.valueOf(art)); + ort.setKdaId(Integer.valueOf(art)); return ort; } @@ -739,31 +739,31 @@ * * @return The new LOrt object. */ - public LOrt toLOrt() { + public LOrtszuordnung toLOrt() { if (this.ortId == null && (this.ortCode == null || this.ortCode.length() == 0) ) { return null; } if(this.ortCode != null && this.ortCode.length() > 0) { - QueryBuilder builder = - new QueryBuilder( + QueryBuilder builder = + new QueryBuilder( repository.entityManager("stamm"), - SOrt.class); + Ort.class); builder.and("bezeichnung", this.ortCode); @SuppressWarnings("unchecked") - List orte= - (List)repository.filter( + List orte= + (List)repository.filter( builder.getQuery(), "stamm").getData(); if (orte != null && !orte.isEmpty()) { this.ortId = orte.get(0).getId(); } } - LOrt ort = new LOrt(); - ort.setOrt(BigInteger.valueOf(this.ortId)); + LOrtszuordnung ort = new LOrtszuordnung(); + ort.setOrtId(Long.valueOf(this.ortId)); ort.setProbeId(this.probeId); - ort.setOrtsTyp(this.ortTyp); + ort.setOrtszuordnungTyp(this.ortTyp); ort.setOrtszusatztext(this.zusatztext); return ort; } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/Ort.java --- a/src/main/java/de/intevation/lada/model/Ort.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.model; - -import java.io.Serializable; -import java.math.BigInteger; -import java.sql.Timestamp; - -import javax.persistence.Column; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.persistence.Table; -import javax.persistence.Transient; - - -/** - * The persistent class for the ort database table. - */ -@MappedSuperclass -@Table(name="ort") -public class Ort implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) - @Column(name="id", unique=true, nullable=false) - private Integer id; - - @Column(name="letzte_aenderung") - private Timestamp letzteAenderung; - - @Column(name="orts_typ") - private String ortsTyp; - - private String ortszusatztext; - - @Column(name="probe_id") - private Integer probeId; - - @Column(name="ort_id") - private BigInteger ort; - - @Transient - private boolean owner; - - @Transient - private boolean readonly; - - public Ort() { - } - - public Integer getId() { - return this.id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Timestamp getLetzteAenderung() { - return this.letzteAenderung; - } - - public void setLetzteAenderung(Timestamp letzteAenderung) { - this.letzteAenderung = letzteAenderung; - } - - public String getOrtsTyp() { - return this.ortsTyp; - } - - public void setOrtsTyp(String ortsTyp) { - this.ortsTyp = ortsTyp; - } - - public String getOrtszusatztext() { - return this.ortszusatztext; - } - - public void setOrtszusatztext(String ortszusatztext) { - this.ortszusatztext = ortszusatztext; - } - - public Integer getProbeId() { - return this.probeId; - } - - public void setProbeId(Integer probeId) { - this.probeId = probeId; - } - - public BigInteger getOrt() { - return this.ort; - } - - public void setOrt(BigInteger ort) { - this.ort = ort; - } - - public boolean isOwner() { - return owner; - } - - public void setOwner(boolean owner) { - this.owner = owner; - } - - public boolean isReadonly() { - return readonly; - } - - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/Ortszuordnung.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/Ortszuordnung.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,115 @@ +package de.intevation.lada.model; + +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Table; +import javax.persistence.Transient; + + +/** + * The persistent class for the ortszuordnung database table. + */ +@MappedSuperclass +@Table(name="ortszuordnung") +public class Ortszuordnung implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id", unique=true, nullable=false) + private Integer id; + + @Column(name="letzte_aenderung") + private Timestamp letzteAenderung; + + @Column(name="ort_id") + private Long ortId; + + @Column(name="ortszuordnung_typ") + private String ortszuordnungTyp; + + private String ortszusatztext; + + @Column(name="probe_id") + private Integer probeId; + + @Transient + private boolean owner; + + @Transient + private boolean readonly; + + public Ortszuordnung() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Timestamp getLetzteAenderung() { + return this.letzteAenderung; + } + + public void setLetzteAenderung(Timestamp letzteAenderung) { + this.letzteAenderung = letzteAenderung; + } + + public Long getOrtId() { + return this.ortId; + } + + public void setOrtId(Long ortId) { + this.ortId = ortId; + } + + public String getOrtszuordnungTyp() { + return this.ortszuordnungTyp; + } + + public void setOrtszuordnungTyp(String ortszuordnungTyp) { + this.ortszuordnungTyp = ortszuordnungTyp; + } + + public String getOrtszusatztext() { + return this.ortszusatztext; + } + + public void setOrtszusatztext(String ortszusatztext) { + this.ortszusatztext = ortszusatztext; + } + + public Integer getProbeId() { + return this.probeId; + } + + public void setProbeId(Integer probeId) { + this.probeId = probeId; + } + + public boolean isOwner() { + return owner; + } + + public void setOwner(boolean owner) { + this.owner = owner; + } + + public boolean isReadonly() { + return readonly; + } + + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/bund/Ort.java --- a/src/main/java/de/intevation/lada/model/bund/Ort.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.model.bund; - -import javax.persistence.Entity; -import javax.persistence.Table; - - -/** - * The persistent class for the ort database table. - */ -@Entity -@Table(name="ort") -public class Ort extends de.intevation.lada.model.Ort { - private static final long serialVersionUID = 1L; - -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/bund/Ortszuordnung.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/bund/Ortszuordnung.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,21 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.model.bund; + +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * The persistent class for the ortszuordung database table. + */ +@Entity +@Table(name="ortszuordung") +public class Ortszuordnung extends de.intevation.lada.model.Ortszuordnung { + private static final long serialVersionUID = 1L; + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/land/LOrt.java --- a/src/main/java/de/intevation/lada/model/land/LOrt.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.model.land; - -import java.sql.Timestamp; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.Transient; - - -/** - * The persistent class for the ort database table. - */ -@Entity -@Table(name="ort") -public class LOrt extends de.intevation.lada.model.Ort { - private static final long serialVersionUID = 1L; - - @Column(name="tree_modified", insertable=false, updatable=false) - private Timestamp treeModified; - - @OneToOne - @JoinColumn(name="probe_id", insertable=false, updatable=false) - private LProbe probe; - - @Transient - private Timestamp parentModified; - - public Timestamp getTreeModified() { - return treeModified; - } - - public void setTreeModified(Timestamp treeModified) { - this.treeModified = treeModified; - } - - public Timestamp getParentModified() { - if (this.parentModified == null && this.probe != null) { - return this.probe.getTreeModified(); - } - return this.parentModified; - } - - public void setParentModified(Timestamp parentModified) { - this.parentModified = parentModified; - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/land/LOrtszuordnung.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/land/LOrtszuordnung.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,52 @@ +package de.intevation.lada.model.land; + +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + + +/** + * The persistent class for the ortszuordnung database table. + */ +@Entity +@Table(name="ortszuordnung") +public class LOrtszuordnung extends de.intevation.lada.model.Ortszuordnung { + private static final long serialVersionUID = 1L; + + @OneToOne + @JoinColumn(name="probe_id", insertable=false, updatable=false) + private LProbe probe; + + @Column(name="tree_modified") + private Timestamp treeModified; + + @Transient + private Timestamp parentModified; + + public LOrtszuordnung() { + } + + public Timestamp getTreeModified() { + return this.treeModified; + } + + public void setTreeModified(Timestamp treeModified) { + this.treeModified = treeModified; + } + + public Timestamp getParentModified() { + if (this.parentModified == null && this.probe != null) { + return this.probe.getTreeModified(); + } + return this.parentModified; + } + + public void setParentModified(Timestamp parentModified) { + this.parentModified = parentModified; + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/DatensatzErzeuger.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/stamm/DatensatzErzeuger.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,93 @@ +package de.intevation.lada.model.stamm; + +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +/** + * The persistent class for the datensatz_erzeuger database table. + * + */ +@Entity +@Table(name="datensatz_erzeuger") +public class DatensatzErzeuger implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id", unique=true, nullable=false) + private Integer id; + + private String bezeichnung; + + @Column(name="da_erzeuger_id") + private String daErzeugerId; + + @Column(name="letzte_aenderung") + private Timestamp letzteAenderung; + + @Column(name="mst_id") + private String mstId; + + @Column(name="netzbetreiber_id") + private String netzbetreiberId; + + public DatensatzErzeuger() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getBezeichnung() { + return this.bezeichnung; + } + + public void setBezeichnung(String bezeichnung) { + this.bezeichnung = bezeichnung; + } + + public String getDaErzeugerId() { + return this.daErzeugerId; + } + + public void setDaErzeugerId(String daErzeugerId) { + this.daErzeugerId = daErzeugerId; + } + + public Timestamp getLetzteAenderung() { + return this.letzteAenderung; + } + + public void setLetzteAenderung(Timestamp letzteAenderung) { + this.letzteAenderung = letzteAenderung; + } + + public String getMstId() { + return this.mstId; + } + + public void setMstId(String mstId) { + this.mstId = mstId; + } + + public String getNetzbetreiberId() { + return this.netzbetreiberId; + } + + public void setNetzbetreiberId(String netzbetreiberId) { + this.netzbetreiberId = netzbetreiberId; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/MessprogrammKategorie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/stamm/MessprogrammKategorie.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,82 @@ +package de.intevation.lada.model.stamm; + +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +/** + * The persistent class for the messprogramm_kategorie database table. + * + */ +@Entity +@Table(name="messprogramm_kategorie") +public class MessprogrammKategorie implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id", unique=true, nullable=false) + private Integer id; + + private String bezeichnung; + + @Column(name="letzte_aenderung") + private Timestamp letzteAenderung; + + @Column(name="mpl_id") + private String mplId; + + @Column(name="netzbetreiber_id") + private String netzbetreiberId; + + public MessprogrammKategorie() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getBezeichnung() { + return this.bezeichnung; + } + + public void setBezeichnung(String bezeichnung) { + this.bezeichnung = bezeichnung; + } + + public Timestamp getLetzteAenderung() { + return this.letzteAenderung; + } + + public void setLetzteAenderung(Timestamp letzteAenderung) { + this.letzteAenderung = letzteAenderung; + } + + public String getMplId() { + return this.mplId; + } + + public void setMplId(String mplId) { + this.mplId = mplId; + } + + public String getNetzbetreiberId() { + return this.netzbetreiberId; + } + + public void setNetzbetreiberId(String netzbetreiberId) { + this.netzbetreiberId = netzbetreiberId; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/Ort.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/stamm/Ort.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,293 @@ +package de.intevation.lada.model.stamm; + +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +/** + * The persistent class for the ort database table. + * + */ +@Entity +@Table(name="ort") +public class Ort implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id", unique=true, nullable=false) + private Integer id; + + private String aktiv; + + @Column(name="anlage_id") + private Integer anlageId; + + private String berichtstext; + + @Column(name="gem_id") + private String gemId; + + @Column(name="hoehe_land") + private Float hoeheLand; + + @Column(name="kda_id") + private Integer kdaId; + + @Column(name="koord_x_extern") + private String koordXExtern; + + @Column(name="koord_y_extern") + private String koordYExtern; + + private String kurztext; + + private String langtext; + + private Double latitude; + + @Column(name="letzte_aenderung") + private Timestamp letzteAenderung; + + private Double longitude; + + @Column(name="mp_art") + private String mpArt; + + @Column(name="netzbetreiber_id") + private String netzbetreiberId; + + @Column(name="nuts_code") + private String nutsCode; + + @Column(name="ort_id") + private String ortId; + + @Column(name="ort_typ") + private Integer ortTyp; + + @Column(name="oz_id") + private Integer ozId; + + private String sektor; + + @Column(name="staat_id") + private Integer staatId; + + private String unscharf; + + private String zone; + + private String zustaendigkeit; + + public Ort() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getAktiv() { + return this.aktiv; + } + + public void setAktiv(String aktiv) { + this.aktiv = aktiv; + } + + public Integer getAnlageId() { + return this.anlageId; + } + + public void setAnlageId(Integer anlageId) { + this.anlageId = anlageId; + } + + public String getBerichtstext() { + return this.berichtstext; + } + + public void setBerichtstext(String berichtstext) { + this.berichtstext = berichtstext; + } + + public String getGemId() { + return this.gemId; + } + + public void setGemId(String gemId) { + this.gemId = gemId; + } + + public Float getHoeheLand() { + return this.hoeheLand; + } + + public void setHoeheLand(Float hoeheLand) { + this.hoeheLand = hoeheLand; + } + + public Integer getKdaId() { + return this.kdaId; + } + + public void setKdaId(Integer kdaId) { + this.kdaId = kdaId; + } + + public String getKoordXExtern() { + return this.koordXExtern; + } + + public void setKoordXExtern(String koordXExtern) { + this.koordXExtern = koordXExtern; + } + + public String getKoordYExtern() { + return this.koordYExtern; + } + + public void setKoordYExtern(String koordYExtern) { + this.koordYExtern = koordYExtern; + } + + public String getKurztext() { + return this.kurztext; + } + + public void setKurztext(String kurztext) { + this.kurztext = kurztext; + } + + public String getLangtext() { + return this.langtext; + } + + public void setLangtext(String langtext) { + this.langtext = langtext; + } + + public Double getLatitude() { + return this.latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + public Timestamp getLetzteAenderung() { + return this.letzteAenderung; + } + + public void setLetzteAenderung(Timestamp letzteAenderung) { + this.letzteAenderung = letzteAenderung; + } + + public Double getLongitude() { + return this.longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + public String getMpArt() { + return this.mpArt; + } + + public void setMpArt(String mpArt) { + this.mpArt = mpArt; + } + + public String getNetzbetreiberId() { + return this.netzbetreiberId; + } + + public void setNetzbetreiberId(String netzbetreiberId) { + this.netzbetreiberId = netzbetreiberId; + } + + public String getNutsCode() { + return this.nutsCode; + } + + public void setNutsCode(String nutsCode) { + this.nutsCode = nutsCode; + } + + public String getOrtId() { + return this.ortId; + } + + public void setOrtId(String ortId) { + this.ortId = ortId; + } + + public Integer getOrtTyp() { + return this.ortTyp; + } + + public void setOrtTyp(Integer ortTyp) { + this.ortTyp = ortTyp; + } + + public Integer getOzId() { + return this.ozId; + } + + public void setOzId(Integer ozId) { + this.ozId = ozId; + } + + public String getSektor() { + return this.sektor; + } + + public void setSektor(String sektor) { + this.sektor = sektor; + } + + public Integer getStaatId() { + return this.staatId; + } + + public void setStaatId(Integer staatId) { + this.staatId = staatId; + } + + public String getUnscharf() { + return this.unscharf; + } + + public void setUnscharf(String unscharf) { + this.unscharf = unscharf; + } + + public String getZone() { + return this.zone; + } + + public void setZone(String zone) { + this.zone = zone; + } + + public String getZustaendigkeit() { + return this.zustaendigkeit; + } + + public void setZustaendigkeit(String zustaendigkeit) { + this.zustaendigkeit = zustaendigkeit; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/OrtTyp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/stamm/OrtTyp.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,45 @@ +package de.intevation.lada.model.stamm; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + + +/** + * The persistent class for the ort_typ database table. + * + */ +@Entity +@Table(name="ort_typ") +public class OrtTyp implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + private Integer id; + + @Column(name="ort_typ") + private String ortTyp; + + public OrtTyp() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getOrtTyp() { + return this.ortTyp; + } + + public void setOrtTyp(String ortTyp) { + this.ortTyp = ortTyp; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/Probenehmer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/model/stamm/Probenehmer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,181 @@ +package de.intevation.lada.model.stamm; + +import java.io.Serializable; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + + +/** + * The persistent class for the probenehmer database table. + * + */ +@Entity +public class Probenehmer implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id", unique=true, nullable=false) + private Integer id; + + private String bearbeiter; + + private String bemerkung; + + private String betrieb; + + private String bezeichnung; + + @Column(name="kurz_bezeichnung") + private String kurzBezeichnung; + + @Column(name="letzte_aenderung") + private Timestamp letzteAenderung; + + @Column(name="netzbetreiber_id") + private String netzbetreiberId; + + private String ort; + + private String plz; + + @Column(name="prn_id") + private String prnId; + + private String strasse; + + private String telefon; + + private String tp; + + private String typ; + + public Probenehmer() { + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getBearbeiter() { + return this.bearbeiter; + } + + public void setBearbeiter(String bearbeiter) { + this.bearbeiter = bearbeiter; + } + + public String getBemerkung() { + return this.bemerkung; + } + + public void setBemerkung(String bemerkung) { + this.bemerkung = bemerkung; + } + + public String getBetrieb() { + return this.betrieb; + } + + public void setBetrieb(String betrieb) { + this.betrieb = betrieb; + } + + public String getBezeichnung() { + return this.bezeichnung; + } + + public void setBezeichnung(String bezeichnung) { + this.bezeichnung = bezeichnung; + } + + public String getKurzBezeichnung() { + return this.kurzBezeichnung; + } + + public void setKurzBezeichnung(String kurzBezeichnung) { + this.kurzBezeichnung = kurzBezeichnung; + } + + public Timestamp getLetzteAenderung() { + return this.letzteAenderung; + } + + public void setLetzteAenderung(Timestamp letzteAenderung) { + this.letzteAenderung = letzteAenderung; + } + + public String getNetzbetreiberId() { + return this.netzbetreiberId; + } + + public void setNetzbetreiberId(String netzbetreiberId) { + this.netzbetreiberId = netzbetreiberId; + } + + public String getOrt() { + return this.ort; + } + + public void setOrt(String ort) { + this.ort = ort; + } + + public String getPlz() { + return this.plz; + } + + public void setPlz(String plz) { + this.plz = plz; + } + + public String getPrnId() { + return this.prnId; + } + + public void setPrnId(String prnId) { + this.prnId = prnId; + } + + public String getStrasse() { + return this.strasse; + } + + public void setStrasse(String strasse) { + this.strasse = strasse; + } + + public String getTelefon() { + return this.telefon; + } + + public void setTelefon(String telefon) { + this.telefon = telefon; + } + + public String getTp() { + return this.tp; + } + + public void setTp(String tp) { + this.tp = tp; + } + + public String getTyp() { + return this.typ; + } + + public void setTyp(String typ) { + this.typ = typ; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/model/stamm/SOrt.java --- a/src/main/java/de/intevation/lada/model/stamm/SOrt.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.model.stamm; - -import java.io.Serializable; -import java.sql.Timestamp; - -import javax.inject.Inject; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Transient; - -import org.apache.log4j.Logger; - - -/** - * The persistent class for the ort database table. - */ -@Entity -@Table(name="ort") -public class SOrt implements Serializable { - private static final long serialVersionUID = 1L; - @Inject - @Transient - private Logger logger = Logger.getLogger(SOrt.class); - - @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) - @Column(name="id", nullable=false, insertable=false) - private Integer id; - - private String beschreibung; - - private String bezeichnung; - - @Column(name="hoehe_land") - private Float hoeheLand; - - @Column(name="koord_x_extern") - private String koordXExtern; - - @Column(name="koord_y_extern") - private String koordYExtern; - - private Double latitude; - - @Column(name="letzte_aenderung") - private Timestamp letzteAenderung; - - private Double longitude; - - @Column(name="nuts_code") - private String nutsCode; - - @Column(name="o_typ") - private String oTyp; - - private String unscharf; - - @Column(name="kda_id") - private Integer koordinatenartId; - - @Column(name="netzbetreiber_id") - private String netzbetreiberId; - - @Column(name="staat_id") - private Integer staatId; - - @Column(name="gem_id") - private String verwaltungseinheitId; - - public SOrt() { - } - - public Integer getId() { - return this.id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getBeschreibung() { - return this.beschreibung; - } - - public void setBeschreibung(String beschreibung) { - this.beschreibung = beschreibung; - } - - public String getBezeichnung() { - return this.bezeichnung; - } - - public void setBezeichnung(String bezeichnung) { - this.bezeichnung = bezeichnung; - } - - public Float getHoeheLand() { - return this.hoeheLand; - } - - public void setHoeheLand(Float hoeheLand) { - this.hoeheLand = hoeheLand; - } - - public String getKoordXExtern() { - return this.koordXExtern; - } - - public void setKoordXExtern(String koordXExtern) { - this.koordXExtern = koordXExtern; - } - - public String getKoordYExtern() { - return this.koordYExtern; - } - - public void setKoordYExtern(String koordYExtern) { - this.koordYExtern = koordYExtern; - } - - public Double getLatitude() { - return this.latitude; - } - - public void setLatitude(double latitude) { - this.latitude = latitude; - } - - public Timestamp getLetzteAenderung() { - logger.debug("get date: " + this.letzteAenderung.toString()); - return this.letzteAenderung; - } - - public void setLetzteAenderung(Timestamp letzteAenderung) { - logger.debug("set date: " + letzteAenderung.toString()); - this.letzteAenderung = letzteAenderung; - } - - public Double getLongitude() { - return this.longitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - - public String getNutsCode() { - return this.nutsCode; - } - - public void setNutsCode(String nutsCode) { - this.nutsCode = nutsCode; - } - - public String getOTyp() { - return this.oTyp; - } - - public void setOTyp(String oTyp) { - this.oTyp = oTyp; - } - - public String getUnscharf() { - return this.unscharf; - } - - public void setUnscharf(String unscharf) { - this.unscharf = unscharf; - } - - public Integer getKoordinatenartId() { - return this.koordinatenartId; - } - - public void setKoordinatenartId(Integer koordinatenartId) { - this.koordinatenartId = koordinatenartId; - } - - public String getNetzbetreiberId() { - return this.netzbetreiberId; - } - - public void setNetzbetreiberId(String netzbetreiberId) { - this.netzbetreiberId = netzbetreiberId; - } - - public Integer getStaatId() { - return this.staatId; - } - - public void setStaatId(Integer staatId) { - this.staatId = staatId; - } - - public String getVerwaltungseinheitId() { - return this.verwaltungseinheitId; - } - - public void setVerwaltungseinheitId(String verwaltungseinheitId) { - this.verwaltungseinheitId = verwaltungseinheitId; - } - -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/query/QueryConfig.java --- a/src/main/java/de/intevation/lada/query/QueryConfig.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/query/QueryConfig.java Thu Jan 21 09:01:57 2016 +0100 @@ -21,12 +21,13 @@ */ public class QueryConfig { - String id; - String name; - String description; - String sql; - List filters; - List results; + private String id; + private String name; + private String description; + private String sql; + private String type; + private List filters; + private List results; public QueryConfig() { @@ -89,6 +90,20 @@ } /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** * @return the filter */ public List getFilters() { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/query/QueryTools.java --- a/src/main/java/de/intevation/lada/query/QueryTools.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/query/QueryTools.java Thu Jan 21 09:01:57 2016 +0100 @@ -35,6 +35,7 @@ { private static String PROBE_CONFIG = "/probequery.json"; private static String MESSPROGRAMM_CONFIG = "/messprogrammquery.json"; + private static String STAMMDATEN_CONFIG = "/stammdatenquery.json"; /** * Read the config file using the system property * "de.intevation.lada.sqlconfig". @@ -79,6 +80,7 @@ qConf.setName(query.getString("name")); qConf.setDescription(query.getString("description")); qConf.setSql(query.getString("sql")); + qConf.setType(query.getString("type")); JsonArray filters = query.getJsonArray("filters"); List qFilters = new ArrayList(); for (int j = 0; j < filters.size(); j++) { @@ -120,6 +122,10 @@ return getConfig(MESSPROGRAMM_CONFIG); } + public static List getStammdatenConfig() { + return getConfig(STAMMDATEN_CONFIG); + } + /** * Get a query by id. * First reads the config file and returns the {@link QueryConfig} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/KommentarMService.java --- a/src/main/java/de/intevation/lada/rest/KommentarMService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/KommentarMService.java Thu Jan 21 09:01:57 2016 +0100 @@ -66,7 +66,7 @@ * * @author Raimund Renkert */ -@Path("mkommentar") +@Path("rest/mkommentar") @RequestScoped public class KommentarMService { @@ -120,11 +120,8 @@ LMessung.class, id, "land"); - if (!authorization.isAuthorized( - authorization.getInfo(request), messung)) { - if (!authorization.isAuthorized(id, LMessung.class)) { - return new Response(false, 699, null); - } + if (!authorization.isAuthorized(request, messung, RequestMethod.GET, LMessung.class)) { + return new Response(false, 699, null); } QueryBuilder builder = @@ -162,10 +159,8 @@ LMessung.class, kommentar.getMessungsId(), "land"); - if (!authorization.isAuthorized(authorization.getInfo(request), messung)) { - if (!authorization.isAuthorized(messung.getId(), LMessung.class)) { - return new Response(false, 699, null); - } + if (!authorization.isAuthorized(request, messung, RequestMethod.GET, LMessung.class)) { + return new Response(false, 699, null); } return authorization.filter( diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/KommentarPService.java --- a/src/main/java/de/intevation/lada/rest/KommentarPService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/KommentarPService.java Thu Jan 21 09:01:57 2016 +0100 @@ -67,7 +67,7 @@ * * @author Raimund Renkert */ -@Path("pkommentar") +@Path("rest/pkommentar") @RequestScoped public class KommentarPService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/MessprogrammMmtService.java --- a/src/main/java/de/intevation/lada/rest/MessprogrammMmtService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MessprogrammMmtService.java Thu Jan 21 09:01:57 2016 +0100 @@ -66,7 +66,7 @@ * * @author Raimund Renkert */ -@Path("messprogrammmmt") +@Path("rest/messprogrammmmt") @RequestScoped public class MessprogrammMmtService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/MessprogrammService.java --- a/src/main/java/de/intevation/lada/rest/MessprogrammService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MessprogrammService.java Thu Jan 21 09:01:57 2016 +0100 @@ -92,7 +92,7 @@ * * @author Raimund Renkert */ -@Path("messprogramm") +@Path("rest/messprogramm") @RequestScoped public class MessprogrammService { @@ -326,7 +326,9 @@ return new Response(false, 699, null); } messprogramm.setLetzteAenderung(new Timestamp(new Date().getTime())); - messprogramm = factory.findUmweltId(messprogramm); + if (messprogramm.getUmwId() == null || messprogramm.getUmwId().equals("")) { + messprogramm = factory.findUmweltId(messprogramm); + } Response response = defaultRepo.update(messprogramm, "land"); Response updated = defaultRepo.getById( Messprogramm.class, diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/MessungService.java --- a/src/main/java/de/intevation/lada/rest/MessungService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MessungService.java Thu Jan 21 09:01:57 2016 +0100 @@ -84,7 +84,7 @@ * * @author Raimund Renkert */ -@Path("messung") +@Path("rest/messung") @RequestScoped public class MessungService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/MesswertService.java --- a/src/main/java/de/intevation/lada/rest/MesswertService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MesswertService.java Thu Jan 21 09:01:57 2016 +0100 @@ -84,7 +84,7 @@ * * @author Raimund Renkert */ -@Path("messwert") +@Path("rest/messwert") @RequestScoped public class MesswertService { @@ -155,10 +155,13 @@ LMessung.class, id, "land"); - if (!authorization.isAuthorized(authorization.getInfo(request), messung)) { - if (!authorization.isAuthorized(id, LMessung.class)) { - return new Response(false, 699, null); - } + if (!authorization.isAuthorized( + request, + messung, + RequestMethod.GET, + LMessung.class) + ) { + return new Response(false, 697, null); } QueryBuilder builder = new QueryBuilder( @@ -195,10 +198,13 @@ LMessung.class, messwert.getMessungsId(), "land"); - if (!authorization.isAuthorized(authorization.getInfo(request), messung)) { - if (!authorization.isAuthorized(messung.getId(), LMessung.class)) { - return new Response(false, 699, null); - } + if (!authorization.isAuthorized( + request, + messung, + RequestMethod.GET, + LMessung.class) + ) { + return new Response(false, 699, null); } Violation violation = validator.validate(messwert); if (violation.hasErrors() || violation.hasWarnings()) { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/OrtService.java --- a/src/main/java/de/intevation/lada/rest/OrtService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/OrtService.java Thu Jan 21 09:01:57 2016 +0100 @@ -31,7 +31,7 @@ import de.intevation.lada.lock.LockConfig; import de.intevation.lada.lock.LockType; import de.intevation.lada.lock.ObjectLocker; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.auth.Authorization; @@ -79,7 +79,7 @@ * * @author Raimund Renkert */ -@Path("ort") +@Path("rest/ortszuordnung") @RequestScoped public class OrtService { @@ -136,18 +136,18 @@ MultivaluedMap params = info.getQueryParameters(); if (params.isEmpty() || !params.containsKey("probeId")) { logger.debug("get all"); - return defaultRepo.getAll(LOrt.class, "land"); + return defaultRepo.getAll(LOrtszuordnung.class, "land"); } String probeId = params.getFirst("probeId"); - QueryBuilder builder = - new QueryBuilder( + QueryBuilder builder = + new QueryBuilder( defaultRepo.entityManager("land"), - LOrt.class); + LOrtszuordnung.class); builder.and("probeId", probeId); return authorization.filter( request, defaultRepo.filter(builder.getQuery(), "land"), - LOrt.class); + LOrtszuordnung.class); } /** @@ -168,8 +168,8 @@ @PathParam("id") String id ) { Response response = - defaultRepo.getById(LOrt.class, Integer.valueOf(id), "land"); - LOrt ort = (LOrt)response.getData(); + defaultRepo.getById(LOrtszuordnung.class, Integer.valueOf(id), "land"); + LOrtszuordnung ort = (LOrtszuordnung)response.getData(); Violation violation = validator.validate(ort); if (violation.hasErrors() || violation.hasWarnings()) { response.setErrors(violation.getErrors()); @@ -178,7 +178,7 @@ return authorization.filter( request, response, - LOrt.class); + LOrtszuordnung.class); } /** @@ -209,13 +209,13 @@ public Response create( @Context HttpHeaders headers, @Context HttpServletRequest request, - LOrt ort + LOrtszuordnung ort ) { if (!authorization.isAuthorized( request, ort, RequestMethod.POST, - LOrt.class)) { + LOrtszuordnung.class)) { return new Response(false, 699, null); } Violation violation = validator.validate(ort); @@ -235,7 +235,7 @@ return authorization.filter( request, response, - LOrt.class); + LOrtszuordnung.class); } /** @@ -266,13 +266,13 @@ public Response update( @Context HttpHeaders headers, @Context HttpServletRequest request, - LOrt ort + LOrtszuordnung ort ) { if (!authorization.isAuthorized( request, ort, RequestMethod.PUT, - LOrt.class)) { + LOrtszuordnung.class)) { return new Response(false, 699, null); } if (lock.isLocked(ort)) { @@ -289,8 +289,8 @@ ort.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(ort, "land"); Response updated = defaultRepo.getById( - LOrt.class, - ((LOrt)response.getData()).getId(), "land"); + LOrtszuordnung.class, + ((LOrtszuordnung)response.getData()).getId(), "land"); if(violation.hasWarnings()) { updated.setWarnings(violation.getWarnings()); } @@ -298,7 +298,7 @@ return authorization.filter( request, updated, - LOrt.class); + LOrtszuordnung.class); } /** @@ -320,13 +320,13 @@ ) { /* Get the messwert object by id*/ Response object = - defaultRepo.getById(LOrt.class, Integer.valueOf(id), "land"); - LOrt ortObj = (LOrt)object.getData(); + defaultRepo.getById(LOrtszuordnung.class, Integer.valueOf(id), "land"); + LOrtszuordnung ortObj = (LOrtszuordnung)object.getData(); if (!authorization.isAuthorized( request, ortObj, RequestMethod.PUT, - LOrt.class)) { + LOrtszuordnung.class)) { return new Response(false, 699, null); } if (lock.isLocked(ortObj)) { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/ProbeService.java --- a/src/main/java/de/intevation/lada/rest/ProbeService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/ProbeService.java Thu Jan 21 09:01:57 2016 +0100 @@ -111,7 +111,7 @@ * * @author Raimund Renkert */ -@Path("probe") +@Path("rest/probe") @RequestScoped public class ProbeService { @@ -238,13 +238,13 @@ boolean readOnly = authorization.isReadOnly((Integer)entry.get("id")); entry.put("readonly", readOnly); - UserInfo ui = authorization.getInfo(request); QueryBuilder builder = new QueryBuilder( defaultRepo.entityManager("land"), LProbe.class); builder.and("id", (Integer)entry.get("id")); Response r = defaultRepo.filter(builder.getQuery(), "land"); List probe = (List)r.getData(); - entry.put("owner", authorization.isAuthorized(ui, probe.get(0))); + entry.put("owner", authorization.isAuthorized( + request, probe.get(0), RequestMethod.GET, LProbe.class)); } return new Response(true, 200, subList, result.size()); } @@ -450,7 +450,9 @@ if (lock.isLocked(probe)) { return new Response(false, 697, null); } - probe = factory.findMediaDesk(probe); + if (probe.getMediaDesk() == null || probe.getMediaDesk() == "") { + probe = factory.findMediaDesk(probe); + } Violation violation = validator.validate(probe); if (violation.hasErrors()) { Response response = new Response(false, 604, null); @@ -458,7 +460,9 @@ response.setWarnings(violation.getWarnings()); return response; } - factory.findUmweltId(probe); + if (probe.getUmwId() == null || probe.getUmwId() == "") { + factory.findUmweltId(probe); + } probe.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(probe, "land"); Response updated = defaultRepo.getById( diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/QueryService.java --- a/src/main/java/de/intevation/lada/rest/QueryService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/QueryService.java Thu Jan 21 09:01:57 2016 +0100 @@ -46,7 +46,7 @@ * * @author Raimund Renkert */ -@Path("/query") +@Path("rest/query") @RequestScoped public class QueryService { @@ -69,4 +69,14 @@ public Response getMessprogramm() { return new Response(true, 200, QueryTools.getMessprogrammConfig()); } + + /** + * Request all configured stammdaten queries. + */ + @GET + @Path("/stammdaten") + @Produces("application/json") + public Response getStammdaten() { + return new Response(true, 200, QueryTools.getStammdatenConfig()); + } } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/StatusService.java --- a/src/main/java/de/intevation/lada/rest/StatusService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/StatusService.java Thu Jan 21 09:01:57 2016 +0100 @@ -7,9 +7,9 @@ */ package de.intevation.lada.rest; +import java.sql.Timestamp; +import java.util.Date; import java.util.List; -import java.util.Date; -import java.sql.Timestamp; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -83,7 +83,7 @@ * * @author Raimund Renkert */ -@Path("status") +@Path("rest/status") @RequestScoped public class StatusService { @@ -151,10 +151,12 @@ LMessung.class, id, "land"); - if (!authorization.isAuthorized(authorization.getInfo(request), messung)) { - if (!authorization.isAuthorized(id, LMessung.class)) { - return new Response(false, 699, null); - } + if (!authorization.isAuthorized( + request, + messung, + RequestMethod.GET, + LMessung.class)) { + return new Response(false, 697, null); } QueryBuilder builder = @@ -358,7 +360,7 @@ @Context HttpServletRequest request, LStatusProtokoll status ) { - return null; + return new Response(false, 699, null); } /** diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/UserService.java --- a/src/main/java/de/intevation/lada/rest/UserService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/UserService.java Thu Jan 21 09:01:57 2016 +0100 @@ -52,7 +52,7 @@ * * @author Raimund Renkert */ -@Path("user") +@Path("rest/user") @RequestScoped public class UserService{ diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/VersionService.java --- a/src/main/java/de/intevation/lada/rest/VersionService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/VersionService.java Thu Jan 21 09:01:57 2016 +0100 @@ -42,7 +42,7 @@ * * @author Raimund Renkert */ -@Path("version") +@Path("rest/version") @RequestScoped public class VersionService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/ZusatzwertService.java --- a/src/main/java/de/intevation/lada/rest/ZusatzwertService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/ZusatzwertService.java Thu Jan 21 09:01:57 2016 +0100 @@ -75,7 +75,7 @@ * * @author Raimund Renkert */ -@Path("zusatzwert") +@Path("rest/zusatzwert") @RequestScoped public class ZusatzwertService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/exporter/LafExportService.java --- a/src/main/java/de/intevation/lada/rest/exporter/LafExportService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/exporter/LafExportService.java Thu Jan 21 09:01:57 2016 +0100 @@ -47,7 +47,7 @@ * * @author Raimund Renkert */ -@Path("export") +@Path("data/laf/export") @RequestScoped public class LafExportService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/importer/LafImportService.java --- a/src/main/java/de/intevation/lada/rest/importer/LafImportService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/importer/LafImportService.java Thu Jan 21 09:01:57 2016 +0100 @@ -34,7 +34,7 @@ * * @author Raimund Renkert */ -@Path("import") +@Path("data/laf/import") @RequestScoped public class LafImportService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/DatenbasisService.java --- a/src/main/java/de/intevation/lada/rest/stamm/DatenbasisService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/DatenbasisService.java Thu Jan 21 09:01:57 2016 +0100 @@ -49,7 +49,7 @@ * * @author Raimund Renkert */ -@Path("datenbasis") +@Path("rest/datenbasis") @RequestScoped public class DatenbasisService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,176 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.rest.stamm; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import de.intevation.lada.model.stamm.DatensatzErzeuger; +import de.intevation.lada.util.annotation.AuthorizationConfig; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.auth.Authorization; +import de.intevation.lada.util.auth.AuthorizationType; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +/** + * REST service for DatensatzErzeuger objects. + *

+ * The services produce data in the application/json media type. + * A typical response holds information about the action performed and the data. + *

+ * 
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "bezeichnung": [string],
+ *      "daErzeugerId": [string],
+ *      "letzteAenderung": [timestamp],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * 
+ * 
+ * + * @author Raimund Renkert + */ +@Path("rest/datensatzerzeuger") +@RequestScoped +public class DatensatzErzeugerService { + + /** + * The data repository granting read access. + */ + @Inject + @RepositoryConfig(type=RepositoryType.RW) + private Repository repository; + + @Inject + @AuthorizationConfig(type=AuthorizationType.HEADER) + private Authorization authorization; + + /** + * Get all Datenbasis objects. + *

+ * Example: http://example.com/datenbasis + * + * @return Response object containing all Datenbasis objects. + */ + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response get( + @Context HttpHeaders headers, + @Context UriInfo info + ) { + return repository.getAll(DatensatzErzeuger.class, "stamm"); + } + + /** + * Get a single Datenbasis object by id. + *

+ * The id is appended to the URL as a path parameter. + *

+ * Example: http://example.com/datenbasis/{id} + * + * @return Response object containing a single Datenabasis. + */ + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getById( + @Context HttpHeaders headers, + @PathParam("id") String id + ) { + return repository.getById( + DatensatzErzeuger.class, + Integer.valueOf(id), + "stamm"); + } + + @POST + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response create( + @Context HttpServletRequest request, + DatensatzErzeuger datensatzerzeuger + ) { + if (!authorization.isAuthorized( + request, + datensatzerzeuger, + RequestMethod.POST, + DatensatzErzeuger.class) + ) { + return new Response(false, 699, datensatzerzeuger); + } + + return repository.create(datensatzerzeuger, "stamm"); + } + + @PUT + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response update( + @Context HttpServletRequest request, + DatensatzErzeuger datensatzerzeuger + ) { + if (!authorization.isAuthorized( + request, + datensatzerzeuger, + RequestMethod.PUT, + DatensatzErzeuger.class) + ) { + return new Response(false, 699, datensatzerzeuger); + } + + return repository.update(datensatzerzeuger, "stamm"); + } + + @DELETE + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response delete( + @Context HttpServletRequest request, + @PathParam("id") String id + ) { + DatensatzErzeuger datensatzerzeuger = repository.getByIdPlain( + DatensatzErzeuger.class, Integer.valueOf(id), "stamm"); + if (datensatzerzeuger == null || + !authorization.isAuthorized( + request, + datensatzerzeuger, + RequestMethod.DELETE, + DatensatzErzeuger.class + ) + ) { + return new Response(false, 699, null); + } + return repository.delete(datensatzerzeuger, "stamm"); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java --- a/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java Thu Jan 21 09:01:57 2016 +0100 @@ -62,7 +62,7 @@ * * @author Raimund Renkert */ -@Path("deskriptor") +@Path("rest/deskriptor") @RequestScoped public class DeskriptorService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/KoordinatenartService.java --- a/src/main/java/de/intevation/lada/rest/stamm/KoordinatenartService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/KoordinatenartService.java Thu Jan 21 09:01:57 2016 +0100 @@ -49,7 +49,7 @@ * * @author Raimund Renkert */ -@Path("koordinatenart") +@Path("rest/koordinatenart") @RequestScoped public class KoordinatenartService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/LocationService.java --- a/src/main/java/de/intevation/lada/rest/stamm/LocationService.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.rest.stamm; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.UriInfo; - -import de.intevation.lada.model.stamm.SOrt; -import de.intevation.lada.util.annotation.RepositoryConfig; -import de.intevation.lada.util.data.QueryBuilder; -import de.intevation.lada.util.data.Repository; -import de.intevation.lada.util.data.RepositoryType; -import de.intevation.lada.util.rest.Response; - -/** - * REST service for SOrt objects. - *

- * The services produce data in the application/json media type. - * A typical response holds information about the action performed and the data. - *

- * 
- * {
- *  "success": [boolean];
- *  "message": [string],
- *  "data":[{
- *      "id": [number],
- *      "beschreibung": [string],
- *      "bezeichnung": [string],
- *      "hoeheLand": [number],
- *      "koordXExtern": [string],
- *      "koordYExtern": [string],
- *      "latitude": [number],
- *      "letzteAenderung": [timestamp],
- *      "longitude": [number],
- *      "nutsCode": [string],
- *      "unscharf": [string],
- *      "koordinatenartId": [number],
- *      "netzbetreiberId": [number],
- *      "staatId": [number],
- *      "verwaltungseinheitId": [string],
- *      "otyp": [string]
- *  }],
- *  "errors": [object],
- *  "warnings": [object],
- *  "readonly": [boolean],
- *  "totalCount": [number]
- * }
- * 
- * 
- * - * @author Raimund Renkert - */ -@Path("location") -@RequestScoped -public class LocationService { - - /** - * The data repository granting read/write access. - */ - @Inject - @RepositoryConfig(type=RepositoryType.RW) - private Repository defaultRepo; - - /** - * Get all SOrt objects. - *

- * The requested objects can be filtered using a URL parameter named - * ortId. - *

- * Example: http://example.com/location?ortId=[ID] - * - * @return Response object containing all (filtered) SOrt objects. - */ - @GET - @Path("/") - @Produces(MediaType.APPLICATION_JSON) - public Response get( - @Context HttpHeaders headers, - @Context UriInfo info - ) { - MultivaluedMap params = info.getQueryParameters(); - if (params.isEmpty() || !params.containsKey("ortId")) { - return defaultRepo.getAll(SOrt.class, "stamm"); - } - String ortId = params.getFirst("ortId"); - QueryBuilder builder = - new QueryBuilder( - defaultRepo.entityManager("stamm"), - SOrt.class); - builder.and("ortId", ortId); - return defaultRepo.filter(builder.getQuery(), "stamm"); - } - - /** - * Get a single SOrt object by id. - *

- * The id is appended to the URL as a path parameter. - *

- * Example: http://example.com/location/{id} - * - * @return Response object containing a single SOrt. - */ - @GET - @Path("/{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response getById( - @Context HttpHeaders headers, - @PathParam("id") String id - ) { - return defaultRepo.getById( - SOrt.class, - Integer.valueOf(id), - "stamm"); - } - - /** - * Create a SOrt object. - *

- * The new object is embedded in the post data as JSON formatted string. - *

- *

-     * 
-     * {
-     *  "bezeichnung": [string],
-     *  "beschreibung": [string],
-     *  "unscharf": [string],
-     *  "nutsCode": [string],
-     *  "koordXExtern": [string],
-     *  "koordYExtern": [string],
-     *  "hoeheLand": [string],
-     *  "longitude": [number],
-     *  "latitude": [number],
-     *  "staatId": [number],
-     *  "verwaltungseinheitId": [string],
-     *  "otyp": [string],
-     *  "letzteAenderung": [date]
-     * }
-     * 
-     * 
- * @return A response object containing the created SOrt. - */ - @POST - @Path("/") - @Produces(MediaType.APPLICATION_JSON) - public Response create( - @Context HttpHeaders headers, - SOrt ort - ) { - /* Persist the new object*/ - return defaultRepo.create(ort, "stamm"); - } - - /** - * Update an existing SOrt object. - *

- * The object to update should come as JSON formatted string. - *

-     * 
-     * {
-     *  "id": [number],
-     *  "bezeichnung": [string],
-     *  "beschreibung": [string],
-     *  "unscharf": [string],
-     *  "nutsCode": [string],
-     *  "koordXExtern": [string],
-     *  "koordYExtern": [string],
-     *  "hoeheLand": [number],
-     *  "longitude": [number],
-     *  "latitude": [number],
-     *  "staatId": [number],
-     *  "verwaltungseinheitId": [string],
-     *  "otyp": [string],
-     *  "letzteAenderung": [date]
-     * }
-     * 
-     * 
- * - * @return Response object containing the updated SOrt object. - */ - @PUT - @Path("/{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response update(@Context HttpHeaders headers, SOrt ort) { - Response response = defaultRepo.update(ort, "stamm"); - Response updated = defaultRepo.getById( - SOrt.class, - ((SOrt)response.getData()).getId(), "stamm"); - return updated; - } - - /** - * Delete an existing SOrt object by id. - *

- * The id is appended to the URL as a path parameter. - *

- * Example: http://example.com/location/{id} - * - * @return Response object. - */ - @DELETE - @Path("/{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response delete( - @Context HttpHeaders headers, - @PathParam("id") String id - ) { - /* Get the object by id*/ - Response object = - defaultRepo.getById(SOrt.class, Integer.valueOf(id), "stamm"); - SOrt ortObj = (SOrt)object.getData(); - /* Delete the object*/ - return defaultRepo.delete(ortObj, "stamm"); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/MesseinheitService.java --- a/src/main/java/de/intevation/lada/rest/stamm/MesseinheitService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/MesseinheitService.java Thu Jan 21 09:01:57 2016 +0100 @@ -51,7 +51,7 @@ * * @author Raimund Renkert */ -@Path("messeinheit") +@Path("rest/messeinheit") @RequestScoped public class MesseinheitService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java --- a/src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java Thu Jan 21 09:01:57 2016 +0100 @@ -63,7 +63,7 @@ * * @author Raimund Renkert */ -@Path("messgroesse") +@Path("rest/messgroesse") @RequestScoped public class MessgroesseService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/MessmethodeService.java --- a/src/main/java/de/intevation/lada/rest/stamm/MessmethodeService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/MessmethodeService.java Thu Jan 21 09:01:57 2016 +0100 @@ -49,7 +49,7 @@ * * @author Raimund Renkert */ -@Path("messmethode") +@Path("rest/messmethode") @RequestScoped public class MessmethodeService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,177 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.rest.stamm; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import de.intevation.lada.model.stamm.DatensatzErzeuger; +import de.intevation.lada.model.stamm.MessprogrammKategorie; +import de.intevation.lada.util.annotation.AuthorizationConfig; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.auth.Authorization; +import de.intevation.lada.util.auth.AuthorizationType; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +/** + * REST service for DatensatzErzeuger objects. + *

+ * The services produce data in the application/json media type. + * A typical response holds information about the action performed and the data. + *

+ * 
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "bezeichnung": [string],
+ *      "daErzeugerId": [string],
+ *      "letzteAenderung": [timestamp],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * 
+ * 
+ * + * @author Raimund Renkert + */ +@Path("rest/messprogrammkategorie") +@RequestScoped +public class MessprogrammKategorieService { + + /** + * The data repository granting read access. + */ + @Inject + @RepositoryConfig(type=RepositoryType.RW) + private Repository repository; + + @Inject + @AuthorizationConfig(type=AuthorizationType.HEADER) + private Authorization authorization; + + /** + * Get all Datenbasis objects. + *

+ * Example: http://example.com/messprogrammkategorie + * + * @return Response object containing all objects. + */ + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response get( + @Context HttpHeaders headers, + @Context UriInfo info + ) { + return repository.getAll(MessprogrammKategorie.class, "stamm"); + } + + /** + * Get a single object by id. + *

+ * The id is appended to the URL as a path parameter. + *

+ * Example: http://example.com/messprogrammkategorie/{id} + * + * @return Response object containing a single object. + */ + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getById( + @Context HttpHeaders headers, + @PathParam("id") String id + ) { + return repository.getById( + MessprogrammKategorie.class, + Integer.valueOf(id), + "stamm"); + } + + @POST + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response create( + @Context HttpServletRequest request, + MessprogrammKategorie kategorie + ) { + if (!authorization.isAuthorized( + request, + kategorie, + RequestMethod.POST, + MessprogrammKategorie.class) + ) { + return new Response(false, 699, kategorie); + } + + return repository.create(kategorie, "stamm"); + } + + @PUT + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response update( + @Context HttpServletRequest request, + MessprogrammKategorie kategorie + ) { + if (!authorization.isAuthorized( + request, + kategorie, + RequestMethod.PUT, + MessprogrammKategorie.class) + ) { + return new Response(false, 699, kategorie); + } + + return repository.update(kategorie, "stamm"); + } + + @DELETE + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response delete( + @Context HttpServletRequest request, + @PathParam("id") String id + ) { + MessprogrammKategorie kategorie = repository.getByIdPlain( + MessprogrammKategorie.class, Integer.valueOf(id), "stamm"); + if (kategorie == null || + !authorization.isAuthorized( + request, + kategorie, + RequestMethod.DELETE, + MessprogrammKategorie.class + ) + ) { + return new Response(false, 699, null); + } + return repository.delete(kategorie, "stamm"); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/MessstelleService.java --- a/src/main/java/de/intevation/lada/rest/stamm/MessstelleService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/MessstelleService.java Thu Jan 21 09:01:57 2016 +0100 @@ -56,7 +56,7 @@ * * @author Raimund Renkert */ -@Path("messstelle") +@Path("rest/messstelle") @RequestScoped public class MessstelleService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/NetzbetreiberService.java --- a/src/main/java/de/intevation/lada/rest/stamm/NetzbetreiberService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/NetzbetreiberService.java Thu Jan 21 09:01:57 2016 +0100 @@ -61,7 +61,7 @@ * * @author Raimund Renkert */ -@Path("netzbetreiber") +@Path("rest/netzbetreiber") @RequestScoped public class NetzbetreiberService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/OrtService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,266 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.rest.stamm; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; + +import de.intevation.lada.model.stamm.Ort; +import de.intevation.lada.util.annotation.AuthorizationConfig; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.auth.Authorization; +import de.intevation.lada.util.auth.AuthorizationType; +import de.intevation.lada.util.data.QueryBuilder; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +/** + * REST service for SOrt objects. + *

+ * The services produce data in the application/json media type. + * A typical response holds information about the action performed and the data. + *

+ * 
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "beschreibung": [string],
+ *      "bezeichnung": [string],
+ *      "hoeheLand": [number],
+ *      "koordXExtern": [string],
+ *      "koordYExtern": [string],
+ *      "latitude": [number],
+ *      "letzteAenderung": [timestamp],
+ *      "longitude": [number],
+ *      "nutsCode": [string],
+ *      "unscharf": [string],
+ *      "koordinatenartId": [number],
+ *      "netzbetreiberId": [number],
+ *      "staatId": [number],
+ *      "verwaltungseinheitId": [string],
+ *      "otyp": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * 
+ * 
+ * + * @author Raimund Renkert + */ +@Path("rest/ort") +@RequestScoped +public class OrtService { + + /** + * The data repository granting read/write access. + */ + @Inject + @RepositoryConfig(type=RepositoryType.RW) + private Repository defaultRepo; + + @Inject + @AuthorizationConfig(type=AuthorizationType.HEADER) + private Authorization authorization; + + /** + * Get all SOrt objects. + *

+ * The requested objects can be filtered using a URL parameter named + * ortId. + *

+ * Example: http://example.com/location?ortId=[ID] + * + * @return Response object containing all (filtered) SOrt objects. + */ + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response get( + @Context HttpHeaders headers, + @Context UriInfo info + ) { + MultivaluedMap params = info.getQueryParameters(); + if (params.isEmpty() || !params.containsKey("ortId")) { + return defaultRepo.getAll(Ort.class, "stamm"); + } + String ortId = params.getFirst("ortId"); + QueryBuilder builder = + new QueryBuilder( + defaultRepo.entityManager("stamm"), + Ort.class); + builder.and("id", ortId); + return defaultRepo.filter(builder.getQuery(), "stamm"); + } + + /** + * Get a single SOrt object by id. + *

+ * The id is appended to the URL as a path parameter. + *

+ * Example: http://example.com/location/{id} + * + * @return Response object containing a single SOrt. + */ + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getById( + @Context HttpHeaders headers, + @PathParam("id") String id + ) { + return defaultRepo.getById( + Ort.class, + Integer.valueOf(id), + "stamm"); + } + + /** + * Create a SOrt object. + *

+ * The new object is embedded in the post data as JSON formatted string. + *

+ *

+     * 
+     * {
+     *  "bezeichnung": [string],
+     *  "beschreibung": [string],
+     *  "unscharf": [string],
+     *  "nutsCode": [string],
+     *  "koordXExtern": [string],
+     *  "koordYExtern": [string],
+     *  "hoeheLand": [string],
+     *  "longitude": [number],
+     *  "latitude": [number],
+     *  "staatId": [number],
+     *  "verwaltungseinheitId": [string],
+     *  "otyp": [string],
+     *  "letzteAenderung": [date]
+     * }
+     * 
+     * 
+ * @return A response object containing the created SOrt. + */ + @POST + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response create( + @Context HttpServletRequest request, + Ort ort + ) { + if (!authorization.isAuthorized( + request, + ort, + RequestMethod.POST, + Ort.class) + ) { + return new Response(false, 699, ort); + } + /* Persist the new object*/ + return defaultRepo.create(ort, "stamm"); + } + + /** + * Update an existing SOrt object. + *

+ * The object to update should come as JSON formatted string. + *

+     * 
+     * {
+     *  "id": [number],
+     *  "bezeichnung": [string],
+     *  "beschreibung": [string],
+     *  "unscharf": [string],
+     *  "nutsCode": [string],
+     *  "koordXExtern": [string],
+     *  "koordYExtern": [string],
+     *  "hoeheLand": [number],
+     *  "longitude": [number],
+     *  "latitude": [number],
+     *  "staatId": [number],
+     *  "verwaltungseinheitId": [string],
+     *  "otyp": [string],
+     *  "letzteAenderung": [date]
+     * }
+     * 
+     * 
+ * + * @return Response object containing the updated SOrt object. + */ + @PUT + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response update( + @Context HttpServletRequest request, + Ort ort + ) { + if (!authorization.isAuthorized( + request, + ort, + RequestMethod.PUT, + Ort.class) + ) { + return new Response(false, 699, ort); + } + Response response = defaultRepo.update(ort, "stamm"); + Response updated = defaultRepo.getById( + Ort.class, + ((Ort)response.getData()).getId(), "stamm"); + return updated; + } + + /** + * Delete an existing SOrt object by id. + *

+ * The id is appended to the URL as a path parameter. + *

+ * Example: http://example.com/location/{id} + * + * @return Response object. + */ + @DELETE + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response delete( + @Context HttpServletRequest request, + @PathParam("id") String id + ) { + /* Get the object by id*/ + Ort ort = + defaultRepo.getByIdPlain(Ort.class, Integer.valueOf(id), "stamm"); + if (!authorization.isAuthorized( + request, + ort, + RequestMethod.DELETE, + Ort.class) + ) { + return new Response(false, 699, ort); + } + /* Delete the object*/ + return defaultRepo.delete(ort, "stamm"); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/PflichtmessgroesseService.java --- a/src/main/java/de/intevation/lada/rest/stamm/PflichtmessgroesseService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/PflichtmessgroesseService.java Thu Jan 21 09:01:57 2016 +0100 @@ -51,7 +51,7 @@ * * @author Raimund Renkert */ -@Path("pflichtmessgroesse") +@Path("rest/pflichtmessgroesse") @RequestScoped public class PflichtmessgroesseService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/ProbenartService.java --- a/src/main/java/de/intevation/lada/rest/stamm/ProbenartService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/ProbenartService.java Thu Jan 21 09:01:57 2016 +0100 @@ -50,7 +50,7 @@ * * @author Raimund Renkert */ -@Path("probenart") +@Path("rest/probenart") @RequestScoped public class ProbenartService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,174 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.rest.stamm; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import de.intevation.lada.model.stamm.DatensatzErzeuger; +import de.intevation.lada.model.stamm.Probenehmer; +import de.intevation.lada.util.annotation.AuthorizationConfig; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.auth.Authorization; +import de.intevation.lada.util.auth.AuthorizationType; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +/** + * REST service for Probenehmer objects. + *

+ * The services produce data in the application/json media type. + * A typical response holds information about the action performed and the data. + *

+ * 
+ * {
+ *  "success": [boolean];
+ *  "message": [string],
+ *  "data":[{
+ *      "id": [number],
+ *      "mstId": [string],
+ *      "netzbetreiberId": [string]
+ *  }],
+ *  "errors": [object],
+ *  "warnings": [object],
+ *  "readonly": [boolean],
+ *  "totalCount": [number]
+ * }
+ * 
+ * 
+ * + * @author Raimund Renkert + */ +@Path("rest/probenehmer") +@RequestScoped +public class ProbenehmerService { + + /** + * The data repository granting read access. + */ + @Inject + @RepositoryConfig(type=RepositoryType.RW) + private Repository repository; + + @Inject + @AuthorizationConfig(type=AuthorizationType.HEADER) + private Authorization authorization; + + /** + * Get all Probenehmer objects. + *

+ * Example: http://example.com/probenehmer + * + * @return Response object containing all objects. + */ + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response get( + @Context HttpHeaders headers, + @Context UriInfo info + ) { + return repository.getAll(Probenehmer.class, "stamm"); + } + + /** + * Get a single Datenbasis object by id. + *

+ * The id is appended to the URL as a path parameter. + *

+ * Example: http://example.com/probenehmer/{id} + * + * @return Response object containing a single object. + */ + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getById( + @Context HttpHeaders headers, + @PathParam("id") String id + ) { + return repository.getById( + Probenehmer.class, + Integer.valueOf(id), + "stamm"); + } + + @POST + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Response create( + @Context HttpServletRequest request, + Probenehmer probenehmer + ) { + if (!authorization.isAuthorized( + request, + probenehmer, + RequestMethod.POST, + Probenehmer.class) + ) { + return new Response(false, 699, probenehmer); + } + + return repository.create(probenehmer, "stamm"); + } + + @PUT + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response update( + @Context HttpServletRequest request, + Probenehmer probenehmer + ) { + if (!authorization.isAuthorized( + request, + probenehmer, + RequestMethod.PUT, + Probenehmer.class) + ) { + return new Response(false, 699, probenehmer); + } + + return repository.update(probenehmer, "stamm"); + } + + @DELETE + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response delete( + @Context HttpServletRequest request, + @PathParam("id") String id + ) { + Probenehmer probenehmer = repository.getByIdPlain( + Probenehmer.class, Integer.valueOf(id), "stamm"); + if (probenehmer == null || + !authorization.isAuthorized( + request, + probenehmer, + RequestMethod.DELETE, + Probenehmer.class + ) + ) { + return new Response(false, 699, null); + } + return repository.delete(probenehmer, "stamm"); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/ProbenzusatzService.java --- a/src/main/java/de/intevation/lada/rest/stamm/ProbenzusatzService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/ProbenzusatzService.java Thu Jan 21 09:01:57 2016 +0100 @@ -51,7 +51,7 @@ * * @author Raimund Renkert */ -@Path("probenzusatz") +@Path("rest/probenzusatz") @RequestScoped public class ProbenzusatzService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/StaatService.java --- a/src/main/java/de/intevation/lada/rest/stamm/StaatService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/StaatService.java Thu Jan 21 09:01:57 2016 +0100 @@ -55,7 +55,7 @@ * * @author Raimund Renkert */ -@Path("staat") +@Path("rest/staat") @RequestScoped public class StaatService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/StatusStufeService.java --- a/src/main/java/de/intevation/lada/rest/stamm/StatusStufeService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/StatusStufeService.java Thu Jan 21 09:01:57 2016 +0100 @@ -48,7 +48,7 @@ * * @author Raimund Renkert */ -@Path("statusstufe") +@Path("rest/statusstufe") @RequestScoped public class StatusStufeService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java --- a/src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java Thu Jan 21 09:01:57 2016 +0100 @@ -65,7 +65,7 @@ * * @author Raimund Renkert */ -@Path("statuswert") +@Path("rest/statuswert") @RequestScoped public class StatusWertService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/UmweltService.java --- a/src/main/java/de/intevation/lada/rest/stamm/UmweltService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/UmweltService.java Thu Jan 21 09:01:57 2016 +0100 @@ -50,7 +50,7 @@ * * @author Raimund Renkert */ -@Path("umwelt") +@Path("rest/umwelt") @RequestScoped public class UmweltService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/rest/stamm/VerwaltungseinheitService.java --- a/src/main/java/de/intevation/lada/rest/stamm/VerwaltungseinheitService.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/stamm/VerwaltungseinheitService.java Thu Jan 21 09:01:57 2016 +0100 @@ -64,7 +64,7 @@ * * @author Raimund Renkert */ -@Path("verwaltungseinheit") +@Path("rest/verwaltungseinheit") @RequestScoped public class VerwaltungseinheitService { diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/Authorization.java --- a/src/main/java/de/intevation/lada/util/auth/Authorization.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/Authorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -20,7 +20,7 @@ public Response filter(Object source, Response data, Class clazz); public boolean isAuthorized( Object source, Object data, RequestMethod method, Class clazz); - public boolean isAuthorized(int id, Class clazz); - public boolean isAuthorized(UserInfo userInfo, Object data); + //public boolean isAuthorized(int id, Class clazz); + public boolean isAuthorized(UserInfo userInfo, Object data, Class clazz); boolean isReadOnly(Integer probeId); } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/Authorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/Authorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,18 @@ +package de.intevation.lada.util.auth; + +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public interface Authorizer { + + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz); + + public Response filter( + Response data, + UserInfo userInfo, + Class clazz); +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,83 @@ +package de.intevation.lada.util.auth; + +import java.util.List; + +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.model.land.LStatusProtokoll; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.data.QueryBuilder; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.Response; + +public abstract class BaseAuthorizer implements Authorizer { + + /** + * The Repository used to read from Database. + */ + @Inject + @RepositoryConfig(type=RepositoryType.RO) + protected Repository repository; + + /** + * Get the authorization of a single probe. + * + * @param userInfo The user information. + * @param probe The probe to authorize. + */ + protected boolean getAuthorization(UserInfo userInfo, LProbe probe) { + if (userInfo.getMessstellen().contains(probe.getMstId())) { + return true; + } + else { + return false; + } + } + + /** + * Test whether a probe is readonly. + * + * @param probeId The probe Id. + * @return True if the probe is readonly. + */ + public boolean isProbeReadOnly(Integer probeId) { + EntityManager manager = repository.entityManager("land"); + QueryBuilder builder = + new QueryBuilder( + manager, + LMessung.class); + builder.and("probeId", probeId); + Response response = repository.filter(builder.getQuery(), "land"); + @SuppressWarnings("unchecked") + List messungen = (List) response.getData(); + for (int i = 0; i < messungen.size(); i++) { + if (messungen.get(i).getStatus() == null) { + continue; + } + LStatusProtokoll status = repository.getByIdPlain( + LStatusProtokoll.class, messungen.get(i).getStatus(), "land"); + if (status.getStatusWert() != 0 && status.getStatusWert() != 4) { + return true; + } + } + return false; + } + + public boolean isMessungReadOnly(Integer messungsId) { + LMessung messung = + repository.getByIdPlain(LMessung.class, messungsId, "land"); + if (messung.getStatus() == null) { + return false; + } + LStatusProtokoll status = repository.getByIdPlain( + LStatusProtokoll.class, + messung.getStatus(), + "land"); + return (status.getStatusWert() != 0 && status.getStatusWert() != 4); + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java --- a/src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/DefaultAuthorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -83,12 +83,11 @@ * @return true */ @Override - public boolean isAuthorized(UserInfo userInfo, Object data) { + public boolean isAuthorized( + UserInfo userInfo, + Object data, + Class clazz) { return true; } - @Override - public boolean isAuthorized(int id, Class clazz) { - return true; - } } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java --- a/src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -7,23 +7,30 @@ */ package de.intevation.lada.util.auth; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.servlet.http.HttpServletRequest; -import org.apache.log4j.Logger; - +import de.intevation.lada.model.land.LKommentarM; +import de.intevation.lada.model.land.LKommentarP; import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LMesswert; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.LStatusProtokoll; +import de.intevation.lada.model.land.LZusatzWert; import de.intevation.lada.model.stamm.Auth; -import de.intevation.lada.model.stamm.AuthLstUmw; +import de.intevation.lada.model.stamm.DatensatzErzeuger; +import de.intevation.lada.model.stamm.MessprogrammKategorie; +import de.intevation.lada.model.stamm.Ort; +import de.intevation.lada.model.stamm.Probenehmer; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; @@ -41,18 +48,38 @@ public class HeaderAuthorization implements Authorization { /** - * The logger used in this class. - */ - @Inject - private Logger logger; - - /** * The Repository used to read from Database. */ @Inject @RepositoryConfig(type=RepositoryType.RO) private Repository repository; + @SuppressWarnings("rawtypes") + private Map authorizers; + @Inject ProbeAuthorizer probeAuthorizer; + @Inject MessungAuthorizer messungAuthorizer; + @Inject ProbeIdAuthorizer pIdAuthorizer; + @Inject MessungIdAuthorizer mIdAuthorizer; + @Inject NetzbetreiberAuthorizer netzAuthorizer; + + @SuppressWarnings("rawtypes") + @PostConstruct + public void init() { + authorizers = new HashMap(); + authorizers.put(LProbe.class, probeAuthorizer); + authorizers.put(LMessung.class, messungAuthorizer); + authorizers.put(LOrtszuordnung.class, pIdAuthorizer); + authorizers.put(LKommentarP.class, pIdAuthorizer); + authorizers.put(LZusatzWert.class, pIdAuthorizer); + authorizers.put(LKommentarM.class, mIdAuthorizer); + authorizers.put(LMesswert.class, mIdAuthorizer); + authorizers.put(LStatusProtokoll.class, mIdAuthorizer); + authorizers.put(Probenehmer.class, netzAuthorizer); + authorizers.put(DatensatzErzeuger.class, netzAuthorizer); + authorizers.put(MessprogrammKategorie.class, netzAuthorizer); + authorizers.put(Ort.class, netzAuthorizer); + } + /** * Request user informations using the HttpServletRequest. * @@ -87,44 +114,12 @@ if (userInfo == null) { return data; } - if (clazz == LProbe.class) { - return this.authorizeProbe(userInfo, data); - } - if (clazz == LMessung.class) { - return this.authorizeMessung(userInfo, data); - } - Method[] methods = clazz.getMethods(); - for (Method method: methods) { - if (method.getName().equals("getProbeId")) { - return this.authorizeWithProbeId(userInfo, data, clazz); - } - if (method.getName().equals("getMessungsId")) { - return this.authorizeWithMessungsId(userInfo, data, clazz); - } + Authorizer authorizer = authorizers.get(clazz); + //This is a hack... Allows wildcard for unknown classes. + if (authorizer == null) { + return data; } - return data; - } - - @Override - public boolean isAuthorized(int id, Class clazz) { - if (clazz == LMessung.class) { - LMessung messung = repository.getByIdPlain( - LMessung.class, - id, - "land"); - if (messung.getStatus() == null) { - return false; - } - LStatusProtokoll status = repository.getByIdPlain( - LStatusProtokoll.class, - messung.getStatus(), - "land"); - if (status.getStatusWert() == 0) { - return false; - } - return true; - } - return false; + return authorizer.filter(data, userInfo, clazz); } /** @@ -147,97 +142,12 @@ if (userInfo == null) { return false; } - if (clazz == LProbe.class) { - LProbe probe = (LProbe)data; - if (method == RequestMethod.POST) { - return getAuthorization(userInfo, probe); - } - else if (method == RequestMethod.PUT || - method == RequestMethod.DELETE) { - return !isReadOnly(probe.getId()); - } - else { - return false; - } - } - else if (clazz == LMessung.class) { - LMessung messung = (LMessung)data; - Response response = - repository.getById(LProbe.class, messung.getProbeId(), "land"); - LProbe probe = (LProbe)response.getData(); - if (method == RequestMethod.POST) { - return getAuthorization(userInfo, probe); - } - else if (method == RequestMethod.PUT || - method == RequestMethod.DELETE) { - return !this.isMessungReadOnly(messung) && - getAuthorization(userInfo, probe); - } - } - else { - Method[] methods = clazz.getMethods(); - for (Method m: methods) { - if (m.getName().equals("getProbeId")) { - Integer id; - try { - id = (Integer) m.invoke(data); - } catch (IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - logger.warn(e.getCause() + ": " + e.getMessage()); - return false; - } - Response response = - repository.getById(LProbe.class, id, "land"); - LProbe probe = (LProbe)response.getData(); - return !isReadOnly(id) && getAuthorization(userInfo, probe); - - } - if (m.getName().equals("getMessungsId")) { - Integer id; - try { - id = (Integer) m.invoke(data); - } catch (IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - logger.warn(e.getCause() + ": " + e.getMessage()); - return false; - } - Response mResponse = - repository.getById(LMessung.class, id, "land"); - LMessung messung = (LMessung)mResponse.getData(); - Response pResponse = - repository.getById( - LProbe.class, - messung.getProbeId(), - "land"); - LProbe probe = (LProbe)pResponse.getData(); - if (messung.getStatus() == null) { - return false; - } - LStatusProtokoll status = repository.getByIdPlain( - LStatusProtokoll.class, - messung.getStatus(), - "land"); - return status.getStatusWert() == 0 && - getAuthorization(userInfo, probe); - } - } - } - return true; - } - - /** - * Get the authorization of a single probe. - * - * @param userInfo The user information. - * @param probe The probe to authorize. - */ - private boolean getAuthorization(UserInfo userInfo, LProbe probe) { - if (userInfo.getMessstellen().contains(probe.getMstId())) { + Authorizer authorizer = authorizers.get(clazz); + //This is a hack... Allows wildcard for unknown classes. + if (authorizer == null) { return true; } - else { - return false; - } + return authorizer.isAuthorized(data, method, userInfo, clazz); } /** @@ -264,304 +174,6 @@ } /** - * Authorize data that has a messungsId Attribute. - * - * @param userInfo The user information. - * @param data The Response object containing the data. - * @param clazz The data object class. - * @return A Response object containing the data. - */ - @SuppressWarnings("unchecked") - private Response authorizeWithMessungsId( - UserInfo userInfo, - Response data, - Class clazz - ) { - if (data.getData() instanceof List) { - List objects = new ArrayList(); - for (Object object :(List)data.getData()) { - objects.add(authorizeSingleWithMessungsId(userInfo, object, clazz)); - } - data.setData(objects); - } - else { - Object object = data.getData(); - data.setData(authorizeSingleWithMessungsId(userInfo, object, clazz)); - } - return data; - } - - /** - * Authorize data that has a probeId Attribute. - * - * @param userInfo The user information. - * @param data The Response object containing the data. - * @param clazz The data object class. - * @return A Response object containing the data. - */ - @SuppressWarnings("unchecked") - private Response authorizeWithProbeId( - UserInfo userInfo, - Response data, - Class clazz - ) { - if (data.getData() instanceof List) { - List objects = new ArrayList(); - for (Object object :(List)data.getData()) { - objects.add(authorizeSingleWithProbeId( - userInfo, - object, - clazz)); - } - data.setData(objects); - } - else { - Object object = data.getData(); - data.setData(authorizeSingleWithProbeId(userInfo, object, clazz)); - } - return data; - } - - /** - * Authorize a single data object that has a messungsId Attribute. - * - * @param userInfo The user information. - * @param data The Response object containing the data. - * @param clazz The data object class. - * @return A Response object containing the data. - */ - private Object authorizeSingleWithMessungsId( - UserInfo userInfo, - Object data, - Class clazz - ) { - try { - Method getMessungsId = clazz.getMethod("getMessungsId"); - Integer id = (Integer)getMessungsId.invoke(data); - LMessung messung = - (LMessung)repository.getById( - LMessung.class, id, "land").getData(); - LProbe probe = - (LProbe)repository.getById( - LProbe.class, messung.getProbeId(), "land").getData(); - - boolean readOnly = true; - boolean owner = false; - if (!userInfo.getNetzbetreiber().contains( - probe.getNetzbetreiberId())) { - owner = false; - readOnly = true; - } - else { - if (userInfo.getMessstellen().contains(probe.getMstId())) { - owner = true; - } - else { - owner = false; - } - readOnly = this.isMessungReadOnly(messung); - } - - Method setOwner = clazz.getMethod("setOwner", boolean.class); - Method setReadonly = clazz.getMethod("setReadonly", boolean.class); - setOwner.invoke(data, owner); - setReadonly.invoke(data, readOnly); - } catch (NoSuchMethodException | SecurityException - | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - return null; - } - return data; - } - - /** - * Authorize a single data object that has a probeId Attribute. - * - * @param userInfo The user information. - * @param data The Response object containing the data. - * @param clazz The data object class. - * @return A Response object containing the data. - */ - private Object authorizeSingleWithProbeId( - UserInfo userInfo, - Object data, - Class clazz - ) { - try { - Method getProbeId = clazz.getMethod("getProbeId"); - Integer id = null; - if (getProbeId != null) { - id = (Integer) getProbeId.invoke(data); - } - else { - return null; - } - LProbe probe = - (LProbe)repository.getById(LProbe.class, id, "land").getData(); - - boolean readOnly = true; - boolean owner = false; - if (!userInfo.getNetzbetreiber().contains( - probe.getNetzbetreiberId())) { - owner = false; - readOnly = true; - } - else { - if (userInfo.getMessstellen().contains(probe.getMstId())) { - owner = true; - } - else { - owner = false; - } - readOnly = this.isReadOnly(id); - } - - Method setOwner = clazz.getMethod("setOwner", boolean.class); - Method setReadonly = clazz.getMethod("setReadonly", boolean.class); - setOwner.invoke(data, owner); - setReadonly.invoke(data, readOnly); - } catch (NoSuchMethodException | SecurityException - | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - return null; - } - return data; - } - - /** - * Authorize probe objects. - * - * @param userInfo The user information. - * @param data The Response object containing the probe objects. - * @return A Response object containing the data. - */ - @SuppressWarnings("unchecked") - private Response authorizeProbe(UserInfo userInfo, Response data) { - if (data.getData() instanceof List) { - List proben = new ArrayList(); - for (LProbe probe :(List)data.getData()) { - proben.add(authorizeSingleProbe(userInfo, probe)); - } - data.setData(proben); - } - else if (data.getData() instanceof LProbe) { - LProbe probe = (LProbe)data.getData(); - data.setData(authorizeSingleProbe(userInfo, probe)); - } - return data; - } - - /** - * Authorize a sinle probe object. - * - * @param userInfo The user information. - * @param probe The probe object. - * @return The probe. - */ - private LProbe authorizeSingleProbe(UserInfo userInfo, LProbe probe) { - if (!userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { - probe.setOwner(false); - probe.setReadonly(true); - return probe; - } - if (userInfo.getMessstellen().contains(probe.getMstId())) { - probe.setOwner(true); - } - else { - probe.setOwner(false); - } - probe.setReadonly(this.isReadOnly(probe.getId())); - return probe; - } - - /** - * Authorize messung objects. - * - * @param userInfo The user information. - * @param data The Response object containing the messung objects. - * @return A Response object containing the data. - */ - @SuppressWarnings("unchecked") - private Response authorizeMessung(UserInfo userInfo, Response data) { - if (data.getData() instanceof List) { - List messungen = new ArrayList(); - for (LMessung messung :(List)data.getData()) { - messungen.add(authorizeSingleMessung(userInfo, messung)); - } - data.setData(messungen); - } - else if (data.getData() instanceof LMessung) { - LMessung messung = (LMessung)data.getData(); - data.setData(authorizeSingleMessung(userInfo, messung)); - } - return data; - } - - /** - * Authorize a sinle messung object. - * - * @param userInfo The user information. - * @param messung The messung object. - * @return The messung. - */ - private LMessung authorizeSingleMessung( - UserInfo userInfo, - LMessung messung - ) { - LProbe probe = - (LProbe)repository.getById( - LProbe.class, messung.getProbeId(), "land").getData(); - if (!userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { - messung.setOwner(false); - messung.setReadonly(true); - return messung; - } - if (userInfo.getMessstellen().contains(probe.getMstId())) { - messung.setOwner(true); - } - else { - messung.setOwner(false); - } - if (messung.getStatus() == null) { - messung.setReadonly(false); - } - else { - LStatusProtokoll status = repository.getByIdPlain( - LStatusProtokoll.class, - messung.getStatus(), - "land"); - messung.setReadonly( - status.getStatusWert() != 0 && status.getStatusWert() != 4); - } - - boolean statusEdit = false; - if (userInfo.getFunktionen().contains(3)) { - QueryBuilder lstFilter = new QueryBuilder( - repository.entityManager("stamm"), - AuthLstUmw.class); - lstFilter.or("lstId", userInfo.getMessstellen()); - List lsts = - repository.filterPlain(lstFilter.getQuery(), "stamm"); - for (int i = 0; i < lsts.size(); i++) { - if (lsts.get(i).getUmwId().equals(probe.getUmwId())) { - statusEdit = true; - } - } - } - else if (userInfo.getFunktionen().contains(2) && - userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { - statusEdit = true; - } - else if (userInfo.getFunktionen().contains(1) && - userInfo.getMessstellen().contains(probe.getMstId())) { - statusEdit = true; - } - messung.setStatusEdit(statusEdit); - - return messung; - } - - /** * Test whether a probe is readonly. * * @param probeId The probe Id. @@ -580,7 +192,7 @@ List messungen = (List) response.getData(); for (int i = 0; i < messungen.size(); i++) { if (messungen.get(i).getStatus() == null) { - return false; + continue; } LStatusProtokoll status = repository.getByIdPlain( LStatusProtokoll.class, messungen.get(i).getStatus(), "land"); @@ -599,25 +211,16 @@ * @return True if the user is authorized else returns false. */ @Override - public boolean isAuthorized(UserInfo userInfo, Object data) { - if (data instanceof LProbe) { - return getAuthorization(userInfo, (LProbe)data); - } - else if (data instanceof LMessung) { - LProbe probe = repository.getByIdPlain(LProbe.class, ((LMessung)data).getProbeId(), "land"); - return getAuthorization(userInfo, probe); + public boolean isAuthorized( + UserInfo userInfo, + Object data, + Class clazz + ) { + Authorizer authorizer = authorizers.get(clazz); + //This is a hack... Allows wildcard for unknown classes. + if (authorizer == null) { + return true; } - return false; - } - - private boolean isMessungReadOnly(LMessung messung) { - if (messung.getStatus() == null) { - return false; - } - LStatusProtokoll status = repository.getByIdPlain( - LStatusProtokoll.class, - messung.getStatus(), - "land"); - return (status.getStatusWert() != 0 && status.getStatusWert() != 4); + return authorizer.isAuthorized(data, RequestMethod.GET, userInfo, clazz); } } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,120 @@ +package de.intevation.lada.util.auth; + +import java.util.ArrayList; +import java.util.List; + +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.model.land.LStatusProtokoll; +import de.intevation.lada.model.stamm.AuthLstUmw; +import de.intevation.lada.util.data.QueryBuilder; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public class MessungAuthorizer extends BaseAuthorizer { + + @Override + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz + ) { + LMessung messung = (LMessung)data; + Response response = + repository.getById(LProbe.class, messung.getProbeId(), "land"); + LProbe probe = (LProbe)response.getData(); + if (method == RequestMethod.PUT || + method == RequestMethod.DELETE) { + return !this.isMessungReadOnly(messung.getId()) && + getAuthorization(userInfo, probe); + } + return getAuthorization(userInfo, probe); + } + + @SuppressWarnings("unchecked") + @Override + public Response filter( + Response data, + UserInfo userInfo, + Class clazz + ) { + if (data.getData() instanceof List) { + List messungen = new ArrayList(); + for (LMessung messung :(List)data.getData()) { + messungen.add(setAuthData(userInfo, messung)); + } + data.setData(messungen); + } + else if (data.getData() instanceof LMessung) { + LMessung messung = (LMessung)data.getData(); + data.setData(setAuthData(userInfo, messung)); + } + return data; + } + + /** + * Authorize a sinle messung object. + * + * @param userInfo The user information. + * @param messung The messung object. + * @return The messung. + */ + private LMessung setAuthData( + UserInfo userInfo, + LMessung messung + ) { + LProbe probe = + (LProbe)repository.getById( + LProbe.class, messung.getProbeId(), "land").getData(); + if (!userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { + messung.setOwner(false); + messung.setReadonly(true); + return messung; + } + if (userInfo.getMessstellen().contains(probe.getMstId())) { + messung.setOwner(true); + } + else { + messung.setOwner(false); + } + if (messung.getStatus() == null) { + messung.setReadonly(false); + } + else { + LStatusProtokoll status = repository.getByIdPlain( + LStatusProtokoll.class, + messung.getStatus(), + "land"); + messung.setReadonly( + status.getStatusWert() != 0 && status.getStatusWert() != 4); + } + + boolean statusEdit = false; + if (userInfo.getFunktionen().contains(3)) { + QueryBuilder lstFilter = new QueryBuilder( + repository.entityManager("stamm"), + AuthLstUmw.class); + lstFilter.or("lstId", userInfo.getMessstellen()); + List lsts = + repository.filterPlain(lstFilter.getQuery(), "stamm"); + for (int i = 0; i < lsts.size(); i++) { + if (lsts.get(i).getUmwId().equals(probe.getUmwId())) { + statusEdit = true; + } + } + } + else if (userInfo.getFunktionen().contains(2) && + userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { + statusEdit = true; + } + else if (userInfo.getFunktionen().contains(1) && + userInfo.getMessstellen().contains(probe.getMstId())) { + statusEdit = true; + } + messung.setStatusEdit(statusEdit); + + return messung; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,131 @@ +package de.intevation.lada.util.auth; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.model.land.LStatusProtokoll; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public class MessungIdAuthorizer extends BaseAuthorizer { + + @Override + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz + ) { + Method m; + try { + m = clazz.getMethod("getMessungsId"); + } catch (NoSuchMethodException | SecurityException e1) { + return false; + } + Integer id; + try { + id = (Integer) m.invoke(data); + } catch (IllegalAccessException | + IllegalArgumentException | + InvocationTargetException e + ) { + return false; + } + LMessung messung = repository.getByIdPlain(LMessung.class, id, "land"); + LProbe probe = repository.getByIdPlain( + LProbe.class, + messung.getProbeId(), + "land"); + if (messung.getStatus() == null) { + return false; + } + LStatusProtokoll status = repository.getByIdPlain( + LStatusProtokoll.class, + messung.getStatus(), + "land"); + return (method == RequestMethod.POST || + method == RequestMethod.PUT || + method == RequestMethod.DELETE || + status.getStatusWert() != 0) && + getAuthorization(userInfo, probe); + } + + @SuppressWarnings("unchecked") + @Override + public Response filter( + Response data, + UserInfo userInfo, + Class clazz + ) { + if (data.getData() instanceof List) { + List objects = new ArrayList(); + for (Object object :(List)data.getData()) { + objects.add(setAuthData(userInfo, object, clazz)); + } + data.setData(objects); + } + else { + Object object = data.getData(); + data.setData(setAuthData(userInfo, object, clazz)); + } + return data; + } + + /** + * Authorize a single data object that has a messungsId Attribute. + * + * @param userInfo The user information. + * @param data The Response object containing the data. + * @param clazz The data object class. + * @return A Response object containing the data. + */ + private Object setAuthData( + UserInfo userInfo, + Object data, + Class clazz + ) { + try { + Method getMessungsId = clazz.getMethod("getMessungsId"); + Integer id = (Integer)getMessungsId.invoke(data); + LMessung messung = repository.getByIdPlain( + LMessung.class, + id, + "land"); + LProbe probe = repository.getByIdPlain( + LProbe.class, + messung.getProbeId(), + "land"); + + boolean readOnly = true; + boolean owner = false; + if (!userInfo.getNetzbetreiber().contains( + probe.getNetzbetreiberId())) { + owner = false; + readOnly = true; + } + else { + if (userInfo.getMessstellen().contains(probe.getMstId())) { + owner = true; + } + else { + owner = false; + } + readOnly = this.isMessungReadOnly(messung.getId()); + } + + Method setOwner = clazz.getMethod("setOwner", boolean.class); + Method setReadonly = clazz.getMethod("setReadonly", boolean.class); + setOwner.invoke(data, owner); + setReadonly.invoke(data, readOnly); + } catch (NoSuchMethodException | SecurityException + | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + return null; + } + return data; + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/NetzbetreiberAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/NetzbetreiberAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,49 @@ +package de.intevation.lada.util.auth; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public class NetzbetreiberAuthorizer extends BaseAuthorizer { + + @Override + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz + ) { + Method m; + try { + m = clazz.getMethod("getNetzbetreiberId"); + } catch (NoSuchMethodException | SecurityException e1) { + return false; + } + String id; + try { + id = (String) m.invoke(data); + } catch (IllegalAccessException | + IllegalArgumentException | + InvocationTargetException e + ) { + return false; + } + return (method == RequestMethod.POST || + method == RequestMethod.PUT || + method == RequestMethod.DELETE) && + userInfo.getNetzbetreiber().contains(id) && + userInfo.getFunktionen().contains(4); + } + + @Override + public Response filter( + Response data, + UserInfo userInfo, + Class clazz + ) { + return data; + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,70 @@ +package de.intevation.lada.util.auth; + +import java.util.ArrayList; +import java.util.List; + +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public class ProbeAuthorizer extends BaseAuthorizer { + + @Override + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz + ) { + LProbe probe = (LProbe)data; + if (method == RequestMethod.PUT || + method == RequestMethod.DELETE) { + return !isProbeReadOnly(probe.getId()); + } + return getAuthorization(userInfo, probe); + } + + @SuppressWarnings("unchecked") + @Override + public Response filter( + Response data, + UserInfo userInfo, + Class clazz + ) { + if (data.getData() instanceof List) { + List proben = new ArrayList(); + for (LProbe probe :(List)data.getData()) { + proben.add(setAuthData(userInfo, probe)); + } + data.setData(proben); + } + else if (data.getData() instanceof LProbe) { + LProbe probe = (LProbe)data.getData(); + data.setData(setAuthData(userInfo, probe)); + } + return data; + } + + /** + * Set authorization data for the current probe object. + * + * @param userInfo The user information. + * @param probe The probe object. + * @return The probe. + */ + private LProbe setAuthData(UserInfo userInfo, LProbe probe) { + if (!userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { + probe.setOwner(false); + probe.setReadonly(true); + return probe; + } + if (userInfo.getMessstellen().contains(probe.getMstId())) { + probe.setOwner(true); + } + else { + probe.setOwner(false); + } + probe.setReadonly(this.isProbeReadOnly(probe.getId())); + return probe; + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,114 @@ +package de.intevation.lada.util.auth; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.util.rest.RequestMethod; +import de.intevation.lada.util.rest.Response; + +public class ProbeIdAuthorizer extends BaseAuthorizer { + + @Override + public boolean isAuthorized( + Object data, + RequestMethod method, + UserInfo userInfo, + Class clazz + ) { + Method m; + try { + m = clazz.getMethod("getProbeId"); + } catch (NoSuchMethodException | SecurityException e1) { + return false; + } + Integer id; + try { + id = (Integer) m.invoke(data); + } catch (IllegalAccessException | + IllegalArgumentException | + InvocationTargetException e + ) { + return false; + } + LProbe probe = + repository.getByIdPlain(LProbe.class, id, "land"); + return !isProbeReadOnly(id) && getAuthorization(userInfo, probe); + } + + @SuppressWarnings("unchecked") + @Override + public Response filter( + Response data, + UserInfo userInfo, + Class clazz + ) { + if (data.getData() instanceof List) { + List objects = new ArrayList(); + for (Object object :(List)data.getData()) { + objects.add(setAuthData(userInfo, object, clazz)); + } + data.setData(objects); + } + else { + Object object = data.getData(); + data.setData(setAuthData(userInfo, object, clazz)); + } + return data; + } + /** + * Authorize a single data object that has a probeId Attribute. + * + * @param userInfo The user information. + * @param data The Response object containing the data. + * @param clazz The data object class. + * @return A Response object containing the data. + */ + private Object setAuthData( + UserInfo userInfo, + Object data, + Class clazz + ) { + try { + Method getProbeId = clazz.getMethod("getProbeId"); + Integer id = null; + if (getProbeId != null) { + id = (Integer) getProbeId.invoke(data); + } + else { + return null; + } + LProbe probe = + (LProbe)repository.getById(LProbe.class, id, "land").getData(); + + boolean readOnly = true; + boolean owner = false; + if (!userInfo.getNetzbetreiber().contains( + probe.getNetzbetreiberId())) { + owner = false; + readOnly = true; + } + else { + if (userInfo.getMessstellen().contains(probe.getMstId())) { + owner = true; + } + else { + owner = false; + } + readOnly = this.isProbeReadOnly(id); + } + + Method setOwner = clazz.getMethod("setOwner", boolean.class); + Method setReadonly = clazz.getMethod("setReadonly", boolean.class); + setOwner.invoke(data, owner); + setReadonly.invoke(data, readOnly); + } catch (NoSuchMethodException | SecurityException + | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + return null; + } + return data; + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/ShibbolethFilter.java --- a/src/main/java/de/intevation/lada/util/auth/ShibbolethFilter.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/ShibbolethFilter.java Thu Jan 21 09:01:57 2016 +0100 @@ -32,7 +32,7 @@ import org.apache.log4j.Logger; /** ServletFilter used for Shibboleth authentification. */ -@WebFilter("/*") +@WebFilter({"/rest/*", "/data/*"}) public class ShibbolethFilter implements Filter { private static final String CONFIG_FILE = "/shibboleth.properties"; diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/util/auth/TestAuthorization.java --- a/src/main/java/de/intevation/lada/util/auth/TestAuthorization.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/TestAuthorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -59,7 +59,7 @@ } @Override - public boolean isAuthorized(UserInfo userInfo, Object data) { + public boolean isAuthorized(UserInfo userInfo, Object data, Class clazz) { return true; } @@ -67,10 +67,4 @@ public boolean isReadOnly(Integer probeId) { return false; } - - @Override - public boolean isAuthorized(int id, Class clazz) { - return true; - } - } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/validation/OrtValidator.java --- a/src/main/java/de/intevation/lada/validation/OrtValidator.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/validation/OrtValidator.java Thu Jan 21 09:01:57 2016 +0100 @@ -11,7 +11,7 @@ import javax.enterprise.inject.Instance; import javax.inject.Inject; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.validation.annotation.ValidationConfig; import de.intevation.lada.validation.annotation.ValidationRule; import de.intevation.lada.validation.rules.Rule; @@ -35,7 +35,7 @@ @Override public Violation validate(Object object) { Violation violations = new Violation(); - if (!(object instanceof LOrt)) { + if (!(object instanceof LOrtszuordnung)) { violations.addError("ort", 602); return violations; } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java --- a/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java Thu Jan 21 09:01:57 2016 +0100 @@ -16,9 +16,9 @@ import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.PrecisionModel; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.stamm.DeVg; -import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Ort; import de.intevation.lada.model.stamm.Verwaltungseinheit; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; @@ -45,19 +45,19 @@ @SuppressWarnings("unchecked") @Override public Violation execute(Object object) { - LOrt ort = (LOrt)object; - if (!"E".equals(ort.getOrtsTyp())) { + LOrtszuordnung ort = (LOrtszuordnung)object; + if (!"E".equals(ort.getOrtszuordnungTyp())) { return null; } - QueryBuilder ortBuilder = - new QueryBuilder(repository.entityManager("stamm"), SOrt.class); - ortBuilder.and("id", ort.getOrt()); + QueryBuilder ortBuilder = + new QueryBuilder(repository.entityManager("stamm"), Ort.class); + ortBuilder.and("id", ort.getOrtId()); Response response = repository.filter(ortBuilder.getQuery(), "stamm"); - List orte = (List)response.getData(); + List orte = (List)response.getData(); QueryBuilder veBuilder = new QueryBuilder( repository.entityManager("stamm"), Verwaltungseinheit.class); - veBuilder.and("id", orte.get(0).getVerwaltungseinheitId()); + veBuilder.and("id", orte.get(0).getGemId()); Response ver = repository.filter(veBuilder.getQuery(), "stamm"); if (((List)ver.getData()).isEmpty()) { Violation violation = new Violation(); diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java --- a/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java Thu Jan 21 09:01:57 2016 +0100 @@ -11,7 +11,7 @@ import javax.inject.Inject; -import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LOrtszuordnung; import de.intevation.lada.model.land.LProbe; import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.data.QueryBuilder; @@ -44,14 +44,15 @@ violation.addWarning("entnahmeOrt", 631); return violation; } - QueryBuilder builder = - new QueryBuilder(repo.entityManager("land"), LOrt.class); + QueryBuilder builder = + new QueryBuilder( + repo.entityManager("land"), LOrtszuordnung.class); builder.and("probeId", id); Response response = repo.filter(builder.getQuery(), "land"); @SuppressWarnings("unchecked") - List orte = (List)response.getData(); - for (LOrt ort: orte) { - if ("E".equals(ort.getOrtsTyp())) { + List orte = (List)response.getData(); + for (LOrtszuordnung ort: orte) { + if ("E".equals(ort.getOrtszuordnungTyp())) { return null; } } diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/resources/META-INF/persistence.xml --- a/src/main/resources/META-INF/persistence.xml Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/resources/META-INF/persistence.xml Thu Jan 21 09:01:57 2016 +0100 @@ -5,8 +5,7 @@ - java:/jboss/lada-bund - false + java:jboss/lada-bund @@ -19,7 +18,7 @@ - java:/jboss/lada-land + java:jboss/lada-land false @@ -33,7 +32,7 @@ - java:/jboss/lada-stamm + java:jboss/lada-stamm diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/resources/messprogrammquery.json --- a/src/main/resources/messprogrammquery.json Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/resources/messprogrammquery.json Thu Jan 21 09:01:57 2016 +0100 @@ -3,6 +3,7 @@ "name": "Kein Filter", "description": "Abfrage der Messprogramme ohne Filter", "sql": "select m.id as id, m.name as name, m.mst_id as mstId, m.umw_id as umwId from land.messprogramm m", + "type": "messprogramm", "result": [ {"dataIndex": "name", "header": "Name", "width": 100}, {"dataIndex": "mstId", "header": "MST", "width": 100}, diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/resources/probequery.json --- a/src/main/resources/probequery.json Thu Jan 14 10:22:14 2016 +0100 +++ b/src/main/resources/probequery.json Thu Jan 21 09:01:57 2016 +0100 @@ -3,6 +3,7 @@ "name": "Kein Filter", "description": "Abfrage der Proben ohne Filter", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 120}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -17,6 +18,7 @@ "name": "HP-Nr-Filter", "description": "Abfrage der Proben mit Wildcardfilter für die Hauptproben-Nr.", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (p.hauptproben_nr like :hp_nr_id or '' = :hp_nr_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 120}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -32,6 +34,7 @@ "name": "Probe-ID-Filter", "description": "Abfrage der Proben mit Wildcardfilter für die Probe_id", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (pt.probe_id_alt like :probe_id or '' = :probe_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 120}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -47,6 +50,7 @@ "name": "MST und UMW", "description": "Abfrage der Proben gefiltert nach Messtellen ID und ID des Umweltbereichs", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 120}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -63,6 +67,7 @@ "name": "Proben pro Land", "description": "Proben gefiltert nach Ländern", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (netzbetreiber_id = :netz OR '' = :netz)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 100}, @@ -78,6 +83,7 @@ "name": "alle Proben mit Ort", "description": "alle Proben mit Entnahmeort", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where o.orts_typ = 'E' or o.orts_typ is null", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -94,6 +100,7 @@ "name": "Proben pro Land und UMW (Multiselect)", "description": "Abfrage aller Proben gefiltert pro Land und Umweltbereich (mit Mehrfachauswahl)", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, to_char(p.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahmeVon, to_char(p.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahmeBis, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, o.orts_typ as ortsTyp, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where (o.orts_typ = 'E' or o.orts_typ is null) and (p.netzbetreiber_id = :netz OR '' =:netz) and (p.umw_id similar to (:umw_id) OR '' = :umw_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -115,6 +122,7 @@ "name": "Proben und Messungen pro Land und UMW (Multiselect)", "description": "Abfrage aller Proben/Messungen gefiltert pro Land und Umweltbereich (mit Mehrfachauswahl)", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, to_char(p.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahmeVon, to_char(p.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahmeBis, m.mmt_id as mmtId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, o.orts_typ as ortsTyp, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p left outer join land.probe_translation pt on p.id = pt.probe_id left outer join land.messung m on p.id = m.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where (o.orts_typ = 'E' or o.orts_typ is null) and (p.netzbetreiber_id = :netz OR '' =:netz) and (p.umw_id similar to (:umw_id) OR '' = :umw_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, diff -r 2203e5d76071 -r 2fe625c91ab3 src/main/resources/stammdatenquery.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/stammdatenquery.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,42 @@ +[ +{ "id": "1", + "name": "Orte", + "description": "Abfrage der Orte", + "sql": "", + "type": "ort", + "result": [ + ], + "filters": [ + ] +}, { + "id": "2", + "name": "Probenehmer", + "description": "Abfrage aller Probenehmer", + "sql": "", + "type": "probenehmer", + "result": [ + ], + "filters": [ + ] +}, { + "id": "3", + "name": "Datensatzerzeuger", + "description": "Abfrage aller Datensatzerzeuger", + "sql": "", + "type": "datensatzerzeuger", + "result": [ + ], + "filters": [ + ] +}, { + "id": "4", + "name": "Messprogrammkategorie", + "description": "Abfrage der Messprogrammkategorien", + "sql": "", + "type": "messprogrammkategorie", + "result": [ + ], + "filters": [ + ] +} +] diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/BaseTest.java --- a/src/test/java/de/intevation/lada/BaseTest.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/java/de/intevation/lada/BaseTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -24,11 +24,11 @@ */ public class BaseTest { - protected static String ARCHIVE_NAME = "lada-basis-test.war"; + protected static String ARCHIVE_NAME = "lada-server-test.war"; public static String TEST_USER = "testeins"; - public static String TEST_ROLES = "cn=Imis-World, cn=mst_06010, cn=mst_11010, cn=mst_11010_status"; + public static String TEST_ROLES = "cn=Imis-World, cn=mst_06010, cn=mst_11010, cn=mst_06_status, cn=land_06_stamm"; private static Logger logger = Logger.getLogger(BaseTest.class); diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/LadaLandTest.java --- a/src/test/java/de/intevation/lada/LadaLandTest.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,520 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada; - -import java.net.URL; -import java.util.ArrayList; - -import org.apache.log4j.Logger; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; - -import de.intevation.lada.test.land.KommentarM; -import de.intevation.lada.test.land.KommentarP; -import de.intevation.lada.test.land.Messprogramm; -import de.intevation.lada.test.land.Messung; -import de.intevation.lada.test.land.Messwert; -import de.intevation.lada.test.land.Ort; -import de.intevation.lada.test.land.Probe; -import de.intevation.lada.test.land.Query; -import de.intevation.lada.test.land.Status; -import de.intevation.lada.test.land.Zusatzwert; - - -/** - * Class to test the Lada server 'land' services. - * - * @author Raimund Renkert - */ -@RunWith(Arquillian.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class LadaLandTest extends BaseTest { - - private static Logger logger = Logger.getLogger(LadaLandTest.class); - - private Probe probeTest; - private Query queryTest; - private Messung messungTest; - private KommentarP kommentarPTest; - private KommentarM kommentarMTest; - private Messwert messwertTest; - private Ort ortTest; - private Status statusTest; - private Zusatzwert zusatzwertTest; - private Messprogramm messprogrammTest; - - public LadaLandTest() { - probeTest = new Probe(); - queryTest = new Query(); - messungTest = new Messung(); - kommentarPTest = new KommentarP(); - kommentarMTest = new KommentarM(); - messwertTest = new Messwert(); - ortTest = new Ort(); - statusTest = new Status(); - zusatzwertTest = new Zusatzwert(); - messprogrammTest = new Messprogramm(); - testProtocol = new ArrayList(); - verboseLogging = false; - } - - @BeforeClass - public static void beforeTests() { - logger.info("---------- Testing Lada Land Services ----------"); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ProbeGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.probeTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ProbeGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.probeTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ProbeGetByFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.probeTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_GetQueryServices(@ArquillianResource URL baseUrl) - throws Exception { - this.queryTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessungGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messungTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessungGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messungTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessungGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messungTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarPGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarPTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarPGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarPTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarPGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarPTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessprogrammGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messprogrammTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessprogrammGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messprogrammTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MessprogrammGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messprogrammTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing CREATE services. - */ - @Test - @RunAsClient - public final void testB_CreateServices(@ArquillianResource URL baseUrl) - throws Exception { - this.probeTest.createService(baseUrl, testProtocol); - Assert.assertNotNull(this.probeTest.getCreatedProbeId()); - this.messungTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.kommentarPTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.ortTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.zusatzwertTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - Assert.assertNotNull(this.messungTest.getCreatedMessungId()); - this.kommentarMTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - this.messwertTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - this.messprogrammTest.createService( - baseUrl, - testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_probeUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.probeTest.getCreatedProbeId()); - this.probeTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_messungUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.messungTest.getCreatedMessungId()); - this.messungTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_kommentarPUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); - this.kommentarPTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_kommentarMUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); - this.kommentarMTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_messwertUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); - this.messwertTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_ortUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.ortTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_messprogrammUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.messprogrammTest.updateService(baseUrl, testProtocol); - } - - @Test - @RunAsClient - public final void testC_zstatusCreateService(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_zstatusUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.statusTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing DELETE services. - */ - @Test - @RunAsClient - public final void testD_DeleteServices(@ArquillianResource URL baseUrl) - throws Exception { - //Assert.assertNotNull(this.statusTest.getCreatedId()); - //this.statusTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.zusatzwertTest.getCreatedId()); - this.zusatzwertTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.ortTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); - this.messwertTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); - this.kommentarMTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); - this.kommentarPTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.messungTest.getCreatedMessungId()); - this.messungTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.probeTest.getCreatedProbeId()); - this.probeTest.deleteService(baseUrl, testProtocol); - this.messprogrammTest.deleteService(baseUrl, testProtocol); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/LadaStammTest.java --- a/src/test/java/de/intevation/lada/LadaStammTest.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,384 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada; - -import java.io.StringReader; -import java.net.URL; -import java.util.ArrayList; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.log4j.Logger; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.test.stamm.Stammdaten; - - -/** - * Class to test the Lada server stammdaten services. - * - * @author Raimund Renkert - */ -@RunWith(Arquillian.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class LadaStammTest extends BaseTest { - - private static Logger logger = Logger.getLogger(LadaStammTest.class); - - private static Integer createdOrtId; - - private Stammdaten stammdatenTest; - - public LadaStammTest () { - stammdatenTest = new Stammdaten(); - testProtocol = new ArrayList(); - verboseLogging = false; - } - - @BeforeClass - public static void beforeTests() { - logger.info("---------- Testing Lada Stamm Services ----------"); - } - - @Test - @RunAsClient - public final void testDatenbasisAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "datenbasis", testProtocol); - } - - @Test - @RunAsClient - public final void testDatenbasisById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "datenbasis", 9, testProtocol); - } - - @Test - @RunAsClient - public final void testMesseinheitAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "messeinheit", testProtocol); - } - - @Test - @RunAsClient - public final void testMesseinheitById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "messeinheit", 207, testProtocol); - } - - @Test - @RunAsClient - public final void testMessgroesseAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "messgroesse", testProtocol); - } - - @Test - @RunAsClient - public final void testMessgroesseById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "messgroesse", 56, testProtocol); - } - - @Test - @RunAsClient - public final void testMessmethodeAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "messmethode", testProtocol); - } - - @Test - @RunAsClient - public final void testMessmethodeById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "messmethode", "GI", testProtocol); - } - - @Test - @RunAsClient - public final void testMessstelleAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "messstelle", testProtocol); - } - - @Test - @RunAsClient - public final void testMessstelleById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "messstelle", "06010", testProtocol); - } - - @Test - @RunAsClient - public final void testNetzbetreiberAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "netzbetreiber", testProtocol); - } - - @Test - @RunAsClient - public final void testNetzbetreiberById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "netzbetreiber", "06", testProtocol); - } - - @Test - @RunAsClient - public final void testPflichtmessgroesseAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "pflichtmessgroesse", testProtocol); - } - - @Test - @RunAsClient - public final void testPflichtmessgroesseById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "pflichtmessgroesse", 33, testProtocol); - } - - @Test - @RunAsClient - public final void testProbenartAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "probenart", testProtocol); - } - - @Test - @RunAsClient - public final void testProbenartById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "probenart", 1, testProtocol); - } - - @Test - @RunAsClient - public final void testProbenzusatzAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "probenzusatz", testProtocol); - } - - @Test - @RunAsClient - public final void testProbenzusatzById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "probenzusatz", "A74", testProtocol); - } - - @Test - @RunAsClient - public final void testLocationAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "location", testProtocol); - } - - @Test - @RunAsClient - public final void testLocationById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "location", "19", testProtocol); - } - - @Test - @RunAsClient - public final void testKoordinatenartAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "koordinatenart", testProtocol); - } - - @Test - @RunAsClient - public final void testKoordinatenartById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "koordinatenart", 2, testProtocol); - } - - @Test - @RunAsClient - public final void testStaatAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "staat", testProtocol); - } - - @Test - @RunAsClient - public final void testStaatById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "staat", 322, testProtocol); - } - - @Test - @RunAsClient - public final void testUmweltAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "umwelt", testProtocol); - } - - @Test - @RunAsClient - public final void testUmweltById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "umwelt", "L6", testProtocol); - } - - @Test - @RunAsClient - public final void testVerwaltungseinheitAll(@ArquillianResource URL baseUrl) { - stammdatenTest.getAll(baseUrl, "verwaltungseinheit", testProtocol); - } - - @Test - @RunAsClient - public final void testVerwaltungseinheitById(@ArquillianResource URL baseUrl) { - stammdatenTest.getById(baseUrl, "verwaltungseinheit", "09575134", testProtocol); - } - - /* TODO: The location service is moved to the "land"-services in - future version. */ - @Test - @RunAsClient - public final void testLocation1CreateService(@ArquillianResource URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("locationService"); - prot.setType("create"); - prot.setPassed(false); - testProtocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "location"); - /* Send a post request containing a new kommentar*/ - String newObj = "{\"beschreibung\":\"Neuer Ort\"," + - "\"bezeichnung\":\"T123456\",\"hoeheLand\":null," + - "\"koordXExtern\":\"32531152\",\"koordYExtern\":\"5684269\"," + - "\"latitude\":51.30888,\"letzteAenderung\":1376287046332," + - "\"longitude\":9.44693,\"nutsCode\":\"DE731\",\"unscharf\":" + - "\"0\",\"netzbetreiberId\":null,\"staatId\":0," + - "\"verwaltungseinheitId\":\"06611000\",\"otyp\":\"Z\"," + - "\"koordinatenartId\":5}"; - - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(newObj, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdOrtId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("ortId", createdOrtId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - @Test - @RunAsClient - public final void testLocation2UpdateService(@ArquillianResource URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("locationService"); - prot.setType("update"); - prot.setPassed(false); - testProtocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "location/" + createdOrtId); - prot.addInfo("locationId", createdOrtId); - /* Request a kommentar with the id saved when created a kommentar*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldObj = reader.readObject().getJsonObject("data"); - /* Change the text*/ - String updatedEntity = - oldObj.toString().replace("Neuer Ort", "Neuerer Ort"); - prot.addInfo("updated field", "beschreibung"); - prot.addInfo("updated value", "Neuer Ort"); - prot.addInfo("updated to", "Neuerer Ort"); - /* Send the updated kommentar via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "location/" + createdOrtId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedObj = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedObj.getBoolean("success")); - prot.addInfo("success", updatedObj.getBoolean("success")); - Assert.assertEquals("200", updatedObj.getString("message")); - prot.addInfo("message", updatedObj.getString("message")); - Assert.assertEquals("Neuerer Ort", - updatedObj.getJsonObject("data").getString("beschreibung")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - @Test - @RunAsClient - public final void testLocation3DeleteService(@ArquillianResource URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("locationService"); - prot.setType("delete"); - prot.setPassed(false); - testProtocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "location/" + createdOrtId); - prot.addInfo("locationId", createdOrtId); - /* Delete the object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/LadaValidatorTest.java --- a/src/test/java/de/intevation/lada/LadaValidatorTest.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,257 +0,0 @@ -package de.intevation.lada; - -import static de.intevation.lada.BaseTest.ARCHIVE_NAME; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.log4j.Logger; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import de.intevation.lada.test.validator.Messung; -import de.intevation.lada.test.validator.Probe; -import de.intevation.lada.test.validator.Status; -import de.intevation.lada.validation.Validator; -import de.intevation.lada.validation.annotation.ValidationConfig; - -@RunWith(Arquillian.class) -public class LadaValidatorTest { - - private static Logger logger = Logger.getLogger(LadaStammTest.class); - - protected static List testProtocol; - - protected static boolean verboseLogging = false; - - @Inject - @ValidationConfig(type="Probe") - private Validator probeValidator; - private Probe probeTest; - - @Inject - @ValidationConfig(type="Messung") - private Validator messungValidator; - private Messung messungTest; - - @Inject - @ValidationConfig(type="Status") - private Validator statusValidator; - private Status statusTest; - - - public LadaValidatorTest() { - probeTest = new Probe(); - messungTest = new Messung(); - statusTest = new Status(); - testProtocol = new ArrayList(); - } - - /** - * Create a deployable WAR archive. - */ - @Deployment(testable=true) - public static WebArchive createDeployment() throws Exception { - WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME) - .addPackages(true, Package.getPackage("de.intevation.lada")) - .deleteClass("de.intevation.lada.util.auth.ShibbolethFilter") - .addAsResource("log4j.properties", "log4j.properties") - .addAsResource("shibboleth.properties", "shibboleth.properties") - .addAsResource("probequery.json", "probequery.json") - .addAsResource("messprogrammquery.json", "messprogrammquery.json") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsResource("META-INF/test-persistence.xml", - "META-INF/persistence.xml"); - return archive; - } - - - @BeforeClass - public static void beforeTests() { - logger.info("---------- Testing Lada Validator ----------"); - } - - @After - public final void printLogs() { - for (Protocol p : testProtocol) { - logger.info(p.toString(verboseLogging)); - } - } - - @AfterClass - public static final void afterTests() { - System.out.println(""); - } - - @Test - public final void probeHasHauptprobenNr() { - probeTest.setValidator(probeValidator); - probeTest.hasHauptprobenNr(testProtocol); - } - - @Test - public final void probeHasNoHauptprobenNr() { - probeTest.setValidator(probeValidator); - probeTest.hasNoHauptprobenNr(testProtocol); - } - - @Test - public final void probeExistingHauptprobenNrNew() { - probeTest.setValidator(probeValidator); - probeTest.existingHauptprobenNrNew(testProtocol); - } - - @Test - public final void probeUniqueHauptprobenNrNew() { - probeTest.setValidator(probeValidator); - probeTest.uniqueHauptprobenNrNew(testProtocol); - } - - @Test - public final void probeExistingHauptprobenNrUpdate() { - probeTest.setValidator(probeValidator); - probeTest.existingHauptprobenNrUpdate(testProtocol); - } - - @Test - public final void probeUniqueHauptprobenNrUpdate() { - probeTest.setValidator(probeValidator); - probeTest.uniqueHauptprobenNrUpdate(testProtocol); - } - - @Test - public final void probeHasEntnahmeOrt() { - probeTest.setValidator(probeValidator); - probeTest.hasEntnahmeOrt(testProtocol); - } - - @Test - public final void probeHasNoEntnahmeOrt() { - probeTest.setValidator(probeValidator); - probeTest.hasNoEntnahmeOrt(testProtocol); - } - - @Test - public final void probeHasProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.hasProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeHasNoProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.hasNoProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeTimeNoEndProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.timeNoEndProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeTimeNoBeginProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.timeNoBeginProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeTimeBeginAfterEndProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.timeBeginAfterEndProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeTimeBeginFutureProbenahmeBegin() { - probeTest.setValidator(probeValidator); - probeTest.timeBeginFutureProbeentnahmeBegin(testProtocol); - } - - @Test - public final void probeHasUmwelt() { - probeTest.setValidator(probeValidator); - probeTest.hasUmwelt(testProtocol); - } - - @Test - public final void probeHasNoUmwelt() { - probeTest.setValidator(probeValidator); - probeTest.hasNoUmwelt(testProtocol); - } - - @Test - public final void probeHasEmptyUmwelt() { - probeTest.setValidator(probeValidator); - probeTest.hasEmptyUmwelt(testProtocol); - } - - @Test - public final void messungHasNebenprobenNr() { - messungTest.setValidator(messungValidator); - messungTest.hasNebenprobenNr(testProtocol); - } - - @Test - public final void messungHasNoNebenprobenNr() { - messungTest.setValidator(messungValidator); - messungTest.hasNoNebenprobenNr(testProtocol); - } - - @Test - public final void messungHasEmptyNebenprobenNr() { - messungTest.setValidator(messungValidator); - messungTest.hasEmptyNebenprobenNr(testProtocol); - } - - @Test - public final void messungUniqueNebenprobenNrNew() { - messungTest.setValidator(messungValidator); - messungTest.uniqueNebenprobenNrNew(testProtocol); - } - - @Test - public final void messungUniqueNebenprobenNrUpdate() { - messungTest.setValidator(messungValidator); - messungTest.uniqueNebenprobenNrUpdate(testProtocol); - } - - @Test - public final void messungExistingNebenprobenNrNew() { - messungTest.setValidator(messungValidator); - messungTest.existingNebenprobenNrNew(testProtocol); - } - - @Test - public final void messungExistingNebenprobenNrUpdate() { - messungTest.setValidator(messungValidator); - messungTest.existingHauptprobenNrUpdate(testProtocol); - } - - @Test - public final void messungHasMesswert() { - messungTest.setValidator(messungValidator); - messungTest.hasMesswert(testProtocol); - } - - @Test - public final void messungHasNoMesswert() { - messungTest.setValidator(messungValidator); - messungTest.hasNoMesswert(testProtocol); - } - - @Test - public final void statusKombiNegative() { - statusTest.setValidator(statusValidator); - statusTest.checkKombiNegative(testProtocol); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/LandTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/LandTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,378 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada; + +import java.net.URL; +import java.util.ArrayList; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.apache.log4j.Logger; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.persistence.Cleanup; +import org.jboss.arquillian.persistence.CleanupUsingScript; +import org.jboss.arquillian.persistence.DataSource; +import org.jboss.arquillian.persistence.TestExecutionPhase; +import org.jboss.arquillian.persistence.UsingDataSet; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import de.intevation.lada.model.land.LKommentarM; +import de.intevation.lada.model.land.LKommentarP; +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LMesswert; +import de.intevation.lada.model.land.LOrtszuordnung; +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.model.land.LZusatzWert; +import de.intevation.lada.model.land.Messprogramm; +import de.intevation.lada.test.land.KommentarMTest; +import de.intevation.lada.test.land.KommentarPTest; +import de.intevation.lada.test.land.MessprogrammTest; +import de.intevation.lada.test.land.MessungTest; +import de.intevation.lada.test.land.MesswertTest; +import de.intevation.lada.test.land.OrtszuordnungTest; +import de.intevation.lada.test.land.ProbeTest; +import de.intevation.lada.test.land.QueryTest; +import de.intevation.lada.test.land.StatusTest; +import de.intevation.lada.test.land.ZusatzwertTest; + + +/** + * Class to test the Lada server 'land' services. + * + * @author Raimund Renkert + */ +@RunWith(Arquillian.class) +public class LandTest extends BaseTest { + + @Inject + Logger internalLogger; + + @PersistenceContext(unitName="land") + EntityManager em; + + private ProbeTest probeTest; + private MessungTest messungTest; + private KommentarMTest mkommentarTest; + private KommentarPTest pkommentarTest; + private OrtszuordnungTest ortszuordnungTest; + private ZusatzwertTest zusatzwertTest; + private MesswertTest messwertTest; + private StatusTest statusTest; + private MessprogrammTest messprogrammTest; + private QueryTest queryTest; + + public LandTest() { + probeTest = new ProbeTest(); + messungTest = new MessungTest(); + mkommentarTest = new KommentarMTest(); + pkommentarTest = new KommentarPTest(); + ortszuordnungTest = new OrtszuordnungTest(); + zusatzwertTest = new ZusatzwertTest(); + messwertTest = new MesswertTest(); + statusTest = new StatusTest(); + messprogrammTest = new MessprogrammTest(); + queryTest = new QueryTest(); + testProtocol = new ArrayList(); + verboseLogging = false; + } + + @BeforeClass + public static void beforeTests() { + } + + /*------ REST service tests ------*/ + + /** + * Tests for probe operations + */ + @Test + @InSequence(2) + @RunAsClient + public final void testProbe(@ArquillianResource URL baseUrl) + throws Exception { + probeTest.init(baseUrl, testProtocol); + probeTest.execute(); + } + + /** + * Tests for pkommentar operations + */ + @Test + @InSequence(4) + @RunAsClient + public final void testPkommentar(@ArquillianResource URL baseUrl) + throws Exception { + pkommentarTest.init(baseUrl, testProtocol); + pkommentarTest.execute(); + } + + /** + * Tests for ortszurodnung operations + */ + @Test + @InSequence(6) + @RunAsClient + public final void testOrtszuordnung(@ArquillianResource URL baseUrl) + throws Exception { + ortszuordnungTest.init(baseUrl, testProtocol); + ortszuordnungTest.execute(); + } + + /** + * Tests for zustzwert operations + */ + @Test + @InSequence(8) + @RunAsClient + public final void testZusatzwert(@ArquillianResource URL baseUrl) + throws Exception { + zusatzwertTest.init(baseUrl, testProtocol); + zusatzwertTest.execute(); + } + /** + * Tests for messung operations + */ + @Test + @InSequence(10) + @RunAsClient + public final void testMessung(@ArquillianResource URL baseUrl) + throws Exception { + messungTest.init(baseUrl, testProtocol); + messungTest.execute(); + } + + /** + * Tests for mkommentar operations + */ + @Test + @InSequence(12) + @RunAsClient + public final void testMkommentar(@ArquillianResource URL baseUrl) + throws Exception { + mkommentarTest.init(baseUrl, testProtocol); + mkommentarTest.execute(); + } + + /** + * Tests for mkommentar operations + */ + @Test + @InSequence(14) + @RunAsClient + public final void testMesswert(@ArquillianResource URL baseUrl) + throws Exception { + messwertTest.init(baseUrl, testProtocol); + messwertTest.execute(); + } + + @Test + @InSequence(16) + @RunAsClient + public final void testStatus(@ArquillianResource URL baseUrl) + throws Exception { + statusTest.init(baseUrl, testProtocol); + statusTest.execute(); + } + + @Test + @InSequence(18) + @RunAsClient + public final void testMessprogramm(@ArquillianResource URL baseUrl) + throws Exception { + messprogrammTest.init(baseUrl, testProtocol); + messprogrammTest.execute(); + } + + @Test + @InSequence(20) + @RunAsClient + public final void testQuery(@ArquillianResource URL baseUrl) + throws Exception { + queryTest.init(baseUrl, testProtocol); + queryTest.execute(); + } + + /*------ Database operations ------*/ + + /** + * Insert a probe object into the database. + */ + @Test + @InSequence(1) + @UsingDataSet("datasets/dbUnit_probe.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseProbe() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert probe"); + protocol.addInfo("database", "Insert Probe into database"); + testProtocol.add(protocol); + LProbe probe = em.find(LProbe.class, 1000); + Assert.assertNotNull(probe); + protocol.setPassed(true); + } + + /** + * Insert a probe kommentar into the database. + */ + @Test + @InSequence(3) + @UsingDataSet("datasets/dbUnit_pkommentar.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseKommentarP() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert kommentar_p"); + protocol.addInfo("database", "Insert KommentarP into database"); + testProtocol.add(protocol); + LKommentarP kommentar = em.find(LKommentarP.class, 1000); + Assert.assertNotNull(kommentar); + protocol.setPassed(true); + } + + /** + * Insert a ortszuordnung into the database. + */ + @Test + @InSequence(5) + @UsingDataSet("datasets/dbUnit_ortszuordnung.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseOrtszuordnung() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert ortszuordnung"); + protocol.addInfo("database", "Insert Ortszuordnung into database"); + testProtocol.add(protocol); + LOrtszuordnung ortszuordnung = em.find(LOrtszuordnung.class, 1000); + Assert.assertNotNull(ortszuordnung); + protocol.setPassed(true); + } + + /** + * Insert a zusatzwert into the database. + */ + @Test + @InSequence(7) + @UsingDataSet("datasets/dbUnit_zusatzwert.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseZusatzwert() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert zusatzwert"); + protocol.addInfo("database", "Insert Zusatzwert into database"); + testProtocol.add(protocol); + LZusatzWert zusatzwert = em.find(LZusatzWert.class, 1000); + Assert.assertNotNull(zusatzwert); + protocol.setPassed(true); + } + + /** + * Insert a messung object into the database. + */ + @Test + @InSequence(9) + @UsingDataSet("datasets/dbUnit_messung.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseMessung() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert messung"); + protocol.addInfo("database", "Insert Messung into database"); + testProtocol.add(protocol); + LMessung messung = em.find(LMessung.class, 1200); + messung.setStatus(1000); + em.merge(messung); + Assert.assertNotNull(messung); + protocol.setPassed(true); + } + + /** + * Insert a messungs kommentar into the database. + */ + @Test + @InSequence(11) + @UsingDataSet("datasets/dbUnit_mkommentar.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseKommentarM() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert kommentar_m"); + protocol.addInfo("database", "Insert KommentarM into database"); + testProtocol.add(protocol); + LKommentarM kommentar = em.find(LKommentarM.class, 1000); + Assert.assertNotNull(kommentar); + protocol.setPassed(true); + } + + /** + * Insert a messwert into the database. + */ + @Test + @InSequence(13) + @UsingDataSet("datasets/dbUnit_messwert.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseMesswert() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert messwert"); + protocol.addInfo("database", "Insert Messwert into database"); + testProtocol.add(protocol); + LMesswert messwert = em.find(LMesswert.class, 10000); + Assert.assertNotNull(messwert); + protocol.setPassed(true); + } + + /** + * Insert a messprogramm into the database. + */ + @Test + @InSequence(17) + @UsingDataSet("datasets/dbUnit_messprogramm.json") + @DataSource("java:jboss/lada-land") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseMessprogramm() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert messprogramm"); + protocol.addInfo("database", "Insert Messprogramm into database"); + testProtocol.add(protocol); + Messprogramm messprogramm = em.find(Messprogramm.class, 1000); + Assert.assertNotNull(messprogramm); + protocol.setPassed(true); + } + /** + * Cleanup the database. + */ + @Test + @InSequence(19) + @DataSource("java:jboss/lada-land") + @CleanupUsingScript("datasets/cleanup.sql") + public final void cleanUp() { + Protocol protocol = new Protocol(); + protocol.addInfo("database", "Cleaning the database."); + protocol.setName("database"); + protocol.setType("cleanup"); + protocol.setPassed(true); + testProtocol.add(protocol); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/StammdatenTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/StammdatenTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,357 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada; + +import java.net.URL; +import java.util.ArrayList; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.apache.log4j.Logger; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.persistence.Cleanup; +import org.jboss.arquillian.persistence.DataSource; +import org.jboss.arquillian.persistence.TestExecutionPhase; +import org.jboss.arquillian.persistence.UsingDataSet; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import de.intevation.lada.model.stamm.DatensatzErzeuger; +import de.intevation.lada.model.stamm.MessprogrammKategorie; +import de.intevation.lada.model.stamm.Ort; +import de.intevation.lada.model.stamm.Probenehmer; +import de.intevation.lada.test.stamm.DatensatzErzeugerTest; +import de.intevation.lada.test.stamm.MessprogrammKategorieTest; +import de.intevation.lada.test.stamm.OrtTest; +import de.intevation.lada.test.stamm.ProbenehmerTest; +import de.intevation.lada.test.stamm.Stammdaten; + + +/** + * Class to test the Lada server stammdaten services. + * + * @author Raimund Renkert + */ +@RunWith(Arquillian.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class StammdatenTest extends BaseTest { + + private static Logger logger = Logger.getLogger(StammdatenTest.class); + + @PersistenceContext(unitName="stamm") + EntityManager em; + + private Stammdaten stammdatenTest; + private DatensatzErzeugerTest datensatzerzeugerTest; + private ProbenehmerTest probenehmerTest; + private MessprogrammKategorieTest messprogrammkategorieTest; + private OrtTest ortTest; + + public StammdatenTest () { + stammdatenTest = new Stammdaten(); + datensatzerzeugerTest = new DatensatzErzeugerTest(); + probenehmerTest = new ProbenehmerTest(); + messprogrammkategorieTest = new MessprogrammKategorieTest(); + ortTest = new OrtTest(); + testProtocol = new ArrayList(); + verboseLogging = false; + } + + @BeforeClass + public static void beforeTests() { + logger.info("---------- Testing Lada Stamm Services ----------"); + } + + /** + * Insert a probe object into the database. + */ + @Test + @InSequence(1) + @UsingDataSet("datasets/dbUnit_datensatzerzeuger.json") + @DataSource("java:jboss/lada-stamm") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseDatensatzerzeuger() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert datensatzerzeuger"); + protocol.addInfo("database", "Insert datensatzerzeuger into database"); + testProtocol.add(protocol); + DatensatzErzeuger erzeuger = em.find(DatensatzErzeuger.class, 1000); + Assert.assertNotNull(erzeuger); + protocol.setPassed(true); + } + + /** + * Tests for probe operations + */ + @Test + @InSequence(2) + @RunAsClient + public final void testDatensatzerzeuger(@ArquillianResource URL baseUrl) + throws Exception { + datensatzerzeugerTest.init(baseUrl, testProtocol); + datensatzerzeugerTest.execute(); + } + + /** + * Insert a probe object into the database. + */ + @Test + @InSequence(3) + @UsingDataSet("datasets/dbUnit_probenehmer.json") + @DataSource("java:jboss/lada-stamm") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseProbenehmer() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert probenehmer"); + protocol.addInfo("database", "Insert Probenehmer into database"); + testProtocol.add(protocol); + Probenehmer probenehmer = em.find(Probenehmer.class, 1000); + Assert.assertNotNull(probenehmer); + protocol.setPassed(true); + } + + /** + * Tests for probe operations + */ + @Test + @InSequence(4) + @RunAsClient + public final void testProbenehmer(@ArquillianResource URL baseUrl) + throws Exception { + probenehmerTest.init(baseUrl, testProtocol); + probenehmerTest.execute(); + } + + /** + * Insert a probe object into the database. + */ + @Test + @InSequence(5) + @UsingDataSet("datasets/dbUnit_messprogrammkategorie.json") + @DataSource("java:jboss/lada-stamm") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseMessprogrammKategorie() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert messprogrammkategorie"); + protocol.addInfo("database", "Insert messprogrammkategorie into database"); + testProtocol.add(protocol); + MessprogrammKategorie kategorie = em.find(MessprogrammKategorie.class, 1000); + Assert.assertNotNull(kategorie); + protocol.setPassed(true); + } + + /** + * Tests for probe operations + */ + @Test + @InSequence(6) + @RunAsClient + public final void testMessprogrammKategorie(@ArquillianResource URL baseUrl) + throws Exception { + messprogrammkategorieTest.init(baseUrl, testProtocol); + messprogrammkategorieTest.execute(); + } + + /** + * Insert a probe object into the database. + */ + @Test + @InSequence(7) + @UsingDataSet("datasets/dbUnit_ort.json") + @DataSource("java:jboss/lada-stamm") + @Cleanup(phase=TestExecutionPhase.NONE) + public final void prepareDatabaseOrt() throws Exception { + Protocol protocol = new Protocol(); + protocol.setName("database"); + protocol.setType("insert ort"); + protocol.addInfo("database", "Insert ortinto database"); + testProtocol.add(protocol); + Ort ort = em.find(Ort.class, 1000); + Assert.assertNotNull(ort); + protocol.setPassed(true); + } + + /** + * Tests for probe operations + */ + @Test + @InSequence(8) + @RunAsClient + public final void testOrt(@ArquillianResource URL baseUrl) + throws Exception { + ortTest.init(baseUrl, testProtocol); + ortTest.execute(); + } + + @Test + @RunAsClient + public final void testDatenbasisAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "datenbasis", testProtocol); + } + + @Test + @RunAsClient + public final void testDatenbasisById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "datenbasis", 9, testProtocol); + } + + @Test + @RunAsClient + public final void testMesseinheitAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "messeinheit", testProtocol); + } + + @Test + @RunAsClient + public final void testMesseinheitById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "messeinheit", 207, testProtocol); + } + + @Test + @RunAsClient + public final void testMessgroesseAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "messgroesse", testProtocol); + } + + @Test + @RunAsClient + public final void testMessgroesseById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "messgroesse", 56, testProtocol); + } + + @Test + @RunAsClient + public final void testMessmethodeAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "messmethode", testProtocol); + } + + @Test + @RunAsClient + public final void testMessmethodeById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "messmethode", "GI", testProtocol); + } + + @Test + @RunAsClient + public final void testMessstelleAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "messstelle", testProtocol); + } + + @Test + @RunAsClient + public final void testMessstelleById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "messstelle", "06010", testProtocol); + } + + @Test + @RunAsClient + public final void testNetzbetreiberAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "netzbetreiber", testProtocol); + } + + @Test + @RunAsClient + public final void testNetzbetreiberById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "netzbetreiber", "06", testProtocol); + } + + @Test + @RunAsClient + public final void testPflichtmessgroesseAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "pflichtmessgroesse", testProtocol); + } + + @Test + @RunAsClient + public final void testPflichtmessgroesseById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "pflichtmessgroesse", 33, testProtocol); + } + + @Test + @RunAsClient + public final void testProbenartAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "probenart", testProtocol); + } + + @Test + @RunAsClient + public final void testProbenartById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "probenart", 1, testProtocol); + } + + @Test + @RunAsClient + public final void testProbenzusatzAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "probenzusatz", testProtocol); + } + + @Test + @RunAsClient + public final void testProbenzusatzById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "probenzusatz", "A74", testProtocol); + } + + @Test + @RunAsClient + public final void testKoordinatenartAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "koordinatenart", testProtocol); + } + + @Test + @RunAsClient + public final void testKoordinatenartById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "koordinatenart", 2, testProtocol); + } + + @Test + @RunAsClient + public final void testStaatAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "staat", testProtocol); + } + + @Test + @RunAsClient + public final void testStaatById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "staat", 322, testProtocol); + } + + @Test + @RunAsClient + public final void testUmweltAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "umwelt", testProtocol); + } + + @Test + @RunAsClient + public final void testUmweltById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "umwelt", "L6", testProtocol); + } + + @Test + @RunAsClient + public final void testVerwaltungseinheitAll(@ArquillianResource URL baseUrl) { + stammdatenTest.getAll(baseUrl, "verwaltungseinheit", testProtocol); + } + + @Test + @RunAsClient + public final void testVerwaltungseinheitById(@ArquillianResource URL baseUrl) { + stammdatenTest.getById(baseUrl, "verwaltungseinheit", "09575134", testProtocol); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/ValidatorTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/ValidatorTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,256 @@ +package de.intevation.lada; + +import static de.intevation.lada.BaseTest.ARCHIVE_NAME; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.apache.log4j.Logger; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import de.intevation.lada.test.validator.Messung; +import de.intevation.lada.test.validator.Probe; +import de.intevation.lada.test.validator.Status; +import de.intevation.lada.validation.Validator; +import de.intevation.lada.validation.annotation.ValidationConfig; + +@RunWith(Arquillian.class) +public class ValidatorTest { + + private static Logger logger = Logger.getLogger(StammdatenTest.class); + + protected static List testProtocol; + + protected static boolean verboseLogging = false; + + @Inject + @ValidationConfig(type="Probe") + private Validator probeValidator; + private Probe probeTest; + + @Inject + @ValidationConfig(type="Messung") + private Validator messungValidator; + private Messung messungTest; + + @Inject + @ValidationConfig(type="Status") + private Validator statusValidator; + private Status statusTest; + + + public ValidatorTest() { + probeTest = new Probe(); + messungTest = new Messung(); + statusTest = new Status(); + testProtocol = new ArrayList(); + } + + /** + * Create a deployable WAR archive. + */ + @Deployment(testable=true) + public static WebArchive createDeployment() throws Exception { + WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME) + .addPackages(true, Package.getPackage("de.intevation.lada")) + .addAsResource("log4j.properties", "log4j.properties") + .addAsResource("shibboleth.properties", "shibboleth.properties") + .addAsResource("probequery.json", "probequery.json") + .addAsResource("messprogrammquery.json", "messprogrammquery.json") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsResource("META-INF/test-persistence.xml", + "META-INF/persistence.xml"); + return archive; + } + + + @BeforeClass + public static void beforeTests() { + logger.info("---------- Testing Lada Validator ----------"); + } + + @After + public final void printLogs() { + for (Protocol p : testProtocol) { + logger.info(p.toString(verboseLogging)); + } + } + + @AfterClass + public static final void afterTests() { + System.out.println(""); + } + + @Test + public final void probeHasHauptprobenNr() { + probeTest.setValidator(probeValidator); + probeTest.hasHauptprobenNr(testProtocol); + } + + @Test + public final void probeHasNoHauptprobenNr() { + probeTest.setValidator(probeValidator); + probeTest.hasNoHauptprobenNr(testProtocol); + } + + @Test + public final void probeExistingHauptprobenNrNew() { + probeTest.setValidator(probeValidator); + probeTest.existingHauptprobenNrNew(testProtocol); + } + + @Test + public final void probeUniqueHauptprobenNrNew() { + probeTest.setValidator(probeValidator); + probeTest.uniqueHauptprobenNrNew(testProtocol); + } + + @Test + public final void probeExistingHauptprobenNrUpdate() { + probeTest.setValidator(probeValidator); + probeTest.existingHauptprobenNrUpdate(testProtocol); + } + + @Test + public final void probeUniqueHauptprobenNrUpdate() { + probeTest.setValidator(probeValidator); + probeTest.uniqueHauptprobenNrUpdate(testProtocol); + } + + @Test + public final void probeHasEntnahmeOrt() { + probeTest.setValidator(probeValidator); + probeTest.hasEntnahmeOrt(testProtocol); + } + + @Test + public final void probeHasNoEntnahmeOrt() { + probeTest.setValidator(probeValidator); + probeTest.hasNoEntnahmeOrt(testProtocol); + } + + @Test + public final void probeHasProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.hasProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeHasNoProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.hasNoProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeTimeNoEndProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.timeNoEndProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeTimeNoBeginProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.timeNoBeginProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeTimeBeginAfterEndProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.timeBeginAfterEndProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeTimeBeginFutureProbenahmeBegin() { + probeTest.setValidator(probeValidator); + probeTest.timeBeginFutureProbeentnahmeBegin(testProtocol); + } + + @Test + public final void probeHasUmwelt() { + probeTest.setValidator(probeValidator); + probeTest.hasUmwelt(testProtocol); + } + + @Test + public final void probeHasNoUmwelt() { + probeTest.setValidator(probeValidator); + probeTest.hasNoUmwelt(testProtocol); + } + + @Test + public final void probeHasEmptyUmwelt() { + probeTest.setValidator(probeValidator); + probeTest.hasEmptyUmwelt(testProtocol); + } + + @Test + public final void messungHasNebenprobenNr() { + messungTest.setValidator(messungValidator); + messungTest.hasNebenprobenNr(testProtocol); + } + + @Test + public final void messungHasNoNebenprobenNr() { + messungTest.setValidator(messungValidator); + messungTest.hasNoNebenprobenNr(testProtocol); + } + + @Test + public final void messungHasEmptyNebenprobenNr() { + messungTest.setValidator(messungValidator); + messungTest.hasEmptyNebenprobenNr(testProtocol); + } + + @Test + public final void messungUniqueNebenprobenNrNew() { + messungTest.setValidator(messungValidator); + messungTest.uniqueNebenprobenNrNew(testProtocol); + } + + @Test + public final void messungUniqueNebenprobenNrUpdate() { + messungTest.setValidator(messungValidator); + messungTest.uniqueNebenprobenNrUpdate(testProtocol); + } + + @Test + public final void messungExistingNebenprobenNrNew() { + messungTest.setValidator(messungValidator); + messungTest.existingNebenprobenNrNew(testProtocol); + } + + @Test + public final void messungExistingNebenprobenNrUpdate() { + messungTest.setValidator(messungValidator); + messungTest.existingHauptprobenNrUpdate(testProtocol); + } + + @Test + public final void messungHasMesswert() { + messungTest.setValidator(messungValidator); + messungTest.hasMesswert(testProtocol); + } + + @Test + public final void messungHasNoMesswert() { + messungTest.setValidator(messungValidator); + messungTest.hasNoMesswert(testProtocol); + } + + @Test + public final void statusKombiNegative() { + statusTest.setValidator(statusValidator); + statusTest.checkKombiNegative(testProtocol); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/ServiceTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/ServiceTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,364 @@ +package de.intevation.lada.test; + +import java.io.InputStream; +import java.io.StringReader; +import java.net.URL; +import java.sql.Timestamp; +import java.util.List; +import java.util.Map.Entry; +import java.util.Scanner; + +import javax.json.Json; +import javax.json.JsonException; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonReader; +import javax.json.JsonValue; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.commons.lang.WordUtils; +import org.junit.Assert; + +import de.intevation.lada.BaseTest; +import de.intevation.lada.Protocol; +import de.intevation.lada.test.land.ProbeTest; + +public class ServiceTest { + + protected List protocol; + + protected List timestampAttributes; + + protected URL baseUrl; + + public void init(URL baseUrl, List protocol) { + this.baseUrl = baseUrl; + this.protocol = protocol; + } + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + protected JsonObject readJsonResource(String resource) { + InputStream stream = + ProbeTest.class.getResourceAsStream(resource); + Scanner scanner = new Scanner(stream, "UTF-8"); + scanner.useDelimiter("\\A"); + String raw = scanner.next(); + scanner.close(); + JsonReader reader = Json.createReader(new StringReader(raw)); + JsonObject content = reader.readObject(); + reader.close(); + return content; + } + + protected JsonObjectBuilder convertObject(JsonObject object) { + JsonObjectBuilder builder = Json.createObjectBuilder(); + for (Entry entry : object.entrySet()) { + String key = WordUtils.capitalize( + entry.getKey(), new char[]{'_'}).replaceAll("_",""); + key = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toLowerCase()); + if (timestampAttributes.contains(key)) { + Timestamp timestamp = Timestamp.valueOf(entry.getValue().toString().replaceAll("\"", "")); + builder.add(key, timestamp.getTime()); + } + else { + builder.add(key, entry.getValue()); + } + } + return builder; + } + + public JsonObject getAll(String name, String parameter) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + parameter); + /* Request all objects*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .get(); + String entity = response.readEntity(String.class); + try{ + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject content = reader.readObject(); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("message", content.getString("message")); + Assert.assertNotNull(content.getJsonArray("data")); + prot.addInfo("objects", content.getJsonArray("data").size()); + prot.setPassed(true); + return content; + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } + /** + * Test the GET Service by requesting a single object by id. + * + * @param baseUrl The url pointing to the test deployment. + */ + public JsonObject getById( + String name, + String parameter, + JsonObject expected + ) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + parameter); + prot.addInfo("parameter", parameter); + /* Request a object by id*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader fromServiceReader = + Json.createReader(new StringReader(entity)); + JsonObject content = fromServiceReader.readObject(); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("message", content.getString("message")); + Assert.assertFalse(content.getJsonObject("data").isEmpty()); + JsonObject object = content.getJsonObject("data"); + for (Entry entry : expected.entrySet()) { + if (entry.getKey().equals("parentModified") || + entry.getKey().equals("treeModified")) { + continue; + } + Assert.assertEquals(entry.getValue(), object.get(entry.getKey())); + } + prot.addInfo("object", "equals"); + prot.setPassed(true); + return content; + } + catch(JsonException je) { + prot.addInfo("exception",je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } + + /** + * Test the GET service using filters. + * + * @param baseUrl The url poining to the test deployment. + */ + public JsonObject filter(String name, String parameter) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24"); + prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24"); + /* Request the objects using the filter*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject content = reader.readObject(); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("message", content.getString("message")); + Assert.assertNotNull(content.getJsonArray("data")); + prot.addInfo("objects", content.getJsonArray("data").size()); + prot.setPassed(true); + return content; + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } + + /** + * Test the CREATE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public JsonObject create(String name, String parameter, JsonObject create) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + parameter); + /* Send a post request containing a new probe*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON)); + String entity = response.readEntity(String.class); + System.out.println(entity); + /* Try to parse the response*/ + JsonReader fromServiceReader = + Json.createReader(new StringReader(entity)); + JsonObject content = fromServiceReader.readObject(); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("message", content.getString("message")); + prot.setPassed(true); + return content; + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } + + /** + * Test the probe update service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public JsonObject update( + String name, + String parameter, + String updateAttribute, + String oldValue, + String newValue + ) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + parameter); + /* Request a with the saved id*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject oldObject = reader.readObject().getJsonObject("data"); + /* Change the hauptprobenNr*/ + String updatedEntity = + oldObject.toString().replace(oldValue, newValue); + prot.addInfo("updated datafield", updateAttribute); + prot.addInfo("updated value", oldValue); + prot.addInfo("updated to", newValue); + /* Send the updated probe via put request*/ + WebTarget putTarget = client.target(baseUrl + parameter); + Response updated = putTarget.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); + /* Try to parse the response*/ + JsonReader updatedReader = Json.createReader( + new StringReader(updated.readEntity(String.class))); + JsonObject updatedObject = updatedReader.readObject(); + /* Verify the response*/ + Assert.assertTrue(updatedObject.getBoolean("success")); + prot.addInfo("success", updatedObject.getBoolean("success")); + Assert.assertEquals("200", updatedObject.getString("message")); + prot.addInfo("message", updatedObject.getString("message")); + Assert.assertEquals(newValue, + updatedObject.getJsonObject("data").getString(updateAttribute)); + prot.setPassed(true); + return updatedObject; + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } + + /** + * Test the DELETE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public JsonObject delete(String name, String parameter) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName(name + " service"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + parameter); + prot.addInfo("parameter", parameter); + /* Delete a probe with the id saved when created a probe*/ + Response response = target.request() + .header("X-SHIB-user", BaseTest.TEST_USER) + .header("X-SHIB-roles", BaseTest.TEST_ROLES) + .delete(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject content = reader.readObject(); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("message", content.getString("message")); + prot.setPassed(true); + return content; + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + return null; + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/KommentarM.java --- a/src/test/java/de/intevation/lada/test/land/KommentarM.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,347 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.sql.Date; -import java.util.List; -import java.util.TimeZone; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - - -/** - * Class containing test cases for messung kommentar objects. - * - * @author Raimund Renkert - */ -public class KommentarM { - - private static final int KOMMENTAR_ID = 507; - - private static final String COMPARE_KOMMENTARM = - "{\"messungsId\":988,\"datum\":1346932500000,\"erzeuger\":\"3002\"," + - "\"id\":" + KOMMENTAR_ID + - ",\"text\":\"Testkommentar 01\",\"owner\":true," + - "\"readonly\":false}"; - - private static final String CREATE_KOMMENTARM = - "{\"messungsId\":\"MID\",\"erzeuger\":\"06010\",\"text\":" + - "\"test\",\"datum\":\"2015-02-09T10:58:36\",\"owner\":false}"; - - private List protocol; - - private static Integer createdKommentarId; - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * @return The created KommentarId - */ - public Integer getCreatedKommentarId() { - return createdKommentarId; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "mkommentar"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertFalse(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("699", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_KOMMENTARM)); - JsonObject staticKommentar = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target( - baseUrl + "mkommentar/" + KOMMENTAR_ID); - prot.addInfo("kommentarId", KOMMENTAR_ID); - /* Request an object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertEquals(staticKommentar, - content.getJsonObject("data")); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar?messungsId=988"); - prot.addInfo("filter", "messungsId=988"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "mkommentar"); - /* Send a post request containing a new kommentar*/ - String mess = CREATE_KOMMENTARM.replace("MID", messungId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post( - Entity.entity(mess, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdKommentarId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("kommentarId", createdKommentarId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Request a kommentar with the id saved when created a kommentar*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldKommentar = reader.readObject().getJsonObject("data"); - /* Change the text*/ - String updatedEntity = - oldKommentar.toString().replace("test", "neu"); - prot.addInfo("updated field", "text"); - prot.addInfo("updated value", "test"); - prot.addInfo("updated to", "neu"); - /* Send the updated kommentar via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "mkommentar/" + createdKommentarId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedMessung = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedMessung.getBoolean("success")); - prot.addInfo("success", updatedMessung.getBoolean("success")); - Assert.assertEquals("200", updatedMessung.getString("message")); - prot.addInfo("message", updatedMessung.getString("message")); - Assert.assertEquals("neu", - updatedMessung.getJsonObject("data").getString("text")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Delete a kommentar with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/KommentarMTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/KommentarMTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,63 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class KommentarMTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "datum", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_mkommentar.json"); + JsonObject messung = content.getJsonArray("land.kommentar_m").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/mkommentar.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("mkommentar", "rest/mkommentar?messungsId=1000"); + getById("mkommentar", "rest/mkommentar/1000", expectedById); + JsonObject created = create("mkommentar", "rest/mkommentar", create); + update("mkommentar", "rest/mkommentar/1000", "text", "Testkommentar", "Testkommentar geändert"); + delete("mkommentar", "rest/mkommentar/" + created.getJsonObject("data").get("id")); + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/KommentarP.java --- a/src/test/java/de/intevation/lada/test/land/KommentarP.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,343 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - - -/** - * Class containing test cases for probekommentar objects. - * - * @author Raimund Renkert - */ -public class KommentarP { - - private static final String COMPARE_KOMMENTARP = - "{\"datum\":1321005677000,\"erzeuger\":\"06010\",\"id\":1,\"text\":" + - "\"Die Probe wurde in Darmstadt gammaspektrometrisch gemessen und " + - "für die Sr-Bestimmung verascht. \",\"probeId\":361,\"owner\":true," + - "\"readonly\":false}"; - - private static final String CREATE_KOMMENTARP = - "{\"probeId\":\"PID\",\"erzeuger\":\"11010\",\"text\":" + - "\"test\",\"datum\":\"2015-02-09T10:58:36\"}"; - - private List protocol; - - private static Integer createdKommentarId; - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * @return The created KommentarId - */ - public Integer getCreatedKommentarId() { - return createdKommentarId; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_KOMMENTARP)); - JsonObject staticKommentar = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar/1"); - prot.addInfo("kommentarId", 1); - /* Request an object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertEquals(staticKommentar, - content.getJsonObject("data")); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar?probeId=400"); - prot.addInfo("filter", "probeId=400"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar"); - /* Send a post request containing a new kommentar*/ - String mess = CREATE_KOMMENTARP.replace("PID", probeId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(mess, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdKommentarId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("kommentarId", createdKommentarId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Request a kommentar with the id saved when created a kommentar*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldKommentar = reader.readObject().getJsonObject("data"); - /* Change the text*/ - String updatedEntity = - oldKommentar.toString().replace("test", "neu"); - prot.addInfo("updated field", "text"); - prot.addInfo("updated value", "test"); - prot.addInfo("updated to", "neu"); - /* Send the updated kommentar via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "pkommentar/" + createdKommentarId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedMessung = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedMessung.getBoolean("success")); - prot.addInfo("success", updatedMessung.getBoolean("success")); - Assert.assertEquals("200", updatedMessung.getString("message")); - prot.addInfo("message", updatedMessung.getString("message")); - Assert.assertEquals("neu", - updatedMessung.getJsonObject("data").getString("text")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Delete a kommentar with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/KommentarPTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/KommentarPTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,62 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class KommentarPTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "datum", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_pkommentar.json"); + JsonObject messung = content.getJsonArray("land.kommentar_p").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/pkommentar.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("pkommentar", "rest/pkommentar?probeId=1000"); + getById("pkommentar", "rest/pkommentar/1000", expectedById); + JsonObject created = create("pkommentar", "rest/pkommentar", create); + update("pkommentar", "rest/pkommentar/1000", "text", "Testkommentar", "Testkommentar geändert"); + delete("pkommentar", "rest/pkommentar/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/MessprogrammTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/MessprogrammTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,66 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class MessprogrammTest extends ServiceTest { + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung", + "treeModified" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_messprogramm.json"); + JsonObject messprogramm = content.getJsonArray("land.messprogramm").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messprogramm); + builder.add("baId", JsonValue.NULL); + builder.add("gueltigVon", JsonValue.NULL); + builder.add("gueltigBis", JsonValue.NULL); + builder.add("intervallOffset", JsonValue.NULL); + builder.add("ortId", JsonValue.NULL); + builder.add("probeKommentar", JsonValue.NULL); + builder.add("probeNehmerId", JsonValue.NULL); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/messprogramm.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("messprogramm", "rest/messprogramm"); + getById("messprogramm", "rest/messprogramm/1000", expectedById); + filter("messprogramm", "rest/messprogramm?qid=1"); + update("messprogramm", "rest/messprogramm/1000", "mediaDesk", "D: 50 90 01 06 02 05 00 00 00 00 00 00", "D: 50 90 01 06 02 05 00 00 00 00 00 01"); + JsonObject created = create("messprogramm", "rest/messprogramm", create); + delete("messprogramm", "rest/messprogramm/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Messung.java --- a/src/test/java/de/intevation/lada/test/land/Messung.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,335 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - -/** - * Class containing test cases for messung objects. - * - * @author Raimund Renkert - */ -public class Messung { - - private static final String COMPARE_MESSUNG = - "{\"id\":1,\"fertig\":true,\"letzteAenderung\":1331536340000," + - "\"messdauer\":73929,\"messzeitpunkt\":1329139620000,\"mmtId\":" + - "\"G1\",\"probeId\":575,\"owner\":false,\"readonly\":false," + - "\"nebenprobenNr\":\"01G1\",\"geplant\":true,"; - - private static final String CREATE_MESSUNG = - "{\"probeId\":\"PID\",\"mmtId\":\"A4\",\"nebenprobenNr\":\"10R1\"," + - "\"messdauer\":10,\"fertig\":false,\"letzteAenderung\":null," + - "\"geplant\":true,\"messzeitpunkt\":\"2015-02-09T10:58:36\"}"; - - private List protocol; - - private static Integer createdMessungId; - - public Integer getCreatedMessungId() { - return createdMessungId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung/1"); - prot.addInfo("messungId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung?probeId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung"); - /* Send a post request containing a new object*/ - String mess = CREATE_MESSUNG.replace("PID", probeId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(mess, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdMessungId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("messungId", createdMessungId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung/" + createdMessungId); - prot.addInfo("messungsId", createdMessungId); - /* Request a messung with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldMessung = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - oldMessung.toString().replace("A4", "G1"); - prot.addInfo("updated field", "mmtId"); - prot.addInfo("updated value", "A4"); - prot.addInfo("updated to", "G1"); - /* Send the updated messung via put request*/ - WebTarget putTarget = client.target(baseUrl + "messung/" + createdMessungId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedMessung = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedMessung.getBoolean("success")); - prot.addInfo("success", updatedMessung.getBoolean("success")); - Assert.assertEquals("200", updatedMessung.getString("message")); - prot.addInfo("message", updatedMessung.getString("message")); - Assert.assertEquals("G1", - updatedMessung.getJsonObject("data").getString("mmtId")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung/" + createdMessungId); - prot.addInfo("messungId", createdMessungId); - /* Delete a messung with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/MessungTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/MessungTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,68 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class MessungTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung", + "messzeitpunkt", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_messung.json"); + JsonObject messung = content.getJsonArray("land.messung").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + JsonObject trans = + content.getJsonArray("land.messung_translation").getJsonObject(0); + builder.add("messungsIdAlt", trans.get("messungs_id_alt")); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + builder.add("statusEdit", JsonValue.TRUE); + builder.add("status", 1000); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/messung.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("messung", "rest/messung"); + getById("messung", "rest/messung/1200", expectedById); + JsonObject created = create("messung", "rest/messung", create); + update("messung", "rest/messung/1200", "nebenprobenNr", "T100", "U200"); + delete("messung", "rest/messung/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Messwert.java --- a/src/test/java/de/intevation/lada/test/land/Messwert.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,337 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - -/** - * Class containing test cases for messwert objects. - * - * @author Raimund Renkert - */ -public class Messwert { - - private static final int MESSUNGS_ID = 591; - - private static final String COMPARE_MESSWERT = - "{\"id\":1,\"grenzwertueberschreitung\":null,\"letzteAenderung\":" + - "1327305368000,\"mehId\":69,\"messfehler\":1.1,\"messgroesseId\":28," + - "\"messungsId\":749,\"messwert\":97.0,\"messwertNwg\":null," + - "\"nwgZuMesswert\":null,\"owner\":false,\"readonly\":false," + - "\"treeModified\":null,\"parentModified\":null}"; - - private static final String CREATE_MESSWERT = - "{\"messungsId\":MID,\"messgroesseId\":242,\"messwert\":1," + - "\"messwertNwg\":\"\",\"messfehler\":1,\"nwgZuMesswert\":3," + - "\"mehId\":207,\"grenzwertueberschreitung\":false," + - "\"letzteAenderung\":null}"; - - private List protocol; - - private static Integer createdMesswertId; - - public Integer getCreatedMesswertId() { - return createdMesswertId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertFalse(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("699", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert/1"); - prot.addInfo("messwertId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert?messungsId=" + MESSUNGS_ID); - prot.addInfo("filter", "messungsId=" + MESSUNGS_ID); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert"); - /* Send a post request containing a new object*/ - String mess = CREATE_MESSWERT.replace("MID", messungId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(mess, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdMesswertId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("messwertId", createdMesswertId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert/" + createdMesswertId); - prot.addInfo("messwertId", createdMesswertId); - /* Request a messwert with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldMesswert = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - oldMesswert.toString().replace("207", "69"); - prot.addInfo("updated field", "mehId"); - prot.addInfo("updated value", "207"); - prot.addInfo("updated to", "69"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "messwert/" + createdMesswertId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedMessung = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedMessung.getBoolean("success")); - prot.addInfo("success", updatedMessung.getBoolean("success")); - Assert.assertEquals("200", updatedMessung.getString("message")); - prot.addInfo("message", updatedMessung.getString("message")); - Assert.assertEquals(69, - updatedMessung.getJsonObject("data").getInt("mehId")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert/" + createdMesswertId); - prot.addInfo("messwertId", createdMesswertId); - /* Delete a messwert with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/MesswertTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/MesswertTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,62 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class MesswertTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_messwert.json"); + JsonObject messung = content.getJsonArray("land.messwert").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/messwert.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("messwert", "rest/messwert?messungsId=1000"); + getById("messwert", "rest/messwert/10000", expectedById); + JsonObject created = create("messwert", "rest/messwert", create); + update("messwert", "rest/messwert/10000", "messwertNwg", "<", ">"); + delete("messwert", "rest/messwert/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Ort.java --- a/src/test/java/de/intevation/lada/test/land/Ort.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,333 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - -/** - * Class containing test cases for ort objects. - * - * @author Raimund Renkert - */ -public class Ort { - - private static final String COMPARE = - "{\"id\":1,\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + - "\"ortszusatztext\":null,\"probeId\":96,\"ort\":213,\"owner\":false," + - "\"readonly\":false,\"treeModified\":null,\"parentModified\":null}"; - - private static final String CREATE = - "{\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + - "\"ortszusatztext\":\"textzusatz\",\"probeId\":PID,\"ort\":213}"; - - private List protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort/1"); - prot.addInfo("ortId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort?probeId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort"); - /* Send a post request containing a new object*/ - String mess = CREATE.replace("PID", probeId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(mess, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("ortId", createdId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort/" + createdId); - prot.addInfo("ortId", createdId); - /* Request an object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("textzusatz", "changedzusatz"); - prot.addInfo("updated field", "ortszusatztext"); - prot.addInfo("updated value", "text"); - prot.addInfo("updated to", "zusatz"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "ort/" + createdId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedObj = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedObj.getBoolean("success")); - prot.addInfo("success", updatedObj.getBoolean("success")); - Assert.assertEquals("200", updatedObj.getString("message")); - prot.addInfo("message", updatedObj.getString("message")); - Assert.assertEquals("changedzusatz", - updatedObj.getJsonObject("data").getString("ortszusatztext")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort/" + createdId); - prot.addInfo("ortId", createdId); - /* Delete the object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/OrtszuordnungTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/OrtszuordnungTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,61 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class OrtszuordnungTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_ortszuordnung.json"); + JsonObject messung = content.getJsonArray("land.ortszuordnung").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/ortszuordnung.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("ortszuordnung", "rest/ortszuordnung"); + getById("ortszuordnung", "rest/ortszuordnung/1000", expectedById); + JsonObject created = create("ortszuordnung", "rest/ortszuordnung", create); + update("ortszuordnung", "rest/ortszuordnung/1000", "ortszusatztext", "Test", "Test geändert"); + delete("ortszuordnung", "rest/ortszuordnung/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Probe.java --- a/src/test/java/de/intevation/lada/test/land/Probe.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,346 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - - -/** - * Class containing test cases for probe objects. - * - * @author Raimund Renkert - */ -public class Probe { - - private static final String COMPARE_PROBE = - "{\"id\":1,\"baId\":\"1\",\"datenbasisId\":2," + - "\"letzteAenderung\":1339570306000,\"media\":\"Trinkwasser " + - "Zentralversorgung Oberflächenwasser aufbereitet\",\"mediaDesk\":" + - "\"D: 59 04 01 00 05 05 01 02 00 00 00 00\",\"mittelungsdauer\":" + - "null,\"mstId\":\"06010\",\"netzbetreiberId\":\"06\"," + - "\"probeentnahmeBeginn\":1336467600000,\"probeentnahmeEnde\":" + - "null,\"probenartId\":1,\"test\":false,\"umwId\":\"N72\"," + - "\"hauptprobenNr\":\"120510002\",\"erzeugerId\":null,\"mpKat\":\"1\"," + - "\"mplId\":null,\"mprId\":3749,\"probeNehmerId\":726," + - "\"solldatumBeginn\":1336341600000,\"solldatumEnde\":1336939199000," + - "\"treeModified\":null,\"readonly\":false,\"owner\":false," + - "\"probeIdAlt\":\"000007581034X\"}"; - - private static final String CREATE_PROBE = - "{\"baId\":\"1\",\"datenbasisId\":2,\"erzeugerId\":\"\"," + - "\"hauptprobenNr\":\"4554567890\",\"media\":\"\",\"mediaDesk\":" + - "\"\",\"mittelungsdauer\":\"\",\"mpKat\":\"\",\"mplId\":\"\"," + - "\"mprId\":\"\",\"mstId\":\"11010\",\"netzbetreiberId\":\"11\"," + - "\"probeNehmerId\":3,\"probenartId\":1,\"test\":true,\"umwId\":" + - "\"A1\",\"letzteAenderung\":\"2015-02-09T10:58:36\"" + - ",\"probeentnahmeBeginn\":\"2015-02-08T10:58:36\"," + - "\"probeentnahmeEnde\":\"2015-02-09T10:58:36\",\"solldatumBeginn\":" + - "\"2015-02-09T10:58:36\",\"solldatumEnde\":\"2015-02-09T10:58:36\"}"; - - private List protocol; - - private static Integer createdProbeId; - - public Integer getCreatedProbeId() { - return createdProbeId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe/1"); - prot.addInfo("probeId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception",je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe?qid=2&mst_id=11010&umw_id=N24"); - prot.addInfo("filter", "qid=2&mst_id=11010&umw_id=N24"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe"); - /* Send a post request containing a new probe*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(CREATE_PROBE, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdProbeId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("probeId", createdProbeId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the probe update service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe/" + createdProbeId); - prot.addInfo("probeId", createdProbeId); - /* Request a with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldProbe = reader.readObject().getJsonObject("data"); - /* Change the hauptprobenNr*/ - String updatedEntity = - oldProbe.toString().replace("4554567890", "2345678911"); - prot.addInfo("updated datafield", "hauptprobenNr"); - prot.addInfo("updated value", "1234567890"); - prot.addInfo("updated to", "2345678911"); - /* Send the updated probe via put request*/ - WebTarget putTarget = client.target(baseUrl + "probe/" + createdProbeId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedProbe = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedProbe.getBoolean("success")); - prot.addInfo("success", updatedProbe.getBoolean("success")); - Assert.assertEquals("200", updatedProbe.getString("message")); - prot.addInfo("message", updatedProbe.getString("message")); - Assert.assertEquals("2345678911", - updatedProbe.getJsonObject("data").getString("hauptprobenNr")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe/" + createdProbeId); - prot.addInfo("probeId", createdProbeId); - /* Delete a probe with the id saved when created a probe*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/ProbeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/ProbeTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,72 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class ProbeTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung", + "probeentnahmeBeginn", + "solldatumBeginn", + "solldatumEnde", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_probe.json"); + JsonObject probe = content.getJsonArray("land.probe").getJsonObject(0); + JsonObjectBuilder builder = convertObject(probe); + JsonObject trans = + content.getJsonArray("land.probe_translation").getJsonObject(0); + builder.add("probeIdAlt", trans.get("probe_id_alt")); + builder.add("mittelungsdauer", JsonValue.NULL); + builder.add("probeentnahmeEnde", JsonValue.NULL); + builder.add("erzeugerId", JsonValue.NULL); + builder.add("mplId", JsonValue.NULL); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/probe.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("probe", "rest/probe"); + getById("probe", "rest/probe/1000", expectedById); + filter("probe", "rest/probe?qid=2&mst_id=11010&umw_id=N24"); + JsonObject created = create("probe", "rest/probe", create); + update("probe", "rest/probe/1000", "hauptprobenNr", "120510002", "130510002"); + delete("probe", "rest/probe/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Query.java --- a/src/test/java/de/intevation/lada/test/land/Query.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - - -/** - * Class containing test cases for query config. - * - * @author Raimund Renkert - */ -public class Query { - - private List protocol; - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all queries. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("QueryService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "query/probe"); - /* Request all queries*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verfiy the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/QueryTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/QueryTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,30 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.List; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class QueryTest extends ServiceTest { + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + } + + public final void execute() { + getAll("query", "rest/query/probe"); + getAll("query", "rest/query/messprogramm"); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Status.java --- a/src/test/java/de/intevation/lada/test/land/Status.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,335 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - -/** - * Class containing test cases for status objects. - * - * @author Raimund Renkert - */ -public class Status { - - private static final int MESSUNGS_ID = 591; - - private static final String COMPARE = - "{\"id\":1,\"erzeuger\":\"06010\",\"messungsId\":440,\"status\":3," + - "\"owner\":false,\"readonly\":false,\"treeModified\":null," + - "\"parentModified\":null," + - "\"sdatum\":1373846400000,\"skommentar\":\"test\"}"; - - private static final String CREATE = - "{\"erzeuger\":\"06010\",\"messungsId\":MID,\"statusStufe\":1," + - "\"statusWert\":1," + - "\"datum\":1373846400000,\"text\":\"status test\"}"; - - private List protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertFalse(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("699", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status/511"); - prot.addInfo("statusId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status?messungsId=" + MESSUNGS_ID); - prot.addInfo("filter", "messungsId=" + MESSUNGS_ID); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status"); - /* Send a post request containing a new object*/ - String stat = CREATE.replace("MID", messungId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(stat, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("statusId", createdId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status/" + createdId); - prot.addInfo("statusId", createdId); - /* Request an object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("statusWert\":1", "statusWert\":0"); - prot.addInfo("updated field", "statusWert"); - prot.addInfo("updated value", "1"); - prot.addInfo("updated to", "0"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "status/" + createdId); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedObj = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedObj.getBoolean("success")); - prot.addInfo("success", updatedObj.getBoolean("success")); - Assert.assertEquals("200", updatedObj.getString("message")); - prot.addInfo("message", updatedObj.getString("message")); - Assert.assertEquals(0, - updatedObj.getJsonObject("data").getJsonNumber("statusWert").intValue()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status/" + createdId); - prot.addInfo("statusId", createdId); - /* Delete the object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/StatusTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/StatusTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,64 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class StatusTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "datum", + "treeModified" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_messung.json"); + JsonObject status = content.getJsonArray("land.status_protokoll").getJsonObject(0); + JsonObjectBuilder builder = convertObject(status); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/status.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("status", "rest/status?messungsId=1000"); + getById("status", "rest/status/1000", expectedById); + //update("status", "rest/status/1000", "text", "Initialer Status", "Initialer Status geändert"); + //JsonObject created = + create("status", "rest/status", create); + //delete("status", "rest/status/" + created.getJsonObject("data").get("id")); + } + +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/Zusatzwert.java --- a/src/test/java/de/intevation/lada/test/land/Zusatzwert.java Thu Jan 14 10:22:14 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,335 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.test.land; - -import java.io.StringReader; -import java.net.URL; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.junit.Assert; - -import de.intevation.lada.BaseTest; -import de.intevation.lada.Protocol; - -/** - * Class containing test cases for zusatzwert objects. - * - * @author Raimund Renkert - */ -public class Zusatzwert { - - private static final String COMPARE = - "{\"id\":1,\"letzteAenderung\":1335177176000,\"messfehler\":48.0," + - "\"messwertPzs\":7.5,\"nwgZuMesswert\":null,\"probeId\":84," + - "\"pzsId\":\"A76\",\"owner\":false,\"readonly\":false," + - "\"treeModified\":null,\"parentModified\":null}"; - - private static final String CREATE = - "{\"letzteAenderung\":1335177176000,\"messfehler\":18.0," + - "\"messwertPzs\":3.5,\"nwgZuMesswert\":null,\"probeId\":PID," + - "\"pzsId\":\"A76\"}"; - - private List protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getAllService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert"); - /* Request all objects*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - try{ - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject content = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertNotNull(content.getJsonArray("data")); - prot.addInfo("objects", content.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void getByIdService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert/1"); - prot.addInfo("zustzwertId", 1); - /* Request a object by id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - Assert.assertFalse(content.getJsonObject("data").isEmpty()); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - public final void filterService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert?probeIdId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the objects using the filter*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void createService( - URL baseUrl, - List protocol, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert"); - /* Send a post request containing a new object*/ - String zus = CREATE.replace("PID", probeId.toString()); - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .post(Entity.entity(zus, MediaType.APPLICATION_JSON)); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader fromServiceReader = - Json.createReader(new StringReader(entity)); - JsonObject content = fromServiceReader.readObject(); - /* Save the id*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("zusatzwertId", createdId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("message", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void updateService(URL baseUrl, List protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert/" + createdId); - prot.addInfo("zusatzwertId", createdId); - /* Request an object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("3.5", "14"); - prot.addInfo("updated field", "messwertPzs"); - prot.addInfo("updated value", "3.5"); - prot.addInfo("updated to", "14"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "zusatzwert"); - Response updated = putTarget.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); - /* Try to parse the response*/ - JsonReader updatedReader = Json.createReader( - new StringReader(updated.readEntity(String.class))); - JsonObject updatedObj = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedObj.getBoolean("success")); - prot.addInfo("success", updatedObj.getBoolean("success")); - Assert.assertEquals("200", updatedObj.getString("message")); - prot.addInfo("message", updatedObj.getString("message")); - Assert.assertEquals(14, - updatedObj.getJsonObject("data").getJsonNumber("messwertPzs")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - public final void deleteService(URL baseUrl, List protocol) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert/" + createdId); - prot.addInfo("zusatzwertId", createdId); - /* Delete the object with the saved id*/ - Response response = target.request() - .header("X-SHIB-user", BaseTest.TEST_USER) - .header("X-SHIB-roles", BaseTest.TEST_ROLES) - .delete(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject respObj = reader.readObject(); - /* Verify the response*/ - Assert.assertTrue(respObj.getBoolean("success")); - prot.addInfo("success", respObj.getBoolean("success")); - Assert.assertEquals("200", respObj.getString("message")); - prot.addInfo("message", respObj.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/land/ZusatzwertTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/ZusatzwertTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,62 @@ +package de.intevation.lada.test.land; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class ZusatzwertTest extends ServiceTest { + + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung", + "treeModified" + }); + + // Prepare expected probe object + JsonObject content = readJsonResource("/datasets/dbUnit_zusatzwert.json"); + JsonObject messung = content.getJsonArray("land.zusatz_wert").getJsonObject(0); + JsonObjectBuilder builder = convertObject(messung); + builder.add("parentModified", 1450371851654L); + builder.add("readonly", JsonValue.FALSE); + builder.add("owner", JsonValue.TRUE); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load probe object to test POST request + create = readJsonResource("/datasets/zusatzwert.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("zusatzwert", "rest/zusatzwert"); + getById("zusatzwert", "rest/zusatzwert/1000", expectedById); + JsonObject created = create("zusatzwert", "rest/zusatzwert", create); + update("zusatzwert", "rest/zusatzwert/1000", "pzsId", "A77", "A78"); + delete("zusatzwert", "rest/zusatzwert/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/stamm/DatensatzErzeugerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/stamm/DatensatzErzeugerTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,57 @@ +package de.intevation.lada.test.stamm; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class DatensatzErzeugerTest extends ServiceTest { + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_datensatzerzeuger.json"); + JsonObject erzeuger = content.getJsonArray("stammdaten.datensatz_erzeuger").getJsonObject(0); + JsonObjectBuilder builder = convertObject(erzeuger); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/datensatzerzeuger.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("datensatzerzeuger", "rest/datensatzerzeuger"); + getById("datensatzerzeuger", "rest/datensatzerzeuger/1000", expectedById); + update("datensatzerzeuger", "rest/datensatzerzeuger/1000", "bezeichnung", "Testbezeichnung", "geändert"); + JsonObject created = create("datensatzerzeuger", "rest/datensatzerzeuger", create); + delete("datensatzerzeuger", "rest/datensatzerzeuger/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/stamm/MessprogrammKategorieTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/stamm/MessprogrammKategorieTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,57 @@ +package de.intevation.lada.test.stamm; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonValue; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class MessprogrammKategorieTest extends ServiceTest { + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_messprogrammkategorie.json"); + JsonObject erzeuger = content.getJsonArray("stammdaten.messprogramm_kategorie").getJsonObject(0); + JsonObjectBuilder builder = convertObject(erzeuger); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/messprogrammkategorie.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("messprogrammkategorie", "rest/messprogrammkategorie"); + getById("messprogrammkategorie", "rest/messprogrammkategorie/1000", expectedById); + update("messprogrammkategorie", "rest/messprogrammkategorie/1000", "bezeichnung", "Testbezeichnung", "geändert"); + JsonObject created = create("messprogrammkategorie", "rest/messprogrammkategorie", create); + delete("messprogrammkategorie", "rest/messprogrammkategorie/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/stamm/OrtTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/stamm/OrtTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,56 @@ +package de.intevation.lada.test.stamm; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class OrtTest extends ServiceTest { + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_ort.json"); + JsonObject erzeuger = content.getJsonArray("stammdaten.ort").getJsonObject(0); + JsonObjectBuilder builder = convertObject(erzeuger); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/ort.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("ort", "rest/ort"); + getById("ort", "rest/ort/1000", expectedById); + update("ort", "rest/ort/1000", "langtext", "Langer Text", "Längerer Text"); + JsonObject created = create("ort", "rest/ort", create); + delete("ort", "rest/ort/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/stamm/ProbenehmerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/stamm/ProbenehmerTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,56 @@ +package de.intevation.lada.test.stamm; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; + +import org.junit.Assert; + +import de.intevation.lada.Protocol; +import de.intevation.lada.test.ServiceTest; + +public class ProbenehmerTest extends ServiceTest { + private JsonObject expectedById; + private JsonObject create; + + /** + * @return The test protocol + */ + public List getProtocol() { + return protocol; + } + + @Override + public void init( + URL baseUrl, + List protocol + ) { + super.init(baseUrl, protocol); + // Attributes with timestamps + timestampAttributes = Arrays.asList(new String[]{ + "letzteAenderung" + }); + + // Prepare expected object + JsonObject content = readJsonResource("/datasets/dbUnit_probenehmer.json"); + JsonObject probenehmer = content.getJsonArray("stammdaten.probenehmer").getJsonObject(0); + JsonObjectBuilder builder = convertObject(probenehmer); + expectedById = builder.build(); + Assert.assertNotNull(expectedById); + + // Load object to test POST request + create = readJsonResource("/datasets/probenehmer.json"); + Assert.assertNotNull(create); + } + + public final void execute() { + getAll("probenehmer", "rest/probenehmer"); + getById("probenehmer", "rest/probenehmer/1000", expectedById); + update("probenehmer", "rest/probenehmer/1000", "bezeichnung", "Testbezeichnung", "geändert"); + JsonObject created = create("probenehmer", "rest/probenehmer", create); + delete("probenehmer", "rest/probenehmer/" + created.getJsonObject("data").get("id")); + } +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/java/de/intevation/lada/test/stamm/Stammdaten.java --- a/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java Thu Jan 21 09:01:57 2016 +0100 @@ -16,7 +16,6 @@ import javax.ws.rs.core.Response; import org.junit.Assert; - import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -25,8 +24,10 @@ public class Stammdaten { + @SuppressWarnings("rawtypes") private static Map matchers; + @SuppressWarnings("rawtypes") public Stammdaten() { matchers = new HashMap(); @@ -186,14 +187,14 @@ public final void getAll(URL baseUrl, String type, List protocol) { System.out.print("."); Protocol prot = new Protocol(); - prot.setName(type + "Service"); + prot.setName(type + " service"); prot.setType("get all"); prot.setPassed(false); protocol.add(prot); Assert.assertNotNull(type); /* Create a client*/ Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + type); + WebTarget target = client.target(baseUrl + "rest/" + type); /* Request all objects*/ Response response = target.request() .header("X-SHIB-user", BaseTest.TEST_USER) @@ -219,6 +220,7 @@ prot.setPassed(true); } + @SuppressWarnings("unchecked") public final void getById( URL baseUrl, String type, @@ -234,7 +236,7 @@ try { /* Create a client*/ Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + type +"/" + id); + WebTarget target = client.target(baseUrl + "rest/" + type +"/" + id); prot.addInfo(type + "Id", id); /* Request an object by id*/ Response response = target.request() diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/META-INF/test-persistence.xml --- a/src/test/resources/META-INF/test-persistence.xml Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/resources/META-INF/test-persistence.xml Thu Jan 21 09:01:57 2016 +0100 @@ -3,12 +3,10 @@ xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> - - java:/jboss/lada-bund + java:jboss/lada-bund false - @@ -17,7 +15,7 @@ org.hibernate.ejb.HibernatePersistence - java:/jboss/lada-land + java:jboss/lada-land false @@ -28,7 +26,7 @@ org.hibernate.ejb.HibernatePersistence - java:/jboss/lada-stamm + java:jboss/lada-stamm diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/arquillian.xml --- a/src/test/resources/arquillian.xml Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/resources/arquillian.xml Thu Jan 21 09:01:57 2016 +0100 @@ -20,20 +20,23 @@ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> - + - - + + - - - + + + - + + + true + diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/cleanup.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/cleanup.sql Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,6 @@ +DELETE FROM land.probe WHERE id = 1000; +DELETE FROM land.messprogramm WHERE id = 1000; +DELETE FROM stammdaten.datensatz_erzeuger WHERE id = 1000; +DELETE FROM stammdaten.probenehmer WHERE id = 1000; +DELETE FROM stammdaten.messprogramm_kategorie WHERE id = 1000; +DELETE FROM stammdaten.ort WHERE id = 1000; \ No newline at end of file diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/datensatzerzeuger.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/datensatzerzeuger.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,7 @@ +{ + "daErzeugerId": "06", + "letzteAenderung": 1381413048800, + "mstId": "06010", + "bezeichnung": "Test 1", + "netzbetreiberId": "06" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_datensatzerzeuger.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_datensatzerzeuger.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,10 @@ +{ + "stammdaten.datensatz_erzeuger": [{ + "id": 1000, + "bezeichnung": "Testbezeichnung", + "netzbetreiber_id": "06", + "mst_id": "06010", + "da_erzeuger_id": "06", + "letzte_aenderung": "2015-03-01 12:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_messprogramm.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_messprogramm.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,18 @@ +{ + "land.messprogramm": [{ + "id": 1000, + "name": "testprogramm", + "test": false, + "netzbetreiber_id": "06", + "mst_id": "06010", + "datenbasis_id": 2, + "gem_id": "11000000", + "media_desk": "D: 50 90 01 06 02 05 00 00 00 00 00 00", + "umw_id": "N81", + "probenart_id": 3, + "probenintervall": "M", + "teilintervall_von": 1, + "teilintervall_bis": 30, + "letzte_aenderung": "2015-03-01 12:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_messprogrammkategorie.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_messprogrammkategorie.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,9 @@ +{ + "stammdaten.messprogramm_kategorie": [{ + "id": 1000, + "netzbetreiber_id": "06", + "mpl_id": "mp2", + "bezeichnung": "Testbezeichnung", + "letzte_aenderung": "2015-03-01 12:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_messung.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_messung.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,29 @@ +{ + "land.messung": [{ + "id": 1200, + "probe_id": 1000, + "nebenproben_nr": "T100", + "mmt_id": "G1", + "messdauer": 3600, + "messzeitpunkt": "2012-05-06 14:00:00", + "fertig": false, + "letzte_aenderung": "2012-05-08 12:00:00", + "geplant": true, + "tree_modified": "2012-05-09 12:00:00" + }], + "land.messung_translation": [{ + "id": 1200, + "messungs_id": 1200, + "messungs_id_alt": 453 + }], + "land.status_protokoll": [{ + "id": 1000, + "erzeuger": "06010", + "datum": "2012-05-08 11:00:00", + "text": "Initialer Status", + "messungs_id": 1200, + "status_stufe": 1, + "status_wert": 0, + "tree_modified": "2012-05-09 12:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_messwert.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_messwert.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,14 @@ +{ + "land.messwert":[{ + "id": 10000, + "messungs_id": 1200, + "messgroesse_id": 29, + "messwert_nwg": "<", + "messwert": 28.0, + "messfehler": 3.3, + "nwg_zu_messwert": 2.4, + "meh_id": 65, + "grenzwertueberschreitung": false, + "letzte_aenderung": "2012-05-09 09:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_mkommentar.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_mkommentar.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,9 @@ +{ + "land.kommentar_m": [{ + "id":1000, + "erzeuger":"06010", + "datum":"2012-05-08 11:00:00", + "text":"Testkommentar", + "messungs_id":1200 + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_ort.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_ort.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,21 @@ +{ + "stammdaten.ort": [{ + "id": 1000, + "netzbetreiber_id": "06", + "ort_id": "D_ 00191", + "langtext": "Langer Text", + "staat_id": 0, + "gem_id": "11000000", + "unscharf": "t", + "nuts_code": "DE716", + "kda_id": 5, + "koord_x_extern": "32487017", + "koord_y_extern": "5519769", + "letzte_aenderung": "2015-03-01 12:00:00", + "latitude": 49.83021, + "longitude": 8.81948, + "ort_typ": 1, + "kurztext": "kurz", + "berichtstext": "bericht" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_ortszuordnung.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_ortszuordnung.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,10 @@ +{ + "land.ortszuordnung": [{ + "id": 1000, + "probe_id": 1000, + "ort_id": 23, + "ortszuordnung_typ": "E", + "ortszusatztext": "Test", + "letzte_aenderung": "2012-05-07 09:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_pkommentar.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_pkommentar.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,9 @@ +{ + "land.kommentar_p": [{ + "id": 1000, + "erzeuger": "06010", + "datum": "2012-05-11 12:01:00", + "text": "Testkommentar", + "probe_id": 1000 + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_probe.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_probe.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,28 @@ +{ + "land.probe": [{ + "id": 1000, + "ba_id": "1", + "datenbasis_id": 2, + "letzte_aenderung": "2012-05-05 11:12:00", + "media": "Trinkwasser Zentralversorgung Oberflächenwasser aufbereitet", + "media_desk": "D: 59 04 01 00 05 05 01 02 00 00 00 00", + "mst_id": "06010", + "netzbetreiber_id": "06", + "probeentnahme_beginn": "2012-05-03 13:07:00", + "probenart_id": 1, + "test": false, + "umw_id":"N72", + "hauptproben_nr": "120510002", + "mp_kat": "1", + "mpr_id": 3749, + "probe_nehmer_id": 726, + "solldatum_beginn": "2012-05-01 16:00:00", + "solldatum_ende": "2012-05-05 16:00:00", + "tree_modified": "2012-05-08 10:00:00" + }], + "land.probe_translation": [{ + "id": 1100, + "probe_id": 1000, + "probe_id_alt": "T001" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_probenehmer.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_probenehmer.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,19 @@ +{ + "stammdaten.probenehmer": [{ + "id": 1000, + "netzbetreiber_id": "06", + "prn_id": "AV6", + "bearbeiter": "Testbearbeiter", + "bemerkung": "Testbemerkung", + "betrieb": "Testbetrieb", + "bezeichnung": "Testbezeichnung", + "kurz_bezeichnung": "Testkurz", + "ort": "Testhausen", + "plz": "12345", + "strasse": "Teststrasse", + "telefon": "01100011", + "tp": "kpt", + "typ": "a", + "letzte_aenderung": "2015-03-01 12:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/dbUnit_zusatzwert.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/dbUnit_zusatzwert.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,11 @@ +{ + "land.zusatz_wert": [{ + "id": 1000, + "probe_id": 1000, + "pzs_id": "A77", + "messwert_pzs": 12.0, + "messfehler": 8.0, + "nwg_zu_messwert": 3.0, + "letzte_aenderung": "2012-05-08 14:00:00" + }] +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/messprogramm.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/messprogramm.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,22 @@ +{ + "baId": null, + "datenbasisId": 2, + "gemId": "11000000", + "gueltigBis": null, + "gueltigVon": null, + "intervallOffset": null, + "letzteAenderung": 1381413048800, + "mediaDesk": "D: 01 01 01 01 01 01 00 00 00 00 00 00", + "mstId": "06010", + "name": "Test 1", + "netzbetreiberId": "06", + "ortId": null, + "probeKommentar": null, + "probeNehmerId": null, + "probenartId": 3, + "probenintervall": "M", + "teilintervallBis": 30, + "teilintervallVon": 1, + "test": false, + "umwId": "N11" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/messprogrammkategorie.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/messprogrammkategorie.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,5 @@ +{ + "bezeichnung": "Testbezeichnung", + "netzbetreiberId": "06", + "mplId": "mp5" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/messung.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/messung.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,9 @@ +{ + "probeId":"1000", + "mmtId":"A4", + "nebenprobenNr":"10R1", + "messdauer":10, + "fertig":false, + "geplant":true, + "messzeitpunkt":"2015-02-09T10:58:36" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/messwert.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/messwert.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,11 @@ +{ + "messungsId": 1200, + "messgroesseId": 242, + "messwert":1, + "messwertNwg":"", + "messfehler":1, + "nwgZuMesswert":3, + "mehId":207, + "grenzwertueberschreitung":false +} + diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/mkommentar.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/mkommentar.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,7 @@ +{ + "messungsId":1200, + "erzeuger":"06010", + "text":"test", + "datum":"2015-02-09T10:58:36" +} + diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/ort.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/ort.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,17 @@ +{ + "netzbetreiberId": "06", + "ortId": "D_ 00191", + "langtext": "Langer Text", + "staatId": 0, + "gemId": "11000000", + "unscharf": "t", + "nutsCode": "DE716", + "kdaId": 5, + "koordXExtern": "32487017", + "koordYExtern": "5519769", + "latitude": 49.83021, + "longitude": 8.81948, + "ortTyp": 1, + "kurztext": "kurz", + "berichtstext": "bericht" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/ortszuordnung.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/ortszuordnung.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,6 @@ +{ + "ortszuordnungTyp": "Z", + "ortszusatztext": "textzusatz", + "probeId": 1000, + "ortId":213 +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/pkommentar.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/pkommentar.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,6 @@ +{ + "probeId": "1000", + "erzeuger": "06010", + "text": "test", + "datum": "2015-02-09T10:58:36" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/probe.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/probe.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,23 @@ +{ + "baId":"1", + "datenbasisId":2, + "erzeugerId":"", + "hauptprobenNr":"4554554550", + "media":"", + "mediaDesk": "", + "mittelungsdauer":"", + "mpKat":"", + "mplId":"", + "mprId":"", + "mstId":"06010", + "netzbetreiberId":"11", + "probeNehmerId":3, + "probenartId":1, + "test":true, + "umwId":"A11", + "letzteAenderung":"2015-02-09T10:58:36", + "probeentnahmeBeginn":"2015-02-08T10:58:36", + "probeentnahmeEnde":"2015-02-09T10:58:36", + "solldatumBeginn":"2015-02-09T10:58:36", + "solldatumEnde":"2015-02-09T10:58:36" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/probenehmer.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/probenehmer.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,16 @@ +{ + "netzbetreiberId": "06", + "prnId": "AR6", + "bearbeiter": "Testbearbeiter", + "bemerkung": "Testbemerkung", + "betrieb": "Testbetrieb", + "bezeichnung": "Testbezeichnung", + "kurzBezeichnung": "Testkurz", + "ort": "Testhausen", + "plz": "12345", + "strasse": "Teststrasse", + "telefon": "01100011", + "tp": "kpt", + "typ": "a", + "letzteAenderung": "2015-03-01T12:00:00" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/status.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/status.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,9 @@ +{ + "erzeuger": "06010", + "messungsId": 1200, + "statusStufe":1, + "statusWert":2, + "datum": "2012-05-10T09:09:00", + "text": "Status geändert" +} + diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/datasets/zusatzwert.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/datasets/zusatzwert.json Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,7 @@ +{ + "messfehler":18.0, + "messwertPzs":3.5, + "nwgZuMesswert":null, + "probeId":1000, + "pzsId":"A76" +} diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/log4j.properties --- a/src/test/resources/log4j.properties Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/resources/log4j.properties Thu Jan 21 09:01:57 2016 +0100 @@ -8,3 +8,4 @@ log4j.appender.lada.MaxBackupIndex=5 log4j.appender.lada.layout=org.apache.log4j.PatternLayout log4j.appender.lada.layout.ConversionPattern=%d: %m%n +log4j.logger.org.dbunit=ERROR diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/messprogrammquery.json --- a/src/test/resources/messprogrammquery.json Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/resources/messprogrammquery.json Thu Jan 21 09:01:57 2016 +0100 @@ -1,6 +1,7 @@ [ { "id": "1", "name": "Kein Filter", + "type": "messprogramm", "description": "Abfrage der Messprogramme ohne Filter", "sql": "select m.id as id, m.name as name, m.mst_id as mstId, m.umw_id as umwId from land.messprogramm m", "result": [ diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/probequery.json --- a/src/test/resources/probequery.json Thu Jan 14 10:22:14 2016 +0100 +++ b/src/test/resources/probequery.json Thu Jan 21 09:01:57 2016 +0100 @@ -3,6 +3,7 @@ "name": "Kein Filter", "description": "Abfrage der Proben ohne Filter", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "mstId", "header": "MST", "width": 100}, @@ -15,6 +16,7 @@ "name": "MST und UMW", "description": "Abfrage der Proben gefiltert nach Messtellen ID und ID des Umweltbereichs", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "mstId", "header": "MST", "width": 100}, @@ -29,6 +31,7 @@ "name": "Proben pro Land", "description": "Proben gefiltert nach Ländern", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (netzbetreiber_id = :netz OR '' = :netz)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 100}, @@ -44,6 +47,7 @@ "name": "alle Proben mit Ort", "description": "alle Proben mit Entnahmeort", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where o.orts_typ = 'E' or o.orts_typ is null", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, @@ -60,6 +64,7 @@ "name": "Proben pro Land und UMW (Multiselect)", "description": "Abfrage aller Proben gefiltert pro Land und Umweltbereich (mit Mehrfachauswahl)", "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, to_char(p.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahmeVon, to_char(p.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahmeBis, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, o.orts_typ as ortsTyp, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where (o.orts_typ = 'E' or o.orts_typ is null) and (p.netzbetreiber_id = :netz OR '' =:netz) and (p.umw_id similar to (:umw_id) OR '' = :umw_id)", + "type": "probe", "result": [ {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, diff -r 2203e5d76071 -r 2fe625c91ab3 src/test/resources/shibboleth.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/resources/shibboleth.properties Thu Jan 21 09:01:57 2016 +0100 @@ -0,0 +1,2 @@ +applicationId=default +enabled=false