Merge remote-tracking branch 'origin/dmp-refactoring' into dmp-refactoring

This commit is contained in:
Alexandros Mandilaras 2024-04-25 18:01:15 +03:00
commit 9c2f8ecf4e
32 changed files with 700 additions and 29 deletions

View File

@ -10,6 +10,8 @@ public class OutboxIntegrationEvent extends IntegrationEvent {
public static final String FORGET_ME_COMPLETED = "FORGET_ME_COMPLETED";
public static final String NOTIFY = "NOTIFY";
public static final String TENANT_DEFAULT_LOCALE_REMOVAL = "TENANT_DEFAULT_LOCALE_REMOVAL";
public static final String TENANT_DEFAULT_LOCALE_TOUCHED = "TENANT_DEFAULT_LOCALE_TOUCHED";
public static final String TENANT_REACTIVATE = "TENANT_REACTIVATE";

View File

@ -2,10 +2,14 @@ package eu.eudat.integrationevent.outbox;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
@ConfigurationProperties(prefix = "queue.task.publisher.options")
public class OutboxProperties {
private final String exchange;
private final String tenantDefaultLocaleRemovalTopic;
private final String tenantDefaultLocaleTouchedTopic;
private final String tenantTouchTopic;
@ -35,6 +39,8 @@ public class OutboxProperties {
private final String generateFileTopic;
public OutboxProperties(String exchange,
String tenantDefaultLocaleRemovalTopic,
String tenantDefaultLocaleTouchedTopic,
String tenantTouchTopic,
String tenantRemovalTopic,
String tenantReactivationTopic,
@ -51,6 +57,8 @@ public class OutboxProperties {
String generateFileTopic
) {
this.exchange = exchange;
this.tenantDefaultLocaleRemovalTopic = tenantDefaultLocaleRemovalTopic;
this.tenantDefaultLocaleTouchedTopic = tenantDefaultLocaleTouchedTopic;
this.tenantTouchTopic = tenantTouchTopic;
this.tenantRemovalTopic = tenantRemovalTopic;
this.tenantReactivationTopic = tenantReactivationTopic;
@ -71,6 +79,14 @@ public class OutboxProperties {
return exchange;
}
public String getTenantDefaultLocaleRemovalTopic() {
return tenantDefaultLocaleRemovalTopic;
}
public String getTenantDefaultLocaleTouchedTopic() {
return tenantDefaultLocaleTouchedTopic;
}
public String getTenantTouchTopic() {
return tenantTouchTopic;
}

View File

@ -429,6 +429,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
routingKey = this.outboxProperties.getNotifyTopic();
break;
}
case OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_REMOVAL: {
routingKey = this.outboxProperties.getTenantDefaultLocaleRemovalTopic();
break;
}
case OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_TOUCHED: {
routingKey = this.outboxProperties.getTenantDefaultLocaleTouchedTopic();
break;
}
case OutboxIntegrationEvent.WHAT_YOU_KNOW_ABOUT_ME_COMPLETED: {
routingKey = this.outboxProperties.getWhatYouKnowAboutMeCompletedTopic();
break;

View File

@ -0,0 +1,22 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaleremoval;
import eu.eudat.integrationevent.TrackedEvent;
import java.util.UUID;
public class TenantDefaultLocaleRemovalIntegrationEvent extends TrackedEvent {
private UUID tenantId;
public TenantDefaultLocaleRemovalIntegrationEvent() {
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
}

View File

@ -0,0 +1,7 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaleremoval;
import javax.management.InvalidApplicationException;
public interface TenantDefaultLocaleRemovalIntegrationEventHandler {
void handle(TenantDefaultLocaleRemovalIntegrationEvent event) throws InvalidApplicationException;
}

View File

@ -0,0 +1,40 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaleremoval;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
import eu.eudat.integrationevent.outbox.OutboxService;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.management.InvalidApplicationException;
import java.util.UUID;
@Component
@RequestScope
public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements TenantDefaultLocaleRemovalIntegrationEventHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.class));
private final OutboxService outboxService;
private final TenantScope tenantScope;
@Autowired
public TenantDefaultLocaleRemovalIntegrationEventHandlerImpl(
OutboxService outboxService, TenantScope tenantScope) {
this.outboxService = outboxService;
this.tenantScope = tenantScope;
}
@Override
public void handle(TenantDefaultLocaleRemovalIntegrationEvent event) throws InvalidApplicationException {
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
message.setMessageId(UUID.randomUUID());
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_REMOVAL);
message.setEvent(event);
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
this.outboxService.publish(message);
}
}

View File

@ -0,0 +1,49 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaletouched;
import eu.eudat.integrationevent.TrackedEvent;
import java.util.UUID;
public class TenantDefaultLocaleTouchedIntegrationEvent extends TrackedEvent {
private UUID tenantId;
private String timezone;
private String language;
private String culture;
public TenantDefaultLocaleTouchedIntegrationEvent() {
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
}

View File

@ -0,0 +1,7 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaletouched;
import javax.management.InvalidApplicationException;
public interface TenantDefaultLocaleTouchedIntegrationEventHandler {
void handle(TenantDefaultLocaleTouchedIntegrationEvent event) throws InvalidApplicationException;
}

View File

@ -0,0 +1,40 @@
package eu.eudat.integrationevent.outbox.tenantdefaultlocaletouched;
import eu.eudat.commons.scope.tenant.TenantScope;
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
import eu.eudat.integrationevent.outbox.OutboxService;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.management.InvalidApplicationException;
import java.util.UUID;
@Component
@RequestScope
public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements TenantDefaultLocaleTouchedIntegrationEventHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.class));
private final OutboxService outboxService;
private final TenantScope tenantScope;
@Autowired
public TenantDefaultLocaleTouchedIntegrationEventHandlerImpl(
OutboxService outboxService, TenantScope tenantScope) {
this.outboxService = outboxService;
this.tenantScope = tenantScope;
}
@Override
public void handle(TenantDefaultLocaleTouchedIntegrationEvent event) throws InvalidApplicationException {
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
message.setMessageId(UUID.randomUUID());
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_TOUCHED);
message.setEvent(event);
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
this.outboxService.publish(message);
}
}

