tenant fixes
This commit is contained in:
parent
fa6d100b41
commit
f156d79ace
|
@ -9,9 +9,9 @@ import gr.cite.annotation.integrationevent.TrackedEvent;
|
||||||
import gr.cite.annotation.integrationevent.inbox.annotationentitiesremoval.AnnotationEntitiesRemovalIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.annotationentitiesremoval.AnnotationEntitiesRemovalIntegrationEventHandler;
|
||||||
import gr.cite.annotation.integrationevent.inbox.annotationentitiestouch.AnnotationEntitiesTouchedIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.annotationentitiestouch.AnnotationEntitiesTouchedIntegrationEventHandler;
|
||||||
import gr.cite.annotation.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler;
|
||||||
import gr.cite.annotation.integrationevent.inbox.tenanttouch.TenantTouchedIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.tenanttouched.TenantTouchedIntegrationEventHandler;
|
||||||
import gr.cite.annotation.integrationevent.inbox.userremoval.UserRemovalIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.userremoval.UserRemovalIntegrationEventHandler;
|
||||||
import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEventHandler;
|
||||||
import gr.cite.annotation.query.QueueInboxQuery;
|
import gr.cite.annotation.query.QueueInboxQuery;
|
||||||
import gr.cite.queueinbox.entity.QueueInbox;
|
import gr.cite.queueinbox.entity.QueueInbox;
|
||||||
import gr.cite.queueinbox.entity.QueueInboxStatus;
|
import gr.cite.queueinbox.entity.QueueInboxStatus;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.tenantremoval;
|
package gr.cite.annotation.integrationevent.inbox.tenantremoval;
|
||||||
|
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
||||||
|
|
||||||
public interface TenantRemovalIntegrationEventHandler extends IntegrationEventHandler {
|
public interface TenantRemovalIntegrationEventHandler extends IntegrationEventHandler {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.tenantremoval;
|
package gr.cite.annotation.integrationevent.inbox.tenantremoval;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||||
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
||||||
import gr.cite.annotation.audit.AuditableAction;
|
import gr.cite.annotation.audit.AuditableAction;
|
||||||
import gr.cite.annotation.common.JsonHandlingService;
|
import gr.cite.annotation.common.JsonHandlingService;
|
||||||
import gr.cite.annotation.data.TenantEntityManager;
|
import gr.cite.annotation.data.TenantEntityManager;
|
||||||
|
@ -7,8 +9,6 @@ import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus;
|
||||||
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
||||||
import gr.cite.annotation.service.tenant.TenantService;
|
import gr.cite.annotation.service.tenant.TenantService;
|
||||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
|
||||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -34,12 +34,12 @@ public class TenantRemovalIntegrationEventHandlerImpl implements TenantRemovalIn
|
||||||
private final TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler;
|
private final TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler;
|
||||||
public TenantRemovalIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantService tenantService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler) {
|
public TenantRemovalIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantService tenantService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler) {
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.currentPrincipalResolver = currentPrincipalResolver;
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
||||||
this.claimExtractorProperties = claimExtractorProperties;
|
this.claimExtractorProperties = claimExtractorProperties;
|
||||||
this.tenantService = tenantService;
|
this.tenantService = tenantService;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.tenantEntityManager = tenantEntityManager;
|
this.tenantEntityManager = tenantEntityManager;
|
||||||
this.tenantRemovalConsistencyHandler = tenantRemovalConsistencyHandler;
|
this.tenantRemovalConsistencyHandler = tenantRemovalConsistencyHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.tenanttouch;
|
package gr.cite.annotation.integrationevent.inbox.tenanttouched;
|
||||||
|
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.TrackedEvent;
|
import gr.cite.annotation.integrationevent.TrackedEvent;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.tenanttouch;
|
package gr.cite.annotation.integrationevent.inbox.tenanttouched;
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.tenanttouch;
|
package gr.cite.annotation.integrationevent.inbox.tenanttouched;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||||
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
||||||
import gr.cite.annotation.audit.AuditableAction;
|
import gr.cite.annotation.audit.AuditableAction;
|
||||||
import gr.cite.annotation.common.JsonHandlingService;
|
import gr.cite.annotation.common.JsonHandlingService;
|
||||||
import gr.cite.annotation.data.TenantEntityManager;
|
import gr.cite.annotation.data.TenantEntityManager;
|
||||||
|
@ -8,8 +10,6 @@ import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
||||||
import gr.cite.annotation.model.persist.TenantTouchedIntegrationEventPersist;
|
import gr.cite.annotation.model.persist.TenantTouchedIntegrationEventPersist;
|
||||||
import gr.cite.annotation.service.tenant.TenantService;
|
import gr.cite.annotation.service.tenant.TenantService;
|
||||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
|
||||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
|
@ -1,5 +1,6 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
||||||
|
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.inbox.ConsistencyPredicates;
|
import gr.cite.annotation.integrationevent.inbox.ConsistencyPredicates;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
||||||
|
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
||||||
|
|
||||||
public interface UserRemovalIntegrationEventHandler extends IntegrationEventHandler {
|
public interface UserRemovalIntegrationEventHandler extends IntegrationEventHandler {
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
package gr.cite.annotation.integrationevent.inbox.userremoval;
|
||||||
|
|
||||||
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||||
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
||||||
import gr.cite.annotation.audit.AuditableAction;
|
import gr.cite.annotation.audit.AuditableAction;
|
||||||
import gr.cite.annotation.common.JsonHandlingService;
|
import gr.cite.annotation.common.JsonHandlingService;
|
||||||
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
||||||
import gr.cite.annotation.data.TenantEntity;
|
|
||||||
import gr.cite.annotation.data.TenantEntityManager;
|
import gr.cite.annotation.data.TenantEntityManager;
|
||||||
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus;
|
import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus;
|
||||||
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
||||||
import gr.cite.annotation.model.Tenant;
|
|
||||||
import gr.cite.annotation.query.TenantQuery;
|
|
||||||
import gr.cite.annotation.service.user.UserService;
|
import gr.cite.annotation.service.user.UserService;
|
||||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
|
||||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
@ -26,7 +21,6 @@ import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -42,7 +36,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
private final ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private final QueryFactory queryFactory;
|
|
||||||
private final TenantScope tenantScope;
|
private final TenantScope tenantScope;
|
||||||
private final CurrentPrincipalResolver currentPrincipalResolver;
|
private final CurrentPrincipalResolver currentPrincipalResolver;
|
||||||
private final ClaimExtractorProperties claimExtractorProperties;
|
private final ClaimExtractorProperties claimExtractorProperties;
|
||||||
|
@ -52,21 +45,20 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
private final TenantEntityManager tenantEntityManager;
|
private final TenantEntityManager tenantEntityManager;
|
||||||
|
|
||||||
public UserRemovalIntegrationEventHandlerImpl(
|
public UserRemovalIntegrationEventHandlerImpl(
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
ErrorThesaurusProperties errors,
|
ErrorThesaurusProperties errors,
|
||||||
MessageSource messageSource, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager
|
MessageSource messageSource, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager
|
||||||
) {
|
) {
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.queryFactory = queryFactory;
|
this.tenantScope = tenantScope;
|
||||||
this.tenantScope = tenantScope;
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
||||||
this.currentPrincipalResolver = currentPrincipalResolver;
|
this.claimExtractorProperties = claimExtractorProperties;
|
||||||
this.claimExtractorProperties = claimExtractorProperties;
|
this.userRemovalConsistencyHandler = userRemovalConsistencyHandler;
|
||||||
this.userRemovalConsistencyHandler = userRemovalConsistencyHandler;
|
this.userService = userService;
|
||||||
this.userService = userService;
|
this.auditService = auditService;
|
||||||
this.auditService = auditService;
|
this.tenantEntityManager = tenantEntityManager;
|
||||||
this.tenantEntityManager = tenantEntityManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,29 +73,21 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
|
|
||||||
EventProcessingStatus status = EventProcessingStatus.Success;
|
EventProcessingStatus status = EventProcessingStatus.Success;
|
||||||
try {
|
try {
|
||||||
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
|
|
||||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().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, properties.getTenantId(), tenant.getCode());
|
|
||||||
} else if (this.tenantScope.isMultitenant()) {
|
|
||||||
// logger.error("missing tenant from event message");
|
|
||||||
// return EventProcessingStatus.Error;
|
|
||||||
this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
||||||
|
|
||||||
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
try{
|
||||||
status = EventProcessingStatus.Postponed;
|
this.tenantEntityManager.disableTenantFilters();
|
||||||
currentPrincipalResolver.pop();
|
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
status = EventProcessingStatus.Postponed;
|
||||||
return status;
|
currentPrincipalResolver.pop();
|
||||||
}
|
tenantScope.removeTempTenant(this.tenantEntityManager);
|
||||||
|
return status;
|
||||||
userService.deleteAndSave(event.getUserId());
|
}
|
||||||
|
|
||||||
|
userService.deleteAndSave(event.getUserId());
|
||||||
|
} finally {
|
||||||
|
this.tenantEntityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
|
|
||||||
auditService.track(AuditableAction.User_Delete, Map.ofEntries(
|
auditService.track(AuditableAction.User_Delete, Map.ofEntries(
|
||||||
new AbstractMap.SimpleEntry<String, Object>("id", event.getUserId())
|
new AbstractMap.SimpleEntry<String, Object>("id", event.getUserId())
|
||||||
|
@ -114,11 +98,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
try {
|
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
} catch (InvalidApplicationException e) {
|
|
||||||
logger.error( e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.usertouch;
|
package gr.cite.annotation.integrationevent.inbox.usertouched;
|
||||||
|
|
||||||
import gr.cite.annotation.common.enums.ContactInfoType;
|
import gr.cite.annotation.common.enums.ContactInfoType;
|
||||||
import gr.cite.annotation.common.validation.BaseValidator;
|
import gr.cite.annotation.common.validation.BaseValidator;
|
||||||
import gr.cite.annotation.convention.ConventionService;
|
import gr.cite.annotation.convention.ConventionService;
|
||||||
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.annotation.integrationevent.TrackedEvent;
|
import gr.cite.annotation.integrationevent.TrackedEvent;
|
||||||
import gr.cite.annotation.model.persist.UserTouchedIntegrationEventPersist;
|
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import gr.cite.tools.validation.specification.Specification;
|
import gr.cite.tools.validation.specification.Specification;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
@ -162,7 +161,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
|
||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(UserTouchedIntegrationEvent.UserContactInfo.UserTouchedIntegrationUserContactInfoEventValidator.ValidatorName)
|
@Component(UserTouchedIntegrationUserContactInfoEventValidator.ValidatorName)
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public static class UserTouchedIntegrationUserContactInfoEventValidator extends BaseValidator<UserContactInfo> {
|
public static class UserTouchedIntegrationUserContactInfoEventValidator extends BaseValidator<UserContactInfo> {
|
||||||
|
|
||||||
|
@ -211,7 +210,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
|
||||||
this.subjectId = subjectId;
|
this.subjectId = subjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(UserCredential.UserTouchedIntegrationUserCredentialEventValidator.ValidatorName)
|
@Component(UserTouchedIntegrationUserCredentialEventValidator.ValidatorName)
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public static class UserTouchedIntegrationUserCredentialEventValidator extends BaseValidator<UserCredential> {
|
public static class UserTouchedIntegrationUserCredentialEventValidator extends BaseValidator<UserCredential> {
|
||||||
|
|
||||||
|
@ -253,7 +252,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
|
||||||
this.tenant = tenant;
|
this.tenant = tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(TenantUser.UserTouchedIntegrationTenantUserEventValidator.ValidatorName)
|
@Component(UserTouchedIntegrationTenantUserEventValidator.ValidatorName)
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public static class UserTouchedIntegrationTenantUserEventValidator extends BaseValidator<TenantUser> {
|
public static class UserTouchedIntegrationTenantUserEventValidator extends BaseValidator<TenantUser> {
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(UserTouchedIntegrationEvent.UserTouchedIntegrationEventValidator.ValidatorName)
|
@Component(UserTouchedIntegrationEventValidator.ValidatorName)
|
||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public static class UserTouchedIntegrationEventValidator extends BaseValidator<UserTouchedIntegrationEvent> {
|
public static class UserTouchedIntegrationEventValidator extends BaseValidator<UserTouchedIntegrationEvent> {
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
|
||||||
.failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())),
|
.failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(() -> !this.isEmpty(item.getName()))
|
.iff(() -> !this.isEmpty(item.getName()))
|
||||||
.must(() -> this.lessEqualLength(item.getName(), UserTouchedIntegrationEventPersist._nameLength))
|
.must(() -> this.lessEqualLength(item.getName(), UserTouchedIntegrationEvent._nameLength))
|
||||||
.failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())),
|
.failOn(UserTouchedIntegrationEvent._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserTouchedIntegrationEvent._name}, LocaleContextHolder.getLocale())),
|
||||||
this.navSpec()
|
this.navSpec()
|
||||||
.iff(() -> !this.isListNullOrEmpty(item.getUserContactInfo()))
|
.iff(() -> !this.isListNullOrEmpty(item.getUserContactInfo()))
|
|
@ -1,4 +1,5 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.usertouch;
|
package gr.cite.annotation.integrationevent.inbox.usertouched;
|
||||||
|
|
||||||
|
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler;
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
package gr.cite.annotation.integrationevent.inbox.usertouch;
|
package gr.cite.annotation.integrationevent.inbox.usertouched;
|
||||||
|
|
||||||
import gr.cite.annotation.data.TenantEntityManager;
|
|
||||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||||
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
||||||
import gr.cite.annotation.audit.AuditableAction;
|
import gr.cite.annotation.audit.AuditableAction;
|
||||||
import gr.cite.annotation.common.JsonHandlingService;
|
import gr.cite.annotation.common.JsonHandlingService;
|
||||||
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
||||||
import gr.cite.annotation.data.TenantEntity;
|
import gr.cite.annotation.data.TenantEntityManager;
|
||||||
import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus;
|
import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus;
|
||||||
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
import gr.cite.annotation.integrationevent.inbox.InboxPrincipal;
|
||||||
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties;
|
||||||
import gr.cite.annotation.model.Tenant;
|
|
||||||
import gr.cite.annotation.query.TenantQuery;
|
|
||||||
import gr.cite.annotation.service.user.UserService;
|
import gr.cite.annotation.service.user.UserService;
|
||||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -23,7 +19,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -46,17 +41,17 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
private final TenantEntityManager tenantEntityManager;
|
private final TenantEntityManager tenantEntityManager;
|
||||||
|
|
||||||
public UserTouchedIntegrationEventHandlerImpl(
|
public UserTouchedIntegrationEventHandlerImpl(
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
ValidatorFactory validatorFactory, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager) {
|
ValidatorFactory validatorFactory, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager) {
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.validatorFactory = validatorFactory;
|
this.validatorFactory = validatorFactory;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.tenantScope = tenantScope;
|
this.tenantScope = tenantScope;
|
||||||
this.currentPrincipalResolver = currentPrincipalResolver;
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
||||||
this.claimExtractorProperties = claimExtractorProperties;
|
this.claimExtractorProperties = claimExtractorProperties;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.tenantEntityManager = tenantEntityManager;
|
this.tenantEntityManager = tenantEntityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,23 +66,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
|
|
||||||
EventProcessingStatus status = EventProcessingStatus.Success;
|
EventProcessingStatus status = EventProcessingStatus.Success;
|
||||||
try {
|
try {
|
||||||
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
|
|
||||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().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, properties.getTenantId(), tenant.getCode());
|
|
||||||
} else if (this.tenantScope.isMultitenant()) {
|
|
||||||
// logger.error("missing tenant from event message");
|
|
||||||
// return EventProcessingStatus.Error;
|
|
||||||
this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
||||||
|
try {
|
||||||
userService.persist(event, null);
|
this.tenantEntityManager.disableTenantFilters();
|
||||||
|
userService.persist(event, null);
|
||||||
|
} finally {
|
||||||
|
this.tenantEntityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
auditService.track(AuditableAction.User_Persist, Map.ofEntries(
|
auditService.track(AuditableAction.User_Persist, Map.ofEntries(
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", event)
|
new AbstractMap.SimpleEntry<String, Object>("model", event)
|
||||||
));
|
));
|
||||||
|
@ -97,13 +83,8 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
try {
|
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
} catch (InvalidApplicationException e) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ package gr.cite.annotation.model.persist;
|
||||||
import gr.cite.annotation.common.validation.BaseValidator;
|
import gr.cite.annotation.common.validation.BaseValidator;
|
||||||
import gr.cite.annotation.convention.ConventionService;
|
import gr.cite.annotation.convention.ConventionService;
|
||||||
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
import gr.cite.annotation.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent;
|
import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent;
|
||||||
import gr.cite.tools.validation.specification.Specification;
|
import gr.cite.tools.validation.specification.Specification;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package gr.cite.annotation.service.user;
|
package gr.cite.annotation.service.user;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent;
|
import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent;
|
||||||
import gr.cite.annotation.model.User;
|
import gr.cite.annotation.model.User;
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.exception.MyForbiddenException;
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import gr.cite.annotation.common.enums.IsActive;
|
||||||
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
import gr.cite.annotation.common.scope.tenant.TenantScope;
|
||||||
import gr.cite.annotation.convention.ConventionService;
|
import gr.cite.annotation.convention.ConventionService;
|
||||||
import gr.cite.annotation.data.*;
|
import gr.cite.annotation.data.*;
|
||||||
import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent;
|
import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent;
|
||||||
import gr.cite.annotation.model.Tenant;
|
import gr.cite.annotation.model.Tenant;
|
||||||
import gr.cite.annotation.model.User;
|
import gr.cite.annotation.model.User;
|
||||||
import gr.cite.annotation.model.builder.UserBuilder;
|
import gr.cite.annotation.model.builder.UserBuilder;
|
||||||
|
|
|
@ -5,16 +5,18 @@ import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||||
import org.opencdmp.data.DescriptionEntity;
|
import org.opencdmp.data.DescriptionEntity;
|
||||||
|
import org.opencdmp.data.DmpEntity;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxService;
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
||||||
import org.opencdmp.model.description.Description;
|
import org.opencdmp.model.description.Description;
|
||||||
|
import org.opencdmp.model.dmp.Dmp;
|
||||||
import org.opencdmp.query.DescriptionQuery;
|
import org.opencdmp.query.DescriptionQuery;
|
||||||
|
import org.opencdmp.query.DmpQuery;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -28,41 +30,44 @@ public class AnnotationEntityRemovalIntegrationEventHandlerImpl implements Annot
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
|
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private final TenantScope tenantScope;
|
|
||||||
|
|
||||||
public AnnotationEntityRemovalIntegrationEventHandlerImpl(OutboxService outboxService, QueryFactory queryFactory, TenantScope tenantScope) {
|
public AnnotationEntityRemovalIntegrationEventHandlerImpl(OutboxService outboxService, QueryFactory queryFactory, TenantScope tenantScope) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.tenantScope = tenantScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handle(AnnotationEntitiesRemovalIntegrationEvent event) throws InvalidApplicationException {
|
private void handle(AnnotationEntitiesRemovalIntegrationEvent event, UUID tenantId) {
|
||||||
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.ANNOTATION_ENTITY_REMOVE);
|
message.setType(OutboxIntegrationEvent.ANNOTATION_ENTITY_REMOVE);
|
||||||
message.setEvent(event);
|
message.setEvent(event);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant());
|
|
||||||
this.outboxService.publish(message);
|
this.outboxService.publish(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDescription(UUID descriptionId) throws InvalidApplicationException {
|
public void handleDescription(UUID descriptionId) {
|
||||||
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
DescriptionEntity description = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).firstAs(new BaseFieldSet().ensure(Description._id).ensure(DescriptionEntity._tenantId));
|
||||||
|
if (description == null) return;
|
||||||
|
|
||||||
|
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
||||||
event.setEntityIds(List.of(descriptionId));
|
event.setEntityIds(List.of(descriptionId));
|
||||||
|
|
||||||
this.handle(event);
|
this.handle(event, description.getTenantId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDmp(UUID dmpId) throws InvalidApplicationException {
|
public void handleDmp(UUID dmpId) {
|
||||||
|
DmpEntity dmp = this.queryFactory.query(DmpQuery.class).disableTracking().ids(dmpId).firstAs(new BaseFieldSet().ensure(Dmp._id).ensure(DmpEntity._tenantId));
|
||||||
|
if(dmp == null) return;
|
||||||
|
|
||||||
List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().dmpIds(dmpId).collectAs(new BaseFieldSet().ensure(Description._id));
|
List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().dmpIds(dmpId).collectAs(new BaseFieldSet().ensure(Description._id));
|
||||||
|
|
||||||
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
||||||
event.setEntityIds(new ArrayList<>());
|
event.setEntityIds(new ArrayList<>());
|
||||||
event.getEntityIds().add(dmpId);
|
event.getEntityIds().add(dmpId);
|
||||||
|
|
||||||
for (DescriptionEntity description : descriptionEntities) event.getEntityIds().add(description.getId());
|
for (DescriptionEntity description : descriptionEntities) event.getEntityIds().add(description.getId());
|
||||||
|
|
||||||
this.handle(event);
|
this.handle(event, dmp.getTenantId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent {
|
||||||
private List<AnnotationEntityTouchedIntegrationEvent> events;
|
private List<AnnotationEntityTouchedIntegrationEvent> events;
|
||||||
|
|
||||||
public List<AnnotationEntityTouchedIntegrationEvent> getEvents() {
|
public List<AnnotationEntityTouchedIntegrationEvent> getEvents() {
|
||||||
return events;
|
return this.events;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEvents(List<AnnotationEntityTouchedIntegrationEvent> events) {
|
public void setEvents(List<AnnotationEntityTouchedIntegrationEvent> events) {
|
||||||
|
@ -24,7 +24,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent {
|
||||||
private List<UUID> userIds;
|
private List<UUID> userIds;
|
||||||
|
|
||||||
public UUID getEntityId() {
|
public UUID getEntityId() {
|
||||||
return entityId;
|
return this.entityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEntityId(UUID entityId) {
|
public void setEntityId(UUID entityId) {
|
||||||
|
@ -32,7 +32,7 @@ public class AnnotationEntitiesTouchedIntegrationEvent extends TrackedEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getUserIds() {
|
public List<UUID> getUserIds() {
|
||||||
return userIds;
|
return this.userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserIds(List<UUID> userIds) {
|
public void setUserIds(List<UUID> userIds) {
|
||||||
|
|
|
@ -3,8 +3,6 @@ package org.opencdmp.integrationevent.outbox.notification;
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxService;
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.annotation.RequestScope;
|
import org.springframework.web.context.annotation.RequestScope;
|
||||||
|
@ -16,8 +14,6 @@ import java.util.UUID;
|
||||||
@RequestScope
|
@RequestScope
|
||||||
public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEventHandler {
|
public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEventHandler {
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class));
|
|
||||||
|
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
private final TenantScope tenantScope;
|
private final TenantScope tenantScope;
|
||||||
|
|
||||||
|
@ -34,7 +30,7 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.NOTIFY);
|
message.setType(OutboxIntegrationEvent.NOTIFY);
|
||||||
message.setEvent(event);
|
message.setEvent(event);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
|
if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant());
|
||||||
this.outboxService.publish(message);
|
this.outboxService.publish(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.opencdmp.integrationevent.outbox.tenantdefaultlocaleremoval;
|
package org.opencdmp.integrationevent.outbox.tenantdefaultlocaleremoval;
|
||||||
|
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxService;
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -19,13 +18,11 @@ public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements Te
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleRemovalIntegrationEventHandlerImpl.class));
|
||||||
|
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
private final TenantScope tenantScope;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TenantDefaultLocaleRemovalIntegrationEventHandlerImpl(
|
public TenantDefaultLocaleRemovalIntegrationEventHandlerImpl(
|
||||||
OutboxService outboxService, TenantScope tenantScope) {
|
OutboxService outboxService) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
this.tenantScope = tenantScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +31,7 @@ public class TenantDefaultLocaleRemovalIntegrationEventHandlerImpl implements Te
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_REMOVAL);
|
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_REMOVAL);
|
||||||
message.setEvent(event);
|
message.setEvent(event);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
|
message.setTenantId(event.getTenantId());
|
||||||
this.outboxService.publish(message);
|
this.outboxService.publish(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.opencdmp.integrationevent.outbox.tenantdefaultlocaletouched;
|
package org.opencdmp.integrationevent.outbox.tenantdefaultlocaletouched;
|
||||||
|
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxService;
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -19,13 +18,11 @@ public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements Te
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDefaultLocaleTouchedIntegrationEventHandlerImpl.class));
|
||||||
|
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
private final TenantScope tenantScope;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TenantDefaultLocaleTouchedIntegrationEventHandlerImpl(
|
public TenantDefaultLocaleTouchedIntegrationEventHandlerImpl(
|
||||||
OutboxService outboxService, TenantScope tenantScope) {
|
OutboxService outboxService) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
this.tenantScope = tenantScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +31,7 @@ public class TenantDefaultLocaleTouchedIntegrationEventHandlerImpl implements Te
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_TOUCHED);
|
message.setType(OutboxIntegrationEvent.TENANT_DEFAULT_LOCALE_TOUCHED);
|
||||||
message.setEvent(event);
|
message.setEvent(event);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
|
message.setTenantId(event.getTenantId());
|
||||||
this.outboxService.publish(message);
|
this.outboxService.publish(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.opencdmp.integrationevent.outbox.userremoval;
|
package org.opencdmp.integrationevent.outbox.userremoval;
|
||||||
|
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxService;
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -14,7 +13,7 @@ import javax.management.InvalidApplicationException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Component("outboxuserremovalintegrationeventhandler")
|
@Component("outboxuserremovalintegrationeventhandler")
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegrationEventHandler {
|
public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegrationEventHandler {
|
||||||
|
|
||||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRemovalIntegrationEventHandlerImpl.class));
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRemovalIntegrationEventHandlerImpl.class));
|
||||||
|
@ -22,12 +21,10 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
private final TenantScope tenantScope;
|
|
||||||
|
|
||||||
public UserRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext, TenantScope tenantScope) {
|
public UserRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.tenantScope = tenantScope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,7 +36,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.USER_REMOVE);
|
message.setType(OutboxIntegrationEvent.USER_REMOVE);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
|
|
||||||
UserRemovalIntegrationEvent event = new UserRemovalIntegrationEvent();
|
UserRemovalIntegrationEvent event = new UserRemovalIntegrationEvent();
|
||||||
event.setUserId(userId);
|
event.setUserId(userId);
|
||||||
message.setEvent(event);
|
message.setEvent(event);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.commons.JsonHandlingService;
|
import org.opencdmp.commons.JsonHandlingService;
|
||||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
|
||||||
import org.opencdmp.commons.types.user.AdditionalInfoEntity;
|
import org.opencdmp.commons.types.user.AdditionalInfoEntity;
|
||||||
import org.opencdmp.data.*;
|
import org.opencdmp.data.*;
|
||||||
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
||||||
|
@ -39,16 +38,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
private final OutboxService outboxService;
|
private final OutboxService outboxService;
|
||||||
private final JsonHandlingService jsonHandlingService;
|
private final JsonHandlingService jsonHandlingService;
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private final TenantScope tenantScope;
|
|
||||||
private final TenantEntityManager entityManager;
|
private final TenantEntityManager entityManager;
|
||||||
|
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
public UserTouchedIntegrationEventHandlerImpl(
|
public UserTouchedIntegrationEventHandlerImpl(
|
||||||
OutboxService outboxService, JsonHandlingService jsonHandlingService, MessageSource messageSource, TenantScope tenantScope, TenantEntityManager entityManager, QueryFactory queryFactory) {
|
OutboxService outboxService, JsonHandlingService jsonHandlingService, MessageSource messageSource, TenantEntityManager entityManager, QueryFactory queryFactory) {
|
||||||
this.outboxService = outboxService;
|
this.outboxService = outboxService;
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.tenantScope = tenantScope;
|
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +55,6 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
||||||
message.setMessageId(UUID.randomUUID());
|
message.setMessageId(UUID.randomUUID());
|
||||||
message.setType(OutboxIntegrationEvent.USER_TOUCH);
|
message.setType(OutboxIntegrationEvent.USER_TOUCH);
|
||||||
if (this.tenantScope.isSet()) message.setTenantId(this.tenantScope.getTenant());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.entityManager.disableTenantFilters();
|
this.entityManager.disableTenantFilters();
|
||||||
|
|
|
@ -428,6 +428,8 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
return DmpEntity._publicAfter;
|
return DmpEntity._publicAfter;
|
||||||
else if (item.match(Dmp._versionStatus))
|
else if (item.match(Dmp._versionStatus))
|
||||||
return DmpEntity._versionStatus;
|
return DmpEntity._versionStatus;
|
||||||
|
else if (item.match(DmpEntity._tenantId))
|
||||||
|
return DmpEntity._tenantId;
|
||||||
else if (item.match(Dmp._belongsToCurrentTenant))
|
else if (item.match(Dmp._belongsToCurrentTenant))
|
||||||
return DmpEntity._tenantId;
|
return DmpEntity._tenantId;
|
||||||
else
|
else
|
||||||
|
|
|
@ -163,32 +163,34 @@ public class TenantServiceImpl implements TenantService {
|
||||||
List<UserRoleEntity> existingItems;
|
List<UserRoleEntity> existingItems;
|
||||||
List<UserCredentialEntity> userCredentialEntities;
|
List<UserCredentialEntity> userCredentialEntities;
|
||||||
try {
|
try {
|
||||||
this.tenantScope.setTempTenant(this.entityManager, null, this.tenantScope.getDefaultTenantCode());
|
this.entityManager.disableTenantFilters();
|
||||||
|
|
||||||
existingItems = this.queryFactory.query(UserRoleQuery.class).disableTracking().tenantIsSet(false).roles(this.authorizationProperties.getGlobalAdminRole()).collect();
|
existingItems = this.queryFactory.query(UserRoleQuery.class).disableTracking().tenantIsSet(false).roles(this.authorizationProperties.getGlobalAdminRole()).collect();
|
||||||
userCredentialEntities = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()).collect();
|
userCredentialEntities = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()).collect();
|
||||||
} finally {
|
|
||||||
this.tenantScope.removeTempTenant(this.entityManager);
|
List<String> keycloakIdsToAddToTenantGroup = new ArrayList<>();
|
||||||
}
|
|
||||||
try {
|
|
||||||
this.tenantScope.setTempTenant(this.entityManager, tenant.getId(), tenant.getCode());
|
|
||||||
for (UUID userId : existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()) {
|
for (UUID userId : existingItems.stream().map(UserRoleEntity::getUserId).distinct().toList()) {
|
||||||
UserCredentialEntity userCredential = userCredentialEntities.stream().filter(x-> !this.conventionService.isNullOrEmpty(x.getExternalId()) && x.getUserId().equals(userId)).findFirst().orElse(null);
|
UserCredentialEntity userCredential = userCredentialEntities.stream().filter(x-> !this.conventionService.isNullOrEmpty(x.getExternalId()) && x.getUserId().equals(userId)).findFirst().orElse(null);
|
||||||
if (userCredential == null) continue;
|
if (userCredential == null) continue;
|
||||||
UserRoleEntity item = new UserRoleEntity();
|
UserRoleEntity item = new UserRoleEntity();
|
||||||
item.setId(UUID.randomUUID());
|
item.setId(UUID.randomUUID());
|
||||||
item.setUserId(userId);
|
item.setUserId(userId);
|
||||||
|
item.setTenantId(tenant.getId());
|
||||||
item.setRole(this.authorizationProperties.getTenantAdminRole());
|
item.setRole(this.authorizationProperties.getTenantAdminRole());
|
||||||
item.setCreatedAt(Instant.now());
|
item.setCreatedAt(Instant.now());
|
||||||
this.entityManager.persist(item);
|
this.entityManager.persist(item);
|
||||||
|
keycloakIdsToAddToTenantGroup.add(userCredential.getExternalId());
|
||||||
this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), this.tenantScope.getTenantCode(), this.authorizationProperties.getTenantAdminRole());
|
this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), this.tenantScope.getTenantCode(), this.authorizationProperties.getTenantAdminRole());
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
this.tenantScope.removeTempTenant(this.entityManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
for (String externalId : keycloakIdsToAddToTenantGroup) {
|
||||||
|
this.keycloakService.addUserToTenantRoleGroup(externalId, this.tenantScope.getTenantCode(), this.authorizationProperties.getTenantAdminRole());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.entityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -280,8 +280,12 @@ public class UserServiceImpl implements UserService {
|
||||||
logger.debug("deleting User: {}", id);
|
logger.debug("deleting User: {}", id);
|
||||||
|
|
||||||
this.authorizationService.authorizeForce(Permission.DeleteUser);
|
this.authorizationService.authorizeForce(Permission.DeleteUser);
|
||||||
|
try {
|
||||||
this.deleterFactory.deleter(UserDeleter.class).deleteAndSaveByIds(List.of(id));
|
this.entityManager.disableTenantFilters();
|
||||||
|
this.deleterFactory.deleter(UserDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||||
|
} finally {
|
||||||
|
this.entityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
this.userRemovalIntegrationEventHandler.handle(id);
|
this.userRemovalIntegrationEventHandler.handle(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +345,7 @@ public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
private void applyGlobalRoles(UUID userId, UserRolePatchPersist model) throws InvalidApplicationException {
|
private void applyGlobalRoles(UUID userId, UserRolePatchPersist model) throws InvalidApplicationException {
|
||||||
try {
|
try {
|
||||||
this.tenantScope.setTempTenant(this.entityManager, null, this.tenantScope.getDefaultTenantCode());
|
this.entityManager.disableTenantFilters();
|
||||||
|
|
||||||
List<UserRoleEntity> existingItems = this.queryFactory.query(UserRoleQuery.class).userIds(userId).tenantIsSet(false).roles(this.authorizationProperties.getAllowedGlobalRoles()).collect();
|
List<UserRoleEntity> existingItems = this.queryFactory.query(UserRoleQuery.class).userIds(userId).tenantIsSet(false).roles(this.authorizationProperties.getAllowedGlobalRoles()).collect();
|
||||||
List<UUID> foundIds = new ArrayList<>();
|
List<UUID> foundIds = new ArrayList<>();
|
||||||
|
@ -365,7 +369,7 @@ public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
} finally {
|
} finally {
|
||||||
this.tenantScope.removeTempTenant(this.entityManager);
|
this.entityManager.reloadTenantFilters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,131 +627,155 @@ public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncKeycloakRoles(UUID userId){
|
private void syncKeycloakRoles(UUID userId) throws InvalidApplicationException {
|
||||||
List<UserCredentialEntity> userCredentials = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(userId).collect();
|
try {
|
||||||
List<UserRoleEntity> userRoles = this.queryFactory.query(UserRoleQuery.class).disableTracking().userIds(userId).collect();
|
this.entityManager.disableTenantFilters();
|
||||||
List<TenantEntity> tenants = this.queryFactory.query(TenantQuery.class).disableTracking().ids(userRoles.stream().map(TenantScopedBaseEntity::getTenantId).filter(Objects::nonNull).toList()).collect();
|
List<UserCredentialEntity> userCredentials = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(userId).collect();
|
||||||
|
List<UserRoleEntity> userRoles = this.queryFactory.query(UserRoleQuery.class).disableTracking().userIds(userId).collect();
|
||||||
for (UserCredentialEntity userCredential : userCredentials){
|
List<TenantEntity> tenants = this.queryFactory.query(TenantQuery.class).disableTracking().ids(userRoles.stream().map(TenantScopedBaseEntity::getTenantId).filter(Objects::nonNull).toList()).collect();
|
||||||
this.keycloakService.removeFromAllGroups(userCredential.getExternalId());
|
|
||||||
for (UserRoleEntity userRole : userRoles) {
|
for (UserCredentialEntity userCredential : userCredentials){
|
||||||
if (this.authorizationProperties.getAllowedGlobalRoles().contains(userRole.getRole())){
|
this.keycloakService.removeFromAllGroups(userCredential.getExternalId());
|
||||||
this.keycloakService.addUserToGlobalRoleGroup(userCredential.getExternalId(), userRole.getRole());
|
for (UserRoleEntity userRole : userRoles) {
|
||||||
} else if (this.authorizationProperties.getAllowedTenantRoles().contains(userRole.getRole())){
|
if (this.authorizationProperties.getAllowedGlobalRoles().contains(userRole.getRole())){
|
||||||
String tenantCode = userRole.getTenantId() == null ? this.tenantScope.getDefaultTenantCode() : tenants.stream().filter(x-> x.getId().equals(userRole.getTenantId())).map(TenantEntity::getCode).findFirst().orElse(null);
|
this.keycloakService.addUserToGlobalRoleGroup(userCredential.getExternalId(), userRole.getRole());
|
||||||
if (!this.conventionService.isNullOrEmpty(tenantCode)) this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), tenantCode, userRole.getRole());
|
} else if (this.authorizationProperties.getAllowedTenantRoles().contains(userRole.getRole())){
|
||||||
|
String tenantCode = userRole.getTenantId() == null ? this.tenantScope.getDefaultTenantCode() : tenants.stream().filter(x-> x.getId().equals(userRole.getTenantId())).map(TenantEntity::getCode).findFirst().orElse(null);
|
||||||
|
if (!this.conventionService.isNullOrEmpty(tenantCode)) this.keycloakService.addUserToTenantRoleGroup(userCredential.getExternalId(), tenantCode, userRole.getRole());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
this.entityManager.reloadTenantFilters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeNewUserToOld(UserEntity newUser, UserEntity oldUser) throws IOException, InvalidApplicationException {
|
private void mergeNewUserToOld(UserEntity newUser, UserEntity oldUser) throws IOException, InvalidApplicationException {
|
||||||
List<UserCredentialEntity> userCredentials = this.queryFactory.query(UserCredentialQuery.class).userIds(oldUser.getId()).collect();
|
try {
|
||||||
for (UserCredentialEntity userCredential : userCredentials){
|
this.entityManager.disableTenantFilters();
|
||||||
userCredential.setUserId(newUser.getId());
|
List<UserCredentialEntity> userCredentials = this.queryFactory.query(UserCredentialQuery.class).userIds(oldUser.getId()).collect();
|
||||||
this.entityManager.merge(userCredential);
|
for (UserCredentialEntity userCredential : userCredentials) {
|
||||||
}
|
userCredential.setUserId(newUser.getId());
|
||||||
|
this.entityManager.merge(userCredential);
|
||||||
List<UserContactInfoEntity> userContacts = this.queryFactory.query(UserContactInfoQuery.class).userIds(oldUser.getId()).collect();
|
|
||||||
UserContactInfoQuery newUserContactInfoQuery = this.queryFactory.query(UserContactInfoQuery.class).userIds(newUser.getId());
|
|
||||||
newUserContactInfoQuery.setOrder(new Ordering().addDescending(UserContactInfo._ordinal));
|
|
||||||
UserContactInfoEntity newUserContactInfo = newUserContactInfoQuery.first();
|
|
||||||
int ordinal = newUserContactInfo == null ? 0 : newUserContactInfo.getOrdinal() + 1;
|
|
||||||
for (UserContactInfoEntity userContactInfo : userContacts){
|
|
||||||
userContactInfo.setUserId(newUser.getId());
|
|
||||||
userContactInfo.setOrdinal(ordinal);
|
|
||||||
this.entityManager.merge(userContactInfo);
|
|
||||||
ordinal++;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<UserRoleEntity> userRoles = this.queryFactory.query(UserRoleQuery.class).userIds(oldUser.getId()).collect();
|
|
||||||
List<UserRoleEntity> newUserRoles = this.queryFactory.query(UserRoleQuery.class).userIds(newUser.getId()).collect();
|
|
||||||
List<UserRoleEntity> rolesToDelete = new ArrayList<>();
|
|
||||||
for (UserRoleEntity userRole : userRoles){
|
|
||||||
if (newUserRoles.stream().anyMatch(x-> x.getRole().equals(userRole.getRole()))) {
|
|
||||||
rolesToDelete.add(userRole);
|
|
||||||
} else {
|
|
||||||
userRole.setUserId(newUser.getId());
|
|
||||||
this.entityManager.merge(userRole);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.deleterFactory.deleter(UserRoleDeleter.class).delete(rolesToDelete);
|
|
||||||
|
|
||||||
List<UserSettingsEntity> userSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(oldUser.getId()).collect();
|
List<UserContactInfoEntity> userContacts = this.queryFactory.query(UserContactInfoQuery.class).userIds(oldUser.getId()).collect();
|
||||||
List<UserSettingsEntity> newUserSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(newUser.getId()).collect();
|
UserContactInfoQuery newUserContactInfoQuery = this.queryFactory.query(UserContactInfoQuery.class).userIds(newUser.getId());
|
||||||
List<UserSettingsEntity> userSettingsToDelete = new ArrayList<>();
|
newUserContactInfoQuery.setOrder(new Ordering().addDescending(UserContactInfo._ordinal));
|
||||||
for (UserSettingsEntity userSetting : userSettings){
|
UserContactInfoEntity newUserContactInfo = newUserContactInfoQuery.first();
|
||||||
if (newUserSettings.stream().anyMatch(x-> x.getKey().equals(userSetting.getKey()))) {
|
int ordinal = newUserContactInfo == null ? 0 : newUserContactInfo.getOrdinal() + 1;
|
||||||
userSettingsToDelete.add(userSetting);
|
for (UserContactInfoEntity userContactInfo : userContacts) {
|
||||||
} else {
|
userContactInfo.setUserId(newUser.getId());
|
||||||
userSetting.setEntityId(newUser.getId());
|
userContactInfo.setOrdinal(ordinal);
|
||||||
this.entityManager.merge(userSetting);
|
this.entityManager.merge(userContactInfo);
|
||||||
|
ordinal++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.deleterFactory.deleter(UserSettingsSettingsDeleter.class).delete(userSettingsToDelete);
|
|
||||||
|
|
||||||
List<TagEntity> tags = this.queryFactory.query(TagQuery.class).createdByIds(oldUser.getId()).collect();
|
List<UserRoleEntity> userRoles = this.queryFactory.query(UserRoleQuery.class).userIds(oldUser.getId()).collect();
|
||||||
for (TagEntity tag : tags){
|
List<UserRoleEntity> newUserRoles = this.queryFactory.query(UserRoleQuery.class).userIds(newUser.getId()).collect();
|
||||||
tag.setCreatedById(newUser.getId());
|
List<UserRoleEntity> rolesToDelete = new ArrayList<>();
|
||||||
this.entityManager.merge(tag);
|
for (UserRoleEntity userRole : userRoles) {
|
||||||
}
|
if (newUserRoles.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userRole.getTenantId()) && x.getRole().equals(userRole.getRole()))) {
|
||||||
|
rolesToDelete.add(userRole);
|
||||||
|
} else {
|
||||||
|
userRole.setUserId(newUser.getId());
|
||||||
|
this.entityManager.merge(userRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.deleterFactory.deleter(UserRoleDeleter.class).delete(rolesToDelete);
|
||||||
|
|
||||||
List<StorageFileEntity> storageFiles = this.queryFactory.query(StorageFileQuery.class).ownerIds(oldUser.getId()).collect();
|
List<TenantUserEntity> userTenantUsers = this.queryFactory.query(TenantUserQuery.class).userIds(oldUser.getId()).collect();
|
||||||
for (StorageFileEntity storageFile : storageFiles){
|
List<TenantUserEntity> newTenantUsers = this.queryFactory.query(TenantUserQuery.class).userIds(newUser.getId()).collect();
|
||||||
storageFile.setOwnerId(newUser.getId());
|
List<TenantUserEntity> tenantUsersToDelete = new ArrayList<>();
|
||||||
this.entityManager.merge(storageFile);
|
for (TenantUserEntity userTenantUser : userTenantUsers) {
|
||||||
}
|
if (newTenantUsers.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userTenantUser.getTenantId()))) {
|
||||||
|
tenantUsersToDelete.add(userTenantUser);
|
||||||
|
} else {
|
||||||
|
userTenantUser.setUserId(newUser.getId());
|
||||||
|
this.entityManager.merge(userTenantUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.deleterFactory.deleter(TenantUserDeleter.class).delete(tenantUsersToDelete);
|
||||||
|
|
||||||
List<LockEntity> locks = this.queryFactory.query(LockQuery.class).lockedByIds(oldUser.getId()).collect();
|
List<UserSettingsEntity> userSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(oldUser.getId()).collect();
|
||||||
for (LockEntity lock : locks){
|
List<UserSettingsEntity> newUserSettings = this.queryFactory.query(UserSettingsQuery.class).entityIds(newUser.getId()).collect();
|
||||||
lock.setLockedBy(newUser.getId());
|
List<UserSettingsEntity> userSettingsToDelete = new ArrayList<>();
|
||||||
this.entityManager.merge(lock);
|
for (UserSettingsEntity userSetting : userSettings) {
|
||||||
}
|
if (newUserSettings.stream().anyMatch(x -> Objects.equals(x.getTenantId(), userSetting.getTenantId()) &&x.getKey().equals(userSetting.getKey()))) {
|
||||||
|
userSettingsToDelete.add(userSetting);
|
||||||
|
} else {
|
||||||
|
userSetting.setEntityId(newUser.getId());
|
||||||
|
this.entityManager.merge(userSetting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.deleterFactory.deleter(UserSettingsSettingsDeleter.class).delete(userSettingsToDelete);
|
||||||
|
|
||||||
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class).userIds(oldUser.getId()).collect();
|
List<TagEntity> tags = this.queryFactory.query(TagQuery.class).createdByIds(oldUser.getId()).collect();
|
||||||
for (DmpUserEntity dmpUser : dmpUsers){
|
for (TagEntity tag : tags) {
|
||||||
dmpUser.setUserId(newUser.getId());
|
tag.setCreatedById(newUser.getId());
|
||||||
this.entityManager.merge(dmpUser);
|
this.entityManager.merge(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UserDescriptionTemplateEntity> userDescriptionTemplates = this.queryFactory.query(UserDescriptionTemplateQuery.class).userIds(oldUser.getId()).collect();
|
List<StorageFileEntity> storageFiles = this.queryFactory.query(StorageFileQuery.class).ownerIds(oldUser.getId()).collect();
|
||||||
for (UserDescriptionTemplateEntity userDescriptionTemplate : userDescriptionTemplates){
|
for (StorageFileEntity storageFile : storageFiles) {
|
||||||
userDescriptionTemplate.setUserId(newUser.getId());
|
storageFile.setOwnerId(newUser.getId());
|
||||||
this.entityManager.merge(userDescriptionTemplate);
|
this.entityManager.merge(storageFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DmpEntity> dmps = this.queryFactory.query(DmpQuery.class).creatorIds(oldUser.getId()).collect();
|
List<LockEntity> locks = this.queryFactory.query(LockQuery.class).lockedByIds(oldUser.getId()).collect();
|
||||||
for (DmpEntity dmp : dmps){
|
for (LockEntity lock : locks) {
|
||||||
dmp.setCreatorId(newUser.getId());
|
lock.setLockedBy(newUser.getId());
|
||||||
this.entityManager.merge(dmp);
|
this.entityManager.merge(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).createdByIds(oldUser.getId()).collect();
|
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class).userIds(oldUser.getId()).collect();
|
||||||
for (DescriptionEntity description : descriptions){
|
for (DmpUserEntity dmpUser : dmpUsers) {
|
||||||
description.setCreatedById(newUser.getId());
|
dmpUser.setUserId(newUser.getId());
|
||||||
this.entityManager.merge(description);
|
this.entityManager.merge(dmpUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
oldUser.setIsActive(IsActive.Inactive);
|
|
||||||
|
|
||||||
this.entityManager.merge(oldUser);
|
List<UserDescriptionTemplateEntity> userDescriptionTemplates = this.queryFactory.query(UserDescriptionTemplateQuery.class).userIds(oldUser.getId()).collect();
|
||||||
|
for (UserDescriptionTemplateEntity userDescriptionTemplate : userDescriptionTemplates) {
|
||||||
this.entityManager.flush();
|
userDescriptionTemplate.setUserId(newUser.getId());
|
||||||
|
this.entityManager.merge(userDescriptionTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
for (DmpEntity dmp : dmps){
|
List<DmpEntity> dmps = this.queryFactory.query(DmpQuery.class).creatorIds(oldUser.getId()).collect();
|
||||||
this.elasticService.persistDmp(dmp);
|
for (DmpEntity dmp : dmps) {
|
||||||
}
|
dmp.setCreatorId(newUser.getId());
|
||||||
|
this.entityManager.merge(dmp);
|
||||||
|
}
|
||||||
|
|
||||||
for (DescriptionEntity description : descriptions){
|
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).createdByIds(oldUser.getId()).collect();
|
||||||
this.elasticService.persistDescription(description);
|
for (DescriptionEntity description : descriptions) {
|
||||||
}
|
description.setCreatedById(newUser.getId());
|
||||||
|
this.entityManager.merge(description);
|
||||||
|
}
|
||||||
|
|
||||||
for (DmpEntity dmp : dmps){
|
oldUser.setIsActive(IsActive.Inactive);
|
||||||
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DescriptionEntity description : descriptions){
|
this.entityManager.merge(oldUser);
|
||||||
this.annotationEntityTouchedIntegrationEventHandler.handleDescription(description.getId());
|
|
||||||
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
for (DmpEntity dmp : dmps) {
|
||||||
|
this.elasticService.persistDmp(dmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DescriptionEntity description : descriptions) {
|
||||||
|
this.elasticService.persistDescription(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DmpEntity dmp : dmps) {
|
||||||
|
this.annotationEntityTouchedIntegrationEventHandler.handleDmp(dmp.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DescriptionEntity description : descriptions) {
|
||||||
|
this.annotationEntityTouchedIntegrationEventHandler.handleDescription(description.getId());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.entityManager.reloadTenantFilters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<ng-container *ngIf="hasDescriptionTemplates(section)">
|
<ng-container *ngIf="hasDescriptionTemplates(section)">
|
||||||
<mat-icon [matTooltipDisabled]="hasValidMultiplicity(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES.MAX-MULTIPLICITY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
|
<mat-icon [matTooltipDisabled]="hasValidMultiplicity(section)" [matTooltip]="'DMP-EDITOR.DESCRIPTION-TEMPLATES.MAX-MULTIPLICITY' | translate">add</mat-icon>{{'DMP-EDITOR.ACTIONS.ADD-DESCRIPTION-IN-SECTION' | translate}}
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -42,7 +42,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
private final ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private final QueryFactory queryFactory;
|
|
||||||
private final TenantScope tenantScope;
|
private final TenantScope tenantScope;
|
||||||
private final CurrentPrincipalResolver currentPrincipalResolver;
|
private final CurrentPrincipalResolver currentPrincipalResolver;
|
||||||
private final ClaimExtractorProperties claimExtractorProperties;
|
private final ClaimExtractorProperties claimExtractorProperties;
|
||||||
|
@ -54,12 +53,11 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
public UserRemovalIntegrationEventHandlerImpl(
|
public UserRemovalIntegrationEventHandlerImpl(
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
ErrorThesaurusProperties errors,
|
ErrorThesaurusProperties errors,
|
||||||
MessageSource messageSource, QueryFactory queryFactory, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager
|
MessageSource messageSource, TenantScope tenantScope, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, UserRemovalConsistencyHandler userRemovalConsistencyHandler, UserService userService, AuditService auditService, TenantEntityManager tenantEntityManager
|
||||||
) {
|
) {
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.queryFactory = queryFactory;
|
|
||||||
this.tenantScope = tenantScope;
|
this.tenantScope = tenantScope;
|
||||||
this.currentPrincipalResolver = currentPrincipalResolver;
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
||||||
this.claimExtractorProperties = claimExtractorProperties;
|
this.claimExtractorProperties = claimExtractorProperties;
|
||||||
|
@ -81,29 +79,21 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
|
|
||||||
EventProcessingStatus status = EventProcessingStatus.Success;
|
EventProcessingStatus status = EventProcessingStatus.Success;
|
||||||
try {
|
try {
|
||||||
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
|
|
||||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().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, properties.getTenantId(), tenant.getCode());
|
|
||||||
} else if (this.tenantScope.isMultitenant()) {
|
|
||||||
// logger.error("missing tenant from event message");
|
|
||||||
// return EventProcessingStatus.Error;
|
|
||||||
this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
||||||
|
|
||||||
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
try{
|
||||||
status = EventProcessingStatus.Postponed;
|
this.tenantEntityManager.disableTenantFilters();
|
||||||
currentPrincipalResolver.pop();
|
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
status = EventProcessingStatus.Postponed;
|
||||||
return status;
|
currentPrincipalResolver.pop();
|
||||||
}
|
tenantScope.removeTempTenant(this.tenantEntityManager);
|
||||||
|
return status;
|
||||||
userService.deleteAndSave(event.getUserId());
|
}
|
||||||
|
|
||||||
|
userService.deleteAndSave(event.getUserId());
|
||||||
|
} finally {
|
||||||
|
this.tenantEntityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
|
|
||||||
auditService.track(AuditableAction.User_Delete, Map.ofEntries(
|
auditService.track(AuditableAction.User_Delete, Map.ofEntries(
|
||||||
new AbstractMap.SimpleEntry<String, Object>("id", event.getUserId())
|
new AbstractMap.SimpleEntry<String, Object>("id", event.getUserId())
|
||||||
|
@ -114,11 +104,6 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
|
||||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
try {
|
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
} catch (InvalidApplicationException e) {
|
|
||||||
logger.error( e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -71,23 +71,14 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
|
|
||||||
EventProcessingStatus status = EventProcessingStatus.Success;
|
EventProcessingStatus status = EventProcessingStatus.Success;
|
||||||
try {
|
try {
|
||||||
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) {
|
|
||||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).disableTracking().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, properties.getTenantId(), tenant.getCode());
|
|
||||||
} else if (this.tenantScope.isMultitenant()) {
|
|
||||||
// logger.error("missing tenant from event message");
|
|
||||||
// return EventProcessingStatus.Error;
|
|
||||||
this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
||||||
|
try {
|
||||||
userService.persist(event, null);
|
this.tenantEntityManager.disableTenantFilters();
|
||||||
|
userService.persist(event, null);
|
||||||
|
} finally {
|
||||||
|
this.tenantEntityManager.reloadTenantFilters();
|
||||||
|
}
|
||||||
auditService.track(AuditableAction.User_Persist, Map.ofEntries(
|
auditService.track(AuditableAction.User_Persist, Map.ofEntries(
|
||||||
new AbstractMap.SimpleEntry<String, Object>("model", event)
|
new AbstractMap.SimpleEntry<String, Object>("model", event)
|
||||||
));
|
));
|
||||||
|
@ -97,11 +88,6 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
|
||||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
currentPrincipalResolver.pop();
|
currentPrincipalResolver.pop();
|
||||||
try {
|
|
||||||
tenantScope.removeTempTenant(this.tenantEntityManager);
|
|
||||||
} catch (InvalidApplicationException e) {
|
|
||||||
logger.error( e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class UserServiceImpl implements UserService {
|
||||||
public User persist(UserTouchedIntegrationEvent model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
|
public User persist(UserTouchedIntegrationEvent model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
|
||||||
logger.debug(new MapLogEntry("persisting user").And("model", model).And("fields", fields));
|
logger.debug(new MapLogEntry("persisting user").And("model", model).And("fields", fields));
|
||||||
|
|
||||||
// this.authorizationService.authorizeAtLeastOneForce(model.getId() != null ? List.of(new OwnedResource(model.getId())) : null, Permission.EditUser);
|
this.authorizationService.authorize(Permission.EditUser);
|
||||||
|
|
||||||
Boolean isValid = this.conventionService.isValidGuid(model.getId());
|
Boolean isValid = this.conventionService.isValidGuid(model.getId());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue