From bca01441115d967ffe8e9176a16c86fbc872fd34 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 24 Jan 2024 17:49:50 +0200 Subject: [PATCH] Adding notification related user table scripts, altering existing foreign keys, aligning more entities --- .../data/UserContactInfoEntity.java | 2 +- .../data/UserCredentialEntity.java | 2 +- .../gr/cite/notification/data/UserEntity.java | 2 +- .../model/UserNotificationPreference.java | 29 ++++++++++-------- .../UserNotificationPreferenceBuilder.java | 10 +++---- .../UserNotificationPreferenceQuery.java | 12 ++++---- ...UserNotificationPreferenceServiceImpl.java | 5 ++-- ...034_add_ntf_UserNotificationPreference.sql | 18 +++++------ .../updates/00.01.043_Add_ntf_User.sql | 20 +++++++++++++ .../00.01.044_Add_ntf_User_ContactInfo.sql | 30 +++++++++++++++++++ .../00.01.045_Add_ntf_User_Credential.sql | 29 ++++++++++++++++++ 11 files changed, 121 insertions(+), 38 deletions(-) create mode 100644 dmp-db-scema/updates/00.01.043_Add_ntf_User.sql create mode 100644 dmp-db-scema/updates/00.01.044_Add_ntf_User_ContactInfo.sql create mode 100644 dmp-db-scema/updates/00.01.045_Add_ntf_User_Credential.sql diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserContactInfoEntity.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserContactInfoEntity.java index 75b3fba01..d77568e29 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserContactInfoEntity.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserContactInfoEntity.java @@ -9,7 +9,7 @@ import java.time.Instant; import java.util.UUID; @Entity -@Table(name = "\"UserContactInfo\"") +@Table(name = "\"ntf_UserContactInfo\"") public class UserContactInfoEntity extends TenantScopedBaseEntity { @Id diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserCredentialEntity.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserCredentialEntity.java index 015fd1b7f..726e0ed5e 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserCredentialEntity.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserCredentialEntity.java @@ -8,7 +8,7 @@ import java.time.Instant; import java.util.UUID; @Entity -@Table(name = "\"UserCredential\"") +@Table(name = "\"ntf_UserCredential\"") public class UserCredentialEntity extends TenantScopedBaseEntity { @Id diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserEntity.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserEntity.java index 477695f65..1e0a29e44 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserEntity.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/UserEntity.java @@ -8,7 +8,7 @@ import java.time.Instant; import java.util.UUID; @Entity -@Table(name = "\"User\"") +@Table(name = "\"ntf_User\"") public class UserEntity { @Id diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/UserNotificationPreference.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/UserNotificationPreference.java index d36614e65..dc6477cee 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/UserNotificationPreference.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/UserNotificationPreference.java @@ -1,31 +1,36 @@ package gr.cite.notification.model; import gr.cite.notification.common.enums.NotificationContactType; -import gr.cite.notification.data.composite.CompositeUserNotificationPreferenceId; -import gr.cite.notification.data.tenant.TenantScopedBaseEntity; -import jakarta.persistence.*; import java.time.Instant; import java.util.UUID; public class UserNotificationPreference { - public static class Field { - public static final String USER_ID = "userId"; - public static final String TYPE = "type"; - public static final String CHANNEL = "channel"; - public static final String ORDINAL = "ordinal"; - public static final String CREATED_AT = "createdAt"; - public static final String TENANT_ID = "tenantId"; - } - private UUID userId; + + public static final String _userId = "userId"; + private UUID type; + + public static final String _type = "type"; + private UUID tenantId; + + public static final String _tenantId = "tenantId"; + private NotificationContactType channel; + + public static final String _channel = "channel"; + private Integer ordinal; + + public static final String _ordinal = "ordinal"; + private Instant createdAt; + public static final String _createdAt = "createdAt"; + public UUID getUserId() { return userId; } diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java index 718e2510f..667ad53d7 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java @@ -42,11 +42,11 @@ public class UserNotificationPreferenceBuilder extends BaseBuilder models = new ArrayList<>(); for(UserNotificationPreferenceEntity d : data){ UserNotificationPreference m = new UserNotificationPreference(); - if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.USER_ID))) m.setUserId(d.getUserId()); - if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.TENANT_ID))) m.setTenantId(d.getTenantId()); - if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.TYPE))) m.setType(d.getType()); - if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.CHANNEL))) m.setChannel(d.getChannel()); - if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.ORDINAL))) m.setOrdinal(d.getOrdinal()); + if(fields.hasField(this.asIndexer(UserNotificationPreference._userId))) m.setUserId(d.getUserId()); + if(fields.hasField(this.asIndexer(UserNotificationPreference._tenantId))) m.setTenantId(d.getTenantId()); + if(fields.hasField(this.asIndexer(UserNotificationPreference._type))) m.setType(d.getType()); + if(fields.hasField(this.asIndexer(UserNotificationPreference._channel))) m.setChannel(d.getChannel()); + if(fields.hasField(this.asIndexer(UserNotificationPreference._ordinal))) m.setOrdinal(d.getOrdinal()); if(fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt()); models.add(m); } diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java index 0839c03f2..4d1795eaf 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java @@ -88,12 +88,12 @@ public class UserNotificationPreferenceQuery extends QueryBase> collectUserNotificationPreferences(List ids) { return this.builderFactory.builder(UserNotificationPreferenceBuilder.class) - .build(new BaseFieldSet(UserNotificationPreference.Field.USER_ID, UserNotificationPreference.Field.TYPE, - UserNotificationPreference.Field.CHANNEL, UserNotificationPreference.Field.ORDINAL), this.queryFactory + .build(new BaseFieldSet(UserNotificationPreference._userId, UserNotificationPreference._type, + UserNotificationPreference._channel, UserNotificationPreference._ordinal), this.queryFactory .query(UserNotificationPreferenceQuery.class) .userId(ids).collect()).stream().collect(Collectors.groupingBy(UserNotificationPreference::getUserId)); //GK: Yep that exist on JAVA Streams } diff --git a/dmp-db-scema/updates/00.01.034_add_ntf_UserNotificationPreference.sql b/dmp-db-scema/updates/00.01.034_add_ntf_UserNotificationPreference.sql index 1458b0109..8fd1116ba 100644 --- a/dmp-db-scema/updates/00.01.034_add_ntf_UserNotificationPreference.sql +++ b/dmp-db-scema/updates/00.01.034_add_ntf_UserNotificationPreference.sql @@ -7,18 +7,18 @@ BEGIN CREATE TABLE public."ntf_UserNotificationPreference" ( "user" uuid NOT NULL, - type uuid NOT NULL, - channel smallint NOT NULL, - ordinal numeric NOT NULL, - created_at timestamp without time zone NOT NULL, - tenant uuid, - CONSTRAINT "ntf_UserNotificationPreference_pkey" PRIMARY KEY ("user", type, channel), - CONSTRAINT "ntf_UserNotificationPreference_tennant_fkey" FOREIGN KEY (tenant) - REFERENCES public."Tenant" (id) MATCH SIMPLE + "type" uuid NOT NULL, + "channel" smallint NOT NULL, + "ordinal" numeric NOT NULL, + "created_at" timestamp without time zone NOT NULL, + "tenant" uuid, + CONSTRAINT "ntf_UserNotificationPreference_pkey" PRIMARY KEY ("user", "type", "channel"), + CONSTRAINT "ntf_UserNotificationPreference_tenant_fkey" FOREIGN KEY ("tenant") + REFERENCES public."ntf_Tenant" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "ntf_UserNotificationPreference_user_fkey" FOREIGN KEY ("user") - REFERENCES public."User" (id) MATCH SIMPLE + REFERENCES public."ntf_User" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ); diff --git a/dmp-db-scema/updates/00.01.043_Add_ntf_User.sql b/dmp-db-scema/updates/00.01.043_Add_ntf_User.sql new file mode 100644 index 000000000..52c5263a5 --- /dev/null +++ b/dmp-db-scema/updates/00.01.043_Add_ntf_User.sql @@ -0,0 +1,20 @@ +DO $$DECLARE + this_version CONSTANT varchar := '00.01.043'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + + CREATE TABLE IF NOT EXISTS public."ntf_User" +( + "id" uuid NOT NULL, + "name" character varying(250) COLLATE pg_catalog."default", + "additional_info" character varying COLLATE pg_catalog."default", + "created_at" timestamp without time zone NOT NULL DEFAULT now(), + "updated_at" timestamp without time zone NOT NULL DEFAULT now(), + "is_active" smallint NOT NULL DEFAULT 1, + CONSTRAINT "Ntf_User_pkey" PRIMARY KEY (id) +) + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.043', '2024-01-24 12:00:00.000000+02', now(), 'Add table ntf_User.'); + +END$$; \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.044_Add_ntf_User_ContactInfo.sql b/dmp-db-scema/updates/00.01.044_Add_ntf_User_ContactInfo.sql new file mode 100644 index 000000000..369df5437 --- /dev/null +++ b/dmp-db-scema/updates/00.01.044_Add_ntf_User_ContactInfo.sql @@ -0,0 +1,30 @@ +DO $$DECLARE + this_version CONSTANT varchar := '00.01.044'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + +CREATE TABLE IF NOT EXISTS public."ntf_UserContactInfo" +( + "id" uuid NOT NULL, + "user" uuid NOT NULL, + "ordinal" integer NOT NULL DEFAULT 0, + "type" smallint NOT NULL, + "value" character varying(512) COLLATE pg_catalog."default" NOT NULL, + "created_at" timestamp without time zone NOT NULL, + "tenant" uuid, + CONSTRAINT "ntf_UserContactInfo_pkey" PRIMARY KEY (id), + CONSTRAINT "ntf_UserContactInfo_tenant_fkey" FOREIGN KEY ("tenant") + REFERENCES public."ntf_Tenant" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID, + CONSTRAINT "ntf_UserContactInfo_user_fkey" FOREIGN KEY ("user") + REFERENCES public."ntf_User" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +) + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.044', '2024-01-24 12:00:00.000000+02', now(), 'Add table ntf_UserContactInfo.'); + +END$$; \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.045_Add_ntf_User_Credential.sql b/dmp-db-scema/updates/00.01.045_Add_ntf_User_Credential.sql new file mode 100644 index 000000000..130da6892 --- /dev/null +++ b/dmp-db-scema/updates/00.01.045_Add_ntf_User_Credential.sql @@ -0,0 +1,29 @@ +DO $$DECLARE + this_version CONSTANT varchar := '00.01.045'; +BEGIN + PERFORM * FROM "DBVersion" WHERE version = this_version; + IF FOUND THEN RETURN; END IF; + +CREATE TABLE IF NOT EXISTS public."ntf_UserCredential" +( + "id" uuid NOT NULL, + "user" uuid NOT NULL, + "external_id" character varying(512) COLLATE pg_catalog."default" NOT NULL, + "created_at" timestamp without time zone NOT NULL, + "tenant" uuid, + "data" character varying COLLATE pg_catalog."default", + CONSTRAINT "ntf_UserCredential_pkey" PRIMARY KEY (id), + CONSTRAINT "ntf_UserCredential_tenant_fkey" FOREIGN KEY ("tenant") + REFERENCES public."ntf_Tenant" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID, + CONSTRAINT "ntf_UserCredential_user_fkey" FOREIGN KEY ("user") + REFERENCES public."ntf_User" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +) + + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.045', '2024-01-24 12:00:00.000000+02', now(), 'Add table ntf_UserCredential.'); + +END$$; \ No newline at end of file