View File

@ -18,6 +18,10 @@ import eu.eudat.data.TenantEntityManager;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.event.EventBroker;
import eu.eudat.event.TenantConfigurationTouchedEvent;
import eu.eudat.integrationevent.outbox.tenantdefaultlocaleremoval.TenantDefaultLocaleRemovalIntegrationEvent;
import eu.eudat.integrationevent.outbox.tenantdefaultlocaleremoval.TenantDefaultLocaleRemovalIntegrationEventHandler;
import eu.eudat.integrationevent.outbox.tenantdefaultlocaletouched.TenantDefaultLocaleTouchedIntegrationEvent;
import eu.eudat.integrationevent.outbox.tenantdefaultlocaletouched.TenantDefaultLocaleTouchedIntegrationEventHandler;
import eu.eudat.model.StorageFile;
import eu.eudat.model.builder.tenantconfiguration.TenantConfigurationBuilder;
import eu.eudat.model.deleter.TenantConfigurationDeleter;
@ -88,6 +92,9 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
private final QueryFactory queryFactory;
private final EventBroker eventBroker;
private final TenantScope tenantScope;
private final TenantDefaultLocaleTouchedIntegrationEventHandler tenantDefaultLocaleTouchedIntegrationEventHandler;
private final TenantDefaultLocaleRemovalIntegrationEventHandler tenantDefaultLocaleRemovalIntegrationEventHandler;
@Autowired
public TenantConfigurationServiceImpl(
TenantEntityManager entityManager,
@ -96,7 +103,7 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource, JsonHandlingService jsonHandlingService, EncryptionService encryptionService, TenantProperties tenantProperties, StorageFileService storageFileService, QueryFactory queryFactory, EventBroker eventBroker, TenantScope tenantScope) {
MessageSource messageSource, JsonHandlingService jsonHandlingService, EncryptionService encryptionService, TenantProperties tenantProperties, StorageFileService storageFileService, QueryFactory queryFactory, EventBroker eventBroker, TenantScope tenantScope, TenantDefaultLocaleTouchedIntegrationEventHandler tenantDefaultLocaleTouchedIntegrationEventHandler, TenantDefaultLocaleRemovalIntegrationEventHandler tenantDefaultLocaleRemovalIntegrationEventHandler) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -111,6 +118,8 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
this.queryFactory = queryFactory;
this.eventBroker = eventBroker;
this.tenantScope = tenantScope;
this.tenantDefaultLocaleTouchedIntegrationEventHandler = tenantDefaultLocaleTouchedIntegrationEventHandler;
this.tenantDefaultLocaleRemovalIntegrationEventHandler = tenantDefaultLocaleRemovalIntegrationEventHandler;
}
public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
@ -166,6 +175,16 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType()));
}
if (data.getType().equals(TenantConfigurationType.DefaultUserLocale)){
TenantDefaultLocaleTouchedIntegrationEvent event = new TenantDefaultLocaleTouchedIntegrationEvent();
DefaultUserLocaleTenantConfigurationEntity defaultUserLocaleTenantConfiguration = this.jsonHandlingService.fromJson(DefaultUserLocaleTenantConfigurationEntity.class, data.getValue());
event.setTenantId(data.getTenantId());
event.setLanguage(defaultUserLocaleTenantConfiguration.getLanguage());
event.setCulture(defaultUserLocaleTenantConfiguration.getCulture());
event.setTimezone(defaultUserLocaleTenantConfiguration.getTimezone());
this.tenantDefaultLocaleTouchedIntegrationEventHandler.handle(event);
}
return this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, TenantConfiguration._id), data);
}
@ -277,6 +296,12 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
} else {
this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType()));
}
if (data.getType().equals(TenantConfigurationType.DefaultUserLocale)){
TenantDefaultLocaleRemovalIntegrationEvent event = new TenantDefaultLocaleRemovalIntegrationEvent();
event.setTenantId(data.getTenantId());
this.tenantDefaultLocaleRemovalIntegrationEventHandler.handle(event);
}
}
}

View File

@ -25,6 +25,8 @@ queue:
enable: true
options:
exchange: null
tenant-default-locale-removal-topic: tenant_default_locale.remove
tenant-default-locale-touched-topic: tenant_default_locale.touch
forget-me-completed-topic: forgetme.completed
notify-topic: notification.notify
tenant-reactivation-topic: tenant.reactivated

View File

@ -17,7 +17,7 @@ BEGIN
CREATE TABLE public."ntf_TenantConfiguration"
(
id uuid NOT NULL,
tenant uuid NOT NULL,
tenant uuid NULL,
type smallint NOT NULL,
value character varying COLLATE pg_catalog."default" NOT NULL,
is_active smallint NOT NULL,

View File

@ -10,7 +10,7 @@ spring:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
naming:
physical-strategy: gr.cite.notification.config.db.PrefixPhysicalNamingStrategy
physical-strategy: gr.cite.notification.data.namingstrategy.PrefixPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
datasource:
url: ${DB_CONNECTION_STRING}

View File

@ -47,3 +47,9 @@ error-thesaurus:
tenant-tampering:
code: 123
message: Tenant tampering
tenant-configuration-type-can-not-change:
code: 124
message: Tenant configuration type can not change
multiple-tenant-configuration-type-not-allowed:
code: 125
message: Multiple Tenant Configuration Type Not Allowed

View File

@ -88,17 +88,24 @@ permissions:
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
#Tenant Configuration
# TenantConfiguration
BrowseTenantConfiguration:
roles:
- TenantAdmin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
EditTenantConfiguration:
roles:
- TenantAdmin
clients: [ ]
clients: [ "opendmp-api-dev" ]
allowAnonymous: false
allowAuthenticated: false
DeleteTenantConfiguration:
roles:
- TenantAdmin
clients: [ "opendmp-api-dev" ]
allowAnonymous: false
allowAuthenticated: false
#User Notification Preference

View File

@ -38,6 +38,8 @@ queue:
enable: false
options:
exchange: null
tenant-default-locale-removal-topic: tenant_default_locale.remove
tenant-default-locale-touched-topic: tenant_default_locale.touch
notify-topic: notification.notify
tenant-removal-topic: tenant.remove
tenant-touched-topic: tenant.touch

View File

@ -36,6 +36,8 @@ public class AuditableAction {
public static final EventId Tenant_Configuration_Persist = new EventId(21002, "Tenant_Configuration_Persist");
public static final EventId Tenant_Configuration_Delete = new EventId(21003, "Tenant_Configuration_Delete");
public static final EventId TenantConfiguration_LookupByType = new EventId(210004, "TenantConfiguration_LookupByType");
public static final EventId Tenant_Configuration_DefaultUserLocale_Delete = new EventId(21005, "Tenant_Configuration_DefaultUserLocale_Delete");
public static final EventId Tenant_Configuration_DefaultUserLocale_Persist = new EventId(21006, "Tenant_Configuration_DefaultUserLocale_Persist");
public static final EventId User_Notification_Preference_Query = new EventId(22000, "User_Notification_Preference_Query");
public static final EventId User_Notification_Preference_Lookup = new EventId(22001, "User_Notification_Preference_Lookup");

View File

@ -33,6 +33,8 @@ public class AppRabbitConfigurer extends RabbitConfigurer {
public InboxBindings inboxBindingsCreator() {
List<String> bindingItems = new ArrayList<>();
bindingItems.addAll(this.inboxProperties.getNotifyTopic());
bindingItems.addAll(this.inboxProperties.getTenantDefaultLocaleRemovalTopic());
bindingItems.addAll(this.inboxProperties.getTenantDefaultLocaleTouchedTopic());
bindingItems.addAll(this.inboxProperties.getTenantRemovalTopic());
bindingItems.addAll(this.inboxProperties.getTenantTouchedTopic());
bindingItems.addAll(this.inboxProperties.getUserRemovalTopic());

View File

@ -10,6 +10,8 @@ public class InboxProperties {
private final String exchange;
private final List<String> notifyTopic;
private final List<String> tenantDefaultLocaleRemovalTopic;
private final List<String> tenantDefaultLocaleTouchedTopic;
private final List<String> tenantRemovalTopic;
@ -20,15 +22,19 @@ public class InboxProperties {
private final List<String> userTouchedTopic;
public InboxProperties(
String exchange,
List<String> notifyTopic,
List<String> tenantRemovalTopic,
List<String> tenantTouchedTopic,
List<String> userRemovalTopic,
List<String> userTouchedTopic) {
String exchange,
List<String> notifyTopic,
List<String> tenantDefaultLocaleRemovalTopic,
List<String> tenantDefaultLocaleTouchedTopic,
List<String> tenantRemovalTopic,
List<String> tenantTouchedTopic,
List<String> userRemovalTopic,
List<String> userTouchedTopic) {
this.exchange = exchange;
this.notifyTopic = notifyTopic;
this.tenantRemovalTopic = tenantRemovalTopic;
this.tenantDefaultLocaleRemovalTopic = tenantDefaultLocaleRemovalTopic;
this.tenantDefaultLocaleTouchedTopic = tenantDefaultLocaleTouchedTopic;
this.tenantRemovalTopic = tenantRemovalTopic;
this.tenantTouchedTopic = tenantTouchedTopic;
this.userRemovalTopic = userRemovalTopic;
this.userTouchedTopic = userTouchedTopic;
@ -38,6 +44,14 @@ public class InboxProperties {
return notifyTopic;
}
public List<String> getTenantDefaultLocaleRemovalTopic() {
return tenantDefaultLocaleRemovalTopic;
}
public List<String> getTenantDefaultLocaleTouchedTopic() {
return tenantDefaultLocaleTouchedTopic;
}
public List<String> getTenantRemovalTopic() {
return tenantRemovalTopic;
}

View File

@ -7,6 +7,8 @@ import gr.cite.notification.data.QueueInboxEntity;
import gr.cite.notification.data.TenantEntityManager;
import gr.cite.notification.integrationevent.TrackedEvent;
import gr.cite.notification.integrationevent.inbox.notify.NotifyIntegrationEventHandler;
import gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval.TenantDefaultLocaleRemovalIntegrationEventHandler;
import gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched.TenantDefaultLocaleTouchedIntegrationEventHandler;
import gr.cite.notification.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler;
import gr.cite.notification.integrationevent.inbox.tenanttouched.TenantTouchedIntegrationEventHandler;
import gr.cite.notification.integrationevent.inbox.userremoval.UserRemovalIntegrationEventHandler;
@ -347,6 +349,10 @@ public class InboxRepositoryImpl implements InboxRepository {
handler = this.applicationContext.getBean(UserTouchedIntegrationEventHandler.class);
else if (this.routingKeyMatched(queueInboxMessage.getRoute(), this.inboxProperties.getNotifyTopic()))
handler = this.applicationContext.getBean(NotifyIntegrationEventHandler.class);
else if (this.routingKeyMatched(queueInboxMessage.getRoute(), this.inboxProperties.getTenantDefaultLocaleRemovalTopic()))
handler = this.applicationContext.getBean(TenantDefaultLocaleRemovalIntegrationEventHandler.class);
else if (this.routingKeyMatched(queueInboxMessage.getRoute(), this.inboxProperties.getTenantDefaultLocaleTouchedTopic()))
handler = this.applicationContext.getBean(TenantDefaultLocaleTouchedIntegrationEventHandler.class);
else {
logger.error("No handler found for message routing key '{}'. Discarding.", queueInboxMessage.getRoute());
handler = null;

View File

@ -0,0 +1,27 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval;
import gr.cite.notification.integrationevent.inbox.ConsistencyHandler;
import gr.cite.notification.query.TenantQuery;
import gr.cite.tools.data.query.QueryFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDefaultLocaleRemovalConsistencyHandler implements ConsistencyHandler<TenantDefaultLocaleRemovalConsistencyPredicates> {
private final QueryFactory queryFactory;
public TenantDefaultLocaleRemovalConsistencyHandler(QueryFactory queryFactory) {
this.queryFactory = queryFactory;
}
@Override
public Boolean isConsistent(TenantDefaultLocaleRemovalConsistencyPredicates consistencyPredicates) {
if (consistencyPredicates.getTenantId() == null) return true;
long count = this.queryFactory.query(TenantQuery.class).ids(consistencyPredicates.getTenantId()).count();
return count > 0;
}
}

View File

@ -0,0 +1,23 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval;
import gr.cite.notification.integrationevent.inbox.ConsistencyPredicates;
import java.util.UUID;
public class TenantDefaultLocaleRemovalConsistencyPredicates implements ConsistencyPredicates {
private UUID tenantId;
public TenantDefaultLocaleRemovalConsistencyPredicates(UUID tenantId) {
this.tenantId = tenantId;
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
}

View File

@ -0,0 +1,18 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval;
import gr.cite.notification.integrationevent.TrackedEvent;
import java.util.UUID;
public class TenantDefaultLocaleRemovalIntegrationEvent extends TrackedEvent {
private UUID tenantId;
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
}

View File

@ -0,0 +1,8 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval;
import gr.cite.notification.integrationevent.inbox.IntegrationEventHandler;
public interface TenantDefaultLocaleRemovalIntegrationEventHandler extends IntegrationEventHandler {
}

View File

@ -0,0 +1,106 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval;
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
import gr.cite.notification.audit.AuditableAction;
import gr.cite.notification.common.JsonHandlingService;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.data.TenantEntity;
import gr.cite.notification.data.TenantEntityManager;
import gr.cite.notification.integrationevent.inbox.EventProcessingStatus;
import gr.cite.notification.integrationevent.inbox.InboxPrincipal;
import gr.cite.notification.integrationevent.inbox.IntegrationEventProperties;
import gr.cite.notification.model.Tenant;
import gr.cite.notification.query.TenantQuery;
import gr.cite.notification.service.tenantconfiguration.TenantConfigurationService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.AbstractMap;
import java.util.Map;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements TenantDefaultLocaleRemovalIntegrationEventHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.class));
private final JsonHandlingService jsonHandlingService;
private final CurrentPrincipalResolver currentPrincipalResolver;
private final ClaimExtractorProperties claimExtractorProperties;
private final TenantConfigurationService tenantConfigurationService;
private final AuditService auditService;
private final TenantEntityManager tenantEntityManager;
private final TenantScope tenantScope;
private final QueryFactory queryFactory;
private final TenantDefaultLocaleRemovalConsistencyHandler tenantConfigurationRemovalConsistencyHandler;
public TenantDefaultLocaleRemovalIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantConfigurationService tenantConfigurationService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantScope tenantScope, QueryFactory queryFactory, TenantDefaultLocaleRemovalConsistencyHandler tenantConfigurationRemovalConsistencyHandler) {
this.jsonHandlingService = jsonHandlingService;
this.currentPrincipalResolver = currentPrincipalResolver;
this.claimExtractorProperties = claimExtractorProperties;
this.tenantConfigurationService = tenantConfigurationService;
this.auditService = auditService;
this.tenantEntityManager = tenantEntityManager;
this.tenantScope = tenantScope;
this.queryFactory = queryFactory;
this.tenantConfigurationRemovalConsistencyHandler = tenantConfigurationRemovalConsistencyHandler;
}
@Override
public EventProcessingStatus handle(IntegrationEventProperties properties, String message) {
TenantDefaultLocaleRemovalIntegrationEvent event = this.jsonHandlingService.fromJsonSafe(TenantDefaultLocaleRemovalIntegrationEvent.class, message);
if (event == null)
return EventProcessingStatus.Error;
EventProcessingStatus status = EventProcessingStatus.Success;
try {
if (!(tenantConfigurationRemovalConsistencyHandler.isConsistent(new TenantDefaultLocaleRemovalConsistencyPredicates(event.getTenantId())))) {
status = EventProcessingStatus.Postponed;
return status;
}
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
if (tenant == null) {
logger.error("missing tenant from event message");
return EventProcessingStatus.Error;
}
this.tenantScope.setTempTenant(tenantEntityManager.getEntityManager(), properties.getTenantId(), tenant.getCode());
} else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message");
// return EventProcessingStatus.Error;
this.tenantScope.setTempTenant(tenantEntityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
}
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
TenantConfigurationEntity tenantConfiguration = tenantConfigurationService.getTenantConfigurationEntityForType(TenantConfigurationType.DefaultUserLocale);
if (tenantConfiguration == null){
status = EventProcessingStatus.Discard;
currentPrincipalResolver.pop();
return status;
}
tenantConfigurationService.deleteAndSave(tenantConfiguration.getId());
auditService.track(AuditableAction.Tenant_Configuration_DefaultUserLocale_Delete, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("tenantId", event.getTenantId() != null ? event.getTenantId() : "")
));
//auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} catch (Exception ex) {
status = EventProcessingStatus.Error;
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
} finally {
currentPrincipalResolver.pop();
}
return status;
}
}

View File

@ -0,0 +1,27 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched;
import gr.cite.notification.integrationevent.inbox.ConsistencyHandler;
import gr.cite.notification.query.TenantQuery;
import gr.cite.tools.data.query.QueryFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDefaultLocaleTouchedConsistencyHandler implements ConsistencyHandler<TenantDefaultLocaleTouchedConsistencyPredicates> {
private final QueryFactory queryFactory;
public TenantDefaultLocaleTouchedConsistencyHandler(QueryFactory queryFactory) {
this.queryFactory = queryFactory;
}
@Override
public Boolean isConsistent(TenantDefaultLocaleTouchedConsistencyPredicates consistencyPredicates) {
if (consistencyPredicates.getTenantId() == null) return true;
long count = this.queryFactory.query(TenantQuery.class).ids(consistencyPredicates.getTenantId()).count();
return count > 0;
}
}

View File

@ -0,0 +1,23 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched;
import gr.cite.notification.integrationevent.inbox.ConsistencyPredicates;
import java.util.UUID;
public class TenantDefaultLocaleTouchedConsistencyPredicates implements ConsistencyPredicates {
private UUID tenantId;
public TenantDefaultLocaleTouchedConsistencyPredicates(UUID tenantId) {
this.tenantId = tenantId;
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
}

View File

@ -0,0 +1,46 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched;
import gr.cite.notification.integrationevent.TrackedEvent;
import java.util.UUID;
public class TenantDefaultLocaleTouchedIntegrationEvent extends TrackedEvent {
private UUID tenantId;
private String timezone;
private String language;
private String culture;
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
}

View File

@ -0,0 +1,8 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched;
import gr.cite.notification.integrationevent.inbox.IntegrationEventHandler;
public interface TenantDefaultLocaleTouchedIntegrationEventHandler extends IntegrationEventHandler {
}

View File

@ -0,0 +1,129 @@
package gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched;
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
import gr.cite.notification.audit.AuditableAction;
import gr.cite.notification.common.JsonHandlingService;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.data.TenantEntity;
import gr.cite.notification.data.TenantEntityManager;
import gr.cite.notification.integrationevent.inbox.EventProcessingStatus;
import gr.cite.notification.integrationevent.inbox.InboxPrincipal;
import gr.cite.notification.integrationevent.inbox.IntegrationEventProperties;
import gr.cite.notification.model.Tenant;
import gr.cite.notification.model.persist.tenantconfiguration.DefaultUserLocaleTenantConfigurationPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist;
import gr.cite.notification.query.TenantQuery;
import gr.cite.notification.service.tenantconfiguration.TenantConfigurationService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.AbstractMap;
import java.util.Map;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements TenantDefaultLocaleTouchedIntegrationEventHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.class));
private final JsonHandlingService jsonHandlingService;
private final CurrentPrincipalResolver currentPrincipalResolver;
private final ClaimExtractorProperties claimExtractorProperties;
private final TenantConfigurationService tenantConfigurationService;
private final AuditService auditService;
private final TenantEntityManager tenantEntityManager;
private final TenantScope tenantScope;
private final QueryFactory queryFactory;
private final ConventionService conventionService;
private final ValidatorFactory validatorFactory;
private final TenantDefaultLocaleTouchedConsistencyHandler tenantDefaultLocaleTouchedConsistencyHandler;
public TenantDefaultLocaleTouchedIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantConfigurationService tenantConfigurationService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantScope tenantScope, QueryFactory queryFactory, ConventionService conventionService, ValidatorFactory validatorFactory, TenantDefaultLocaleTouchedConsistencyHandler tenantDefaultLocaleTouchedConsistencyHandler) {
this.jsonHandlingService = jsonHandlingService;
this.currentPrincipalResolver = currentPrincipalResolver;
this.claimExtractorProperties = claimExtractorProperties;
this.tenantConfigurationService = tenantConfigurationService;
this.auditService = auditService;
this.tenantEntityManager = tenantEntityManager;
this.tenantScope = tenantScope;
this.queryFactory = queryFactory;
this.conventionService = conventionService;
this.validatorFactory = validatorFactory;
this.tenantDefaultLocaleTouchedConsistencyHandler = tenantDefaultLocaleTouchedConsistencyHandler;
}
@Override
public EventProcessingStatus handle(IntegrationEventProperties properties, String message) {
TenantDefaultLocaleTouchedIntegrationEvent event = this.jsonHandlingService.fromJsonSafe(TenantDefaultLocaleTouchedIntegrationEvent.class, message);
if (event == null)
return EventProcessingStatus.Error;
EventProcessingStatus status = EventProcessingStatus.Success;
try {
if (!(tenantDefaultLocaleTouchedConsistencyHandler.isConsistent(new TenantDefaultLocaleTouchedConsistencyPredicates(event.getTenantId())))) {
status = EventProcessingStatus.Postponed;
return status;
}
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(properties.getTenantId()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
if (tenant == null) {
logger.error("missing tenant from event message");
return EventProcessingStatus.Error;
}
this.tenantScope.setTempTenant(tenantEntityManager.getEntityManager(), properties.getTenantId(), tenant.getCode());
} else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message");
// return EventProcessingStatus.Error;
this.tenantScope.setTempTenant(tenantEntityManager.getEntityManager(), null, this.tenantScope.getDefaultTenantCode());
}
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
TenantConfigurationPersist persist = new TenantConfigurationPersist();
persist.setType(TenantConfigurationType.DefaultUserLocale);
persist.setDefaultUserLocale(new DefaultUserLocaleTenantConfigurationPersist());
persist.getDefaultUserLocale().setCulture(event.getCulture());
persist.getDefaultUserLocale().setLanguage(event.getLanguage());
persist.getDefaultUserLocale().setTimezone(event.getTimezone());
TenantConfigurationEntity tenantConfiguration = tenantConfigurationService.getTenantConfigurationEntityForType(TenantConfigurationType.DefaultUserLocale);
if (tenantConfiguration != null){
persist.setId(tenantConfiguration.getId());
persist.setHash(this.conventionService.hashValue(tenantConfiguration.getUpdatedAt()));
}
Validator validator = this.validatorFactory.validator(TenantConfigurationPersist.TenantConfigurationPersistValidator.class);
validator.validate(persist);
if (!validator.result().isValid()) {
status = EventProcessingStatus.Error;
currentPrincipalResolver.pop();
return status;
}
tenantConfigurationService.persist(persist, new BaseFieldSet());
auditService.track(AuditableAction.Tenant_Configuration_DefaultUserLocale_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("tenantId", event.getTenantId() != null ? event.getTenantId() : "")
));
//auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} catch (Exception ex) {
status = EventProcessingStatus.Error;
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
} finally {
currentPrincipalResolver.pop();
}
return status;
}
}

