Adding notification related user table scripts, altering existing foreign keys, aligning more entities

This commit is contained in:
Thomas Georgios Giannos 2024-01-24 17:49:50 +02:00
parent 0faa5f731a
commit bca0144111
11 changed files with 121 additions and 38 deletions

View File

@ -9,7 +9,7 @@ import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "\"UserContactInfo\"") @Table(name = "\"ntf_UserContactInfo\"")
public class UserContactInfoEntity extends TenantScopedBaseEntity { public class UserContactInfoEntity extends TenantScopedBaseEntity {
@Id @Id

View File

@ -8,7 +8,7 @@ import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "\"UserCredential\"") @Table(name = "\"ntf_UserCredential\"")
public class UserCredentialEntity extends TenantScopedBaseEntity { public class UserCredentialEntity extends TenantScopedBaseEntity {
@Id @Id

View File

@ -8,7 +8,7 @@ import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "\"User\"") @Table(name = "\"ntf_User\"")
public class UserEntity { public class UserEntity {
@Id @Id

View File

@ -1,31 +1,36 @@
package gr.cite.notification.model; package gr.cite.notification.model;
import gr.cite.notification.common.enums.NotificationContactType; 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.time.Instant;
import java.util.UUID; import java.util.UUID;
public class UserNotificationPreference { 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; private UUID userId;
public static final String _userId = "userId";
private UUID type; private UUID type;
public static final String _type = "type";
private UUID tenantId; private UUID tenantId;
public static final String _tenantId = "tenantId";
private NotificationContactType channel; private NotificationContactType channel;
public static final String _channel = "channel";
private Integer ordinal; private Integer ordinal;
public static final String _ordinal = "ordinal";
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt";
public UUID getUserId() { public UUID getUserId() {
return userId; return userId;
} }

View File

@ -42,11 +42,11 @@ public class UserNotificationPreferenceBuilder extends BaseBuilder<UserNotificat
List<UserNotificationPreference> models = new ArrayList<>(); List<UserNotificationPreference> models = new ArrayList<>();
for(UserNotificationPreferenceEntity d : data){ for(UserNotificationPreferenceEntity d : data){
UserNotificationPreference m = new UserNotificationPreference(); UserNotificationPreference m = new UserNotificationPreference();
if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.USER_ID))) m.setUserId(d.getUserId()); if(fields.hasField(this.asIndexer(UserNotificationPreference._userId))) m.setUserId(d.getUserId());
if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.TENANT_ID))) m.setTenantId(d.getTenantId()); if(fields.hasField(this.asIndexer(UserNotificationPreference._tenantId))) m.setTenantId(d.getTenantId());
if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.TYPE))) m.setType(d.getType()); if(fields.hasField(this.asIndexer(UserNotificationPreference._type))) m.setType(d.getType());
if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.CHANNEL))) m.setChannel(d.getChannel()); if(fields.hasField(this.asIndexer(UserNotificationPreference._channel))) m.setChannel(d.getChannel());
if(fields.hasField(this.asIndexer(UserNotificationPreference.Field.ORDINAL))) m.setOrdinal(d.getOrdinal()); if(fields.hasField(this.asIndexer(UserNotificationPreference._ordinal))) m.setOrdinal(d.getOrdinal());
if(fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt()); if(fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt());
models.add(m); models.add(m);
} }

View File

