add fallback notification template
This commit is contained in:
parent
8d5b3d0426
commit
88b4bb0d2f
|
@ -1,8 +1,8 @@
|
|||
package gr.cite.notification.common.types.notificationtemplate;
|
||||
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FieldOptionsEntity {
|
||||
|
||||
|
@ -10,7 +10,7 @@ public class FieldOptionsEntity {
|
|||
|
||||
private List<FieldInfoEntity> optional;
|
||||
|
||||
private Dictionary<String, String> formatting;
|
||||
private Map<String, String> formatting;
|
||||
|
||||
public List<String> getMandatory() {
|
||||
return mandatory;
|
||||
|
@ -28,11 +28,11 @@ public class FieldOptionsEntity {
|
|||
this.optional = optional;
|
||||
}
|
||||
|
||||
public Dictionary<String, String> getFormatting() {
|
||||
public Map<String, String> getFormatting() {
|
||||
return formatting;
|
||||
}
|
||||
|
||||
public void setFormatting(Dictionary<String, String> formatting) {
|
||||
public void setFormatting(Map<String, String> formatting) {
|
||||
this.formatting = formatting;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class NotificationTemplateEntity extends TenantScopedBaseEntity {
|
|||
|
||||
@Column(name = "\"language\"", columnDefinition = "uuid", nullable = false)
|
||||
private UUID languageId;
|
||||
public final static String _language = "language";
|
||||
public final static String _languageId = "languageId";
|
||||
|
||||
@Column(name = "\"value\"", nullable = false)
|
||||
private String value;
|
||||
|
|
|
@ -2,8 +2,8 @@ package gr.cite.notification.model.notificationtemplate;
|
|||
|
||||
import gr.cite.notification.common.types.notification.FieldInfo;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FieldOptions {
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class FieldOptions {
|
|||
private List<FieldInfo> optional;
|
||||
public final static String _optional = "optional";
|
||||
|
||||
private Dictionary<String, String> formatting;
|
||||
private Map<String, String> formatting;
|
||||
public final static String _formatting = "formatting";
|
||||
|
||||
public List<String> getMandatory() {
|
||||
|
@ -32,11 +32,11 @@ public class FieldOptions {
|
|||
this.optional = optional;
|
||||
}
|
||||
|
||||
public Dictionary<String, String> getFormatting() {
|
||||
public Map<String, String> getFormatting() {
|
||||
return formatting;
|
||||
}
|
||||
|
||||
public void setFormatting(Dictionary<String, String> formatting) {
|
||||
public void setFormatting(Map<String, String> formatting) {
|
||||
this.formatting = formatting;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@ package gr.cite.notification.model.persist.notificationtemplate;
|
|||
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FieldOptionsPersist {
|
||||
|
||||
|
@ -15,7 +14,7 @@ public class FieldOptionsPersist {
|
|||
private List<FieldInfoPersist> optional;
|
||||
|
||||
@Valid
|
||||
private Dictionary<String, String> formatting;
|
||||
private Map<String, String> formatting;
|
||||
|
||||
public List<String> getMandatory() {
|
||||
return mandatory;
|
||||
|
@ -33,11 +32,11 @@ public class FieldOptionsPersist {
|
|||
this.optional = optional;
|
||||
}
|
||||
|
||||
public Dictionary<String, String> getFormatting() {
|
||||
public Map<String, String> getFormatting() {
|
||||
return formatting;
|
||||
}
|
||||
|
||||
public void setFormatting(Dictionary<String, String> formatting) {
|
||||
public void setFormatting(Map<String, String> formatting) {
|
||||
this.formatting = formatting;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package gr.cite.notification.query;
|
|||
|
||||
import gr.cite.notification.authorization.AuthorizationFlags;
|
||||
import gr.cite.notification.common.enums.*;
|
||||
import gr.cite.notification.data.LanguageEntity;
|
||||
import gr.cite.notification.data.NotificationTemplateEntity;
|
||||
import gr.cite.notification.model.NotificationTemplate;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
|
@ -14,6 +15,7 @@ import org.springframework.stereotype.Component;
|
|||
import javax.persistence.Tuple;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Subquery;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -25,6 +27,10 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
|
||||
private Collection<UUID> excludedIds;
|
||||
private Collection<IsActive> isActives;
|
||||
private Collection<UUID> notificationTypes;
|
||||
private Collection<UUID> languages;
|
||||
private LanguageQuery languageQuery;
|
||||
|
||||
private List<NotificationTemplateChannel> channels;
|
||||
private List<NotificationTemplateKind> kinds;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
@ -59,6 +65,41 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery notificationTypes(UUID value) {
|
||||
this.notificationTypes = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery notificationTypes(UUID... value) {
|
||||
this.notificationTypes = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery notificationTypes(Collection<UUID> values) {
|
||||
this.notificationTypes = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery languages(UUID value) {
|
||||
this.languages = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery languages(UUID... value) {
|
||||
this.languages = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery languages(Collection<UUID> values) {
|
||||
this.languages = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery languageSubQuery(LanguageQuery subQuery) {
|
||||
this.languageQuery = subQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery channels(NotificationTemplateChannel... channels) {
|
||||
this.channels = List.of(channels);
|
||||
return this;
|
||||
|
@ -115,6 +156,8 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
return this.isNullOrEmpty(this.ids)
|
||||
&& this.isNullOrEmpty(this.isActives)
|
||||
&& this.isNullOrEmpty(this.kinds)
|
||||
&& this.isNullOrEmpty(this.notificationTypes)
|
||||
&& this.isNullOrEmpty(this.languages)
|
||||
&& this.isNullOrEmpty(this.channels);
|
||||
}
|
||||
|
||||
|
@ -140,6 +183,26 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
predicates.add(inClause);
|
||||
}
|
||||
|
||||
if (this.notificationTypes != null) {
|
||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(NotificationTemplateEntity._notificationType));
|
||||
for (UUID item : this.notificationTypes)
|
||||
inClause.value(item);
|
||||
predicates.add(inClause);
|
||||
}
|
||||
|
||||
if (this.languages != null) {
|
||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(NotificationTemplateEntity._languageId));
|
||||
for (UUID item : this.languages)
|
||||
inClause.value(item);
|
||||
predicates.add(inClause);
|
||||
}
|
||||
|
||||
if (this.languageQuery != null) {
|
||||
Subquery<LanguageEntity> subQuery = queryContext.Query.subquery(this.languageQuery.entityClass());
|
||||
this.applySubQuery(this.languageQuery, queryContext.CriteriaBuilder, subQuery);
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(NotificationTemplateEntity._languageId)).value(subQuery));
|
||||
}
|
||||
|
||||
if (this.channels != null) {
|
||||
CriteriaBuilder.In<NotificationTemplateChannel> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(NotificationTemplateEntity._channel));
|
||||
for (NotificationTemplateChannel item : this.channels)
|
||||
|
@ -176,8 +239,8 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
else if (item.match(NotificationTemplate._kind)) return NotificationTemplateEntity._kind;
|
||||
else if (item.match(NotificationTemplate._notificationType)) return NotificationTemplateEntity._notificationType;
|
||||
else if (item.prefix(NotificationTemplate._value)) return NotificationTemplateEntity._value;
|
||||
else if (item.match(NotificationTemplate._language)) return NotificationTemplateEntity._language;
|
||||
else if (item.prefix(NotificationTemplate._language)) return NotificationTemplateEntity._language;
|
||||
else if (item.match(NotificationTemplate._language)) return NotificationTemplateEntity._languageId;
|
||||
else if (item.prefix(NotificationTemplate._language)) return NotificationTemplateEntity._languageId;
|
||||
else if (item.match(NotificationTemplate._createdAt)) return NotificationTemplateEntity._createdAt;
|
||||
else if (item.match(NotificationTemplate._updatedAt)) return NotificationTemplateEntity._updatedAt;
|
||||
else if (item.match(NotificationTemplate._isActive)) return NotificationTemplateEntity._isActive;
|
||||
|
@ -193,7 +256,7 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
item.setKind(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._kind, NotificationTemplateKind.class));
|
||||
item.setNotificationType(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._notificationType, UUID.class));
|
||||
item.setValue(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._value, String.class));
|
||||
item.setLanguageId(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._language, UUID.class));
|
||||
item.setLanguageId(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._languageId, UUID.class));
|
||||
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._createdAt, Instant.class));
|
||||
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._updatedAt, Instant.class));
|
||||
item.setIsActive(QueryBase.convertSafe(tuple, columns, NotificationTemplateEntity._isActive, IsActive.class));
|
||||
|
|
|
@ -2,20 +2,29 @@ package gr.cite.notification.service.message.builder;
|
|||
|
||||
import gr.cite.notification.cache.NotificationTemplateCache;
|
||||
import gr.cite.notification.common.StringUtils;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.enums.NotificationContactType;
|
||||
import gr.cite.notification.common.enums.NotificationTemplateChannel;
|
||||
import gr.cite.notification.common.enums.NotificationTemplateKind;
|
||||
import gr.cite.notification.common.types.notification.FieldInfo;
|
||||
import gr.cite.notification.config.notification.NotificationConfig;
|
||||
import gr.cite.notification.config.notification.NotificationProperties;
|
||||
import gr.cite.notification.data.LanguageEntity;
|
||||
import gr.cite.notification.data.NotificationEntity;
|
||||
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.notification.model.NotificationTemplate;
|
||||
import gr.cite.notification.query.LanguageQuery;
|
||||
import gr.cite.notification.query.NotificationTemplateQuery;
|
||||
import gr.cite.notification.service.formatting.FormattingService;
|
||||
import gr.cite.notification.service.message.common.MessageBuilderBase;
|
||||
import gr.cite.notification.service.message.infobuilder.MessageInfoBuilderService;
|
||||
import gr.cite.notification.service.message.model.EmailMessage;
|
||||
import gr.cite.notification.service.message.model.Message;
|
||||
import gr.cite.notification.service.message.model.MessageInfo;
|
||||
import gr.cite.notification.service.notificationtemplate.NotificationTemplateService;
|
||||
import gr.cite.tools.cipher.CipherService;
|
||||
import gr.cite.tools.cipher.config.CipherProfileProperties;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -23,6 +32,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.annotation.RequestScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -34,6 +44,8 @@ public class EmailMessageBuilder extends MessageBuilderBase implements MessageBu
|
|||
private final Map<String, Map<UUID, NotificationProperties.Flow>> flowMap;
|
||||
private final MessageInfoBuilderService messageInfoBuilderService;
|
||||
private final Map<UUID, FieldCiphering> cipherFields;
|
||||
private final NotificationTemplateService notificationTemplateService;
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
@Autowired
|
||||
public EmailMessageBuilder(NotificationProperties properties,
|
||||
|
@ -46,12 +58,14 @@ public class EmailMessageBuilder extends MessageBuilderBase implements MessageBu
|
|||
CipherService cipherService,
|
||||
CipherProfileProperties cipherProfileProperties,
|
||||
FormattingService formattingService,
|
||||
NotificationTemplateCache cache) {
|
||||
NotificationTemplateCache cache, NotificationTemplateService notificationTemplateService, QueryFactory queryFactory) {
|
||||
super(logger, errors, cipherService, cipherProfileProperties, formattingService, cache);
|
||||
this.properties = properties;
|
||||
this.flowMap = flowMap;
|
||||
this.messageInfoBuilderService = messageInfoBuilderService;
|
||||
this.cipherFields = cipherFields;
|
||||
this.notificationTemplateService = notificationTemplateService;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,18 +73,35 @@ public class EmailMessageBuilder extends MessageBuilderBase implements MessageBu
|
|||
MessageInfo messageInfo = this.messageInfoBuilderService.buildMessageInfo(notification);
|
||||
NotificationProperties.Flow flow = this.flowMap.get("email").getOrDefault(notification.getType(), null);
|
||||
if (flow == null) return null;
|
||||
|
||||
NotificationTemplate template = notificationTemplateService.lookupOverriddenTemplates(notification.getType(), NotificationTemplateChannel.Email, this.queryFactory.query(LanguageQuery.class).codes(messageInfo.getLanguage()).isActive(IsActive.Active).first().getId());
|
||||
String subjectTemplate = null;
|
||||
if(!StringUtils.isNullOrEmpty(flow.getSubjectKey())) subjectTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(flow.getSubjectKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(subjectTemplate)) subjectTemplate = this.lookupOrReadLocalizedFile(this.getTemplate().getTemplateCache(), flow.getSubjectPath(), messageInfo.getLanguage());
|
||||
FieldFormatting subjectFormatting = this.buildFieldFormatting(flow.getSubjectFieldOptions());
|
||||
ReplaceResult subjectResult = this.buildTemplate(notification.getId(), subjectTemplate, messageInfo, flow.getSubjectFieldOptions(), subjectFormatting, cipherFields.get(notification.getType()));
|
||||
|
||||
ReplaceResult subjectResult = null;
|
||||
String bodyTemplate = null;
|
||||
if(!StringUtils.isNullOrEmpty(flow.getBodyKey())) bodyTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(flow.getBodyKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(bodyTemplate)) bodyTemplate = this.lookupOrReadLocalizedFile(this.getTemplate().getTemplateCache(), flow.getBodyPath(), messageInfo.getLanguage());
|
||||
FieldFormatting bodyFormatting = this.buildFieldFormatting(flow.getBodyFieldOptions());
|
||||
ReplaceResult bodyResult = this.buildTemplate(notification.getId(), bodyTemplate, messageInfo, flow.getBodyFieldOptions(), bodyFormatting, cipherFields.get(notification.getType()));
|
||||
ReplaceResult bodyResult = null;
|
||||
|
||||
if (template != null && template.getValue() != null){
|
||||
if (!StringUtils.isNullOrEmpty(template.getValue().getSubjectKey())) subjectTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(template.getValue().getSubjectKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(subjectTemplate)) subjectTemplate = template.getValue().getSubjectText();
|
||||
//TODO add formatting function with db fields
|
||||
subjectResult = this.buildTemplate(notification.getId(), subjectTemplate, messageInfo, template.getValue().getSubjectFieldOptions(), null, cipherFields.get(notification.getType()));
|
||||
|
||||
if(!StringUtils.isNullOrEmpty(template.getValue().getBodyKey())) bodyTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(template.getValue().getBodyKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(bodyTemplate)) bodyTemplate = template.getValue().getBodyText();
|
||||
FieldFormatting bodyFormatting = this.buildFieldFormatting(flow.getBodyFieldOptions());
|
||||
bodyResult = this.buildTemplate(notification.getId(), bodyTemplate, messageInfo, template.getValue().getBodyFieldOptions(), bodyFormatting, cipherFields.get(notification.getType()));
|
||||
}else {
|
||||
if(!StringUtils.isNullOrEmpty(flow.getSubjectKey())) subjectTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(flow.getSubjectKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(subjectTemplate)) subjectTemplate = this.lookupOrReadLocalizedFile(this.getTemplate().getTemplateCache(), flow.getSubjectPath(), messageInfo.getLanguage());
|
||||
FieldFormatting subjectFormatting = this.buildFieldFormatting(flow.getSubjectFieldOptions());
|
||||
subjectResult = this.buildTemplate(notification.getId(), subjectTemplate, messageInfo, flow.getSubjectFieldOptions(), subjectFormatting, cipherFields.get(notification.getType()));
|
||||
|
||||
if(!StringUtils.isNullOrEmpty(flow.getBodyKey())) bodyTemplate = messageInfo.getFields().stream().filter(fieldInfo -> fieldInfo.getKey().equals(flow.getBodyKey())).findFirst().orElse(new FieldInfo()).getValue();
|
||||
if (StringUtils.isNullOrEmpty(bodyTemplate)) bodyTemplate = this.lookupOrReadLocalizedFile(this.getTemplate().getTemplateCache(), flow.getBodyPath(), messageInfo.getLanguage());
|
||||
FieldFormatting bodyFormatting = this.buildFieldFormatting(flow.getBodyFieldOptions());
|
||||
bodyResult = this.buildTemplate(notification.getId(), bodyTemplate, messageInfo, flow.getBodyFieldOptions(), bodyFormatting, cipherFields.get(notification.getType()));
|
||||
|
||||
}
|
||||
if (bodyResult != null && subjectResult != null) {
|
||||
EmailMessage emailMessage = new EmailMessage();
|
||||
emailMessage.setBody(bodyResult.getText());
|
||||
|
|
|
@ -5,6 +5,7 @@ import gr.cite.notification.common.StringUtils;
|
|||
import gr.cite.notification.common.types.notification.FieldInfo;
|
||||
import gr.cite.notification.config.notification.NotificationProperties;
|
||||
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.notification.model.notificationtemplate.FieldOptions;
|
||||
import gr.cite.notification.service.formatting.FormattingService;
|
||||
import gr.cite.notification.service.message.model.MessageInfo;
|
||||
import gr.cite.tools.cipher.CipherService;
|
||||
|
@ -128,11 +129,13 @@ public abstract class MessageBuilderBase {
|
|||
theField.setValue(this.decipherValue(field));
|
||||
}
|
||||
|
||||
String format = fieldFormatting.isSet(theField.getKey()) ? fieldFormatting.get(theField.getKey()) : null;
|
||||
String value = this.format(messageInfo.getUserId(), theField, format);
|
||||
if (StringUtils.isNullOrEmpty(value)) continue;
|
||||
text = text.replace(theField.getKey(), value);
|
||||
result.getReplacedKeys().add(theField.getKey());
|
||||
if (fieldFormatting != null){
|
||||
String format = fieldFormatting.isSet(theField.getKey()) ? fieldFormatting.get(theField.getKey()) : null;
|
||||
String value = this.format(messageInfo.getUserId(), theField, format);
|
||||
if (StringUtils.isNullOrEmpty(value)) continue;
|
||||
text = text.replace(theField.getKey(), value);
|
||||
result.getReplacedKeys().add(theField.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
result.setText(text);
|
||||
|
@ -205,6 +208,23 @@ public abstract class MessageBuilderBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected ReplaceResult buildTemplate(UUID notificationId, String template, MessageInfo messageInfo, FieldOptions options, FieldFormatting formatting, FieldCiphering ciphering) {
|
||||
ReplaceResult result = this.applyFieldReplace(template, messageInfo, formatting, ciphering);
|
||||
if (options != null) {
|
||||
Boolean allMandatory = this.ensureMandatoryFields(result, options.getMandatory() != null ? options.getMandatory() : new ArrayList<>());
|
||||
if (!allMandatory) {
|
||||
logger.error("Could not replace all subject mandatory field for notification {}", notificationId);
|
||||
return null;
|
||||
}
|
||||
if (options.getOptional() != null) {
|
||||
for (FieldInfo field : options.getOptional()) {
|
||||
result.setText(this.applyFieldReplace(result.getText(), field, "", formatting));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Boolean ensureMandatoryFields(ReplaceResult result, List<String> mandatory) {
|
||||
for (String field : mandatory) {
|
||||
if (!result.getReplacedKeys().contains(field)) {
|
||||
|
|
|
@ -5,6 +5,9 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.authorization.Permission;
|
||||
import gr.cite.notification.common.JsonHandlingService;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.enums.NotificationTemplateChannel;
|
||||
import gr.cite.notification.common.enums.NotificationTemplateKind;
|
||||
import gr.cite.notification.common.types.notification.FieldInfo;
|
||||
import gr.cite.notification.common.types.notificationtemplate.FieldInfoEntity;
|
||||
import gr.cite.notification.common.types.notificationtemplate.FieldOptionsEntity;
|
||||
import gr.cite.notification.common.types.notificationtemplate.NotificationTemplateValueEntity;
|
||||
|
@ -12,15 +15,20 @@ import gr.cite.notification.convention.ConventionService;
|
|||
import gr.cite.notification.data.NotificationTemplateEntity;
|
||||
import gr.cite.notification.data.TenantScopedEntityManager;
|
||||
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.notification.model.Language;
|
||||
import gr.cite.notification.model.NotificationTemplate;
|
||||
import gr.cite.notification.model.builder.NotificationTemplateBuilder;
|
||||
import gr.cite.notification.model.deleter.NotificationTemplateDeleter;
|
||||
import gr.cite.notification.model.notificationtemplate.FieldOptions;
|
||||
import gr.cite.notification.model.notificationtemplate.NotificationTemplateValue;
|
||||
import gr.cite.notification.model.persist.NotificationTemplatePersist;
|
||||
import gr.cite.notification.model.persist.notificationtemplate.FieldInfoPersist;
|
||||
import gr.cite.notification.model.persist.notificationtemplate.FieldOptionsPersist;
|
||||
import gr.cite.notification.model.persist.notificationtemplate.NotificationTemplateValuePersist;
|
||||
import gr.cite.notification.query.NotificationTemplateQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.exception.MyForbiddenException;
|
||||
import gr.cite.tools.exception.MyNotFoundException;
|
||||
|
@ -53,6 +61,7 @@ public class NotificationServiceTemplateImpl implements NotificationTemplateServ
|
|||
private final AuthorizationService authorizationService;
|
||||
private final DeleterFactory deleterFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private final ConventionService conventionService;
|
||||
private final ErrorThesaurusProperties errors;
|
||||
private final MessageSource messageSource;
|
||||
|
@ -64,7 +73,7 @@ public class NotificationServiceTemplateImpl implements NotificationTemplateServ
|
|||
AuthorizationService authService, AuthorizationService authorizationService,
|
||||
DeleterFactory deleterFactory,
|
||||
BuilderFactory builderFactory,
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory, ConventionService conventionService,
|
||||
ErrorThesaurusProperties errors,
|
||||
MessageSource messageSource,
|
||||
JsonHandlingService jsonHandlingService) {
|
||||
|
@ -73,6 +82,7 @@ public class NotificationServiceTemplateImpl implements NotificationTemplateServ
|
|||
this.authorizationService = authorizationService;
|
||||
this.deleterFactory = deleterFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.conventionService = conventionService;
|
||||
this.errors = errors;
|
||||
this.messageSource = messageSource;
|
||||
|
@ -176,4 +186,57 @@ public class NotificationServiceTemplateImpl implements NotificationTemplateServ
|
|||
this.deleterFactory.deleter(NotificationTemplateDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationTemplate lookupOverriddenTemplates(UUID notificationType, NotificationTemplateChannel channel, UUID language) {
|
||||
NotificationTemplateQuery query = this.queryFactory.query(NotificationTemplateQuery.class)
|
||||
.notificationTypes(notificationType)
|
||||
.channels(channel)
|
||||
.languages(language)
|
||||
.kinds(NotificationTemplateKind.Primary)
|
||||
.isActive(IsActive.Active);
|
||||
|
||||
if (query.first() == null){
|
||||
return null;
|
||||
}
|
||||
FieldSet fieldSet = new BaseFieldSet(
|
||||
NotificationTemplate._id,
|
||||
NotificationTemplate._channel,
|
||||
NotificationTemplate._notificationType,
|
||||
NotificationTemplate._kind,
|
||||
|
||||
NotificationTemplate._language + "." + Language._id,
|
||||
NotificationTemplate._language + "." + Language._code,
|
||||
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectKey,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectText,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions + "." + FieldOptions._mandatory,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions + "." + FieldOptions._optional + "." + FieldInfo._key,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions + "." + FieldOptions._optional + "." +FieldInfo._type,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions + "." + FieldOptions._optional + "." + FieldInfo._value,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._subjectFieldOptions + "." + FieldOptions._formatting,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyKey,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyText,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions + "." + FieldOptions._mandatory,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions + "." + FieldOptions._optional + "." + FieldInfo._key,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions + "." + FieldOptions._optional + "." + FieldInfo._type,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions + "." + FieldOptions._optional + "." + FieldInfo._value,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bodyFieldOptions + "." + FieldOptions._formatting,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._priorityKey,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._allowAttachments,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._cc,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._ccMode,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bcc,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._bccMode,
|
||||
NotificationTemplate._value + "." + NotificationTemplateValue._extraDataKeys,
|
||||
|
||||
NotificationTemplate._createdAt,
|
||||
NotificationTemplate._updatedAt,
|
||||
NotificationTemplate._hash,
|
||||
NotificationTemplate._isActive
|
||||
);
|
||||
return this.builderFactory.builder(NotificationTemplateBuilder.class).build(fieldSet, query.first());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package gr.cite.notification.service.notificationtemplate;
|
||||
|
||||
import gr.cite.notification.common.enums.NotificationTemplateChannel;
|
||||
import gr.cite.notification.model.NotificationTemplate;
|
||||
import gr.cite.notification.model.persist.NotificationTemplatePersist;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
|
@ -15,4 +16,6 @@ public interface NotificationTemplateService {
|
|||
|
||||
NotificationTemplate persist(NotificationTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||
NotificationTemplate lookupOverriddenTemplates(UUID notificationType, NotificationTemplateChannel channel, UUID language);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue