diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllerhandler/GlobalExceptionHandler.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllerhandler/GlobalExceptionHandler.java index 5e7763b30..ebefb8eff 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllerhandler/GlobalExceptionHandler.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllerhandler/GlobalExceptionHandler.java @@ -150,7 +150,7 @@ public class GlobalExceptionHandler { Map.entry("error", "System error") ); } - }; + } String serialization = this.jsonHandlingService.toJsonSafe(result); return new HandledException(statusCode, serialization, logLevel); } diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/AnnotationController.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/AnnotationController.java index 83b503d4e..a318ad8e2 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/AnnotationController.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/AnnotationController.java @@ -72,7 +72,7 @@ public class AnnotationController { this.censorFactory.censor(AnnotationCensor.class).censor(lookup.getProject(), null); - AnnotationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionAssociated); + AnnotationQuery query = lookup.enrich(this.queryFactory).disableTracking().authorize(AuthorizationFlags.OwnerOrPermissionAssociated); List data = query.collect(); List models = this.builderFactory.builder(AnnotationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionAssociated).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); @@ -88,7 +88,7 @@ public class AnnotationController { this.censorFactory.censor(AnnotationCensor.class).censor(fieldSet, null); - AnnotationQuery query = this.queryFactory.query(AnnotationQuery.class).authorize(AuthorizationFlags.OwnerOrPermissionAssociated).ids(id); + AnnotationQuery query = this.queryFactory.query(AnnotationQuery.class).disableTracking().authorize(AuthorizationFlags.OwnerOrPermissionAssociated).ids(id); Annotation model = this.builderFactory.builder(AnnotationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionAssociated).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Annotation.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/PrincipalController.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/PrincipalController.java index 922506475..4850e8641 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/PrincipalController.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/controllers/PrincipalController.java @@ -30,18 +30,15 @@ public class PrincipalController { private final CurrentPrincipalResolver currentPrincipalResolver; private final AccountBuilder accountBuilder; - private final ClaimExtractor claimExtractor; @Autowired public PrincipalController( CurrentPrincipalResolver currentPrincipalResolver, AccountBuilder accountBuilder, - AuditService auditService, - ClaimExtractor claimExtractor) { + AuditService auditService) { this.currentPrincipalResolver = currentPrincipalResolver; this.accountBuilder = accountBuilder; this.auditService = auditService; - this.claimExtractor = claimExtractor; } @GetMapping("me") @@ -76,17 +73,4 @@ public class PrincipalController { } - @GetMapping("my-tenants") - public List myTenants() { - logger.debug("my-tenants"); - - MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal(); - List tenants = this.claimExtractor.asStrings(principal, ClaimNames.TenantCodesClaimName); - - this.auditService.track(AuditableAction.Tenants_Lookup); - //auditService.trackIdentity(AuditableAction.IdentityTracking_Action); - - return tenants == null ? null : tenants.stream().distinct().collect(Collectors.toList()); - } - } diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/tenant/TenantInterceptor.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/tenant/TenantInterceptor.java index ad0c8d8de..70dc50be4 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/tenant/TenantInterceptor.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/tenant/TenantInterceptor.java @@ -6,6 +6,7 @@ import gr.cite.annotation.authorization.Permission; import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.common.scope.tenant.TenantScope; import gr.cite.annotation.common.scope.user.UserScope; +import gr.cite.annotation.data.TenantEntityManager; import gr.cite.annotation.data.TenantUserEntity; import gr.cite.annotation.data.UserEntity; import gr.cite.annotation.data.tenant.TenantScopedBaseEntity; @@ -52,6 +53,7 @@ public class TenantInterceptor implements WebRequestInterceptor { private final UserAllowedTenantCacheService userAllowedTenantCacheService; private final ErrorThesaurusProperties errors; private final QueryUtilsService queryUtilsService; + public final TenantEntityManager tenantEntityManager; @PersistenceContext public EntityManager entityManager; @@ -64,7 +66,7 @@ public class TenantInterceptor implements WebRequestInterceptor { ApplicationContext applicationContext, TenantScopeProperties tenantScopeProperties, UserAllowedTenantCacheService userAllowedTenantCacheService, - ErrorThesaurusProperties errors, QueryUtilsService queryUtilsService) { + ErrorThesaurusProperties errors, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) { this.tenantScope = tenantScope; this.userScope = userScope; this.currentPrincipalResolver = currentPrincipalResolver; @@ -74,6 +76,7 @@ public class TenantInterceptor implements WebRequestInterceptor { this.userAllowedTenantCacheService = userAllowedTenantCacheService; this.errors = errors; this.queryUtilsService = queryUtilsService; + this.tenantEntityManager = tenantEntityManager; } @Override @@ -103,16 +106,7 @@ public class TenantInterceptor implements WebRequestInterceptor { } if (isUserAllowedTenant) { - if(!tenantScope.isDefaultTenant()) { - this.entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); - } else { - this.entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - } + this.tenantEntityManager.reloadTenantFilters(); } else { if (isAllowedNoTenant || this.isWhiteListedEndpoint(request)) { tenantScope.setTenant(null, null); @@ -181,8 +175,8 @@ public class TenantInterceptor implements WebRequestInterceptor { @Override public void postHandle(@NonNull WebRequest request, ModelMap model) { this.tenantScope.setTenant(null, null); + this.tenantEntityManager.disableTenantFilters(); } - @Override public void afterCompletion(@NonNull WebRequest request, Exception ex) { } diff --git a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/user/UserInterceptor.java b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/user/UserInterceptor.java index 8bf390cad..36e86189d 100644 --- a/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/user/UserInterceptor.java +++ b/annotation-service/annotation-web/src/main/java/gr/cite/annotation/web/scope/user/UserInterceptor.java @@ -63,7 +63,7 @@ public class UserInterceptor implements WebRequestInterceptor { this.userScope.setUserId(userId); } private UUID findExistingUserFromDb(String subjectId) { - UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).externalIds(subjectId).firstAs(new BaseFieldSet().ensure(UserCredential._user)); + UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).disableTracking().externalIds(subjectId).firstAs(new BaseFieldSet().ensure(UserCredential._user)); if (userCredential != null) { return userCredential.getUserId(); } diff --git a/annotation-service/annotation/pom.xml b/annotation-service/annotation/pom.xml index 635a3927d..9df319953 100644 --- a/annotation-service/annotation/pom.xml +++ b/annotation-service/annotation/pom.xml @@ -77,7 +77,7 @@ gr.cite exceptions - 1.0.0 + 2.1.0 gr.cite @@ -93,7 +93,7 @@ gr.cite cipher - 1.0.0 + 2.1.0 compile diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/authorization/authorizationcontentresolver/AuthorizationContentResolverImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/authorization/authorizationcontentresolver/AuthorizationContentResolverImpl.java index f1a4d68e8..67b6eed97 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/authorization/authorizationcontentresolver/AuthorizationContentResolverImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/authorization/authorizationcontentresolver/AuthorizationContentResolverImpl.java @@ -48,7 +48,7 @@ public class AuthorizationContentResolverImpl implements AuthorizationContentRes List idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity._entityId); if (idsToResolve.isEmpty()) return affiliatedResources; - List entityUsers = this.queryFactory.query(EntityUserQuery.class).entityIds(ids).userIds(userId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityUser._id).ensure(EntityUser._entityId)); + List entityUsers = this.queryFactory.query(EntityUserQuery.class).disableTracking().entityIds(ids).userIds(userId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityUser._id).ensure(EntityUser._entityId)); for (UUID entityId : entityUsers.stream().map(EntityUserEntity::getEntityId).distinct().toList()){ affiliatedResources.get(entityId).setAffiliated(true); @@ -79,8 +79,8 @@ public class AuthorizationContentResolverImpl implements AuthorizationContentRes List idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity.class.getSimpleName()); if (idsToResolve.isEmpty()) return affiliatedResources; - List annotationEntities = this.queryFactory.query(AnnotationQuery.class).ids(ids).collectAs(new BaseFieldSet().ensure(Annotation._id).ensure(Annotation._entityId).ensure(Annotation._id)); - List entityUsers = this.queryFactory.query(EntityUserQuery.class).entityIds(annotationEntities.stream().map(AnnotationEntity::getEntityId).distinct().toList()).userIds(userId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityUser._id).ensure(EntityUser._entityId)); + List annotationEntities = this.queryFactory.query(AnnotationQuery.class).disableTracking().ids(ids).collectAs(new BaseFieldSet().ensure(Annotation._id).ensure(Annotation._entityId).ensure(Annotation._id)); + List entityUsers = this.queryFactory.query(EntityUserQuery.class).disableTracking().entityIds(annotationEntities.stream().map(AnnotationEntity::getEntityId).distinct().toList()).userIds(userId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityUser._id).ensure(EntityUser._entityId)); Map> dmpUsersMap = entityUsers.stream().collect(Collectors.groupingBy(EntityUserEntity::getEntityId)); for (AnnotationEntity annotation : annotationEntities){ diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/XmlHandlingService.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/XmlHandlingService.java index 89fdc44f9..71ece3a73 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/XmlHandlingService.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/XmlHandlingService.java @@ -70,7 +70,7 @@ public class XmlHandlingService { public T fromXml(Class type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { if (XmlSerializable.class.isAssignableFrom(type)){ XmlSerializable object = (XmlSerializable)type.newInstance(); - return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement()); + return object.fromXml(this.getDocument(xmlString).getDocumentElement()); } else { JAXBContext jaxbContext = JAXBContext.newInstance(type); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/lock/LockByKeyManager.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/lock/LockByKeyManager.java index 038923309..5976e526b 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/lock/LockByKeyManager.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/lock/LockByKeyManager.java @@ -25,7 +25,7 @@ public class LockByKeyManager { } - private static ConcurrentHashMap locks = new ConcurrentHashMap(); + private static final ConcurrentHashMap locks = new ConcurrentHashMap(); public void lock(String key) { LockWrapper lockWrapper = locks.compute(key, (k, v) -> v == null ? new LockWrapper() : v.addThreadInQueue()); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/fake/FakeRequestAttributes.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/fake/FakeRequestAttributes.java index 62390b7d6..51fb71fff 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/fake/FakeRequestAttributes.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/fake/FakeRequestAttributes.java @@ -8,7 +8,7 @@ import java.util.LinkedHashMap; import java.util.Map; public class FakeRequestAttributes implements RequestAttributes { - private Map requestAttributeMap = new HashMap<>(); + private final Map requestAttributeMap = new HashMap<>(); private final Map requestDestructionCallbacks = new LinkedHashMap<>(8); private volatile boolean requestActive = true; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java index ed39ac7a5..f91403fc3 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java @@ -1,5 +1,6 @@ package gr.cite.annotation.common.scope.tenant; +import gr.cite.annotation.data.TenantEntityManager; import gr.cite.annotation.data.tenant.TenantScopedBaseEntity; import jakarta.persistence.EntityManager; import org.hibernate.Session; @@ -27,11 +28,11 @@ public class TenantScope { } public Boolean isMultitenant() { - return multitenancy.isMultitenant(); + return this.multitenancy.isMultitenant(); } public String getDefaultTenantCode() { - return multitenancy.getDefaultTenantCode(); + return this.multitenancy.getDefaultTenantCode(); } public Boolean isSet() { @@ -62,55 +63,18 @@ public class TenantScope { return this.tenantCode.get(); } - public void setTempTenant(EntityManager entityManager, UUID tenant, String tenantCode) { + public void setTempTenant(TenantEntityManager entityManager, UUID tenant, String tenantCode) throws InvalidApplicationException { this.tenant.set(tenant); this.tenantCode.set(tenantCode); - entityManager - .unwrap(Session.class) - .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); - - entityManager - .unwrap(Session.class) - .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - if (this.tenant.get() != null || this.isDefaultTenant()) { - if(!this.isDefaultTenant()) { - entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenant.get().toString()); - } else { - entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - } - } + entityManager.reloadTenantFilters(); } - public void removeTempTenant(EntityManager entityManager) { + public void removeTempTenant(TenantEntityManager entityManager) throws InvalidApplicationException { this.tenant.set(this.initialTenant.get()); this.tenantCode.set(this.initialTenantCode.get()); - - entityManager - .unwrap(Session.class) - .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); - - entityManager - .unwrap(Session.class) - .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - if (this.initialTenant.get() != null || this.isDefaultTenant()) { - if(!this.isDefaultTenant()) { - entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenant.get().toString()); - } else { - entityManager - .unwrap(Session.class) - .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - } - } + entityManager.reloadTenantFilters(); } public void setTenant(UUID tenant, String tenantCode) { @@ -122,6 +86,3 @@ public class TenantScope { } } } - - - diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java index 8d8ab1008..ffc1a90a1 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java @@ -10,6 +10,7 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.UUID; @@ -33,10 +34,10 @@ public class UuidValidator extends BaseValidator { @Override protected List specifications(UUID item) { - return Arrays.asList( - this.spec() - .must(() -> this.isValidGuid(item)) - .failOn("uuid").failWith(messageSource.getMessage("Validation_Required", new Object[]{"uuid"}, LocaleContextHolder.getLocale())) + return Collections.singletonList( + this.spec() + .must(() -> this.isValidGuid(item)) + .failOn("uuid").failWith(messageSource.getMessage("Validation_Required", new Object[]{"uuid"}, LocaleContextHolder.getLocale())) ); } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/TenantEntityManager.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/TenantEntityManager.java index 31f73207c..f0cf76365 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/TenantEntityManager.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/TenantEntityManager.java @@ -33,9 +33,9 @@ public class TenantEntityManager { } public T merge(T entity) throws InvalidApplicationException { - if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { - if (!tenantScope.isDefaultTenant()) { - if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); + if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { + if (!this.tenantScope.isDefaultTenant()) { + if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); } else if (tenantScopedEntity.getTenantId() != null) { throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); } @@ -44,9 +44,9 @@ public class TenantEntityManager { } public void remove(Object entity) throws InvalidApplicationException { - if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { - if (!tenantScope.isDefaultTenant()) { - if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); + if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { + if (!this.tenantScope.isDefaultTenant()) { + if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); } else if (tenantScopedEntity.getTenantId() != null) { throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); } @@ -57,12 +57,22 @@ public class TenantEntityManager { public T find(Class entityClass, Object primaryKey) throws InvalidApplicationException { T entity = this.entityManager.find(entityClass, primaryKey); - if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { - if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) return null; + if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { + if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) return null; } return entity; } + public T find(Class entityClass, Object primaryKey, boolean disableTracking) throws InvalidApplicationException { + T entity = this.entityManager.find(entityClass, primaryKey); + + if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { + if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) return null; + } + if (disableTracking) this.entityManager.detach(entity); + return entity; + } + public void flush() { this.entityManager.flush(); } @@ -80,14 +90,17 @@ public class TenantEntityManager { public void clear() { this.entityManager.clear(); } - - public void enableTenantFilters() throws InvalidApplicationException { - if (!tenantScope.isSet()) return; - if(!tenantScope.isDefaultTenant()) { + + public void reloadTenantFilters() throws InvalidApplicationException { + this.disableTenantFilters(); + + if (!this.tenantScope.isSet()) return; + + if (!this.tenantScope.isDefaultTenant()) { this.entityManager .unwrap(Session.class) .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); + .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenantScope.getTenant().toString()); } else { this.entityManager .unwrap(Session.class) @@ -95,7 +108,24 @@ public class TenantEntityManager { } } - public void disableTenantFilters(){ + public void loadExplictTenantFilters() throws InvalidApplicationException { + this.disableTenantFilters(); + + if (!this.tenantScope.isSet()) return; + + if (!this.tenantScope.isDefaultTenant()) { + this.entityManager + .unwrap(Session.class) + .enableFilter(TenantScopedBaseEntity.TENANT_FILTER_EXPLICT) + .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenantScope.getTenant().toString()); + } else { + this.entityManager + .unwrap(Session.class) + .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + } + } + + public void disableTenantFilters() { this.entityManager .unwrap(Session.class) .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); @@ -103,14 +133,17 @@ public class TenantEntityManager { this.entityManager .unwrap(Session.class) .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + + this.entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER_EXPLICT); } - + public EntityManager getEntityManager() { - return entityManager; + return this.entityManager; } public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; } - } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantFilterAspect.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantFilterAspect.java index 1f5338325..32f63706e 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantFilterAspect.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantFilterAspect.java @@ -1,44 +1,44 @@ -package gr.cite.annotation.data.tenant; - -import gr.cite.annotation.common.scope.tenant.TenantScope; -import jakarta.persistence.EntityManager; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Aspect; -import org.hibernate.Session; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.management.InvalidApplicationException; - -@Aspect -@Component -public class TenantFilterAspect { - - private final TenantScope tenantScope; - - @Autowired - public TenantFilterAspect( - TenantScope tenantScope - ) { - this.tenantScope = tenantScope; - } - - @AfterReturning( - pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))", - returning = "retVal") - public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException { - if (retVal instanceof EntityManager && tenantScope.isSet()) { - Session session = ((EntityManager) retVal).unwrap(Session.class); - if(!tenantScope.isDefaultTenant()) { - session - .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); - } else { - session - .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); - } - } - } - -} +//package gr.cite.annotation.data.tenant; +// +//import gr.cite.annotation.common.scope.tenant.TenantScope; +//import jakarta.persistence.EntityManager; +//import org.aspectj.lang.JoinPoint; +//import org.aspectj.lang.annotation.AfterReturning; +//import org.aspectj.lang.annotation.Aspect; +//import org.hibernate.Session; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Component; +// +//import javax.management.InvalidApplicationException; +// +//@Aspect +//@Component +//public class TenantFilterAspect { +// +// private final TenantScope tenantScope; +// +// @Autowired +// public TenantFilterAspect( +// TenantScope tenantScope +// ) { +// this.tenantScope = tenantScope; +// } +// +// @AfterReturning( +// pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))", +// returning = "retVal") +// public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException { +// if (retVal instanceof EntityManager && tenantScope.isSet()) { +// Session session = ((EntityManager) retVal).unwrap(Session.class); +// if(!tenantScope.isDefaultTenant()) { +// session +// .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) +// .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); +// } else { +// session +// .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); +// } +// } +// } +// +//} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantScopedBaseEntity.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantScopedBaseEntity.java index c34be941e..14dd7f4fb 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantScopedBaseEntity.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/tenant/TenantScopedBaseEntity.java @@ -16,22 +16,25 @@ import java.util.UUID; //@Getter //@Setter //@NoArgsConstructor -@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER, parameters = {@ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class)}) +@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER, parameters = @ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class)) +@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER_EXPLICT, parameters = @ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class)) @FilterDef(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER) -@Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)") @Filter(name = TenantScopedBaseEntity.TENANT_FILTER, condition = "(tenant = (cast(:tenantId as uuid)) or tenant is null)") +@Filter(name = TenantScopedBaseEntity.TENANT_FILTER_EXPLICT, condition = "(tenant = (cast(:tenantId as uuid)))") +@Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)") @EntityListeners(TenantListener.class) public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable { private static final long serialVersionUID = 1L; public static final String TENANT_FILTER = "tenantFilter"; public static final String DEFAULT_TENANT_FILTER = "defaultTenantFilter"; + public static final String TENANT_FILTER_EXPLICT = "tenantFilterExplict"; public static final String TENANT_FILTER_TENANT_PARAM = "tenantId"; @Column(name = "tenant", columnDefinition = "uuid", nullable = true) private UUID tenantId; public static final String _tenantId = "tenantId"; public UUID getTenantId() { - return tenantId; + return this.tenantId; } @Override diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/InboxIntegrationEventConfigurer.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/InboxIntegrationEventConfigurer.java index cf81badb5..f8fa89d4b 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/InboxIntegrationEventConfigurer.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/InboxIntegrationEventConfigurer.java @@ -4,6 +4,7 @@ import gr.cite.annotation.integrationevent.inbox.InboxProperties; import gr.cite.annotation.integrationevent.inbox.InboxRepositoryImpl; import gr.cite.queueinbox.InboxConfigurer; import gr.cite.queueinbox.repository.InboxRepository; +import jakarta.persistence.EntityManagerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; @@ -15,18 +16,20 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(prefix = "queue.task.listener", name = "enable", matchIfMissing = false) public class InboxIntegrationEventConfigurer extends InboxConfigurer { - private ApplicationContext applicationContext; + private final ApplicationContext applicationContext; - private InboxProperties inboxProperties; + private final InboxProperties inboxProperties; - public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) { + private final EntityManagerFactory entityManagerFactory; + public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory) { this.applicationContext = applicationContext; this.inboxProperties = inboxProperties; + this.entityManagerFactory = entityManagerFactory; } @Bean public InboxRepository inboxRepositoryCreator() { - return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties); + return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties, this.entityManagerFactory); } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/OutboxIntegrationEventConfigurer.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/OutboxIntegrationEventConfigurer.java index 52602ad8f..15a0bed4e 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/OutboxIntegrationEventConfigurer.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/OutboxIntegrationEventConfigurer.java @@ -9,6 +9,7 @@ import gr.cite.queueoutbox.repository.OutboxRepository; import gr.cite.rabbitmq.IntegrationEventMessageConstants; import gr.cite.rabbitmq.RabbitProperties; import gr.cite.rabbitmq.broker.MessageHydrator; +import jakarta.persistence.EntityManagerFactory; import org.springframework.amqp.core.MessageProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -25,12 +26,14 @@ import java.util.UUID; @EnableConfigurationProperties({OutboxProperties.class}) @ConditionalOnProperty(prefix = "queue.task.publisher", name = "enable", matchIfMissing = false) public class OutboxIntegrationEventConfigurer extends OutboxConfigurer { - private ApplicationContext applicationContext; - private OutboxProperties outboxProperties; + private final ApplicationContext applicationContext; + private final OutboxProperties outboxProperties; + private final EntityManagerFactory entityManagerFactory; - public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties) { + public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory) { this.applicationContext = applicationContext; this.outboxProperties = outboxProperties; + this.entityManagerFactory = entityManagerFactory; } @Bean @@ -66,7 +69,7 @@ public class OutboxIntegrationEventConfigurer extends OutboxConfigurer { @Bean public OutboxRepository outboxRepositoryCreator() { - return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties); + return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties, this.entityManagerFactory); } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java index ce2831fd8..f13222728 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java @@ -44,13 +44,15 @@ public class InboxRepositoryImpl implements InboxRepository { private final JsonHandlingService jsonHandlingService; private final InboxProperties inboxProperties; + private final EntityManagerFactory entityManagerFactory; public InboxRepositoryImpl( - ApplicationContext applicationContext, - InboxProperties inboxProperties + ApplicationContext applicationContext, + InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory ) { this.applicationContext = applicationContext; - this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class); + this.entityManagerFactory = entityManagerFactory; + this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class); this.inboxProperties = inboxProperties; } @@ -62,8 +64,7 @@ public class InboxRepositoryImpl implements InboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -120,9 +121,7 @@ public class InboxRepositoryImpl implements InboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -166,9 +165,7 @@ public class InboxRepositoryImpl implements InboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -214,9 +211,8 @@ public class InboxRepositoryImpl implements InboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { queueMessage = this.createQueueInboxEntity(inboxCreatorParams); - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -275,9 +271,7 @@ public class InboxRepositoryImpl implements InboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiesremoval/AnnotationEntitiesRemovalIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiesremoval/AnnotationEntitiesRemovalIntegrationEventHandlerImpl.java index 35214a3d1..72a04485e 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiesremoval/AnnotationEntitiesRemovalIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiesremoval/AnnotationEntitiesRemovalIntegrationEventHandlerImpl.java @@ -22,13 +22,8 @@ import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.validation.ValidatorFactory; -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; -import jakarta.persistence.EntityTransaction; -import jakarta.persistence.OptimisticLockException; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -80,16 +75,16 @@ public class AnnotationEntitiesRemovalIntegrationEventHandlerImpl implements Ann EventProcessingStatus status = EventProcessingStatus.Success; try { 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)); + 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.getEntityManager(), properties.getTenantId(), tenant.getCode()); + 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.getEntityManager(), null, this.tenantScope.getDefaultTenantCode()); + this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); } @@ -117,9 +112,9 @@ public class AnnotationEntitiesRemovalIntegrationEventHandlerImpl implements Ann logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); try { - this.tenantEntityManager.enableTenantFilters(); + tenantScope.removeTempTenant(this.tenantEntityManager); + this.tenantEntityManager.reloadTenantFilters(); } catch (InvalidApplicationException e) { } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiestouch/AnnotationEntitiesTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiestouch/AnnotationEntitiesTouchedIntegrationEventHandlerImpl.java index fa3c1d6e9..1a6b06be0 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiestouch/AnnotationEntitiesTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitiestouch/AnnotationEntitiesTouchedIntegrationEventHandlerImpl.java @@ -3,7 +3,6 @@ package gr.cite.annotation.integrationevent.inbox.annotationentitiestouch; import gr.cite.annotation.audit.AuditableAction; import gr.cite.annotation.common.JsonHandlingService; import gr.cite.annotation.common.enums.IsActive; -import gr.cite.annotation.common.scope.fake.FakeRequestScope; import gr.cite.annotation.common.scope.tenant.TenantScope; import gr.cite.annotation.data.EntityUserEntity; import gr.cite.annotation.data.TenantEntity; @@ -14,7 +13,6 @@ import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; import gr.cite.annotation.model.Tenant; import gr.cite.annotation.query.EntityUserQuery; import gr.cite.annotation.query.TenantQuery; -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; @@ -23,13 +21,8 @@ import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.validation.ValidatorFactory; -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; -import jakarta.persistence.EntityTransaction; -import jakarta.persistence.OptimisticLockException; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -81,16 +74,16 @@ public class AnnotationEntitiesTouchedIntegrationEventHandlerImpl implements Ann EventProcessingStatus status = EventProcessingStatus.Success; try { 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)); + 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.getEntityManager(), properties.getTenantId(), tenant.getCode()); + 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.getEntityManager(), null, this.tenantScope.getDefaultTenantCode()); + this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); } currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); @@ -136,9 +129,9 @@ public class AnnotationEntitiesTouchedIntegrationEventHandlerImpl implements Ann logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); try { - this.tenantEntityManager.enableTenantFilters(); + tenantScope.removeTempTenant(this.tenantEntityManager); + this.tenantEntityManager.reloadTenantFilters(); } catch (InvalidApplicationException e) { } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalConsistencyHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalConsistencyHandler.java index 96b0f51a7..f895eed8c 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalConsistencyHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenantremoval/TenantRemovalConsistencyHandler.java @@ -19,7 +19,7 @@ public class TenantRemovalConsistencyHandler implements ConsistencyHandler 0; } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyHandler.java index d1699bd97..d4340e0bb 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/userremoval/UserRemovalConsistencyHandler.java @@ -19,7 +19,7 @@ public class UserRemovalConsistencyHandler implements ConsistencyHandler specifications(UserCredential item) { - return Arrays.asList( - this.spec() - .must(() -> !this.isEmpty(item.getSubjectId())) - .failOn(UserCredential._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserCredential._subjectId}, LocaleContextHolder.getLocale())) + return Collections.singletonList( + this.spec() + .must(() -> !this.isEmpty(item.getSubjectId())) + .failOn(UserCredential._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserCredential._subjectId}, LocaleContextHolder.getLocale())) ); } } @@ -272,10 +273,10 @@ public class UserTouchedIntegrationEvent extends TrackedEvent { @Override protected List specifications(TenantUser item) { - return Arrays.asList( - this.spec() - .must(() -> !this.isNull(item.getTenant())) - .failOn(TenantUser._tenant).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantUser._tenant}, LocaleContextHolder.getLocale())) + return Collections.singletonList( + this.spec() + .must(() -> !this.isNull(item.getTenant())) + .failOn(TenantUser._tenant).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantUser._tenant}, LocaleContextHolder.getLocale())) ); } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java index a338db5f7..a7d87971b 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import javax.management.InvalidApplicationException; import java.util.AbstractMap; import java.util.Map; @@ -71,16 +72,16 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr EventProcessingStatus status = EventProcessingStatus.Success; try { 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)); + 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.getEntityManager(), properties.getTenantId(), tenant.getCode()); + 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.getEntityManager(), null, this.tenantScope.getDefaultTenantCode()); + this.tenantScope.setTempTenant(tenantEntityManager, null, this.tenantScope.getDefaultTenantCode()); } currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties)); @@ -96,7 +97,11 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } finally { currentPrincipalResolver.pop(); - tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); + try { + tenantScope.removeTempTenant(this.tenantEntityManager); + } catch (InvalidApplicationException e) { + logger.error(e.getMessage(), e); + } } return status; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/outbox/OutboxRepositoryImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/outbox/OutboxRepositoryImpl.java index 5ce77cb02..4ec9735c3 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/outbox/OutboxRepositoryImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/outbox/OutboxRepositoryImpl.java @@ -33,17 +33,16 @@ public class OutboxRepositoryImpl implements OutboxRepository { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class)); - private final JsonHandlingService jsonHandlingService; - private final OutboxProperties outboxProperties; - + private final EntityManagerFactory entityManagerFactory; + public OutboxRepositoryImpl( ApplicationContext applicationContext, - OutboxProperties outboxProperties + OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory ) { this.applicationContext = applicationContext; - this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class); this.outboxProperties = outboxProperties; + this.entityManagerFactory = entityManagerFactory; } @Override @@ -54,8 +53,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -115,9 +113,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -161,9 +157,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -209,9 +203,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -265,9 +257,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -309,9 +299,7 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); @@ -353,9 +341,8 @@ public class OutboxRepositoryImpl implements OutboxRepository { try (FakeRequestScope ignored = new FakeRequestScope()) { try { queueMessage = this.mapEvent((OutboxIntegrationEvent) item); - EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); - entityManager = entityManagerFactory.createEntityManager(); + entityManager = this.entityManagerFactory.createEntityManager(); transaction = entityManager.getTransaction(); transaction.begin(); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/AnnotationBuilder.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/AnnotationBuilder.java index 2e57b962f..9228a7d3a 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/AnnotationBuilder.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/AnnotationBuilder.java @@ -100,7 +100,7 @@ public class AnnotationBuilder extends BaseBuilder .map(AnnotationEntity::getSubjectId) .distinct() .collect(Collectors.toList()); - UserQuery query = this.queryFactory.query(UserQuery.class).ids(userIds); + UserQuery query = this.queryFactory.query(UserQuery.class).disableTracking().ids(userIds); Map> users = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, User::getId); users.forEach((key, val) -> { diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/BaseBuilder.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/BaseBuilder.java index 00f27ee18..bc9e04835 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/BaseBuilder.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/builder/BaseBuilder.java @@ -33,7 +33,7 @@ public abstract class BaseBuilder implements Builder { M model = null; return null; //TODO } - List models = this.build(directives, Arrays.asList(data)); + List models = this.build(directives, List.of(data)); return models.stream().findFirst().orElse(null); //TODO } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/AnnotationQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/AnnotationQuery.java index f217b462c..90b83f788 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/AnnotationQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/AnnotationQuery.java @@ -8,7 +8,6 @@ import gr.cite.annotation.common.scope.user.UserScope; import gr.cite.annotation.data.AnnotationEntity; import gr.cite.annotation.data.EntityUserEntity; import gr.cite.annotation.model.Annotation; -import gr.cite.annotation.model.EntityUser; import gr.cite.annotation.query.utils.BuildSubQueryInput; import gr.cite.annotation.query.utils.QueryUtilsService; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -175,6 +174,16 @@ public class AnnotationQuery extends QueryBase { return this; } + public AnnotationQuery enableTracking() { + this.noTracking = false; + return this; + } + + public AnnotationQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Boolean isFalseQuery() { return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java index 6b309a7cc..c21138867 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java @@ -29,9 +29,9 @@ public class EntityUserQuery extends QueryBase { private Collection ids, entityIds, userIds; - private Collection isActives;; + private Collection isActives; - private final AuthorizationService authService; + private final AuthorizationService authService; private final UserScope userScope; @@ -107,6 +107,16 @@ public class EntityUserQuery extends QueryBase { return this; } + public EntityUserQuery enableTracking() { + this.noTracking = false; + return this; + } + + public EntityUserQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Boolean isFalseQuery() { return false; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueInboxQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueInboxQuery.java index c99534127..b96a1be0a 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueInboxQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueInboxQuery.java @@ -120,6 +120,16 @@ public class QueueInboxQuery extends QueryBase { return this; } + public QueueInboxQuery enableTracking() { + this.noTracking = false; + return this; + } + + public QueueInboxQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Class entityClass() { return QueueInboxEntity.class; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueOutboxQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueOutboxQuery.java index a6083fa61..58d4d2cfe 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueOutboxQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/QueueOutboxQuery.java @@ -125,6 +125,16 @@ public class QueueOutboxQuery extends QueryBase { return this; } + public QueueOutboxQuery enableTracking() { + this.noTracking = false; + return this; + } + + public QueueOutboxQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Class entityClass() { return QueueOutboxEntity.class; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantQuery.java index b0d02ba5e..1f3aaa200 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantQuery.java @@ -68,6 +68,16 @@ public class TenantQuery extends QueryBase { return this; } + public TenantQuery enableTracking() { + this.noTracking = false; + return this; + } + + public TenantQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Boolean isFalseQuery() { return this.isEmpty(this.ids) || this.isEmpty(this.isActives); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantUserQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantUserQuery.java index 1fb4acef9..5f78245bd 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantUserQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/TenantUserQuery.java @@ -114,6 +114,16 @@ public class TenantUserQuery extends QueryBase { return this; } + public TenantUserQuery enableTracking() { + this.noTracking = false; + return this; + } + + public TenantUserQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Class entityClass() { return TenantUserEntity.class; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserCredentialQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserCredentialQuery.java index 014582bf8..08bf1ea88 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserCredentialQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserCredentialQuery.java @@ -125,6 +125,16 @@ public class UserCredentialQuery extends QueryBase { return this; } + public UserCredentialQuery enableTracking() { + this.noTracking = false; + return this; + } + + public UserCredentialQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Boolean isFalseQuery() { return diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java index 1e6ac6e4c..7d81d9863 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java @@ -84,6 +84,16 @@ public class UserQuery extends QueryBase { return this; } + public UserQuery enableTracking() { + this.noTracking = false; + return this; + } + + public UserQuery disableTracking() { + this.noTracking = false; + return this; + } + @Override protected Class entityClass() { return UserEntity.class; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/annotation/AnnotationServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/annotation/AnnotationServiceImpl.java index f9aa5815e..7efc4e6f8 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/annotation/AnnotationServiceImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/annotation/AnnotationServiceImpl.java @@ -23,7 +23,6 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import jakarta.transaction.Transactional; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -69,7 +68,6 @@ public class AnnotationServiceImpl implements AnnotationService { } @Override - @Transactional public Annotation persist(AnnotationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException { logger.debug(new MapLogEntry("persisting annotation").And("model", model).And("fields", fields)); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java index 880d0b479..9c1339f2c 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java @@ -30,7 +30,6 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import jakarta.transaction.Transactional; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -85,7 +84,6 @@ public class UserServiceImpl implements UserService { } @Override - @Transactional 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)); @@ -185,7 +183,7 @@ public class UserServiceImpl implements UserService { try { TenantEntity tenant = tenantEntities.stream().filter(x -> x.getId().equals(model.getTenant())).findFirst().orElse(null); if (tenant == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getTenant(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale())); - this.tenantScope.setTempTenant(this.entityManager.getEntityManager(), tenant.getId(), tenant.getCode()); + this.tenantScope.setTempTenant(this.entityManager, tenant.getId(), tenant.getCode()); data = new TenantUserEntity(); data.setId(UUID.randomUUID()); data.setUserId(userId); @@ -195,7 +193,7 @@ public class UserServiceImpl implements UserService { data.setIsActive(IsActive.Active); entityManager.persist(data); } finally { - this.tenantScope.removeTempTenant(this.entityManager.getEntityManager()); + this.tenantScope.removeTempTenant(this.entityManager); } } updatedCreatedIds.add(data.getId()); diff --git a/annotation-service/pom.xml b/annotation-service/pom.xml index 707d22518..76a693429 100644 --- a/annotation-service/pom.xml +++ b/annotation-service/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.2.5 @@ -43,7 +43,7 @@ org.hibernate.orm hibernate-core compile - 6.3.1.Final + 6.5.2.Final org.hibernate.orm @@ -71,7 +71,7 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.3 + 2.17.0 @@ -107,7 +107,7 @@ gr.cite data-tools - 2.1.2 + 2.1.4 @@ -119,7 +119,7 @@ gr.cite validation - 3.0.2 + 3.0.3 @@ -149,6 +149,12 @@ queue-outbox 2.1.1 + + + gr.cite + cache + 2.2.0 + diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/PageEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/PageEntity.java index 0313f713a..59f827790 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/PageEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/PageEntity.java @@ -20,7 +20,7 @@ public class PageEntity { private List sections; public List getSections() { - return sections; + return this.sections; } public void setSections(List sections) { @@ -28,7 +28,7 @@ public class PageEntity { } public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -36,7 +36,7 @@ public class PageEntity { } public int getOrdinal() { - return ordinal; + return this.ordinal; } public void setOrdinal(int ordinal) { @@ -44,7 +44,7 @@ public class PageEntity { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java index fb7c7a443..c79dc0155 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java @@ -76,7 +76,7 @@ public class InAppNotificationController { this.censorFactory.censor(InAppNotificationCensor.class).censor(lookup.getProject(), userId); if (userId == null) throw new MyForbiddenException(this.errors.getNonPersonPrincipal().getCode(), this.errors.getNonPersonPrincipal().getMessage()); - InAppNotificationQuery query = lookup.enrich(this.queryFactory).userId(userId); + InAppNotificationQuery query = lookup.enrich(this.queryFactory).disableTracking().userId(userId); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(InAppNotificationBuilder.class).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); @@ -88,7 +88,7 @@ public class InAppNotificationController { @GetMapping("{id}") @Transactional - public InAppNotification Get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { + public InAppNotification Get(@PathVariable UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { logger.debug(new MapLogEntry("retrieving" + InAppNotification.class.getSimpleName()).And("id", id).And("fields", fieldSet)); UUID userId = this.userScope.getUserId(); diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationController.java index 0cc2889da..abd8b9607 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationController.java @@ -64,7 +64,7 @@ public class NotificationController { this.censorFactory.censor(NotificationCensor.class).censor(lookup.getProject()); - NotificationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); + NotificationQuery query = lookup.enrich(this.queryFactory).disableTracking().authorize(AuthorizationFlags.OwnerOrPermission); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(NotificationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationTemplateController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationTemplateController.java index 44bd2482d..eb4cf3f45 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationTemplateController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/NotificationTemplateController.java @@ -65,7 +65,7 @@ public class NotificationTemplateController { this.censorFactory.censor(NotificationTemplateCensor.class).censor(lookup.getProject()); - NotificationTemplateQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); + NotificationTemplateQuery query = lookup.enrich(this.queryFactory).disableTracking().authorize(AuthorizationFlags.OwnerOrPermission); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(NotificationTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/PrincipalController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/PrincipalController.java index 21438e8cd..71b1dfd47 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/PrincipalController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/PrincipalController.java @@ -29,18 +29,15 @@ public class PrincipalController { private final CurrentPrincipalResolver currentPrincipalResolver; private final AccountBuilder accountBuilder; - private final ClaimExtractor claimExtractor; @Autowired public PrincipalController( CurrentPrincipalResolver currentPrincipalResolver, AccountBuilder accountBuilder, - AuditService auditService, - ClaimExtractor claimExtractor) { + AuditService auditService) { this.currentPrincipalResolver = currentPrincipalResolver; this.accountBuilder = accountBuilder; this.auditService = auditService; - this.claimExtractor = claimExtractor; } @GetMapping("me") diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java index 359d9b586..bfd19884a 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java @@ -86,7 +86,7 @@ public class TenantConfigurationController { this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null); - TenantConfigurationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); + TenantConfigurationQuery query = lookup.enrich(this.queryFactory).disableTracking().authorize(AuthorizationFlags.OwnerOrPermission); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java index 35f37a802..22a46598f 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java @@ -76,7 +76,7 @@ public class UserNotificationPreferenceController { this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(lookup.getProject(), null); - UserNotificationPreferenceQuery query = lookup.enrich(this.queryFactory); + UserNotificationPreferenceQuery query = lookup.enrich(this.queryFactory).disableTracking(); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); diff --git a/notification-service/pom.xml b/notification-service/pom.xml index 5b7f1b0f5..76f3dc093 100644 --- a/notification-service/pom.xml +++ b/notification-service/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.2.5 @@ -43,7 +43,7 @@ org.hibernate.orm hibernate-core compile - 6.3.1.Final + 6.5.2.Final org.hibernate.orm @@ -71,7 +71,7 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.3 + 2.17.0 @@ -107,7 +107,7 @@ gr.cite data-tools - 2.1.2 + 2.1.4 @@ -119,7 +119,7 @@ gr.cite validation - 3.0.2 + 3.0.3