Compare commits

..

No commits in common. "e073fc718ca74c82fcdcf00aba6afa097bcb3304" and "429d4a35eaf2eccda350dff631b0b87c74d6ef80" have entirely different histories.

15 changed files with 99 additions and 203 deletions

View File

@ -6,16 +6,15 @@ BEGIN
CREATE TABLE public."ntf_UserNotificationPreference"
(
id uuid NOT NULL,
"user" uuid NOT NULL,
"type" uuid NOT NULL,
"channel" smallint NOT NULL,
"ordinal" numeric NOT NULL,
"tenant" uuid NULL,
"tenant" uuid,
"created_at" timestamp without time zone NOT NULL,
"updated_at" timestamp without time zone NOT NULL,
"is_active" smallint NOT NULL DEFAULT 1,
CONSTRAINT "ntf_UserNotificationPreference_pkey" PRIMARY KEY (id),
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

View File

@ -1,9 +1,8 @@
import { Guid } from '@common/types/guid';
import { NotificationType } from '@notification-service/core/enum/notification-type.enum';
import { NotificationContactType } from '../enum/notification-contact-type';
import { BaseEntity, BaseEntityPersist } from '@common/base/base-entity.model';
export interface UserNotificationPreference extends BaseEntity {
export interface UserNotificationPreference {
userId?: Guid;
type: NotificationType;
channel: NotificationContactType;
@ -11,7 +10,7 @@ export interface UserNotificationPreference extends BaseEntity {
createdAt?: Date;
}
export interface UserNotificationPreferencePersist extends BaseEntityPersist {
export interface UserNotificationPreferencePersist {
userId?: Guid;
notificationPreferences: { [key: string]: NotificationContactType[] };
}

View File

@ -4,8 +4,6 @@ import { NotificationType } from '@notification-service/core/enum/notification-t
import { NotificationContactType } from '../enum/notification-contact-type';
export class UserNotificationPreferenceLookup extends Lookup implements UserNotificationPreferenceFilter {
ids: Guid[];
excludedIds: Guid[];
userIds?: Guid[];
type?: NotificationType[];
channel?: NotificationContactType[];
@ -16,8 +14,6 @@ export class UserNotificationPreferenceLookup extends Lookup implements UserNoti
}
export interface UserNotificationPreferenceFilter {
ids: Guid[];
excludedIds: Guid[];
userIds?: Guid[];
type?: NotificationType[];
channel?: NotificationContactType[];

View File

@ -10,7 +10,6 @@ import { NotificationServiceEnumUtils } from '@notification-service/core/formatt
import { InAppNotificationService } from './http/inapp-notification.service';
import { NotificationService } from './http/notification-service';
import { NotificationTemplateService } from './http/notification-template.service';
import { TenantConfigurationService } from './http/tenant-configuration.service';
//
//
@ -39,7 +38,6 @@ export class CoreNotificationServiceModule {
NotificationService,
InAppNotificationService,
NotificationTemplateService,
TenantConfigurationService,
UserNotificationPreferenceService
],
};

View File

@ -4,11 +4,8 @@ import gr.cite.notification.audit.AuditableAction;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.data.TenantEntity;
import gr.cite.notification.data.UserNotificationPreferenceEntity;
import gr.cite.notification.event.TenantConfigurationTouchedEvent;
import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.notification.model.builder.UserNotificationPreferenceBuilder;
import gr.cite.notification.model.censorship.UserNotificationPreferenceCensor;
@ -33,12 +30,9 @@ import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import jakarta.transaction.Transactional;
import javax.management.InvalidApplicationException;
import java.util.*;
@RestController
@ -52,22 +46,20 @@ public class UserNotificationPreferenceController {
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final TenantScope tenantScope;
@Autowired
public UserNotificationPreferenceController(BuilderFactory builderFactory,
AuditService auditService,
UserNotificationPreferenceService userNotificationPreferenceService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource, TenantScope tenantScope) {
AuditService auditService,
UserNotificationPreferenceService userNotificationPreferenceService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.userNotificationPreferenceService = userNotificationPreferenceService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
this.tenantScope = tenantScope;
}
@PostMapping("query")
@ -88,7 +80,7 @@ public class UserNotificationPreferenceController {
@GetMapping("user/{userId}/current")
@Transactional
public List<UserNotificationPreference> current(@PathVariable UUID userId, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
public List<UserNotificationPreference> current(@PathVariable UUID userId, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + UserNotificationPreference.class.getSimpleName()).And("userId", userId).And("fields", fieldSet));
this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(fieldSet, userId);
@ -97,13 +89,6 @@ public class UserNotificationPreferenceController {
ordering.addAscending(UserNotificationPreference._ordinal);
UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(userId).isActives(IsActive.Active);
query.setOrder(ordering);
if (this.tenantScope.isMultitenant() && this.tenantScope.isSet()) {
if (!this.tenantScope.isDefaultTenant()) {
query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} else {
query.tenantIsSet(false);
}
}
List<UserNotificationPreference> model = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.collectAs(fieldSet));
this.auditService.track(AuditableAction.User_Notification_Preference_Lookup, Map.ofEntries(

View File

@ -2,6 +2,7 @@ package gr.cite.notification.data;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.data.composite.CompositeUserNotificationPreferenceId;
import gr.cite.notification.data.conventers.IsActiveConverter;
import gr.cite.notification.data.conventers.NotificationContactTypeConverter;
import gr.cite.notification.data.tenant.TenantScopedBaseEntity;
@ -12,23 +13,22 @@ import java.util.UUID;
@Entity
@Table(name = "\"UserNotificationPreference\"")
@IdClass(CompositeUserNotificationPreferenceId.class)
public class UserNotificationPreferenceEntity extends TenantScopedBaseEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "user", columnDefinition = "uuid", nullable = false)
private UUID userId;
public static final String _userId = "userId";
@Id
@Column(name = "type", columnDefinition = "uuid", nullable = false)
private UUID type;
public static final String _type = "type";
@Id
@Column(name = "channel", nullable = false)
@Convert(converter = NotificationContactTypeConverter.class)
private NotificationContactType channel;
@ -56,14 +56,6 @@ public class UserNotificationPreferenceEntity extends TenantScopedBaseEntity {
public static final String _isActive = "isActive";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getUserId() {
return userId;
}

View File

@ -0,0 +1,45 @@
package gr.cite.notification.data.composite;
import gr.cite.notification.common.enums.NotificationContactType;
import java.io.Serializable;
import java.util.UUID;
public class CompositeUserNotificationPreferenceId implements Serializable {
private UUID userId;
private UUID type;
private NotificationContactType channel;
public CompositeUserNotificationPreferenceId() {
}
public CompositeUserNotificationPreferenceId(UUID userId, UUID type, NotificationContactType channel) {
this.userId = userId;
this.type = type;
this.channel = channel;
}
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public UUID getType() {
return type;
}
public void setType(UUID type) {
this.type = type;
}
public NotificationContactType getChannel() {
return channel;
}
public void setChannel(NotificationContactType channel) {
this.channel = channel;
}
}

View File

@ -8,10 +8,6 @@ import java.util.UUID;
public class UserNotificationPreference {
private UUID id;
public static final String _id = "id";
private UUID userId;
public static final String _userId = "userId";
@ -44,14 +40,6 @@ public class UserNotificationPreference {
public static final String _isActive = "isActive";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getUserId() {
return userId;
}

View File

@ -42,7 +42,6 @@ public class UserNotificationPreferenceBuilder extends BaseBuilder<UserNotificat
List<UserNotificationPreference> models = new ArrayList<>();
for(UserNotificationPreferenceEntity d : data){
UserNotificationPreference m = new UserNotificationPreference();
if(fields.hasField(this.asIndexer(UserNotificationPreference._id))) m.setId(d.getId());
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());

View File

@ -2,8 +2,6 @@ package gr.cite.notification.query;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.data.UserCredentialEntity;
import gr.cite.notification.data.UserNotificationPreferenceEntity;
import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.tools.data.query.FieldResolver;
@ -17,16 +15,15 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationPreferenceEntity> {
private Collection<UUID> ids;
private Collection<UUID> excludedIds;
private List<UUID> userId;
private List<IsActive> isActives;
@ -35,58 +32,6 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
private List<NotificationContactType> channel;
private Collection<UUID> tenantIds;
private Boolean tenantIsSet;
public UserNotificationPreferenceQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public UserNotificationPreferenceQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public UserNotificationPreferenceQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public UserNotificationPreferenceQuery tenantIds(UUID value) {
this.tenantIds = List.of(value);
return this;
}
public UserNotificationPreferenceQuery tenantIds(UUID... value) {
this.tenantIds = Arrays.asList(value);
return this;
}
public UserNotificationPreferenceQuery tenantIds(Collection<UUID> values) {
this.tenantIds = values;
return this;
}
public UserNotificationPreferenceQuery tenantIsSet(Boolean values) {
this.tenantIsSet = values;
return this;
}
public UserNotificationPreferenceQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public UserNotificationPreferenceQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public UserNotificationPreferenceQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public UserNotificationPreferenceQuery userId(UUID... userId) {
this.userId = List.of(userId);
return this;
@ -129,7 +74,7 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.tenantIds) ||this.isEmpty(this.excludedIds) ||this.isNullOrEmpty(this.userId) && this.isNullOrEmpty(this.type) && this.isNullOrEmpty(this.channel);
return this.isNullOrEmpty(this.userId) && this.isNullOrEmpty(this.type) && this.isNullOrEmpty(this.channel);
}
@Override
@ -140,28 +85,6 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserNotificationPreferenceEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserNotificationPreferenceEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.tenantIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserNotificationPreferenceEntity._tenantId));
for (UUID item : this.tenantIds) inClause.value(item);
predicates.add(inClause);
}
if (this.tenantIsSet != null) {
if (this.tenantIsSet) predicates.add(queryContext.CriteriaBuilder.isNotNull(queryContext.Root.get(UserNotificationPreferenceEntity._tenantId)));
else predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(UserNotificationPreferenceEntity._tenantId)));
}
if (this.userId != null) {
predicates.add(queryContext.Root.get(UserNotificationPreferenceEntity._userId).in(this.userId));
}
@ -196,8 +119,6 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
protected String fieldNameOf(FieldResolver item) {
if (item.match(UserNotificationPreference._userId))
return UserNotificationPreferenceEntity._userId;
else if (item.match(UserNotificationPreference._id))
return UserNotificationPreferenceEntity._id;
else if (item.match(UserNotificationPreference._tenantId))
return UserNotificationPreferenceEntity._tenantId;
else if (item.match(UserNotificationPreference._type))
@ -219,7 +140,6 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
@Override
protected UserNotificationPreferenceEntity convert(Tuple tuple, Set<String> columns) {
UserNotificationPreferenceEntity item = new UserNotificationPreferenceEntity();
item.setId(QueryBase.convertSafe(tuple, columns, UserNotificationPreferenceEntity._id, UUID.class));
item.setUserId(QueryBase.convertSafe(tuple, columns, UserNotificationPreferenceEntity._userId, UUID.class));
item.setChannel(QueryBase.convertSafe(tuple, columns, UserNotificationPreferenceEntity._channel, NotificationContactType.class));
item.setType(QueryBase.convertSafe(tuple, columns, UserNotificationPreferenceEntity._type, UUID.class));

View File

@ -12,8 +12,6 @@ import java.util.List;
import java.util.UUID;
public class UserNotificationPreferenceLookup extends Lookup {
private List<UUID> ids;
private List<UUID> excludedIds;
private List<UUID> userId;
private List<UUID> type;
private List<NotificationContactType> channel;
@ -47,8 +45,6 @@ public class UserNotificationPreferenceLookup extends Lookup {
if (this.userId != null) query.userId(this.userId);
if (this.channel != null) query.channel(this.channel);
if (this.type != null) query.type(this.type);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);

View File

@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.management.InvalidApplicationException;
import java.util.*;
import java.util.stream.Collectors;
@ -105,13 +104,8 @@ public class ChannelResolutionServiceImpl implements ChannelResolutionService{
private Map<UUID, List<NotificationContactType>> lookupOrCollectUserPolicies(List<UUID> users, UUID type) {
Map<UUID, List<NotificationContactType>> contactsByUser = new HashMap<>();
Map<UUID, List<UserNotificationPreference>> userNotificationPreferences = null;
try {
userNotificationPreferences = this.userNotificationPreferenceService.collectUserNotificationPreferences(users);
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
for (Map.Entry<UUID, List<UserNotificationPreference>> notificationPreference: userNotificationPreferences.entrySet())
Map<UUID, List<UserNotificationPreference>> userNotificationPreferences = this.userNotificationPreferenceService.collectUserNotificationPreferences(users);
for (Map.Entry<UUID, List<UserNotificationPreference>> notificationPreference: userNotificationPreferences.entrySet())
{
contactsByUser.put(notificationPreference.getKey(), notificationPreference.getValue().stream().filter(x -> x.getType() != null && x.getType() == type && x.getChannel() != null).sorted(Comparator.comparingInt(x -> x.getOrdinal())).map(x -> x.getChannel()).collect(Collectors.toList()));
}

View File

@ -73,18 +73,17 @@ public class NotificationServiceImpl implements NotificationService {
private final NotifierFactory notifierFactory;
private final ApplicationContext applicationContext;
private final QueryFactory queryFactory;
private final TenantScope tenantScope;
@Autowired
public NotificationServiceImpl(
TenantEntityManager entityManager,
AuthorizationService authService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource,
ChannelResolutionService channelResolutionService, MessageBuilderFactory messageBuilderFactory, ContactExtractorFactory contactExtractorFactory, NotifierFactory notifierFactory, ApplicationContext applicationContext, QueryFactory queryFactory, TenantScope tenantScope) {
TenantEntityManager entityManager,
AuthorizationService authService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource,
ChannelResolutionService channelResolutionService, MessageBuilderFactory messageBuilderFactory, ContactExtractorFactory contactExtractorFactory, NotifierFactory notifierFactory, ApplicationContext applicationContext, QueryFactory queryFactory) {
this.entityManager = entityManager;
this.authService = authService;
this.deleterFactory = deleterFactory;
@ -98,7 +97,6 @@ public class NotificationServiceImpl implements NotificationService {
this.notifierFactory = notifierFactory;
this.applicationContext = applicationContext;
this.queryFactory = queryFactory;
this.tenantScope = tenantScope;
}
@Override
@ -148,7 +146,6 @@ public class NotificationServiceImpl implements NotificationService {
public SendNotificationResult doNotify(NotificationEntity notification) {
List<NotificationContactType> contactTypes = this.orderContactTypesFromPreferences(notification);
if (this.conventionService.isListNullOrEmpty(contactTypes)) contactTypes = this.orderContactTypes(notification);
if (contactTypes == null) return null;
for (NotificationContactType contactType: contactTypes) {
SendNotificationResult result = this.sendNotification(notification, contactType);
@ -163,14 +160,8 @@ public class NotificationServiceImpl implements NotificationService {
UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(notification.getUserId()).type(notification.getType()).isActives(IsActive.Active);
query.setOrder(ordering);
List<UserNotificationPreferenceEntity> preferences = query.collectAs(new BaseFieldSet().ensure(UserNotificationPreference._channel).ensure(UserNotificationPreference._tenantId).ensure(UserNotificationPreference._id));
if (!this.conventionService.isListNullOrEmpty(preferences)) return preferences.stream().filter(x -> {
try {
return !this.tenantScope.isMultitenant() || this.tenantScope.isDefaultTenant() ? x.getTenantId() == null : x.getTenantId() == this.tenantScope.getTenant();
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}).map(UserNotificationPreferenceEntity::getChannel).collect(Collectors.toList());
List<UserNotificationPreferenceEntity> preferences = query.collectAs(new BaseFieldSet().ensure(UserNotificationPreference._channel));
if (!this.conventionService.isListNullOrEmpty(preferences)) return preferences.stream().map(x -> x.getChannel()).collect(Collectors.toList());
return null;
}

View File

@ -5,7 +5,6 @@ import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.notification.model.persist.UserNotificationPreferencePersist;
import gr.cite.tools.fieldset.FieldSet;
import javax.management.InvalidApplicationException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -15,6 +14,6 @@ public interface UserNotificationPreferenceService {
List<UserNotificationPreference> persist(UserNotificationPreferencePersist model, FieldSet fieldSet);
NotifierListTenantConfigurationEntity collectUserAvailableNotifierList(Set<UUID> notificationTypes);
List<UserNotificationPreference> collectUserNotificationPreferences(UUID id) throws InvalidApplicationException;
Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids) throws InvalidApplicationException;
List<UserNotificationPreference> collectUserNotificationPreferences(UUID id);
Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids);
}

View File

@ -117,7 +117,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
}
@Override
public List<UserNotificationPreference> collectUserNotificationPreferences(UUID id) throws InvalidApplicationException {
public List<UserNotificationPreference> collectUserNotificationPreferences(UUID id) {
Map<UUID, List<UserNotificationPreference>> result = this.collectUserNotificationPreferences(List.of(id));
if (result != null) {
return result.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
@ -127,20 +127,18 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
}
@Override
public Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids) throws InvalidApplicationException {
UserNotificationPreferenceQuery query = this.queryFactory
.query(UserNotificationPreferenceQuery.class)
.userId(ids);
if (this.tenantScope.isMultitenant() && this.tenantScope.isSet()) {
if (!this.tenantScope.isDefaultTenant()) {
query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} else {
query.tenantIsSet(false);
}
}
public Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids) {
return this.builderFactory.builder(UserNotificationPreferenceBuilder.class)
.build(new BaseFieldSet(UserNotificationPreference._userId, UserNotificationPreference._type,
UserNotificationPreference._channel, UserNotificationPreference._ordinal, UserNotificationPreference._tenantId, UserNotificationPreference._id), query.collect()).stream()
UserNotificationPreference._channel, UserNotificationPreference._ordinal), this.queryFactory
.query(UserNotificationPreferenceQuery.class)
.userId(ids).collect()).stream().filter(x -> {
try {
return !this.tenantScope.isMultitenant() || this.tenantScope.isDefaultTenant() ? x.getTenantId() == null : x.getTenantId() == this.tenantScope.getTenant();
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.groupingBy(UserNotificationPreference::getUserId)); //GK: Yep that exist on JAVA Streams
}
@ -180,24 +178,22 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
{
List<UserNotificationPreferenceEntity> preferences = null;
try {
UserNotificationPreferenceQuery query = this.queryFactory
preferences = this.queryFactory
.query(UserNotificationPreferenceQuery.class)
.type(type)
.isActives(IsActive.Active)
.userId(userId);
if (this.tenantScope.isMultitenant() && this.tenantScope.isSet()) {
if (!this.tenantScope.isDefaultTenant()) {
query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} else {
query.tenantIsSet(false);
}
}
preferences = query.collect();
.userId(userId).collect();
int ordinal = 0;
List<UserNotificationPreferenceEntity> updatedPreferences = new ArrayList<>();
for (NotificationContactType contactType : contactTypes) {
UserNotificationPreferenceEntity preference = preferences.stream().filter(x -> x.getChannel() == contactType).findFirst().orElse(null);
UserNotificationPreferenceEntity preference = preferences.stream().filter(x -> {
try {
return x.getChannel() == contactType && (!this.tenantScope.isMultitenant() ||this.tenantScope.isDefaultTenant() ? x.getTenantId() == null : x.getTenantId() == this.tenantScope.getTenant());
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}).findFirst().orElse(null);
boolean isUpdate = preference != null;
if (preference != null) {
@ -205,7 +201,6 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
} else {
preference = new UserNotificationPreferenceEntity();
preference.setId(UUID.randomUUID());
preference.setUserId(userId);
preference.setType(type);
preference.setOrdinal(ordinal);
@ -220,7 +215,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
updatedPreferences.add(preference);
ordinal++;
}
List<UserNotificationPreferenceEntity> toDelete = preferences.stream().filter(x -> !updatedPreferences.stream().map(UserNotificationPreferenceEntity::getChannel).toList().contains(x.getChannel())).toList();
List<UserNotificationPreferenceEntity> toDelete = preferences.stream().filter(x -> !updatedPreferences.stream().map(y-> y.getChannel()).collect(Collectors.toList()).contains(x.getChannel())).collect(Collectors.toList());
for (UserNotificationPreferenceEntity deletable: toDelete) {
this.entityManager.remove(deletable);
}