diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationNotifyState.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationNotifyState.java deleted file mode 100644 index dfc25879f..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationNotifyState.java +++ /dev/null @@ -1,33 +0,0 @@ -package eu.eudat.commons.enums.notification; - -import com.fasterxml.jackson.annotation.JsonValue; -import eu.eudat.commons.enums.EnumUtils; -import eu.eudat.data.converters.enums.DatabaseEnum; - -import java.util.Map; - -public enum NotificationNotifyState implements DatabaseEnum { - PENDING((short)0), - PROCESSING((short)1), - SUCCESSFUL((short)2), - ERROR((short)3), - OMITTED((short)4); - - private final Short value; - - NotificationNotifyState(Short value) { - this.value = value; - } - - @JsonValue - public Short getValue() { - return value; - } - - private static final Map map = EnumUtils.getEnumValueMap(NotificationNotifyState.class); - - public static NotificationNotifyState of(Short i) { - return map.get(i); - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingProcess.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingProcess.java deleted file mode 100644 index 145f2f85d..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingProcess.java +++ /dev/null @@ -1,32 +0,0 @@ -package eu.eudat.commons.enums.notification; - -import com.fasterxml.jackson.annotation.JsonValue; -import eu.eudat.commons.enums.EnumUtils; -import eu.eudat.data.converters.enums.DatabaseEnum; - -import java.util.Map; - -public enum NotificationTrackingProcess implements DatabaseEnum { - PENDING((short)0), - PROCESSING((short)1), - COMPLETED((short)2), - ERROR((short)3), - OMITTED((short)4); - - private final Short value; - - NotificationTrackingProcess(Short value) { - this.value = value; - } - - @JsonValue - public Short getValue() { - return value; - } - - private static final Map map = EnumUtils.getEnumValueMap(NotificationTrackingProcess.class); - - public static NotificationTrackingProcess of(Short i) { - return map.get(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingState.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingState.java deleted file mode 100644 index 6b06c1edf..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/notification/NotificationTrackingState.java +++ /dev/null @@ -1,35 +0,0 @@ -package eu.eudat.commons.enums.notification; - -import com.fasterxml.jackson.annotation.JsonValue; -import eu.eudat.data.converters.enums.DatabaseEnum; -import eu.eudat.commons.enums.EnumUtils; - -import java.util.Map; - -public enum NotificationTrackingState implements DatabaseEnum { - UNDEFINED((short)0), - NA((short)1), - QUEUED((short)2), - SENT((short)3), - DELIVERED((short)4), - UNDELIVERED((short)5), - FAILED((short)6), - UNSENT((short)7); - - private final Short value; - - NotificationTrackingState(Short value) { - this.value = value; - } - - @JsonValue - public Short getValue() { - return value; - } - - private static final Map map = EnumUtils.getEnumValueMap(NotificationTrackingState.class); - - public static NotificationTrackingState of(Short i) { - return map.get(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationContactTypeConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationContactTypeConverter.java deleted file mode 100644 index 18eef5b44..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationContactTypeConverter.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.eudat.data.converters.enums.notification; - -import eu.eudat.commons.enums.notification.NotificationContactType; -import eu.eudat.data.converters.enums.DatabaseEnumConverter; -import jakarta.persistence.Converter; - -@Converter -public class NotificationContactTypeConverter extends DatabaseEnumConverter { - public NotificationContactType of(Short i) { - return NotificationContactType.of(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationNotifyStateConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationNotifyStateConverter.java deleted file mode 100644 index c1d8932af..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationNotifyStateConverter.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.eudat.data.converters.enums.notification; - -import eu.eudat.commons.enums.notification.NotificationNotifyState; -import eu.eudat.data.converters.enums.DatabaseEnumConverter; -import jakarta.persistence.Converter; - -@Converter -public class NotificationNotifyStateConverter extends DatabaseEnumConverter { - public NotificationNotifyState of(Short i) { - return NotificationNotifyState.of(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingProcessConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingProcessConverter.java deleted file mode 100644 index fd12ffcd7..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingProcessConverter.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.eudat.data.converters.enums.notification; - -import eu.eudat.commons.enums.notification.NotificationTrackingProcess; -import eu.eudat.data.converters.enums.DatabaseEnumConverter; -import jakarta.persistence.Converter; - -@Converter -public class NotificationTrackingProcessConverter extends DatabaseEnumConverter { - public NotificationTrackingProcess of(Short i) { - return NotificationTrackingProcess.of(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingStateConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingStateConverter.java deleted file mode 100644 index 149e565df..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/notification/NotificationTrackingStateConverter.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.eudat.data.converters.enums.notification; - - -import eu.eudat.commons.enums.notification.NotificationTrackingState; -import eu.eudat.data.converters.enums.DatabaseEnumConverter; -import jakarta.persistence.Converter; - -@Converter -public class NotificationTrackingStateConverter extends DatabaseEnumConverter { - public NotificationTrackingState of(Short i) { - return NotificationTrackingState.of(i); - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/notification/NotificationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/notification/NotificationEntity.java deleted file mode 100644 index a4815efc0..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/notification/NotificationEntity.java +++ /dev/null @@ -1,225 +0,0 @@ -package eu.eudat.data.notification; - - -import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.enums.notification.NotificationContactType; -import eu.eudat.commons.enums.notification.NotificationNotifyState; -import eu.eudat.commons.enums.notification.NotificationTrackingProcess; -import eu.eudat.commons.enums.notification.NotificationTrackingState; -import eu.eudat.data.converters.enums.IsActiveConverter; -import eu.eudat.data.converters.enums.notification.NotificationContactTypeConverter; -import eu.eudat.data.converters.enums.notification.NotificationNotifyStateConverter; -import eu.eudat.data.converters.enums.notification.NotificationTrackingProcessConverter; -import eu.eudat.data.converters.enums.notification.NotificationTrackingStateConverter; -import eu.eudat.data.tenant.TenantScopedBaseEntity; -import jakarta.persistence.*; -import jakarta.persistence.Table; - -import java.time.Instant; -import java.util.UUID; - -@Entity -@Table(name = "\"ntf_Notification\"") -public class NotificationEntity extends TenantScopedBaseEntity { - - public static class Field { - public final static String _id = "id"; - public static final String _userId = "userId"; - public static final String _type = "type"; - public static final String _contactTypeHint = "contactTypeHint"; - public static final String _contactHint = "contactHint"; - public final static String _notifiedAt = "notifiedAt"; - public final static String _isActive = "isActive"; - public final static String _createdAt = "createdAt"; - public final static String _updatedAt = "updatedAt"; - public final static String _data = "data"; - public final static String _retryCount = "retryCount"; - public final static String _notifyState = "notifyState"; - public final static String _notifiedWith = "notifiedWith"; - public final static String _trackingState = "trackingState"; - public final static String _trackingProcess = "trackingProcess"; - public final static String _trackingData = "trackingData"; - } - - @Id - @Column(name = "\"id\"", columnDefinition = "uuid", updatable = false, nullable = false) - private UUID id; - - @Column(name = "\"user\"", columnDefinition = "uuid") - private UUID userId; - - @Column(name = "\"type\"", columnDefinition = "uuid", nullable = false) - private UUID type; - - @Column(name = "\"contact_type_hint\"") - @Convert(converter = NotificationContactTypeConverter.class) - private NotificationContactType contactTypeHint; - - @Column(name = "\"contact_hint\"") - private String contactHint; - - @Column(name = "\"notify_state\"", nullable = false) - @Convert(converter = NotificationNotifyStateConverter.class) - private NotificationNotifyState notifyState; - - @Column(name = "\"notified_with\"") - @Convert(converter = NotificationContactTypeConverter.class) - private NotificationContactType notifiedWith; - @Column(name = "\"notified_at\"") - private Instant notifiedAt; - - @Column(name = "\"data\"") - private String data; - - @Column(name = "\"retry_count\"") - private Integer retryCount; - - @Column(name = "\"is_active\"", length = 20, nullable = false) - @Convert(converter = IsActiveConverter.class) - private IsActive isActive; - - @Column(name = "\"created_at\"", nullable = false) - private Instant createdAt; - - @Column(name = "\"updated_at\"", nullable = false) - private Instant updatedAt; - - @Column(name = "\"tracking_state\"", nullable = false) - @Convert(converter = NotificationTrackingStateConverter.class) - private NotificationTrackingState trackingState; - - @Column(name = "\"tracking_process\"", nullable = false) - @Convert(converter = NotificationTrackingProcessConverter.class) - private NotificationTrackingProcess trackingProcess; - - @Column(name = "\"tracking_data\"") - private String trackingData; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - 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 getContactTypeHint() { - return contactTypeHint; - } - - public void setContactTypeHint(NotificationContactType contactTypeHint) { - this.contactTypeHint = contactTypeHint; - } - - public String getContactHint() { - return contactHint; - } - - public void setContactHint(String contactHint) { - this.contactHint = contactHint; - } - - public NotificationContactType getNotifiedWith() { - return notifiedWith; - } - - public void setNotifiedWith(NotificationContactType notifiedWith) { - this.notifiedWith = notifiedWith; - } - - public NotificationNotifyState getNotifyState() { - return notifyState; - } - - public void setNotifyState(NotificationNotifyState notifyState) { - this.notifyState = notifyState; - } - - public Instant getNotifiedAt() { - return notifiedAt; - } - - public void setNotifiedAt(Instant notifiedAt) { - this.notifiedAt = notifiedAt; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public Integer getRetryCount() { - return retryCount; - } - - public void setRetryCount(Integer retryCount) { - this.retryCount = retryCount; - } - - public IsActive getIsActive() { - return isActive; - } - - public void setIsActive(IsActive isActive) { - this.isActive = isActive; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public Instant getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Instant updatedAt) { - this.updatedAt = updatedAt; - } - - public NotificationTrackingState getTrackingState() { - return trackingState; - } - - public void setTrackingState(NotificationTrackingState trackingState) { - this.trackingState = trackingState; - } - - public NotificationTrackingProcess getTrackingProcess() { - return trackingProcess; - } - - public void setTrackingProcess(NotificationTrackingProcess trackingProcess) { - this.trackingProcess = trackingProcess; - } - - public String getTrackingData() { - return trackingData; - } - - public void setTrackingData(String trackingData) { - this.trackingData = trackingData; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java index 9da92b00e..db26a534c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java @@ -1,17 +1,9 @@ package eu.eudat.integrationevent.outbox.notification; -import eu.eudat.commons.enums.ContactInfoType; -import eu.eudat.data.UserContactInfoEntity; -import eu.eudat.data.UserEntity; import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; import eu.eudat.integrationevent.outbox.OutboxService; -import eu.eudat.model.persist.notification.NotificationPersist; -import eu.eudat.query.UserContactInfoQuery; -import eu.eudat.query.UserQuery; -import eu.eudat.service.notification.NotificationService; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.validation.ValidatorFactory; import org.slf4j.LoggerFactory; @@ -20,7 +12,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; import javax.management.InvalidApplicationException; -import java.util.List; import java.util.UUID; @Component @@ -29,8 +20,6 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class)); - private final NotificationService notificationService; - private final QueryFactory queryFactory; private final AuditService auditService; @@ -42,11 +31,9 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent @Autowired public NotifyIntegrationEventHandlerImpl( OutboxService outboxService, - NotificationService notificationService, QueryFactory queryFactory, AuditService auditService, ValidatorFactory validatorFactory) { this.outboxService = outboxService; - this.notificationService = notificationService; this.validatorFactory = validatorFactory; this.queryFactory = queryFactory; this.auditService = auditService; @@ -60,29 +47,4 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent message.setEvent(event); this.outboxService.publish(message); } - - private boolean isNotificationConsistent(NotificationPersist notification) { - switch (notification.getContactTypeHint()) { - case IN_APP: { - if (notification.getUserId() == null) - return false; - - List users = this.queryFactory.query(UserQuery.class).ids(notification.getUserId()).collect(); - return !users.isEmpty(); - } - case EMAIL: { - if (notification.getContactHint() != null && !notification.getContactHint().isBlank()) - return true; - - if (notification.getUserId() == null) - return false; - - List userContactInfoEntities = this.queryFactory.query(UserContactInfoQuery.class).types(ContactInfoType.Email).userIds(notification.getUserId()).collect(); - return !userContactInfoEntities.isEmpty(); - } - default: - throw new MyApplicationException("invalid type " + notification.getContactTypeHint()); - - } - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java deleted file mode 100644 index 4876d932c..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/notification/NotificationPersist.java +++ /dev/null @@ -1,220 +0,0 @@ -package eu.eudat.model.persist.notification; - -import eu.eudat.commons.enums.notification.NotificationContactType; -import eu.eudat.commons.enums.notification.NotificationNotifyState; -import eu.eudat.commons.enums.notification.NotificationTrackingProcess; -import eu.eudat.commons.enums.notification.NotificationTrackingState; -import eu.eudat.commons.validation.BaseValidator; -import gr.cite.tools.validation.specification.Specification; -import eu.eudat.convention.ConventionService; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -public class NotificationPersist { - - private UUID id; - - private UUID userId; - - public static final String _userId = "userId"; - - private UUID type; - - private NotificationContactType contactTypeHint; - - public static final String _contactHint = "contactHint"; - private String contactHint; - - private String data; - - private NotificationNotifyState notifyState; - - private NotificationContactType notifiedWith; - - private Integer retryCount; - - private NotificationTrackingState trackingState; - - private NotificationTrackingProcess trackingProcess; - - private String trackingData; - - private String provenanceRef; - - private Instant notifiedAt; - - private String hash; - - public static final String _hash = "hash"; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - 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 getContactTypeHint() { - return contactTypeHint; - } - - public void setContactTypeHint(NotificationContactType contactTypeHint) { - this.contactTypeHint = contactTypeHint; - } - - public String getContactHint() { - return contactHint; - } - - public void setContactHint(String contactHint) { - this.contactHint = contactHint; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public NotificationNotifyState getNotifyState() { - return notifyState; - } - - public void setNotifyState(NotificationNotifyState notifyState) { - this.notifyState = notifyState; - } - - public NotificationContactType getNotifiedWith() { - return notifiedWith; - } - - public void setNotifiedWith(NotificationContactType notifiedWith) { - this.notifiedWith = notifiedWith; - } - - public Integer getRetryCount() { - return retryCount; - } - - public void setRetryCount(Integer retryCount) { - this.retryCount = retryCount; - } - - public NotificationTrackingState getTrackingState() { - return trackingState; - } - - public void setTrackingState(NotificationTrackingState trackingState) { - this.trackingState = trackingState; - } - - public NotificationTrackingProcess getTrackingProcess() { - return trackingProcess; - } - - public void setTrackingProcess(NotificationTrackingProcess trackingProcess) { - this.trackingProcess = trackingProcess; - } - - public String getTrackingData() { - return trackingData; - } - - public void setTrackingData(String trackingData) { - this.trackingData = trackingData; - } - - public String getProvenanceRef() { - return provenanceRef; - } - - public void setProvenanceRef(String provenanceRef) { - this.provenanceRef = provenanceRef; - } - - public Instant getNotifiedAt() { - return notifiedAt; - } - - public void setNotifiedAt(Instant notifiedAt) { - this.notifiedAt = notifiedAt; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Component(NotificationPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class NotificationPersistValidator extends BaseValidator { - - public static final String ValidatorName = "NotificationPersistValidator"; - - private final MessageSource messageSource; - - protected NotificationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return NotificationPersist.class; - } - - @Override - protected List specifications(NotificationPersist item) { - return Arrays.asList( - this.spec() - .iff(() -> this.isValidGuid(item.getId())) - .must(() -> this.isValidHash(item.getHash())) - .failOn(NotificationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._hash}, LocaleContextHolder.getLocale())), - this.spec() - .iff(() -> !this.isValidGuid(item.getId())) - .must(() -> !this.isValidHash(item.getHash())) - .failOn(NotificationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), - this.spec() - .iff(() -> this.isEmpty(item.getContactHint())) - .must(() -> this.isValidGuid(item.getUserId())) - .failOn(NotificationPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._userId}, LocaleContextHolder.getLocale())), - this.spec() - .iff(() -> !this.isValidGuid(item.getUserId())) - .must(() -> !this.isEmpty(item.getContactHint())) - .failOn(NotificationPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist._contactHint}, LocaleContextHolder.getLocale())) - ); - } - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationService.java b/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationService.java deleted file mode 100644 index 664ab13cf..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationService.java +++ /dev/null @@ -1,16 +0,0 @@ -package eu.eudat.service.notification; - -import eu.eudat.model.persist.notification.NotificationPersist; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.exception.MyForbiddenException; -import gr.cite.tools.exception.MyNotFoundException; -import gr.cite.tools.exception.MyValidationException; -import gr.cite.tools.fieldset.FieldSet; - -import javax.management.InvalidApplicationException; - -public interface NotificationService{ - - void persist(NotificationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException; - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java deleted file mode 100644 index 48699b10a..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/service/notification/NotificationServiceImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -package eu.eudat.service.notification; - -import eu.eudat.authorization.Permission; -import eu.eudat.commons.enums.IsActive; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.TenantEntityManager; -import eu.eudat.data.notification.NotificationEntity; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import eu.eudat.model.persist.notification.NotificationPersist; -import gr.cite.commons.web.authz.service.AuthorizationService; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.deleter.DeleterFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.exception.MyForbiddenException; -import gr.cite.tools.exception.MyNotFoundException; -import gr.cite.tools.exception.MyValidationException; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.LoggerService; -import gr.cite.tools.logging.MapLogEntry; -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.stereotype.Service; -import org.springframework.web.context.annotation.RequestScope; - -import javax.management.InvalidApplicationException; -import java.time.Instant; -import java.util.UUID; - -@Service -@RequestScope -public class NotificationServiceImpl implements NotificationService { - - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationServiceImpl.class)); - private final TenantEntityManager entityManager; - private final AuthorizationService authorizationService; - private final DeleterFactory deleterFactory; - private final BuilderFactory builderFactory; - private final ConventionService conventionService; - private final ErrorThesaurusProperties errors; - private final MessageSource messageSource; - - @Autowired - public NotificationServiceImpl( - TenantEntityManager entityManager, - AuthorizationService authorizationService, - DeleterFactory deleterFactory, - BuilderFactory builderFactory, - ConventionService conventionService, - ErrorThesaurusProperties errors, - MessageSource messageSource - ) { - this.entityManager = entityManager; - this.authorizationService = authorizationService; - this.deleterFactory = deleterFactory; - this.builderFactory = builderFactory; - this.conventionService = conventionService; - this.errors = errors; - this.messageSource = messageSource; - } - - @Override - public void persist(NotificationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException { - logger.debug(new MapLogEntry("persisting notification").And("model", model).And("fields", fields)); - - this.authorizationService.authorizeForce(Permission.PublicRole); - - Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); - - NotificationEntity data = null; - if (isUpdate) { - data = this.entityManager.find(NotificationEntity.class, model.getId()); - if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), NotificationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); - } else { - data = new NotificationEntity(); - data.setId(UUID.randomUUID()); - data.setIsActive(IsActive.Active); - data.setCreatedAt(Instant.now()); - } - - data.setNotifiedAt(model.getNotifiedAt()); - data.setContactHint(model.getContactHint()); - data.setContactTypeHint(model.getContactTypeHint()); - data.setType(model.getType()); - data.setUserId(model.getUserId()); - data.setData(model.getData()); - data.setNotifyState(model.getNotifyState()); - data.setNotifiedWith(model.getNotifiedWith()); - data.setRetryCount(model.getRetryCount()); - data.setTrackingState(model.getTrackingState()); - data.setTrackingProcess(model.getTrackingProcess()); - data.setTrackingData(model.getTrackingData()); -// data.setProvenanceRef(model.getProvenanceRef()); - data.setUpdatedAt(Instant.now()); - - if (isUpdate) this.entityManager.merge(data); - else this.entityManager.persist(data); - - this.entityManager.flush(); - - } - -}