@ -88,12 +88,12 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
@Override @Override
protected String fieldNameOf(FieldResolver item) { protected String fieldNameOf(FieldResolver item) {
if (item.match(UserNotificationPreference.Field.USER_ID)) return UserNotificationPreferenceEntity._userId; if (item.match(UserNotificationPreference._userId)) return UserNotificationPreferenceEntity._userId;
else if (item.match(UserNotificationPreference.Field.TENANT_ID)) return UserNotificationPreferenceEntity._tenantId; else if (item.match(UserNotificationPreference._tenantId)) return UserNotificationPreferenceEntity._tenantId;
else if (item.match(UserNotificationPreference.Field.TYPE)) return UserNotificationPreferenceEntity._type; else if (item.match(UserNotificationPreference._type)) return UserNotificationPreferenceEntity._type;
else if (item.match(UserNotificationPreference.Field.CHANNEL)) return UserNotificationPreferenceEntity._channel; else if (item.match(UserNotificationPreference._channel)) return UserNotificationPreferenceEntity._channel;
else if (item.match(UserNotificationPreference.Field.ORDINAL)) return UserNotificationPreferenceEntity._ordinal; else if (item.match(UserNotificationPreference._ordinal)) return UserNotificationPreferenceEntity._ordinal;
else if (item.match(UserNotificationPreference.Field.CREATED_AT)) return UserNotificationPreferenceEntity._createdAt; else if (item.match(UserNotificationPreference._createdAt)) return UserNotificationPreferenceEntity._createdAt;
else return null; else return null;
} }

View File

@ -1,7 +1,6 @@
package gr.cite.notification.service.userNotificationPreference; package gr.cite.notification.service.userNotificationPreference;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.notification.authorization.OwnedResource;
import gr.cite.notification.authorization.Permission; import gr.cite.notification.authorization.Permission;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer;
@ -125,8 +124,8 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
@Override @Override
public Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids) { public Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids) {
return this.builderFactory.builder(UserNotificationPreferenceBuilder.class) return this.builderFactory.builder(UserNotificationPreferenceBuilder.class)
.build(new BaseFieldSet(UserNotificationPreference.Field.USER_ID, UserNotificationPreference.Field.TYPE, .build(new BaseFieldSet(UserNotificationPreference._userId, UserNotificationPreference._type,
UserNotificationPreference.Field.CHANNEL, UserNotificationPreference.Field.ORDINAL), this.queryFactory UserNotificationPreference._channel, UserNotificationPreference._ordinal), this.queryFactory
.query(UserNotificationPreferenceQuery.class) .query(UserNotificationPreferenceQuery.class)
.userId(ids).collect()).stream().collect(Collectors.groupingBy(UserNotificationPreference::getUserId)); //GK: Yep that exist on JAVA Streams .userId(ids).collect()).stream().collect(Collectors.groupingBy(UserNotificationPreference::getUserId)); //GK: Yep that exist on JAVA Streams
} }

View File

@ -7,18 +7,18 @@ BEGIN
CREATE TABLE public."ntf_UserNotificationPreference" CREATE TABLE public."ntf_UserNotificationPreference"
( (
"user" uuid NOT NULL, "user" uuid NOT NULL,
type uuid NOT NULL, "type" uuid NOT NULL,
channel smallint NOT NULL, "channel" smallint NOT NULL,
ordinal numeric NOT NULL, "ordinal" numeric NOT NULL,
created_at timestamp without time zone NOT NULL, "created_at" timestamp without time zone NOT NULL,
tenant uuid, "tenant" uuid,
CONSTRAINT "ntf_UserNotificationPreference_pkey" PRIMARY KEY ("user", type, channel), CONSTRAINT "ntf_UserNotificationPreference_pkey" PRIMARY KEY ("user", "type", "channel"),
CONSTRAINT "ntf_UserNotificationPreference_tennant_fkey" FOREIGN KEY (tenant) CONSTRAINT "ntf_UserNotificationPreference_tenant_fkey" FOREIGN KEY ("tenant")
REFERENCES public."Tenant" (id) MATCH SIMPLE REFERENCES public."ntf_Tenant" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON UPDATE NO ACTION
ON DELETE NO ACTION, ON DELETE NO ACTION,
CONSTRAINT "ntf_UserNotificationPreference_user_fkey" FOREIGN KEY ("user") 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 UPDATE NO ACTION
ON DELETE NO ACTION ON DELETE NO ACTION
); );

View File

@ -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$$;

View File

@ -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$$;

View File

@ -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$$;