View File

@ -1,8 +1,10 @@
package gr.cite.notification.service.tenantconfiguration;
import com.fasterxml.jackson.core.JsonProcessingException;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist;
import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.tools.exception.MyApplicationException;
@ -28,4 +30,6 @@ public interface TenantConfigurationService {
NotifierListTenantConfigurationEntity collectTenantNotifierList();
DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale();
TenantConfigurationEntity getTenantConfigurationEntityForType(TenantConfigurationType type);
}

View File

@ -187,24 +187,21 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
@Override
public NotifierListTenantConfigurationEntity collectTenantNotifierList() {
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.NotifierList);
if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false);
else {
try {
query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}
TenantConfigurationEntity data = query.first();
TenantConfigurationEntity data = this.getTenantConfigurationEntityForType(TenantConfigurationType.NotifierList);
if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null;
return this.jsonHandlingService.fromJsonSafe(NotifierListTenantConfigurationEntity.class, data.getValue());
}
@Override
public DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale() {
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.DefaultUserLocale);
TenantConfigurationEntity data = this.getTenantConfigurationEntityForType(TenantConfigurationType.DefaultUserLocale);
if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null;
return this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, data.getValue());
}
@Override
public TenantConfigurationEntity getTenantConfigurationEntityForType(TenantConfigurationType type){
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(type);
if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false);
else {
try {
@ -214,9 +211,7 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic
}
}
TenantConfigurationEntity data = query.first();
if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null;
return this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, data.getValue());
return query.first();
}
}