Merge branch 'DEVELOP_BE' of ssh://git.eclipse.org:29418/elogbook/elogbook into DEVELOP_BE
diff --git a/.gitignore b/.gitignore
index 01e2636..e705fa8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@
.project
.classpath
/elogbook.iml
+/.idea
diff --git a/db/oracle/01a_drop_DB_1.0.0.sql b/db/oracle/01a_drop_DB_1.0.0.sql
new file mode 100644
index 0000000..231d287
--- /dev/null
+++ b/db/oracle/01a_drop_DB_1.0.0.sql
@@ -0,0 +1,15 @@
+DROP SEQUENCE HTBL_RESP_ID_SEQ;
+DROP SEQUENCE REF_BRANCH_ID_SEQ;
+DROP SEQUENCE REF_GRID_TERRITORY_ID_SEQ;
+DROP SEQUENCE REF_NOTIF_STATUS_ID_SEQ;
+DROP SEQUENCE TBL_NOTIF_ID_SEQ;
+DROP SEQUENCE TBL_NOTIF_INCIDENT_SEQ;
+DROP SEQUENCE TBL_RESP_ID_SEQ;
+
+DROP TABLE TBL_RESPONSIBILITY;
+DROP TABLE HTBL_RESPONSIBILITY;
+DROP TABLE TBL_NOTIFICATION;
+DROP TABLE REF_BRANCH;
+DROP TABLE REF_GRID_TERRITORY;
+DROP TABLE REF_NOTIFICATION_STATUS;
+DROP TABLE REF_VERSION;
\ No newline at end of file
diff --git a/db/oracle/02_create_DB_1.0.0.sql b/db/oracle/02_create_DB_1.0.0.sql
new file mode 100644
index 0000000..2c6445c
--- /dev/null
+++ b/db/oracle/02_create_DB_1.0.0.sql
@@ -0,0 +1,347 @@
+
+CREATE SEQUENCE HTBL_RESP_ID_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE REF_BRANCH_ID_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE REF_GRID_TERRITORY_ID_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE REF_NOTIF_STATUS_ID_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE TBL_NOTIF_ID_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE TBL_NOTIF_INCIDENT_SEQ
+ INCREMENT BY 1;
+
+CREATE SEQUENCE TBL_RESP_ID_SEQ
+ INCREMENT BY 1;
+
+
+CREATE TABLE REF_BRANCH
+(
+ "ID" NUMBER NOT NULL,
+ "NAME" VARCHAR2(50) NOT NULL,
+ "DESCRIPTION" VARCHAR2(255),
+ CONSTRAINT REF_BRANCH_PKEY PRIMARY KEY ("ID")
+);
+
+
+CREATE OR REPLACE TRIGGER "REF_BRANCH_BIR"
+BEFORE INSERT ON REF_BRANCH
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT REF_BRANCH_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "REF_BRANCH_BIR" ENABLE;
+
+-- TABLE: PUBLIC.REF_GRID_TERRITORY
+CREATE TABLE REF_GRID_TERRITORY
+(
+ "ID" INTEGER NOT NULL,
+ "NAME" VARCHAR2(50) NOT NULL,
+ "DESCRIPTION" VARCHAR2(255),
+ "FK_REF_MASTER" INTEGER NOT NULL,
+ CONSTRAINT REF_GRID_TERRITORY_PKEY PRIMARY KEY ("ID"),
+ CONSTRAINT FK_REF_GRID_TERRITORY_SELF FOREIGN KEY ("FK_REF_MASTER")
+ REFERENCES REF_GRID_TERRITORY ("ID")
+ ON DELETE CASCADE
+);
+
+CREATE OR REPLACE TRIGGER "REF_GRID_TERRITORY_BIR"
+BEFORE INSERT ON "REF_GRID_TERRITORY"
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT REF_GRID_TERRITORY_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "REF_GRID_TERRITORY_BIR" ENABLE;
+
+-- INDEX: PUBLIC.FKI_FK_GRID_TERRITORY_SELF
+CREATE INDEX FKI_FK_GRID_TERRITORY_SELF
+ ON "REF_GRID_TERRITORY"
+ ("FK_REF_MASTER");
+
+-- INDEX: REF_GRID_TERR_DESCR_UNIQUE
+CREATE UNIQUE INDEX REF_GRID_TERR_DESCR_UNIQUE
+ ON "REF_GRID_TERRITORY" ("DESCRIPTION");
+
+
+CREATE TABLE REF_NOTIFICATION_STATUS
+(
+ "ID" INTEGER NOT NULL,
+ "NAME" VARCHAR2(50) NOT NULL,
+ CONSTRAINT REF_NOTIFICATION_STATUS_PKEY PRIMARY KEY ("ID")
+);
+
+
+CREATE OR REPLACE TRIGGER "REF_NOTIFICATION_STATUS_BIR"
+BEFORE INSERT ON "REF_NOTIFICATION_STATUS"
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT REF_NOTIF_STATUS_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "REF_NOTIFICATION_STATUS_BIR" ENABLE;
+
+-- TABLE: PUBLIC.REF_VERSION
+CREATE TABLE REF_VERSION
+(
+ "ID" INTEGER NOT NULL,
+ "VERSION" VARCHAR2(100) NOT NULL,
+ CONSTRAINT REF_VERSION_PKEY PRIMARY KEY ("ID")
+);
+
+
+-- TABLE: PUBLIC.TBL_NOTIFICATION
+
+
+
+CREATE TABLE "TBL_NOTIFICATION"
+(
+ "ID" INTEGER NOT NULL,
+ "INCIDENT_ID" INTEGER,
+ "VERSION" INTEGER DEFAULT 0 NOT NULL,
+ "FK_REF_BRANCH" INTEGER,
+ "NOTIFICATION_TEXT" VARCHAR2(200) NOT NULL,
+ "FREE_TEXT" VARCHAR2(1000),
+ "FREE_TEXT_EXTENDED" VARCHAR2(1000),
+ "FK_REF_NOTIFICATION_STATUS" INTEGER NOT NULL,
+ "RESPONSIBILITY_FORWARDING" VARCHAR2(100),
+ "REMINDER_DATE" TIMESTAMP,
+ "EXPECTED_FINISHED_DATE" TIMESTAMP,
+ "RESPONSIBILITY_CONTROL_POINT" VARCHAR2(100),
+ "BEGIN_DATE" TIMESTAMP NOT NULL,
+ "FINISHED_DATE" TIMESTAMP,
+ "CREATE_USER" VARCHAR2(100) NOT NULL,
+ "CREATE_DATE" TIMESTAMP NOT NULL,
+ "MOD_USER" VARCHAR2(100),
+ "MOD_DATE" TIMESTAMP,
+ "FK_REF_GRID_TERRITORY" INTEGER,
+ "ADMIN_FLAG" NUMBER DEFAULT 0 NOT NULL,
+
+ CONSTRAINT TBL_NOTIFICATION_PKEY PRIMARY KEY ("ID"),
+ CONSTRAINT FK_NOTIFICATION_FK_BRANCH FOREIGN KEY ("FK_REF_BRANCH")
+ REFERENCES REF_BRANCH ("ID"),
+ CONSTRAINT FK_NOTIF_FK_GRID_TERR FOREIGN KEY ("FK_REF_GRID_TERRITORY")
+ REFERENCES REF_GRID_TERRITORY ("ID"),
+ CONSTRAINT FK_NOTIF_FK_STATUS FOREIGN KEY ("FK_REF_NOTIFICATION_STATUS")
+ REFERENCES REF_NOTIFICATION_STATUS ("ID")
+);
+
+CREATE OR REPLACE TRIGGER "TBL_NOTIFICATION_BIR"
+BEFORE INSERT ON "TBL_NOTIFICATION"
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT TBL_NOTIF_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "TBL_NOTIFICATION_BIR" ENABLE;
+
+
+CREATE OR REPLACE TRIGGER "TBL_NOTIF_INCIDENT_BIR"
+BEFORE INSERT ON "TBL_NOTIFICATION"
+FOR EACH ROW
+ WHEN (NEW."INCIDENT_ID" IS NULL) BEGIN
+ SELECT TBL_NOTIF_INCIDENT_SEQ.NEXTVAL
+ INTO :NEW."INCIDENT_ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "TBL_NOTIF_INCIDENT_BIR" ENABLE;
+
+-- INDEX: PUBLIC.CREATE_DATE_IDX
+
+CREATE INDEX CREATE_DATE_IDX
+ ON TBL_NOTIFICATION( "CREATE_DATE" );
+
+
+-- INDEX: PUBLIC.FKI_NOTIFICATION_FK_BRANCH
+CREATE INDEX FKI_NOTIFICATION_FK_BRANCH
+ ON TBL_NOTIFICATION("FK_REF_BRANCH");
+
+
+-- INDEX: PUBLIC.FKI_NOTIFICATION_FK_GRID_TERRITORY
+CREATE INDEX FKI_NOTIF_FK_GRID_TERR
+ ON TBL_NOTIFICATION ("FK_REF_GRID_TERRITORY");
+
+
+-- INDEX: PUBLIC.FKI_NOTIFICATION_FK_STATUS
+CREATE INDEX FKI_NOTIFICATION_FK_STATUS
+ ON TBL_NOTIFICATION("FK_REF_NOTIFICATION_STATUS");
+
+
+-- INDEX: PUBLIC.MOD_DATE_IDX
+CREATE INDEX MOD_DATE_IDX
+ ON TBL_NOTIFICATION ("MOD_DATE");
+
+
+-- INDEX: PUBLIC.RESPONSIBILITY_FORWARDING_IDX
+CREATE INDEX RESPONSIBILITY_FORWARDING_IDX
+ ON TBL_NOTIFICATION( "RESPONSIBILITY_FORWARDING");
+
+
+-- INDEX: PUBLIC.TBL_NOTIFICATION_INCIDENT_VERSION_UNIQUE
+CREATE UNIQUE INDEX TBL_NOTIF_INCID_VERSION_UNIQUE
+ ON TBL_NOTIFICATION ("INCIDENT_ID", "VERSION");
+
+-- TABLE: PUBLIC.TBL_RESPONSIBILITY
+CREATE TABLE TBL_RESPONSIBILITY
+(
+ "ID" NUMBER NOT NULL,
+ "FK_REF_GRID_TERRITORY" NUMBER NOT NULL,
+ "FK_REF_BRANCH" NUMBER NOT NULL,
+ "RESPONSIBLE_USER" VARCHAR2(100) NOT NULL,
+ "NEW_RESPONSIBLE_USER" VARCHAR2(100),
+ "CREATE_USER" VARCHAR2(100) NOT NULL,
+ "CREATE_DATE" TIMESTAMP NOT NULL,
+ "MOD_USER" VARCHAR2(100),
+ "MOD_DATE" TIMESTAMP,
+ CONSTRAINT TBL_RESPONSIBILITY_PKEY PRIMARY KEY ("ID"),
+ CONSTRAINT FK_BRANCH FOREIGN KEY ("FK_REF_BRANCH")
+ REFERENCES REF_BRANCH ("ID"),
+ CONSTRAINT FK_GRID_TERRITORY FOREIGN KEY ("FK_REF_GRID_TERRITORY")
+ REFERENCES REF_GRID_TERRITORY ("ID")
+);
+
+CREATE OR REPLACE TRIGGER "TBL_RESPONSIBILITY_BIR"
+BEFORE INSERT ON "TBL_RESPONSIBILITY"
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT TBL_RESP_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "TBL_RESPONSIBILITY_BIR" ENABLE;
+
+
+-- INDEX: PUBLIC.TBL_RESPONSIBILITY_TERRITORY_BRANCH_USER_UNIQUE
+CREATE UNIQUE INDEX TBL_RESP_TERR_BRANCH_UNIQUE
+ ON TBL_RESPONSIBILITY ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH");
+
+-- TABLE: PUBLIC.HTBL_RESPONSIBILITY
+CREATE TABLE HTBL_RESPONSIBILITY
+(
+ "ID" NUMBER NOT NULL,
+ "FK_REF_GRID_TERRITORY" NUMBER NOT NULL,
+ "FK_REF_BRANCH" NUMBER NOT NULL,
+ "TRANSFER_DATE" TIMESTAMP NOT NULL,
+ "TRANSACTION_ID" NUMBER NOT NULL,
+ "RESPONSIBLE_USER" VARCHAR2(100) NOT NULL,
+ "FORMER_RESPONSIBLE_USER" VARCHAR2(100),
+ "CREATE_USER" VARCHAR2(100) NOT NULL,
+ "CREATE_DATE" TIMESTAMP NOT NULL,
+ "MOD_USER" VARCHAR2(100),
+ "MOD_DATE" TIMESTAMP,
+ CONSTRAINT HTBL_RESPONSIBILITY_PKEY PRIMARY KEY ("ID"),
+ CONSTRAINT HTBL_RESP_FK_BRANCH FOREIGN KEY ("FK_REF_BRANCH")
+ REFERENCES REF_BRANCH ("ID"),
+ CONSTRAINT HTBL_RESP_FK_GRID_TERRITORY FOREIGN KEY ("FK_REF_GRID_TERRITORY")
+ REFERENCES REF_GRID_TERRITORY ("ID")
+);
+
+CREATE OR REPLACE TRIGGER "HTBL_RESPONSIBILITY_BIR"
+BEFORE INSERT ON "HTBL_RESPONSIBILITY"
+FOR EACH ROW
+ WHEN (NEW."ID" IS NULL) BEGIN
+ SELECT HTBL_RESP_ID_SEQ.NEXTVAL
+ INTO :NEW."ID"
+ FROM DUAL;
+END;
+/
+ALTER TRIGGER "HTBL_RESPONSIBILITY_BIR" ENABLE;
+
+-- INDEX: PUBLIC.HTBL_RESP_TRANS_ID_UNIQUE
+CREATE UNIQUE INDEX HTBL_RESP_TRANS_ID_UNIQUE
+ ON HTBL_RESPONSIBILITY ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "TRANSACTION_ID");
+
+
+CREATE OR REPLACE VIEW VIEW_ACTIVE_NOTIFICATION AS
+ SELECT S."ID",
+ S."INCIDENT_ID",
+ S."VERSION",
+ S."FK_REF_BRANCH",
+ S."NOTIFICATION_TEXT",
+ S."FREE_TEXT",
+ S."FREE_TEXT_EXTENDED",
+ S."FK_REF_NOTIFICATION_STATUS",
+ S."RESPONSIBILITY_FORWARDING",
+ S."REMINDER_DATE",
+ S."EXPECTED_FINISHED_DATE",
+ S."RESPONSIBILITY_CONTROL_POINT",
+ S."BEGIN_DATE",
+ S."FINISHED_DATE",
+ S."CREATE_USER",
+ S."CREATE_DATE",
+ S."MOD_USER",
+ S."MOD_DATE",
+ S."FK_REF_GRID_TERRITORY",
+ S."ADMIN_FLAG"
+ FROM ( SELECT TBL_NOTIFICATION."ID",
+ TBL_NOTIFICATION."INCIDENT_ID",
+ TBL_NOTIFICATION."VERSION",
+ TBL_NOTIFICATION."FK_REF_BRANCH",
+ TBL_NOTIFICATION."NOTIFICATION_TEXT",
+ TBL_NOTIFICATION."FREE_TEXT",
+ TBL_NOTIFICATION."FREE_TEXT_EXTENDED",
+ TBL_NOTIFICATION."FK_REF_NOTIFICATION_STATUS",
+ TBL_NOTIFICATION."RESPONSIBILITY_FORWARDING",
+ TBL_NOTIFICATION."REMINDER_DATE",
+ TBL_NOTIFICATION."EXPECTED_FINISHED_DATE",
+ TBL_NOTIFICATION."RESPONSIBILITY_CONTROL_POINT",
+ TBL_NOTIFICATION."BEGIN_DATE",
+ TBL_NOTIFICATION."FINISHED_DATE",
+ TBL_NOTIFICATION."CREATE_USER",
+ TBL_NOTIFICATION."CREATE_DATE",
+ TBL_NOTIFICATION."MOD_USER",
+ TBL_NOTIFICATION."MOD_DATE",
+ TBL_NOTIFICATION."FK_REF_GRID_TERRITORY",
+ TBL_NOTIFICATION."ADMIN_FLAG",
+ RANK() OVER (PARTITION BY TBL_NOTIFICATION."INCIDENT_ID" ORDER BY "TBL_NOTIFICATION"."VERSION" DESC) AS RANK
+ FROM TBL_NOTIFICATION) S
+ WHERE S.RANK = 1;
+
+
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 1, 'Offen' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 2, 'In arbeit' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 3, 'Erledigt' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 4, 'Geschlossen' );
+
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 1, 'S', 'Strom' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 2, 'G', 'Gas' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 3, 'F', 'Fernwärme' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 4, 'W', 'Wasser' );
+
+INSERT INTO "REF_GRID_TERRITORY" ("ID", "NAME", "DESCRIPTION", "FK_REF_MASTER") VALUES ( 1, 'MA', 'Mannheim', 1);
+INSERT INTO "REF_GRID_TERRITORY" ("ID", "NAME", "DESCRIPTION", "FK_REF_MASTER") VALUES ( 2, 'OF', 'Offenbach', 2);
+
+INSERT INTO REF_VERSION VALUES (1, '1.0.0_ORA');
+
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 1, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 2, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 3, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 4, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 1, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 2, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 3, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 4, 'Admin','Admin', CURRENT_TIMESTAMP);
+
+
+
+
+
+
+
diff --git a/db/oracle/03_config.DB_1.0.0.sql b/db/oracle/03_config.DB_1.0.0.sql
new file mode 100644
index 0000000..88ccbe1
--- /dev/null
+++ b/db/oracle/03_config.DB_1.0.0.sql
@@ -0,0 +1,25 @@
+
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 1, 'Offen' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 2, 'In arbeit' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 3, 'Erledigt' );
+INSERT INTO "REF_NOTIFICATION_STATUS" ( "ID", "NAME" ) VALUES ( 4, 'Geschlossen' );
+
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 1, 'S', 'Strom' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 2, 'G', 'Gas' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 3, 'F', 'Fernwärme' );
+INSERT INTO "REF_BRANCH" ("ID", "NAME", "DESCRIPTION" ) VALUES ( 4, 'W', 'Wasser' );
+
+INSERT INTO "REF_GRID_TERRITORY" ("ID", "NAME", "DESCRIPTION", "FK_REF_MASTER") VALUES ( 1, 'MA', 'Mannheim', 1);
+INSERT INTO "REF_GRID_TERRITORY" ("ID", "NAME", "DESCRIPTION", "FK_REF_MASTER") VALUES ( 2, 'OF', 'Offenbach', 2);
+
+INSERT INTO REF_VERSION VALUES (1, '1.0.0_ORA');
+
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 1, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 2, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 3, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (1, 4, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 1, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 2, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 3, 'Admin','Admin', CURRENT_TIMESTAMP);
+INSERT INTO "TBL_RESPONSIBILITY" ("FK_REF_GRID_TERRITORY", "FK_REF_BRANCH", "RESPONSIBLE_USER", "CREATE_USER", "CREATE_DATE") VALUES (2, 4, 'Admin','Admin', CURRENT_TIMESTAMP);
+
diff --git a/db/postgreSQL/01a_drop_DB_1.0.0.sql b/db/postgreSQL/01a_drop_DB_1.0.0.sql
index 9ad583e..2170e8c 100644
--- a/db/postgreSQL/01a_drop_DB_1.0.0.sql
+++ b/db/postgreSQL/01a_drop_DB_1.0.0.sql
@@ -8,12 +8,10 @@
drop view public.VIEW_ACTIVE_NOTIFICATION cascade;
drop table public.REF_VERSION cascade;
-DROP SEQUENCE public.HTBL_RESPONSIBILITY_ID_SEQ;
+DROP SEQUENCE public.HTBL_RESP_ID_SEQ;
DROP SEQUENCE public.REF_BRANCH_ID_SEQ;
DROP SEQUENCE public.REF_GRID_TERRITORY_ID_SEQ;
-DROP SEQUENCE public.REF_NOTIFICATION_STATUS_ID_SEQ;
-DROP SEQUENCE public.TBL_NOTIFICATION_ID_SEQ;
-DROP SEQUENCE public.TBL_NOTIFICATION_INCIDENT_ID_SEQ;
-DROP SEQUENCE public.TBL_RESPONSIBILITY_ID_SEQ;
-
-
+DROP SEQUENCE public.REF_NOTIF_STATUS_ID_SEQ;
+DROP SEQUENCE public.TBL_NOTIF_ID_SEQ;
+DROP SEQUENCE public.TBL_NOTIF_INCIDENT_ID_SEQ;
+DROP SEQUENCE public.TBL_RESP_ID_SEQ;
\ No newline at end of file
diff --git a/db/postgreSQL/02_create_DB_1.0.0.sql b/db/postgreSQL/02_create_DB_1.0.0.sql
index fa39c43..ebda479 100644
--- a/db/postgreSQL/02_create_DB_1.0.0.sql
+++ b/db/postgreSQL/02_create_DB_1.0.0.sql
@@ -3,7 +3,7 @@
-CREATE SEQUENCE public.HTBL_RESPONSIBILITY_ID_SEQ
+CREATE SEQUENCE public.HTBL_RESP_ID_SEQ
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
@@ -31,40 +31,40 @@
ALTER TABLE public.REF_GRID_TERRITORY_ID_SEQ
OWNER TO btbservice;
-CREATE SEQUENCE public.REF_NOTIFICATION_STATUS_ID_SEQ
+CREATE SEQUENCE public.REF_NOTIF_STATUS_ID_SEQ
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 5
CACHE 1;
-ALTER TABLE public.REF_NOTIFICATION_STATUS_ID_SEQ
+ALTER TABLE public.REF_NOTIF_STATUS_ID_SEQ
OWNER TO btbservice;
-CREATE SEQUENCE public.TBL_NOTIFICATION_ID_SEQ
+CREATE SEQUENCE public.TBL_NOTIF_ID_SEQ
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1395
CACHE 1;
-ALTER TABLE public.TBL_NOTIFICATION_ID_SEQ
+ALTER TABLE public.TBL_NOTIF_ID_SEQ
OWNER TO btbservice;
-CREATE SEQUENCE public.TBL_NOTIFICATION_INCIDENT_ID_SEQ
+CREATE SEQUENCE public.TBL_NOTIF_INCIDENT_ID_SEQ
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 81
CACHE 1;
-ALTER TABLE public.TBL_NOTIFICATION_INCIDENT_ID_SEQ
+ALTER TABLE public.TBL_NOTIF_INCIDENT_ID_SEQ
OWNER TO btbservice;
-CREATE SEQUENCE public.TBL_RESPONSIBILITY_ID_SEQ
+CREATE SEQUENCE public.TBL_RESP_ID_SEQ
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 21
CACHE 1;
-ALTER TABLE public.TBL_RESPONSIBILITY_ID_SEQ
+ALTER TABLE public.TBL_RESP_ID_SEQ
OWNER TO btbservice;
@@ -122,7 +122,7 @@
CREATE TABLE public.REF_NOTIFICATION_STATUS
(
- id integer NOT NULL DEFAULT nextval('ref_notification_status_id_seq'::regclass),
+ id integer NOT NULL DEFAULT nextval('ref_notif_status_id_seq'::regclass),
name character varying(50) NOT NULL,
CONSTRAINT REF_NOTIFICATION_STATUS_PKEY PRIMARY KEY (id)
)
@@ -150,8 +150,8 @@
CREATE TABLE public.TBL_NOTIFICATION
(
- id integer NOT NULL DEFAULT nextval('tbl_notification_id_seq'::regclass),
- incident_id integer DEFAULT nextval('tbl_notification_incident_id_seq'::regclass),
+ id integer NOT NULL DEFAULT nextval('tbl_notif_id_seq'::regclass),
+ incident_id integer DEFAULT nextval('tbl_notif_incident_id_seq'::regclass),
version integer NOT NULL DEFAULT 0,
fk_ref_branch integer,
notification_text character varying(200) NOT NULL,
@@ -283,7 +283,7 @@
CREATE TABLE public.TBL_RESPONSIBILITY
(
- id integer NOT NULL DEFAULT nextval('tbl_responsibility_id_seq'::regclass),
+ id integer NOT NULL DEFAULT nextval('tbl_resp_id_seq'::regclass),
fk_ref_grid_territory integer NOT NULL,
fk_ref_branch integer NOT NULL,
responsible_user character varying(100) NOT NULL,
@@ -319,7 +319,7 @@
CREATE TABLE public.HTBL_RESPONSIBILITY
(
- id integer NOT NULL DEFAULT nextval('htbl_responsibility_id_seq'::regclass),
+ id integer NOT NULL DEFAULT nextval('htbl_resp_id_seq'::regclass),
fk_ref_grid_territory integer NOT NULL,
fk_ref_branch integer NOT NULL,
transfer_date timestamp without time zone NOT NULL,
diff --git a/db/postgreSQL/03_config_DB_1.0.0.sql b/db/postgreSQL/03_config_DB_1.0.0.sql
index 66f5192..f4ead19 100644
--- a/db/postgreSQL/03_config_DB_1.0.0.sql
+++ b/db/postgreSQL/03_config_DB_1.0.0.sql
@@ -14,11 +14,13 @@
INSERT INTO REF_VERSION VALUES (1, '1.0.0_PG');
+INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (1, 1, 'admin','admin', CURRENT_TIMESTAMP);
INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (1, 2, 'admin','admin', CURRENT_TIMESTAMP);
INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (1, 3, 'admin','admin', CURRENT_TIMESTAMP);
INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (1, 4, 'admin','admin', CURRENT_TIMESTAMP);
INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 1, 'admin','admin', CURRENT_TIMESTAMP);
-INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 3, 'otto','admin', CURRENT_TIMESTAMP);
-INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 4, 'otto','admin', CURRENT_TIMESTAMP);
+INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 2, 'admin','admin', CURRENT_TIMESTAMP);
+INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 3, 'admin','admin', CURRENT_TIMESTAMP);
+INSERT INTO TBL_RESPONSIBILITY ("fk_ref_grid_territory", "fk_ref_branch", "responsible_user", "create_user", "create_date") VALUES (2, 4, 'admin','admin', CURRENT_TIMESTAMP);
diff --git a/deploy/conf/context.xml b/deploy/conf/context.xml
index 237a658..63f4bde 100644
--- a/deploy/conf/context.xml
+++ b/deploy/conf/context.xml
@@ -39,6 +39,14 @@
username="btbservice"
password="btbservice"/>
+ <Resource name="jdbc/okBetriebstagebuchDSO"
+ auth="Container"
+ type="javax.sql.DataSource"
+ driverClassName="oracle.jdbc.driver.OracleDriver"
+ url="jdbc:oracle:thin:@LIDLORADB2.PTA.DE:1521:NAPDB00"
+ username="DIETRICF"
+ password="dietricf000"/>
+
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
diff --git a/deploy/lib/ojdbc7_g.jar b/deploy/lib/ojdbc7_g.jar
new file mode 100644
index 0000000..782074c
--- /dev/null
+++ b/deploy/lib/ojdbc7_g.jar
Binary files differ
diff --git a/pom.xml b/pom.xml
index 1144d9f..e3e4c3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,7 @@
<junit.version>4.12</junit.version>
<easymock.version>3.4</easymock.version>
<powermock-api-easymock.version>1.6.6</powermock-api-easymock.version>
+ <powermock-module-junit4.version>1.7.3</powermock-module-junit4.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<servlet-api>2.5</servlet-api>
<maven.test.skip>false</maven.test.skip>
@@ -115,6 +116,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock-module-junit4.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
@@ -130,6 +137,7 @@
<version>3.2.0</version>
</dependency>
+
</dependencies>
diff --git a/src/main/asciidoc/architectureDocumentation/elogbook_architectureDocumentation.adoc b/src/main/asciidoc/architectureDocumentation/elogbook_architectureDocumentation.adoc
index 2cf1b1e..d554972 100644
--- a/src/main/asciidoc/architectureDocumentation/elogbook_architectureDocumentation.adoc
+++ b/src/main/asciidoc/architectureDocumentation/elogbook_architectureDocumentation.adoc
@@ -58,7 +58,14 @@
* "Architecture Committee Handbook" v1.2 from 14-09-2016
* "Quality Committee Handbook" v1.1 from 18-08-2016
-The project eLogbook@openK bases on the Eclipse Public Lisence 1.0.
+The architecture is based on the AC-Handbook. The
+quality demands are described in the QC-Handbook.
+Both specifications were fully complied with in the project, so that a high quality is given.
+
+The code quality regarding static code analysis and unit test code coverage on the backend side is ensured by the
+use of *sonarqube*. The rule set and the qualtity gate are defined by the default, the so called "sonar way".
+
+The project eLogbook@openK bases on the Eclipse Public Licence 1.0.
=== Stakeholders
@@ -320,14 +327,49 @@
=== Business Context
-The user module eLogbook communicates via the ESB to other modules and systems (see figure 1):
+The user module eLogbook communicates via Restful Webservices and the filesystem with other modules and systems (see figure 1):
* *Core Module "Auth & Auth"* The eLogbook can only be used by authorized users. Therefore, it is essential to invoke the module “Auth & Auth” for authorization and authentication purposes.
* *Source System "SCADA"* The eLogbook needs information from the system “SCADA”. Therefore, it must provide an interface for receiving the according data.
.System-Context of eLogbook
-[options="header,footer"]
-image::SystemContext.png[System-Context of eLogbook]
+[plantuml]
+----
+ Interface iaNa [
+ A&A-API
+ ]
+
+ Interface fs [
+ File system
+ ]
+ Component scada [
+ SCADA
+ ]
+
+ Component el [
+ eLogbook
+ ]
+
+ Component kc [
+ keycloak
+ ]
+ Component aNa [
+ Auth & Auth
+ ]
+ Interface ikc [
+ KC-API
+ ]
+
+
+ kc--ikc
+ aNa->ikc
+ aNa--iaNa
+ el->iaNa
+ scada->fs
+ el->fs
+
+
+----
=== Technical Context
@@ -758,13 +800,16 @@
{
"portalBaseURL" : "http://{hostname}:{port}/portal/rest/beservice",
"fileRowToRead": "9",
- "importFilesFolderPath": "/home/btbservice/importFiles"
+ "importFilesFolderPath": "/home/btbservice/importFiles",
+ "activePersistencyUnit": "betriebstagebuch"
}
----
* *portalBaseURL* - The portal base url should point the the address where the portal backend (the *Auth&Auth*-Server)
can be accessed. This is important for the authorization of the backend services.
* *fileRowToRead* - Defines the line number inside the import-file of the relevant text line.
* *importFilesFolderPath* - Defines the exchange directory for the import functionality
+* *activePersistencyUnit* - Defines the active part of the file persistenc.xml. Choose *"betriebstagebuchORA"* for the
+ usage of OracleDB and *"betriebstagebuch"* to use PostgreSQL.
diff --git a/src/main/java/org/eclipse/openk/elogbook/common/BackendConfig.java b/src/main/java/org/eclipse/openk/elogbook/common/BackendConfig.java
index ce78206..5fc3d24 100644
--- a/src/main/java/org/eclipse/openk/elogbook/common/BackendConfig.java
+++ b/src/main/java/org/eclipse/openk/elogbook/common/BackendConfig.java
@@ -8,6 +8,7 @@
private String importFilesFolderPath;
private String portalBaseURL;
private int fileRowToRead;
+ private String activePersistencyUnit;
private static BackendConfig instance;
@@ -40,6 +41,10 @@
return fileRowToRead;
}
+ public String getActivePersistencyUnit() {
+ return activePersistencyUnit;
+ }
+
public static String getConfigFileName() {
return configFileName;
}
@@ -47,6 +52,8 @@
public static void setConfigFileName(String configFileName) {
BackendConfig.configFileName = configFileName;
}
+
+
}
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/EntityHelper.java b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/EntityHelper.java
index 16c0580..0dd54a8 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/EntityHelper.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/EntityHelper.java
@@ -1,19 +1,45 @@
package org.eclipse.openk.elogbook.persistence.dao;
+import org.eclipse.openk.elogbook.common.BackendConfig;
+
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class EntityHelper {
- private static final String FACTORY_NAME = "betriebstagebuch";
private static EntityManagerFactory entityManagerFactory;
+ private static EntityHelper instance;
+ private boolean useQuotes = false;
private EntityHelper() {
}
+ public static EntityHelper instance() {
+ if( instance == null ) {
+ instance = new EntityHelper();
+
+ try {
+ String param = (String) getEMF().getProperties().get("hibernate.globally_quoted_identifiers");
+ instance.useQuotes = "TRUE".equalsIgnoreCase(param);
+ }
+ catch( Exception e) {
+ instance.useQuotes = false;
+ }
+ }
+ return instance;
+ }
+
public static synchronized EntityManagerFactory getEMF() {
if (entityManagerFactory == null) {
- entityManagerFactory = Persistence.createEntityManagerFactory(FACTORY_NAME);
+ entityManagerFactory = Persistence.createEntityManagerFactory(BackendConfig.getInstance().getActivePersistencyUnit());
}
return entityManagerFactory;
}
+
+ public String makeIdentifier( String ident ) {
+ if (useQuotes) {
+ return "\"" + ident + "\"";
+ } else {
+ return ident;
+ }
+ }
}
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/GenericDaoJpa.java b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/GenericDaoJpa.java
index 7bd5586..e679300 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/GenericDaoJpa.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/GenericDaoJpa.java
@@ -1,16 +1,17 @@
package org.eclipse.openk.elogbook.persistence.dao;
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.eclipse.openk.elogbook.persistence.dao.interfaces.IGenericDao;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.Query;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.Query;
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.eclipse.openk.elogbook.persistence.dao.interfaces.IGenericDao;
/**
* @param <T> - persistent Class.
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/HTblResponsibilityDao.java b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/HTblResponsibilityDao.java
index 01d2e47..70ea67f 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/HTblResponsibilityDao.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/HTblResponsibilityDao.java
@@ -1,22 +1,20 @@
package org.eclipse.openk.elogbook.persistence.dao;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import org.eclipse.openk.elogbook.exceptions.BtbInternalServerError;
+import org.eclipse.openk.elogbook.persistence.model.HTblResponsibility;
+
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
-import org.eclipse.openk.elogbook.exceptions.BtbInternalServerError;
-import org.eclipse.openk.elogbook.persistence.model.HTblResponsibility;
+import java.util.*;
public class HTblResponsibilityDao extends GenericDaoJpa<HTblResponsibility, Integer> {
/** find only HTblResponsibilities starting with transfer date */
- private static String TRANSFER_DATE_FROM = "transferDateFrom";
+ private static final String TRANSFER_DATE_FROM = "transferDateFrom";
/** find only HTblResponsibilities ending with transfer date */
- private static String TRANSFER_DATE_TO = "transferDateTo";
+ private static final String TRANSFER_DATE_TO = "transferDateTo";
public HTblResponsibilityDao() {
super();
@@ -50,9 +48,10 @@
public Integer getLastTransactionId() throws BtbInternalServerError {
try {
- String selectString = "select transaction_id from htbl_responsibility n order by n.transaction_id desc limit 1";
- Query q = getEM().createNativeQuery(selectString);
- return (Integer) q.getSingleResult();
+ String selectString = "FROM HTblResponsibility n WHERE n.transactionId = (SELECT MAX(t2.transactionId) FROM HTblResponsibility t2)";
+ Query q = getEM().createQuery(selectString);
+ q.setMaxResults(1);
+ return ((HTblResponsibility) q.getSingleResult()).getTransactionId();
} catch (NoResultException nre) {
return 0;
} catch (Throwable t) { //NOSONAR
@@ -75,34 +74,42 @@
@SuppressWarnings("unchecked")
public List<HTblResponsibility> findHTblResponsibilitiesInPeriod(Date transferDateFrom, Date transferDateTo)
throws BtbInternalServerError {
- List<HTblResponsibility> hTblResponsibilityList = new ArrayList<>();
try {
- String selectString = "SELECT distinct t.transaction_id , t.transfer_date, t.responsible_user, t.former_responsible_user "
- + "FROM htbl_responsibility t "
- + "WHERE t.transfer_date >= ?transferDateFrom and t.transfer_date <= ?transferDateTo "
- + "ORDER BY t.transfer_date DESC";
- Query q = getEM().createNativeQuery(selectString);
+ String selectString = "from HTblResponsibility t "
+ + "WHERE t.transferDate >= :" + TRANSFER_DATE_FROM
+ + " and t.transferDate <= :" + TRANSFER_DATE_TO
+ + " ORDER BY t.transferDate DESC";
+
+
+ Query q = getEM().createQuery(selectString);
q.setParameter(TRANSFER_DATE_FROM, transferDateFrom);
q.setParameter(TRANSFER_DATE_TO, transferDateTo);
- List<Object[]> resultList = q.getResultList();
- for (Object[] objects : resultList) {
- hTblResponsibilityList.add(mapToHTblResponsibilityFromObject(objects));
+ List<HTblResponsibility> resultList = q.getResultList();
+ List<HTblResponsibility> distinctResultList = new LinkedList<>();
+
+ // build up distinct list regarding the fields in "hashItDistinct"
+ Set<String> uniqueSet = new HashSet<>();
+ for( HTblResponsibility rp: resultList) {
+ String hash = hashItDistinct(rp);
+ if(!uniqueSet.contains(hash)) {
+ uniqueSet.add(hash);
+ distinctResultList.add(rp);
+ }
}
- return hTblResponsibilityList;
+ return distinctResultList;
} catch (Throwable t) { // NOSONAR
LOGGER.error(t.getMessage());
- throw new BtbInternalServerError("Error getting last transaction id of htbl_responsibility");
-
+ throw new BtbInternalServerError("Error finding responsibilities in Period");
}
}
- private HTblResponsibility mapToHTblResponsibilityFromObject(Object[] obj){
- HTblResponsibility hTblResponsibility = new HTblResponsibility();
- hTblResponsibility.setTransactionId((Integer) obj[0]);
- hTblResponsibility.setTransferDate((Timestamp) obj[1]);
- hTblResponsibility.setResponsibleUser((String) obj[2]);
- hTblResponsibility.setFormerResponsibleUser((String) obj[3]);
- return hTblResponsibility;
+ private String hashItDistinct( HTblResponsibility item ) {
+ StringBuilder sb = new StringBuilder();
+ sb.append( item.getTransactionId() ).append("@");
+ sb.append( item.getTransferDate().getTime() ).append("@");
+ sb.append( item.getResponsibleUser() ).append("@");
+ sb.append( item.getFormerResponsibleUser() ).append("@");
+ return sb.toString();
}
/**
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblNotificationDao.java b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblNotificationDao.java
index d0913c7..60640a5 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblNotificationDao.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblNotificationDao.java
@@ -1,11 +1,5 @@
package org.eclipse.openk.elogbook.persistence.dao;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
import org.eclipse.openk.elogbook.common.NotificationStatus;
import org.eclipse.openk.elogbook.exceptions.BtbException;
import org.eclipse.openk.elogbook.exceptions.BtbInternalServerError;
@@ -13,12 +7,27 @@
import org.eclipse.openk.elogbook.persistence.model.TblNotification;
import org.eclipse.openk.elogbook.persistence.model.TblResponsibility;
import org.eclipse.openk.elogbook.persistence.util.NotificationQueryCreator;
+import org.eclipse.openk.elogbook.persistence.util.TimestampConverter;
import org.eclipse.openk.elogbook.viewmodel.GlobalSearchFilter;
import org.eclipse.openk.elogbook.viewmodel.Notification.ListType;
import org.eclipse.openk.elogbook.viewmodel.NotificationSearchFilter;
import org.eclipse.openk.elogbook.viewmodel.ReminderSearchFilter;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
public class TblNotificationDao extends GenericDaoJpa<TblNotification, Integer> {
+ private static final String VIEW_ACTIVE_NOTIFICATION = EntityHelper.instance().makeIdentifier("VIEW_ACTIVE_NOTIFICATION");
+ private static final String FK_REF_NOTIFICATION_STATUS = EntityHelper.instance().makeIdentifier("fk_ref_notification_status");
+ private static final String TBL_NOTIFICATION = EntityHelper.instance().makeIdentifier("TBL_NOTIFICATION");
+ private static final String INCIDENT_ID = EntityHelper.instance().makeIdentifier("incident_id");
+ private static final String VERSION = EntityHelper.instance().makeIdentifier("version");
+ private static final String RESPONSIBILITY_FORWARDING = EntityHelper.instance().makeIdentifier("responsibility_forwarding");
+
+
public TblNotificationDao() {
super();
@@ -43,7 +52,7 @@
*/
public List<TblNotification> getActiveNotifications() throws BtbInternalServerError {
return refreshModelCollection(
- getActiveNotifications(null, null, null, null, new ArrayList<TblResponsibility>()));
+ getActiveNotifications(null, null, null, new ArrayList<TblResponsibility>()));
}
/**
@@ -65,15 +74,15 @@
*/
@SuppressWarnings("unchecked")
private List<TblNotification> getActiveNotifications(NotificationSearchFilter nsf, String whereClause,
- String tablePrefix, ListType listType, List<TblResponsibility> tblResponsibilities)
+ String tablePrefix, List<TblResponsibility> tblResponsibilities)
throws BtbInternalServerError {
try {
NotificationQueryCreator queryCreator = new NotificationQueryCreator(getEM(), tablePrefix);
- Query q = queryCreator.generateNotificationQuery(nsf, whereClause, listType, tblResponsibilities);
+ Query q = queryCreator.generateNotificationQuery(nsf, whereClause, tblResponsibilities);
return refreshModelCollection((List<TblNotification>) q.getResultList());
} catch (Exception e) {
- LOGGER.error("Error retrieving notifications", e);
+ LOGGER.error("Error while retrieving notifications", e);
throw new BtbInternalServerError("Error retrieving notifications");
}
}
@@ -88,15 +97,15 @@
Query q = queryCreator.generateNotificationQueryWithReminder(rsf, whereClause, tblResponsibilities);
return refreshModelCollection((List<TblNotification>) q.getResultList());
} catch (Exception e) {
- LOGGER.error("Error retrieving notifications", e);
- throw new BtbInternalServerError("Error retrieving notifications");
+ LOGGER.error("Error while retrieving notifications with reminder", e);
+ throw new BtbInternalServerError("Error retrieving notifications with reminder");
}
}
public List<TblNotification> getNotificationsWithReminder(ReminderSearchFilter rsf, List<TblResponsibility> tblResponsibilities) throws BtbInternalServerError {
try {
- String where = "v.fk_ref_notification_status IN ( " + NotificationStatus.OPEN.id + "," + NotificationStatus.INPROGRESS.id + " ) ";
+ String where = "v."+FK_REF_NOTIFICATION_STATUS+" IN ( " + NotificationStatus.OPEN.id + "," + NotificationStatus.INPROGRESS.id + " ) ";
return refreshModelCollection(getActiveNotificationsWithReminder(rsf, where, "v", tblResponsibilities));
} catch (Exception t) {
LOGGER.error(t);
@@ -113,8 +122,8 @@
*/
public List<TblNotification> getPastNotifications(NotificationSearchFilter nsf,
List<TblResponsibility> tblResponsibilities) throws BtbInternalServerError {
- String where = "v.fk_ref_notification_status IN ( " + NotificationStatus.CLOSED.id + " ) ";
- return refreshModelCollection(getActiveNotifications(nsf, where, "v", ListType.PAST, tblResponsibilities));
+ String where = "v."+FK_REF_NOTIFICATION_STATUS+" IN ( " + NotificationStatus.CLOSED.id + " ) ";
+ return refreshModelCollection(getActiveNotifications(nsf, where, "v", tblResponsibilities));
}
/**
@@ -127,31 +136,34 @@
*/
public List<TblNotification> getOpenNotifications(NotificationSearchFilter notificationSearchFilter,
List<TblResponsibility> tblResponsibilities) throws BtbInternalServerError {
- String where = "v.fk_ref_notification_status IN (" + NotificationStatus.OPEN.id + ","
+ String where = "v."+FK_REF_NOTIFICATION_STATUS+" IN (" + NotificationStatus.OPEN.id + ","
+ NotificationStatus.INPROGRESS.id + ","
- + NotificationStatus.FINISHED.id+ ")" + " AND v.begin_date < (TIMESTAMP 'tomorrow')";
+ + NotificationStatus.FINISHED.id+ ")";
+ notificationSearchFilter.setDateTo(
+ TimestampConverter.getTimestampWithTime(
+ new Timestamp(System.currentTimeMillis() + 1000 * 60 * 60 * 24), 0, 0, 0 ));
return refreshModelCollection(
- getActiveNotifications(notificationSearchFilter, where, "v", ListType.OPEN, tblResponsibilities));
+ getActiveNotifications(notificationSearchFilter, where, "v", tblResponsibilities));
}
public List<TblNotification> getFutureNotifications(NotificationSearchFilter nsf,
List<TblResponsibility> tblResponsibilities) throws BtbInternalServerError {
- String where = "v.fk_ref_notification_status NOT IN (" + NotificationStatus.CLOSED.id + ","
+ String where = "v."+FK_REF_NOTIFICATION_STATUS+" NOT IN (" + NotificationStatus.CLOSED.id + ","
+ NotificationStatus.FINISHED.id + ")";
- return refreshModelCollection(getActiveNotifications(nsf, where, "v", ListType.FUTURE, tblResponsibilities));
+ return refreshModelCollection(getActiveNotifications(nsf, where, "v", tblResponsibilities));
}
@SuppressWarnings("unchecked")
public List<TblNotification> getByIncidentId(int incidentId) throws BtbInternalServerError {
try {
- String selectString = "select * from tbl_notification n where n.incident_id=? order by n.version desc";
+ String selectString = "select * from "+TBL_NOTIFICATION+" n where n."+INCIDENT_ID+"=? order by n."+VERSION+" desc";
Query q = getEM().createNativeQuery(selectString, TblNotification.class);
q.setParameter(1, incidentId);
return refreshModelCollection(q.getResultList());
} catch (Exception t) {
LOGGER.error(t);
- throw new BtbInternalServerError("Error loading notifications");
+ throw new BtbInternalServerError("Error loading notifications by incidentId");
}
}
@@ -159,7 +171,8 @@
public List<String> getAssignedUserSuggestions() throws BtbInternalServerError {
try {
- String selectString = "select distinct responsibility_forwarding from view_active_notification n where n.responsibility_forwarding is not null";
+ String selectString = "select distinct "+RESPONSIBILITY_FORWARDING+" from "+
+ VIEW_ACTIVE_NOTIFICATION+" n where n."+RESPONSIBILITY_FORWARDING+" is not null";
Query q = getEM().createNativeQuery(selectString);
return q.getResultList();
} catch (Exception t) {
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblResponsibilityDao.java b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblResponsibilityDao.java
index b7edb90..cd885d5 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblResponsibilityDao.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/dao/TblResponsibilityDao.java
@@ -1,13 +1,15 @@
package org.eclipse.openk.elogbook.persistence.dao;
-import java.util.ArrayList;
-import java.util.List;
+import org.eclipse.openk.elogbook.persistence.model.TblResponsibility;
+
import javax.persistence.EntityManager;
import javax.persistence.Query;
-import org.eclipse.openk.elogbook.persistence.model.TblResponsibility;
+import java.util.ArrayList;
+import java.util.List;
public class TblResponsibilityDao extends GenericDaoJpa<TblResponsibility, Integer> {
+ private static final String FROM = " from ";
public TblResponsibilityDao() {
super();
}
@@ -20,7 +22,7 @@
public List<TblResponsibility> getResponsibilitiesForUser(String responsibleUser) {
try {
- String selectString = "from " + TblResponsibility.class.getSimpleName() + " v where v.responsibleUser = :responsibleUser";
+ String selectString = FROM + TblResponsibility.class.getSimpleName() + " v where UPPER(v.responsibleUser) = UPPER(:responsibleUser)";
Query q = getEM().createQuery(selectString);
q.setParameter("responsibleUser", responsibleUser);
return refreshModelCollection((List<TblResponsibility>) q.getResultList());
@@ -34,7 +36,7 @@
public List<TblResponsibility> getPlannedResponsibilitiesForUser(String newResponsibleUser) {
try {
- String selectString = "from " + TblResponsibility.class.getSimpleName() + " v where v.newResponsibleUser = :newResponsibleUser";
+ String selectString = FROM + TblResponsibility.class.getSimpleName() + " v where UPPER(v.newResponsibleUser) = UPPER(:newResponsibleUser)";
Query q = getEM().createQuery(selectString);
q.setParameter("newResponsibleUser", newResponsibleUser);
return refreshModelCollection((List<TblResponsibility>) q.getResultList());
@@ -48,7 +50,7 @@
public List<TblResponsibility> getAllResponsibilities() {
try {
- String selectString = "from " + TblResponsibility.class.getSimpleName() + " v";
+ String selectString = FROM + TblResponsibility.class.getSimpleName() + " v";
Query q = getEM().createQuery(selectString);
return refreshModelCollection((List<TblResponsibility>) q.getResultList());
} catch (Throwable t) { //NOSONAR
@@ -61,7 +63,7 @@
public List<TblResponsibility> getNewOrCurrentResponisbleUser(String modUser) {
try {
- String selectString = "from " + TblResponsibility.class.getSimpleName() + " v where v.responsibleUser = :modUser or v.newResponsibleUser = :modUser";
+ String selectString = FROM + TblResponsibility.class.getSimpleName() + " v where UPPER(v.responsibleUser) = UPPER(:modUser) or UPPER(v.newResponsibleUser) = UPPER(:modUser)";
Query q = getEM().createQuery(selectString);
q.setParameter("modUser", modUser);
return refreshModelCollection((List<TblResponsibility>) q.getResultList());
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/AbstractNotification.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/AbstractNotification.java
index 3356b48..6dd5be7 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/AbstractNotification.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/AbstractNotification.java
@@ -1,17 +1,9 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
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.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.SequenceGenerator;
-
/**
* The persistent class for the tbl_notification database table.
@@ -22,8 +14,8 @@
private static final long serialVersionUID = 1L;
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TBL_NOTIFICATION_ID_SEQ")
- @SequenceGenerator(name = "TBL_NOTIFICATION_ID_SEQ", sequenceName = "TBL_NOTIFICATION_ID_SEQ", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TBL_NOTIF_ID_SEQ")
+ @SequenceGenerator(name = "TBL_NOTIF_ID_SEQ", sequenceName = "TBL_NOTIF_ID_SEQ", allocationSize = 1)
@Column(name = "id", updatable = false)
private Integer id;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/HTblResponsibility.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/HTblResponsibility.java
index 3dcfc2a..11f929c 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/HTblResponsibility.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/HTblResponsibility.java
@@ -1,18 +1,8 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
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.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
/**
@@ -20,16 +10,17 @@
*
*/
@Entity
-@Table(name="htbl_responsibility")
+@Table(name="HTBL_RESPONSIBILITY")
@NamedQueries ({
@NamedQuery(name="HTblResponsibility.findAll", query="SELECT t FROM HTblResponsibility t"),
+@NamedQuery(name="HTblResponsibility.queryMaxId", query="SELECT t FROM HTblResponsibility t WHERE t.id = (SELECT MAX(t2.id) FROM HTblResponsibility t2)"),
})
public class HTblResponsibility implements Serializable {
private static final long serialVersionUID = 1L;
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HTBL_RESPONSIBILITY_ID_SEQ")
- @SequenceGenerator(name = "HTBL_RESPONSIBILITY_ID_SEQ", sequenceName = "HTBL_RESPONSIBILITY_ID_SEQ", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HTBL_RESP_ID_SEQ")
+ @SequenceGenerator(name = "HTBL_RESP_ID_SEQ", sequenceName = "HTBL_RESP_ID_SEQ", allocationSize = 1)
@Column(name = "id", updatable = false)
private Integer id;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefBranch.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefBranch.java
index b66cae7..6c6e029 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefBranch.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefBranch.java
@@ -1,14 +1,8 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
/**
@@ -16,7 +10,7 @@
*
*/
@Entity
-@Table(name="ref_branch")
+@Table(name="REF_BRANCH")
@NamedQuery(name="RefBranch.findAll", query="SELECT r FROM RefBranch r")
public class RefBranch implements Serializable {
private static final long serialVersionUID = 1L;
@@ -26,8 +20,10 @@
@Column(name = "id")
private Integer id;
+ @Column(name = "name")
private String name;
+ @Column(name = "description")
private String description;
public RefBranch() {
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefGridTerritory.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefGridTerritory.java
index 8568809..b424232 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefGridTerritory.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefGridTerritory.java
@@ -1,15 +1,7 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
/**
@@ -17,7 +9,7 @@
*
*/
@Entity
-@Table(name="ref_grid_territory")
+@Table(name="REF_GRID_TERRITORY")
@NamedQuery(name="RefGridTerritory.findAll", query="SELECT r FROM RefGridTerritory r")
public class RefGridTerritory implements Serializable {
private static final long serialVersionUID = 1L;
@@ -34,8 +26,10 @@
@Column(name = "fk_ref_master", nullable = false, updatable = false, insertable = false)
private Integer fkRefMaster;
+ @Column(name = "description")
private String description;
+ @Column(name = "name")
private String name;
public RefGridTerritory() {
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefNotificationStatus.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefNotificationStatus.java
index 3a328b3..c692a80 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefNotificationStatus.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefNotificationStatus.java
@@ -1,13 +1,7 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
/**
@@ -15,7 +9,7 @@
*
*/
@Entity
-@Table(name="ref_notification_status", schema = "public")
+@Table(name="REF_NOTIFICATION_STATUS")
@NamedQuery(name="RefNotificationStatus.findAll", query="SELECT r FROM RefNotificationStatus r")
public class RefNotificationStatus implements Serializable {
private static final long serialVersionUID = 1L;
@@ -25,6 +19,7 @@
@Column(name = "id")
private Integer id;
+ @Column(name = "name")
private String name;
public RefNotificationStatus() {
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefVersion.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefVersion.java
index 06f0974..b6d051f 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefVersion.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/RefVersion.java
@@ -1,20 +1,14 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
/**
* The persistent class for the "REF_VERSION" database table.
*/
@Entity
-@Table(name = "ref_version", schema = "public")
+@Table(name = "REF_VERSION")
@NamedQuery(name = "RefVersion.findAll", query = "SELECT r FROM RefVersion r")
public class RefVersion implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblNotification.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblNotification.java
index 9168fb0..59e11d5 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblNotification.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblNotification.java
@@ -9,7 +9,7 @@
*
*/
@Entity
-@Table(name="tbl_notification")
+@Table(name="TBL_NOTIFICATION")
public class TblNotification extends AbstractNotification {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblResponsibility.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblResponsibility.java
index c91266d..b29907b 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblResponsibility.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/TblResponsibility.java
@@ -1,17 +1,8 @@
package org.eclipse.openk.elogbook.persistence.model;
+import javax.persistence.*;
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.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQuery;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
/**
@@ -19,14 +10,14 @@
*
*/
@Entity
-@Table(name="tbl_responsibility")
+@Table(name="TBL_RESPONSIBILITY")
@NamedQuery(name="TblResponsibility.findAll", query="SELECT t FROM TblResponsibility t")
public class TblResponsibility implements Serializable {
private static final long serialVersionUID = 1L;
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TBL_RESPONSIBILITY_ID_SEQ")
- @SequenceGenerator(name = "TBL_RESPONSIBILITY_ID_SEQ", sequenceName = "TBL_RESPONSIBILITY_ID_SEQ", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TBL_RESP_ID_SEQ")
+ @SequenceGenerator(name = "TBL_RESP_ID_SEQ", sequenceName = "TBL_RESP_ID_SEQ", allocationSize = 1)
@Column(name = "id", updatable = false)
private Integer id;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/model/ViewNotification.java b/src/main/java/org/eclipse/openk/elogbook/persistence/model/ViewNotification.java
index 12f47a1..dee28e4 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/model/ViewNotification.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/model/ViewNotification.java
@@ -9,7 +9,7 @@
*
*/
@Entity
-@Table(name="view_active_notification")
+@Table(name="\"VIEW_ACTIVE_NOTIFICATION\"")
public class ViewNotification extends AbstractNotification {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreator.java b/src/main/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreator.java
index 85f68fe..c3947f6 100644
--- a/src/main/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreator.java
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreator.java
@@ -3,6 +3,7 @@
import org.apache.log4j.Logger;
import org.eclipse.openk.elogbook.common.Globals;
import org.eclipse.openk.elogbook.common.NotificationStatus;
+import org.eclipse.openk.elogbook.persistence.dao.EntityHelper;
import org.eclipse.openk.elogbook.persistence.model.HTblResponsibility;
import org.eclipse.openk.elogbook.persistence.model.TblNotification;
import org.eclipse.openk.elogbook.persistence.model.TblResponsibility;
@@ -14,21 +15,31 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class NotificationQueryCreator {
private static final String AND_LIT = " AND ";
private static final String OR_LIT = " OR ";
private static final String ORDER_LIT = " ORDER BY ";
- private static final String FK_BRANCH_EQUAL = "fk_ref_branch = ";
- private static final String FK_GRID_TERRITORY_EQUAL = "fk_ref_grid_territory = ";
- private static final String FK_BRANCH_NULL = "fk_ref_branch IS NULL";
- private static final String FK_GRID_TERRITORY_NULL = "fk_ref_grid_territory IS NULL";
- private static final String DUMMY_FALSE_VALUE_ORCLAUSE = " false ";
-
+ private static final String IS_NULL = " IS NULL";
+ private static final String FK_REF_BRANCH = EntityHelper.instance().makeIdentifier("fk_ref_branch");
+ private static final String FK_REF_GRID_TERRITORY = EntityHelper.instance().makeIdentifier("fk_ref_grid_territory");
+ private static final String FK_BRANCH_EQUAL = FK_REF_BRANCH + " = ";
+ private static final String FK_GRID_TERRITORY_EQUAL = FK_REF_GRID_TERRITORY+" = ";
+ private static final String FK_BRANCH_NULL = FK_REF_BRANCH + IS_NULL;
+ private static final String FK_GRID_TERRITORY_NULL = FK_REF_GRID_TERRITORY+IS_NULL;
+ private static final String FK_REF_NOTIFICATION_STATUS = EntityHelper.instance().makeIdentifier("fk_ref_notification_status");
+ private static final String DUMMY_FALSE_VALUE_ORCLAUSE = " (1=0) ";
+ private static final String TBL_NOTIFICATION = EntityHelper.instance().makeIdentifier("TBL_NOTIFICATION");
+ private static final String VIEW_ACTIVE_NOTIFICATION = EntityHelper.instance().makeIdentifier("VIEW_ACTIVE_NOTIFICATION");
+ private static final String INCIDENT_ID = EntityHelper.instance().makeIdentifier("incident_id");
+ private static final String VERSION = EntityHelper.instance().makeIdentifier("version");
+ private static final String BEGIN_DATE = EntityHelper.instance().makeIdentifier("begin_date");
+ private static final String MOD_DATE = EntityHelper.instance().makeIdentifier("mod_date");
+ private static final String CREATE_DATE = EntityHelper.instance().makeIdentifier("create_date");
+ private static final String REMINDER_DATE = EntityHelper.instance().makeIdentifier("reminder_date");
+
+
private static final Logger LOGGER = Logger.getLogger(NotificationQueryCreator.class.getName());
private EntityManager em;
@@ -36,7 +47,7 @@
private Map<Integer, Object> latebindParamMap = new HashMap<>();
private int iCounter = 1;
- public NotificationQueryCreator(EntityManager em, String tablePrefix) {
+ public NotificationQueryCreator(EntityManager em, String tablePrefix ) {
this.em = em;
if (tablePrefix != null && !tablePrefix.isEmpty()) {
this.tablePrefix = tablePrefix + ".";
@@ -57,14 +68,14 @@
* @return the generated query
*/
public Query generateNotificationQuery(NotificationSearchFilter notificationSearchFilter, String baseWhereClause,
- ListType listType, List<TblResponsibility> tblResponsibilities) {
+ List<TblResponsibility> tblResponsibilities) {
- StringBuilder sql = new StringBuilder("select * from view_active_notification v where 1=1 ");
+ StringBuilder sql = new StringBuilder("select * from "+VIEW_ACTIVE_NOTIFICATION+" v where 1=1 "); // NOSONAR
if (baseWhereClause != null && !baseWhereClause.isEmpty()) {
sql.append(AND_LIT).append(baseWhereClause);
}
if (notificationSearchFilter != null) {
- sql.append(extendWhereClauseApplyingSearchFilter(notificationSearchFilter, listType, tblResponsibilities));
+ sql.append(extendWhereClauseApplyingSearchFilter(notificationSearchFilter, tblResponsibilities));
}
sql.append(getNotificationOrder());
// _fd: No String comes unescaped from outside the program -> So SONAR
@@ -77,7 +88,7 @@
public Query generateNotificationQueryWithReminder(ReminderSearchFilter rsf, String baseWhereClause,
List<TblResponsibility> tblResponsibilities) {
- StringBuilder sql = new StringBuilder("select * from view_active_notification v where 1=1 ");
+ StringBuilder sql = new StringBuilder("select * from "+VIEW_ACTIVE_NOTIFICATION+" v where 1=1 "); // NOSONAR
if (baseWhereClause != null && !baseWhereClause.isEmpty()) {
sql.append(AND_LIT).append(baseWhereClause);
}
@@ -105,28 +116,37 @@
*/
public Query generateFindHistoricalNotificationsByResponsibilityQuery(List<HTblResponsibility> hTblResponsibilities,
ListType listType) {
- StringBuilder sqlSB = new StringBuilder("select * from " + " tbl_notification t1 join ( "
- + " select incident_id, max(version) as version FROM tbl_notification t " + " WHERE ");
- sqlSB.append("(");
- sqlSB.append(" mod_Date < ? ").append(OR_LIT).append(" mod_Date IS NULL").append(AND_LIT)
- .append("create_Date < ? ");
+ List<Object> paramList = new LinkedList<>();
+ StringBuilder sqlSB = new StringBuilder("select * from " + TBL_NOTIFICATION + " t1 join ( "
+ + " select "+INCIDENT_ID+ ", "
+ + " max("+VERSION+") as VERSION "
+ + " FROM "+TBL_NOTIFICATION+" t " + " WHERE ");
+ sqlSB.append("( "+MOD_DATE+" < ? ").append(OR_LIT)
+ .append(" "+MOD_DATE+" IS NULL").append(AND_LIT)
+ .append(" "+CREATE_DATE + " < ? ");
sqlSB.append(")");
- sqlSB.append(" GROUP BY incident_id");
- sqlSB.append(" ) t2 ON ( t1.incident_id = t2.incident_id AND t1.version = t2.version) where ");
+ sqlSB.append(" GROUP BY "+INCIDENT_ID);
+ sqlSB.append(" ) t2 ON ( t1."+INCIDENT_ID+" = t2."+INCIDENT_ID);
+ sqlSB.append(" AND t1."+VERSION+" = t2.VERSION) where ");
+ paramList.add(hTblResponsibilities.get(0).getTransferDate());
+ paramList.add(hTblResponsibilities.get(0).getTransferDate());
sqlSB.append("(").append(DUMMY_FALSE_VALUE_ORCLAUSE);
for (HTblResponsibility hTblResponsibility : hTblResponsibilities) {
sqlSB.append(OR_LIT);
sqlSB.append(FK_BRANCH_EQUAL).append(hTblResponsibility.getRefBranch().getId()).append(AND_LIT)
.append(FK_GRID_TERRITORY_EQUAL).append(hTblResponsibility.getRefGridTerritory().getId());
}
-
+ sqlSB.append(")");
extendFindHistoricalNotificationsByResponsibilityQueryListTypeSpecific(sqlSB, listType,
- hTblResponsibilities.get(0).getTransferDate());
- sqlSB.append(")").append(getNotificationOrder());
+ hTblResponsibilities.get(0).getTransferDate(), paramList);
+ sqlSB.append(getNotificationOrder());
+
Query query = em.createNativeQuery(sqlSB.toString(), TblNotification.class);
- query.setParameter(1, hTblResponsibilities.get(0).getTransferDate());
- query.setParameter(2, hTblResponsibilities.get(0).getTransferDate());
+ int i = 1;
+ for( Object o: paramList) {
+ query.setParameter(i++, o);
+ }
return query;
}
@@ -255,24 +275,35 @@
* the list type
*/
private void extendFindHistoricalNotificationsByResponsibilityQueryListTypeSpecific(StringBuilder sqlSB,
- ListType listType, Timestamp transferDate) {
- sqlSB.append(AND_LIT).append("fk_ref_notification_status ");
+ ListType listType, Timestamp transferDate, List<Object> paramList) {
+ sqlSB.append(AND_LIT).append( FK_REF_NOTIFICATION_STATUS + " ");
switch (listType) {
case PAST:
sqlSB.append("IN ").append("(").append(NotificationStatus.CLOSED.id).append(", ")
- .append(NotificationStatus.FINISHED.id).append(")").append(AND_LIT).append("begin_date <= '")
- .append(transferDate).append("'").append(AND_LIT).append("begin_date > TIMESTAMP '")
- .append(transferDate).append("' - INTERVAL '7 days'");
+ .append(NotificationStatus.FINISHED.id).append(")")
+ .append(AND_LIT).append( BEGIN_DATE ).append(" <= ?") // NOSONAR
+ .append(AND_LIT).append( BEGIN_DATE ).append(" > ?"); // NOSONAR
+ paramList.add(transferDate);
+ paramList.add(TimestampConverter.getTimestampWithTime(
+ new Timestamp(transferDate.getTime()-1*(1000*60*60*24)),
+ 0, 0, 0));
break;
case OPEN:
sqlSB.append("IN ").append("(").append(NotificationStatus.OPEN.id).append(", ")
.append(NotificationStatus.INPROGRESS.id).append(", ").append(NotificationStatus.FINISHED.id)
- .append(")").append(AND_LIT).append("begin_date < TIMESTAMP '").append(transferDate)
- .append("' + INTERVAL '1 day '");
+ .append(")")
+ .append(AND_LIT).append(BEGIN_DATE).append(" < ?");
+ paramList.add(TimestampConverter.getTimestampWithTime(
+ new Timestamp(transferDate.getTime()+1*(1000*60*60*24)),
+ 0, 0, 0));
break;
case FUTURE:
sqlSB.append("NOT IN ").append("(").append(NotificationStatus.CLOSED.id).append(", ")
- .append(NotificationStatus.FINISHED.id).append(")");
+ .append(NotificationStatus.FINISHED.id).append(")")
+ .append(AND_LIT).append(BEGIN_DATE).append(" >= ?");
+ paramList.add(TimestampConverter.getTimestampWithTime(
+ new Timestamp(transferDate.getTime()+1*(1000*60*60*24)),
+ 0, 0, 0 ));
break;
default:
break;
@@ -283,20 +314,16 @@
* Create the where clause.
*
* @param nsf
- * The Object obtained from view model
- * @param listType
- * the listType (where clause creation depends from it)
+
* @param tblResponsibilities
* the list with the {@link TblResponsibility} objects
* @return he appropriate String to extend the where-clause
*/
- private String extendWhereClauseApplyingSearchFilter(NotificationSearchFilter nsf, ListType listType,
- List<TblResponsibility> tblResponsibilities) {
+ private String extendWhereClauseApplyingSearchFilter(NotificationSearchFilter nsf, List<TblResponsibility> tblResponsibilities) {
StringBuilder ret = new StringBuilder();
- if (listType == ListType.PAST || listType == ListType.FUTURE) {
- ret.append(extendWhereClauseByDates(nsf));
- }
+ ret.append(extendWhereClauseByDates(nsf));
+
ret.append(extendWhereClauseByResponsibility(tblResponsibilities));
return ret.toString();
}
@@ -321,13 +348,13 @@
private String extendWhereClauseByDates(NotificationSearchFilter nsf) {
StringBuilder ret = new StringBuilder();
if (nsf.getDateFrom() != null) {
- ret.append(AND_LIT).append(tablePrefix).append("begin_date >= ?");
+ ret.append(AND_LIT).append(tablePrefix).append(BEGIN_DATE).append(" >= ?");
latebindParamMap.put(iCounter, nsf.getDateFrom());
iCounter++;
}
if (nsf.getDateTo() != null) {
- ret.append(AND_LIT).append(tablePrefix).append("begin_date <= ?");
+ ret.append(AND_LIT).append(tablePrefix).append(BEGIN_DATE).append(" <= ?");
latebindParamMap.put(iCounter, nsf.getDateTo());
}
return ret.toString();
@@ -336,7 +363,7 @@
private String extendWhereClauseByReminderDate(ReminderSearchFilter rsf) {
StringBuilder ret = new StringBuilder();
if (rsf.getReminderDate() != null) {
- ret.append(AND_LIT).append(tablePrefix).append("reminder_date <= ?");
+ ret.append(AND_LIT).append(tablePrefix).append(REMINDER_DATE).append(" <= ?");
latebindParamMap.put(iCounter, rsf.getReminderDate());
}
@@ -394,6 +421,8 @@
}
private String getNotificationOrder() {
- return ORDER_LIT + tablePrefix + "fk_ref_branch ASC, fk_ref_grid_territory ASC, " + tablePrefix + "begin_date";
+ return ORDER_LIT + tablePrefix + FK_REF_BRANCH+" ASC, "+FK_REF_GRID_TERRITORY+" ASC, " + tablePrefix + BEGIN_DATE;
}
+
+
}
\ No newline at end of file
diff --git a/src/main/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverter.java b/src/main/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverter.java
new file mode 100644
index 0000000..736564c
--- /dev/null
+++ b/src/main/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverter.java
@@ -0,0 +1,16 @@
+package org.eclipse.openk.elogbook.persistence.util;
+
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+public class TimestampConverter {
+ private TimestampConverter() { }
+
+ public static Timestamp getTimestampWithTime(Timestamp tsorg, int hours, int minutes, int seconds) {
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(tsorg.getTime());
+ Calendar c2 = Calendar.getInstance();
+ c2.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), hours, minutes, seconds);
+ return new Timestamp(c2.getTimeInMillis());
+ }
+}
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
index f6a4e42..57c51be 100644
--- a/src/main/resources/META-INF/persistence.xml
+++ b/src/main/resources/META-INF/persistence.xml
@@ -13,10 +13,21 @@
<class>org.eclipse.openk.elogbook.persistence.model.TblResponsibility</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
- <!--<property name="eclipselink.logging.file" value="../logs/eclipselink.log"/>-->
- <!--<property name="eclipselink.logging.level" value="FINE" />-->
- <!--<property name="eclipselink.logging.level.sql" value="FINE"/>-->
- <!--<property name="eclipselink.logging.parameters" value="true"/>-->
+ </properties>
+ </persistence-unit>
+ <persistence-unit name="betriebstagebuchORA">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <non-jta-data-source>java:comp/env/jdbc/okBetriebstagebuchDSO</non-jta-data-source>
+ <class>org.eclipse.openk.elogbook.persistence.model.RefVersion</class>
+ <class>org.eclipse.openk.elogbook.persistence.model.RefBranch</class>
+ <class>org.eclipse.openk.elogbook.persistence.model.RefGridTerritory</class>
+ <class>org.eclipse.openk.elogbook.persistence.model.RefNotificationStatus</class>
+ <class>org.eclipse.openk.elogbook.persistence.model.TblNotification</class>
+ <class>org.eclipse.openk.elogbook.persistence.model.TblResponsibility</class>
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
+ <property name="eclipselink.target-database" value="Oracle"/>
</properties>
</persistence-unit>
</persistence>
diff --git a/src/main/resources/backendConfigCustom.json b/src/main/resources/backendConfigCustom.json
index 6d1bf17..1ebe18e 100644
--- a/src/main/resources/backendConfigCustom.json
+++ b/src/main/resources/backendConfigCustom.json
@@ -1,5 +1,6 @@
{
- "portalBaseURL" : "http://localhost:8088/portal/rest/beservice",
+ "portalBaseURL" : "http://localhost:8080/portal/rest/beservice",
"fileRowToRead": "9",
- "importFilesFolderPath": "C:/FilesToImport"
+ "importFilesFolderPath": "C:/FilesToImport",
+ "activePersistencyUnit": "betriebstagebuchORA"
}
diff --git a/src/main/resources/backendConfigDevLocal.json b/src/main/resources/backendConfigDevLocal.json
index f645c06..308e1ea 100644
--- a/src/main/resources/backendConfigDevLocal.json
+++ b/src/main/resources/backendConfigDevLocal.json
@@ -1,5 +1,6 @@
{
"portalBaseURL" : "http://localhost:8080/portal/rest/beservice",
"fileRowToRead": "9",
- "importFilesFolderPath": "C:/FilesToImport"
+ "importFilesFolderPath": "C:/FilesToImport",
+ "activePersistencyUnit": "betriebstagebuch"
}
diff --git a/src/main/resources/backendConfigDevServer.json b/src/main/resources/backendConfigDevServer.json
index e25858a..1c0849f 100644
--- a/src/main/resources/backendConfigDevServer.json
+++ b/src/main/resources/backendConfigDevServer.json
@@ -1,5 +1,6 @@
{
"portalBaseURL" : "http://localhost:8880/portal/rest/beservice",
"fileRowToRead": "9",
- "importFilesFolderPath": "C:/FilesToImport"
+ "importFilesFolderPath": "C:/FilesToImport",
+ "activePersistencyUnit": "betriebstagebuch"
}
diff --git a/src/main/resources/backendConfigProduction.json b/src/main/resources/backendConfigProduction.json
index 264af28..e7d47d3 100644
--- a/src/main/resources/backendConfigProduction.json
+++ b/src/main/resources/backendConfigProduction.json
@@ -1,5 +1,6 @@
{
"portalBaseURL" : "http://localhost:8080/portal/rest/beservice",
"fileRowToRead": "9",
- "importFilesFolderPath": "/home/btbservice/importFiles"
+ "importFilesFolderPath": "/home/btbservice/importFiles",
+ "activePersistencyUnit": "betriebstagebuch"
}
\ No newline at end of file
diff --git a/src/test/java/org/eclipse/openk/elogbook/controller/BackendControllerTest.java b/src/test/java/org/eclipse/openk/elogbook/controller/BackendControllerTest.java
index 408d07a..e9a30a9 100644
--- a/src/test/java/org/eclipse/openk/elogbook/controller/BackendControllerTest.java
+++ b/src/test/java/org/eclipse/openk/elogbook/controller/BackendControllerTest.java
@@ -1,104 +1,29 @@
package org.eclipse.openk.elogbook.controller;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import org.eclipse.openk.elogbook.common.mapper.NotificationMapper;
+import org.eclipse.openk.elogbook.common.util.ResourceLoaderBase;
+import org.eclipse.openk.elogbook.exceptions.BtbInternalServerError;
+import org.eclipse.openk.elogbook.exceptions.BtbLocked;
+import org.eclipse.openk.elogbook.persistence.dao.HTblResponsibilityDao;
+import org.eclipse.openk.elogbook.persistence.dao.RefVersionDao;
+import org.eclipse.openk.elogbook.persistence.dao.TblNotificationDao;
+import org.eclipse.openk.elogbook.persistence.dao.TblResponsibilityDao;
+import org.eclipse.openk.elogbook.persistence.model.*;
+import org.eclipse.openk.elogbook.viewmodel.*;
+import org.junit.Test;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import org.eclipse.openk.elogbook.common.JsonGeneratorBase;
-import org.eclipse.openk.elogbook.common.mapper.NotificationMapper;
-import org.eclipse.openk.elogbook.common.util.ResourceLoaderBase;
-import org.eclipse.openk.elogbook.exceptions.BtbInternalServerError;
-import org.eclipse.openk.elogbook.exceptions.BtbLocked;
-import org.eclipse.openk.elogbook.exceptions.BtbUnauthorized;
-import org.eclipse.openk.elogbook.persistence.dao.HTblResponsibilityDao;
-import org.eclipse.openk.elogbook.persistence.dao.RefVersionDao;
-import org.eclipse.openk.elogbook.persistence.dao.TblNotificationDao;
-import org.eclipse.openk.elogbook.persistence.dao.TblResponsibilityDao;
-import org.eclipse.openk.elogbook.persistence.model.HTblResponsibility;
-import org.eclipse.openk.elogbook.persistence.model.RefBranch;
-import org.eclipse.openk.elogbook.persistence.model.RefGridTerritory;
-import org.eclipse.openk.elogbook.persistence.model.RefNotificationStatus;
-import org.eclipse.openk.elogbook.persistence.model.RefVersion;
-import org.eclipse.openk.elogbook.persistence.model.TblNotification;
-import org.eclipse.openk.elogbook.persistence.model.TblResponsibility;
-import org.eclipse.openk.elogbook.viewmodel.HistoricalShiftChanges;
-import org.eclipse.openk.elogbook.viewmodel.LoginCredentials;
-import org.eclipse.openk.elogbook.viewmodel.Notification;
-import org.eclipse.openk.elogbook.viewmodel.NotificationSearchFilter;
-import org.eclipse.openk.elogbook.viewmodel.ReminderSearchFilter;
-import org.eclipse.openk.elogbook.viewmodel.UserAuthentication;
-import org.eclipse.openk.elogbook.viewmodel.VersionInfo;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.reflect.Whitebox;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class BackendControllerTest extends ResourceLoaderBase {
- //FIXME resolve Tests
- @Ignore
- @Test
- public void testGetUsers() throws Exception {
- BackendControllerUser bec = new BackendControllerUser();
- List<UserAuthentication> userAuthenticationList = bec.getUsers("");
-
- assertNotNull(userAuthenticationList);
- assertTrue(userAuthenticationList.size()== 5);
- assertEquals(userAuthenticationList.get(0).getId(), 1);
- assertEquals(userAuthenticationList.get(0).getUsername(), "max");
- assertEquals(userAuthenticationList.get(0).getPassword(), "max");
- assertEquals(userAuthenticationList.get(0).isSpecialUser(), false);
- assertEquals(userAuthenticationList.get(0).isSelected(), false);
- assertEquals(userAuthenticationList.get(2).getId(), 3);
-
- }
-
- //FIXME resolve Tests
- @Ignore
- @Test
- public void testAuthenticateUser() throws Exception {
- BackendControllerUser bec = new BackendControllerUser();
- LoginCredentials lcr= new LoginCredentials();
- lcr.setUserName("max");
- lcr.setPassword("max");
-
- UserAuthentication ua = bec.authenticate(JsonGeneratorBase.getGson().toJson(lcr));
- assertNotNull(ua);
- assertEquals(ua.getUsername(), lcr.getUserName());
- assertEquals(ua.getPassword(), lcr.getPassword());
- }
-
- //FIXME resolve Tests
- @Ignore
- @Test( expected = BtbUnauthorized.class )
- public void testAuthenticateUser_UnknownUser() throws Exception {
- BackendControllerUser bec = new BackendControllerUser();
- LoginCredentials lcr= new LoginCredentials();
- lcr.setUserName("Unknown");
- lcr.setPassword("max");
-
- bec.authenticate(JsonGeneratorBase.getGson().toJson(lcr));
- }
-
- //FIXME resolve Tests
- @Ignore
- @Test( expected = BtbUnauthorized.class )
- public void testAuthenticateUser_UnknownPassword() throws Exception {
- BackendControllerUser bec = new BackendControllerUser();
- LoginCredentials lcr= new LoginCredentials();
- lcr.setUserName("max");
- lcr.setPassword("Unknown");
-
- bec.authenticate(JsonGeneratorBase.getGson().toJson(lcr));
- }
@Test
public void testGetVersionInfoImpl_OK() throws Exception {
diff --git a/src/test/java/org/eclipse/openk/elogbook/exceptions/BtbExceptionMapperTest.java b/src/test/java/org/eclipse/openk/elogbook/exceptions/BtbExceptionMapperTest.java
index 6c6ee54..8695439 100644
--- a/src/test/java/org/eclipse/openk/elogbook/exceptions/BtbExceptionMapperTest.java
+++ b/src/test/java/org/eclipse/openk/elogbook/exceptions/BtbExceptionMapperTest.java
@@ -1,14 +1,14 @@
package org.eclipse.openk.elogbook.exceptions;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
-
import org.eclipse.openk.elogbook.common.JsonGeneratorBase;
import org.eclipse.openk.elogbook.common.util.ResourceLoaderBase;
import org.eclipse.openk.elogbook.viewmodel.ErrorReturn;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class BtbExceptionMapperTest extends ResourceLoaderBase {
@Test
public void testToJson() {
diff --git a/src/test/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreatorTest.java b/src/test/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreatorTest.java
index eef41e1..9f5f01f 100644
--- a/src/test/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreatorTest.java
+++ b/src/test/java/org/eclipse/openk/elogbook/persistence/util/NotificationQueryCreatorTest.java
@@ -1,5 +1,6 @@
package org.eclipse.openk.elogbook.persistence.util;
+import org.easymock.EasyMock;
import org.eclipse.openk.elogbook.persistence.model.*;
import org.eclipse.openk.elogbook.viewmodel.GlobalSearchFilter;
import org.eclipse.openk.elogbook.viewmodel.Notification.ListType;
@@ -18,7 +19,8 @@
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertTrue;
public class NotificationQueryCreatorTest {
@@ -26,6 +28,7 @@
TypedQuery<TblNotification> mockedTypedQuery;
EntityManager mockedEm;
NotificationQueryCreator notificationQueryCreator;
+ Map<String, Object> propertyMap = new HashMap<>();
@Before
public void initialize(){
@@ -37,45 +40,45 @@
@Test
public void testgenerateNotificationQueryListTypeNull() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
NotificationSearchFilter nsf = new NotificationSearchFilter();
nsf.setDateFrom(new Date(System.currentTimeMillis()));
nsf.setDateTo(new Date(System.currentTimeMillis()));
- notificationQueryCreator.generateNotificationQuery(nsf, "AAA", null, new ArrayList<TblResponsibility>());
+ notificationQueryCreator.generateNotificationQuery(nsf, "AAA", new ArrayList<TblResponsibility>());
}
@Test
public void testgenerateNotificationQuery_firstTwoArgsEmpty() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "v");
NotificationSearchFilter nsf = new NotificationSearchFilter();
- notificationQueryCreator.generateNotificationQuery(nsf, "", null, new ArrayList<TblResponsibility>());
+ notificationQueryCreator.generateNotificationQuery(nsf, "", new ArrayList<TblResponsibility>());
}
@Test
public void testgenerateNotificationQuery_firstTwoArgsNull() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, null);
- notificationQueryCreator.generateNotificationQuery(null, null, ListType.OPEN, new ArrayList<TblResponsibility>());
+ notificationQueryCreator.generateNotificationQuery(null, null, new ArrayList<TblResponsibility>());
}
@Test
public void testgenerateNotificationQueryWithReminder() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
@@ -87,8 +90,8 @@
@Test
public void testgenerateNotificationQueryWithReminder_firstTwoArgsEmpty() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "v");
@@ -99,8 +102,8 @@
@Test
public void testgenerateNotificationQueryWithReminder_firstTwoArgsNull() {
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, null);
@@ -118,7 +121,7 @@
notificationSearchFilter.setDateTo(null);
String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", notificationSearchFilter,
- ListType.OPEN, new ArrayList<TblResponsibility>());
+ new ArrayList<TblResponsibility>());
assertEquals(paramMap.size(), 0);
assertFalse(ret.contains("."));
assertFalse(ret.contains(">="));
@@ -133,7 +136,7 @@
nsf.setDateFrom(new Date(System.currentTimeMillis()));
nsf.setDateTo(new Date(System.currentTimeMillis()));
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.OPEN,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
new ArrayList<TblResponsibility>());
assertTrue(!ret.isEmpty());
}
@@ -146,7 +149,7 @@
nsf.setDateFrom(null);
nsf.setDateTo(null);
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.PAST,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
new ArrayList<TblResponsibility>());
assertTrue(! ret.isEmpty());
}
@@ -159,7 +162,7 @@
nsf.setDateFrom(createDate(2017, 3, 8));
nsf.setDateTo(createDate(2017,4,2));
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.FUTURE,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
new ArrayList<TblResponsibility>());
assertTrue("AND w.begin_date >= ? AND w.begin_date <= ? AND (fk_ref_branch IS NULL AND fk_ref_grid_territory IS NULL)".equalsIgnoreCase(ret.trim()));
}
@@ -179,7 +182,7 @@
List<TblResponsibility> tblResponsibilities = new ArrayList<>();
tblResponsibilities.add(createTblResponsibility(1, 1, 1, 1));
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.PAST,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
tblResponsibilities);
assertTrue(" AND w.begin_date >= ? AND w.begin_date <= ? AND (fk_ref_branch IS NULL AND fk_ref_grid_territory IS NULL OR ((fk_ref_branch IS NULL OR fk_ref_branch = 1) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 1)))".equals(ret));
}
@@ -195,7 +198,7 @@
nsf.setDateFrom(createDate(2017, Calendar.JANUARY, 1));
nsf.setDateTo(createDate(2017, Calendar.JUNE, 1));
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.PAST,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
new ArrayList<TblResponsibility>());
assertTrue(" AND w.begin_date >= ? AND w.begin_date <= ? AND (fk_ref_branch IS NULL AND fk_ref_grid_territory IS NULL)".equals(ret));
}
@@ -213,11 +216,11 @@
tblResponsibilities.add(createTblResponsibility(2, 7, 13, 2));
tblResponsibilities.add(createTblResponsibility(3, 7, 14, 2));
- String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf, ListType.OPEN,
+ String ret = Whitebox.invokeMethod(queryCreator, "extendWhereClauseApplyingSearchFilter", nsf,
tblResponsibilities);
StringBuilder sb = new StringBuilder("( AND fk_ref_branch IS NULL AND fk_ref_grid_territory IS NULL OR ");
- sb.append("((fk_ref_branch IS NULL OR fk_ref_branch = 7) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 1) OR ")
- .append("(fk_ref_branch IS NULL OR fk_ref_branch = 7) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 2) OR ")
+ sb.append("((fk_ref_branch IS NULL OR fk_ref_branch = 7) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 1) OR ")
+ .append("(fk_ref_branch IS NULL OR fk_ref_branch = 7) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 2) OR ")
.append("(fk_ref_branch IS NULL OR fk_ref_branch = 7) AND (fk_ref_grid_territory IS NULL OR fk_ref_grid_territory = 2)))");
assertTrue((sb.toString()).length() == ret.length());
@@ -229,8 +232,8 @@
List<HTblResponsibility> hTblResponsibilities = new ArrayList<>();
hTblResponsibilities.add(hTblResponsibility);
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
@@ -244,8 +247,8 @@
List<HTblResponsibility> hTblResponsibilities = new ArrayList<>();
hTblResponsibilities.add(hTblResponsibility);
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
@@ -259,8 +262,8 @@
List<HTblResponsibility> hTblResponsibilities = new ArrayList<>();
hTblResponsibilities.add(hTblResponsibility);
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
@@ -274,8 +277,8 @@
List<HTblResponsibility> hTblResponsibilities = new ArrayList<>();
hTblResponsibilities.add(hTblResponsibility);
- expect(mockedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedQuery);
- expect(mockedEm.createNativeQuery(anyString(), eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
+ expect(mockedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedQuery);
+ expect(mockedEm.createNativeQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedQuery).anyTimes();
replay(mockedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
@@ -322,8 +325,8 @@
}
private void mockTypedQuery (GlobalSearchFilter gsf) {
- expect(mockedTypedQuery.setParameter(anyInt(), anyObject())).andReturn(mockedTypedQuery);
- expect(mockedEm.createQuery(anyString(), eq(TblNotification.class))).andReturn(mockedTypedQuery).anyTimes();
+ expect(mockedTypedQuery.setParameter(EasyMock.anyInt(), EasyMock.anyObject())).andReturn(mockedTypedQuery);
+ expect(mockedEm.createQuery(EasyMock.anyString(), EasyMock.eq(TblNotification.class))).andReturn(mockedTypedQuery).anyTimes();
replay(mockedTypedQuery);
replay(mockedEm);
notificationQueryCreator = new NotificationQueryCreator(mockedEm, "");
diff --git a/src/test/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverterTest.java b/src/test/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverterTest.java
new file mode 100644
index 0000000..dfbb88b
--- /dev/null
+++ b/src/test/java/org/eclipse/openk/elogbook/persistence/util/TimestampConverterTest.java
@@ -0,0 +1,31 @@
+package org.eclipse.openk.elogbook.persistence.util;
+
+import org.junit.Test;
+
+import java.sql.Timestamp;
+
+import static junit.framework.TestCase.assertTrue;
+
+public class TimestampConverterTest {
+
+ @Test
+ public void testGetTimestampWithTime() {
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+ Timestamp tsRatherNow = TimestampConverter.getTimestampWithTime(ts, 14, 04, 29);
+ Timestamp tsBefore1 = TimestampConverter.getTimestampWithTime(ts, 14, 04, 28);
+ Timestamp tsBefore2 = TimestampConverter.getTimestampWithTime(ts, 14, 03, 29);
+ Timestamp tsBefore3 = TimestampConverter.getTimestampWithTime(ts, 13, 04, 29);
+ Timestamp tsAfter1 = TimestampConverter.getTimestampWithTime(ts, 14, 04, 30);
+ Timestamp tsAfter2 = TimestampConverter.getTimestampWithTime(ts, 14, 05, 29);
+ Timestamp tsAfter3 = TimestampConverter.getTimestampWithTime(ts, 15, 04, 29);
+
+ assertTrue( tsBefore1.before(tsRatherNow) );
+ assertTrue( tsBefore2.before(tsBefore1) );
+ assertTrue( tsBefore3.before(tsBefore2) );
+
+ assertTrue( tsAfter1.after(tsRatherNow));
+ assertTrue( tsAfter2.after(tsAfter1));
+ assertTrue( tsAfter3.after(tsAfter2));
+
+ }
+}