annotation fixes

This commit is contained in:
Efstratios Giannopoulos 2024-05-28 17:11:42 +03:00
parent f770de9b30
commit f152dd7b4a
47 changed files with 319 additions and 279 deletions

View File

@ -150,7 +150,7 @@ public class GlobalExceptionHandler {
Map.entry("error", "System error") Map.entry("error", "System error")
); );
} }
}; }
String serialization = this.jsonHandlingService.toJsonSafe(result); String serialization = this.jsonHandlingService.toJsonSafe(result);
return new HandledException(statusCode, serialization, logLevel); return new HandledException(statusCode, serialization, logLevel);
} }

View File

@ -72,7 +72,7 @@ public class AnnotationController {
this.censorFactory.censor(AnnotationCensor.class).censor(lookup.getProject(), null); 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<AnnotationEntity> data = query.collect(); List<AnnotationEntity> data = query.collect();
List<Annotation> models = this.builderFactory.builder(AnnotationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionAssociated).build(lookup.getProject(), data); List<Annotation> 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(); 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); 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)); Annotation model = this.builderFactory.builder(AnnotationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionAssociated).build(fieldSet, query.firstAs(fieldSet));
if (model == null) if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Annotation.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Annotation.class.getSimpleName()}, LocaleContextHolder.getLocale()));

View File

@ -30,18 +30,15 @@ public class PrincipalController {
private final CurrentPrincipalResolver currentPrincipalResolver; private final CurrentPrincipalResolver currentPrincipalResolver;
private final AccountBuilder accountBuilder; private final AccountBuilder accountBuilder;
private final ClaimExtractor claimExtractor;
@Autowired @Autowired
public PrincipalController( public PrincipalController(
CurrentPrincipalResolver currentPrincipalResolver, CurrentPrincipalResolver currentPrincipalResolver,
AccountBuilder accountBuilder, AccountBuilder accountBuilder,
AuditService auditService, AuditService auditService) {
ClaimExtractor claimExtractor) {
this.currentPrincipalResolver = currentPrincipalResolver; this.currentPrincipalResolver = currentPrincipalResolver;
this.accountBuilder = accountBuilder; this.accountBuilder = accountBuilder;
this.auditService = auditService; this.auditService = auditService;
this.claimExtractor = claimExtractor;
} }
@GetMapping("me") @GetMapping("me")
@ -76,17 +73,4 @@ public class PrincipalController {
} }
@GetMapping("my-tenants")
public List<String> myTenants() {
logger.debug("my-tenants");
MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal();
List<String> 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());
}
} }

View File

@ -6,6 +6,7 @@ import gr.cite.annotation.authorization.Permission;
import gr.cite.annotation.common.enums.IsActive; 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.common.scope.user.UserScope; 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.TenantUserEntity;
import gr.cite.annotation.data.UserEntity; import gr.cite.annotation.data.UserEntity;
import gr.cite.annotation.data.tenant.TenantScopedBaseEntity; import gr.cite.annotation.data.tenant.TenantScopedBaseEntity;
@ -52,6 +53,7 @@ public class TenantInterceptor implements WebRequestInterceptor {
private final UserAllowedTenantCacheService userAllowedTenantCacheService; private final UserAllowedTenantCacheService userAllowedTenantCacheService;
private final ErrorThesaurusProperties errors; private final ErrorThesaurusProperties errors;
private final QueryUtilsService queryUtilsService; private final QueryUtilsService queryUtilsService;
public final TenantEntityManager tenantEntityManager;
@PersistenceContext @PersistenceContext
public EntityManager entityManager; public EntityManager entityManager;
@ -64,7 +66,7 @@ public class TenantInterceptor implements WebRequestInterceptor {
ApplicationContext applicationContext, ApplicationContext applicationContext,
TenantScopeProperties tenantScopeProperties, TenantScopeProperties tenantScopeProperties,
UserAllowedTenantCacheService userAllowedTenantCacheService, UserAllowedTenantCacheService userAllowedTenantCacheService,
ErrorThesaurusProperties errors, QueryUtilsService queryUtilsService) { ErrorThesaurusProperties errors, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
this.tenantScope = tenantScope; this.tenantScope = tenantScope;
this.userScope = userScope; this.userScope = userScope;
this.currentPrincipalResolver = currentPrincipalResolver; this.currentPrincipalResolver = currentPrincipalResolver;
@ -74,6 +76,7 @@ public class TenantInterceptor implements WebRequestInterceptor {
this.userAllowedTenantCacheService = userAllowedTenantCacheService; this.userAllowedTenantCacheService = userAllowedTenantCacheService;
this.errors = errors; this.errors = errors;
this.queryUtilsService = queryUtilsService; this.queryUtilsService = queryUtilsService;
this.tenantEntityManager = tenantEntityManager;
} }
@Override @Override
@ -103,16 +106,7 @@ public class TenantInterceptor implements WebRequestInterceptor {
} }
if (isUserAllowedTenant) { if (isUserAllowedTenant) {
if(!tenantScope.isDefaultTenant()) { this.tenantEntityManager.reloadTenantFilters();
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);
}
} else { } else {
if (isAllowedNoTenant || this.isWhiteListedEndpoint(request)) { if (isAllowedNoTenant || this.isWhiteListedEndpoint(request)) {
tenantScope.setTenant(null, null); tenantScope.setTenant(null, null);
@ -181,8 +175,8 @@ public class TenantInterceptor implements WebRequestInterceptor {
@Override @Override
public void postHandle(@NonNull WebRequest request, ModelMap model) { public void postHandle(@NonNull WebRequest request, ModelMap model) {
this.tenantScope.setTenant(null, null); this.tenantScope.setTenant(null, null);
this.tenantEntityManager.disableTenantFilters();
} }
@Override @Override
public void afterCompletion(@NonNull WebRequest request, Exception ex) { public void afterCompletion(@NonNull WebRequest request, Exception ex) {
} }

View File

@ -63,7 +63,7 @@ public class UserInterceptor implements WebRequestInterceptor {
this.userScope.setUserId(userId); this.userScope.setUserId(userId);
} }
private UUID findExistingUserFromDb(String subjectId) { 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) { if (userCredential != null) {
return userCredential.getUserId(); return userCredential.getUserId();
} }

View File

@ -77,7 +77,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>exceptions</artifactId> <artifactId>exceptions</artifactId>
<version>1.0.0</version> <version>2.1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
@ -93,7 +93,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>cipher</artifactId> <artifactId>cipher</artifactId>
<version>1.0.0</version> <version>2.1.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -48,7 +48,7 @@ public class AuthorizationContentResolverImpl implements AuthorizationContentRes
List<UUID> idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity._entityId); List<UUID> idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity._entityId);
if (idsToResolve.isEmpty()) return affiliatedResources; if (idsToResolve.isEmpty()) return affiliatedResources;
List<EntityUserEntity> entityUsers = this.queryFactory.query(EntityUserQuery.class).entityIds(ids).userIds(userId).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(EntityUser._id).ensure(EntityUser._entityId)); List<EntityUserEntity> 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()){ for (UUID entityId : entityUsers.stream().map(EntityUserEntity::getEntityId).distinct().toList()){
affiliatedResources.get(entityId).setAffiliated(true); affiliatedResources.get(entityId).setAffiliated(true);
@ -79,8 +79,8 @@ public class AuthorizationContentResolverImpl implements AuthorizationContentRes
List<UUID> idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity.class.getSimpleName()); List<UUID> idsToResolve = this.getAffiliatedFromCache(ids, userId, affiliatedResources, AnnotationEntity.class.getSimpleName());
if (idsToResolve.isEmpty()) return affiliatedResources; if (idsToResolve.isEmpty()) return affiliatedResources;
List<AnnotationEntity> annotationEntities = this.queryFactory.query(AnnotationQuery.class).ids(ids).collectAs(new BaseFieldSet().ensure(Annotation._id).ensure(Annotation._entityId).ensure(Annotation._id)); List<AnnotationEntity> annotationEntities = this.queryFactory.query(AnnotationQuery.class).disableTracking().ids(ids).collectAs(new BaseFieldSet().ensure(Annotation._id).ensure(Annotation._entityId).ensure(Annotation._id));
List<EntityUserEntity> 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<EntityUserEntity> 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<UUID, List<EntityUserEntity>> dmpUsersMap = entityUsers.stream().collect(Collectors.groupingBy(EntityUserEntity::getEntityId)); Map<UUID, List<EntityUserEntity>> dmpUsersMap = entityUsers.stream().collect(Collectors.groupingBy(EntityUserEntity::getEntityId));
for (AnnotationEntity annotation : annotationEntities){ for (AnnotationEntity annotation : annotationEntities){

View File

@ -70,7 +70,7 @@ public class XmlHandlingService {
public <T> T fromXml(Class<T> type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { public <T> T fromXml(Class<T> type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException {
if (XmlSerializable.class.isAssignableFrom(type)){ if (XmlSerializable.class.isAssignableFrom(type)){
XmlSerializable<T> object = (XmlSerializable<T>)type.newInstance(); XmlSerializable<T> object = (XmlSerializable<T>)type.newInstance();
return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement()); return object.fromXml(this.getDocument(xmlString).getDocumentElement());
} else { } else {
JAXBContext jaxbContext = JAXBContext.newInstance(type); JAXBContext jaxbContext = JAXBContext.newInstance(type);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

View File

@ -25,7 +25,7 @@ public class LockByKeyManager {
} }
private static ConcurrentHashMap<String, LockWrapper> locks = new ConcurrentHashMap<String, LockWrapper>(); private static final ConcurrentHashMap<String, LockWrapper> locks = new ConcurrentHashMap<String, LockWrapper>();
public void lock(String key) { public void lock(String key) {
LockWrapper lockWrapper = locks.compute(key, (k, v) -> v == null ? new LockWrapper() : v.addThreadInQueue()); LockWrapper lockWrapper = locks.compute(key, (k, v) -> v == null ? new LockWrapper() : v.addThreadInQueue());

View File

@ -8,7 +8,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class FakeRequestAttributes implements RequestAttributes { public class FakeRequestAttributes implements RequestAttributes {
private Map<String, Object> requestAttributeMap = new HashMap<>(); private final Map<String, Object> requestAttributeMap = new HashMap<>();
private final Map<String, Runnable> requestDestructionCallbacks = new LinkedHashMap<>(8); private final Map<String, Runnable> requestDestructionCallbacks = new LinkedHashMap<>(8);
private volatile boolean requestActive = true; private volatile boolean requestActive = true;

View File

@ -1,5 +1,6 @@
package gr.cite.annotation.common.scope.tenant; package gr.cite.annotation.common.scope.tenant;
import gr.cite.annotation.data.TenantEntityManager;
import gr.cite.annotation.data.tenant.TenantScopedBaseEntity; import gr.cite.annotation.data.tenant.TenantScopedBaseEntity;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import org.hibernate.Session; import org.hibernate.Session;
@ -27,11 +28,11 @@ public class TenantScope {
} }
public Boolean isMultitenant() { public Boolean isMultitenant() {
return multitenancy.isMultitenant(); return this.multitenancy.isMultitenant();
} }
public String getDefaultTenantCode() { public String getDefaultTenantCode() {
return multitenancy.getDefaultTenantCode(); return this.multitenancy.getDefaultTenantCode();
} }
public Boolean isSet() { public Boolean isSet() {
@ -62,55 +63,18 @@ public class TenantScope {
return this.tenantCode.get(); 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.tenant.set(tenant);
this.tenantCode.set(tenantCode); this.tenantCode.set(tenantCode);
entityManager entityManager.reloadTenantFilters();
.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);
}
}
} }
public void removeTempTenant(EntityManager entityManager) { public void removeTempTenant(TenantEntityManager entityManager) throws InvalidApplicationException {
this.tenant.set(this.initialTenant.get()); this.tenant.set(this.initialTenant.get());
this.tenantCode.set(this.initialTenantCode.get()); this.tenantCode.set(this.initialTenantCode.get());
entityManager.reloadTenantFilters();
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);
}
}
} }
public void setTenant(UUID tenant, String tenantCode) { public void setTenant(UUID tenant, String tenantCode) {
@ -122,6 +86,3 @@ public class TenantScope {
} }
} }
} }

View File

@ -10,6 +10,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -33,10 +34,10 @@ public class UuidValidator extends BaseValidator<UUID> {
@Override @Override
protected List<Specification> specifications(UUID item) { protected List<Specification> specifications(UUID item) {
return Arrays.asList( return Collections.singletonList(
this.spec() this.spec()
.must(() -> this.isValidGuid(item)) .must(() -> this.isValidGuid(item))
.failOn("uuid").failWith(messageSource.getMessage("Validation_Required", new Object[]{"uuid"}, LocaleContextHolder.getLocale())) .failOn("uuid").failWith(messageSource.getMessage("Validation_Required", new Object[]{"uuid"}, LocaleContextHolder.getLocale()))
); );
} }
} }

View File

@ -33,9 +33,9 @@ public class TenantEntityManager {
} }
public <T> T merge(T entity) throws InvalidApplicationException { public <T> T merge(T entity) throws InvalidApplicationException {
if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) {
if (!tenantScope.isDefaultTenant()) { if (!this.tenantScope.isDefaultTenant()) {
if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); 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) { } else if (tenantScopedEntity.getTenantId() != null) {
throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); 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 { public void remove(Object entity) throws InvalidApplicationException {
if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) {
if (!tenantScope.isDefaultTenant()) { if (!this.tenantScope.isDefaultTenant()) {
if (tenantScopedEntity.getTenantId() == null || !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); 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) { } else if (tenantScopedEntity.getTenantId() != null) {
throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage()); throw new MyForbiddenException(this.errors.getTenantTampering().getCode(), this.errors.getTenantTampering().getMessage());
} }
@ -57,12 +57,22 @@ public class TenantEntityManager {
public <T> T find(Class<T> entityClass, Object primaryKey) throws InvalidApplicationException { public <T> T find(Class<T> entityClass, Object primaryKey) throws InvalidApplicationException {
T entity = this.entityManager.find(entityClass, primaryKey); T entity = this.entityManager.find(entityClass, primaryKey);
if (tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) { if (this.tenantScope.isMultitenant() && (entity instanceof TenantScoped tenantScopedEntity)) {
if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(tenantScope.getTenant())) return null; if (tenantScopedEntity.getTenantId() != null && !tenantScopedEntity.getTenantId().equals(this.tenantScope.getTenant())) return null;
} }
return entity; return entity;
} }
public <T> T find(Class<T> 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() { public void flush() {
this.entityManager.flush(); this.entityManager.flush();
} }
@ -81,13 +91,16 @@ public class TenantEntityManager {
this.entityManager.clear(); this.entityManager.clear();
} }
public void enableTenantFilters() throws InvalidApplicationException { public void reloadTenantFilters() throws InvalidApplicationException {
if (!tenantScope.isSet()) return; this.disableTenantFilters();
if(!tenantScope.isDefaultTenant()) {
if (!this.tenantScope.isSet()) return;
if (!this.tenantScope.isDefaultTenant()) {
this.entityManager this.entityManager
.unwrap(Session.class) .unwrap(Session.class)
.enableFilter(TenantScopedBaseEntity.TENANT_FILTER) .enableFilter(TenantScopedBaseEntity.TENANT_FILTER)
.setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenantScope.getTenant().toString());
} else { } else {
this.entityManager this.entityManager
.unwrap(Session.class) .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 this.entityManager
.unwrap(Session.class) .unwrap(Session.class)
.disableFilter(TenantScopedBaseEntity.TENANT_FILTER); .disableFilter(TenantScopedBaseEntity.TENANT_FILTER);
@ -103,14 +133,17 @@ public class TenantEntityManager {
this.entityManager this.entityManager
.unwrap(Session.class) .unwrap(Session.class)
.disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER);
this.entityManager
.unwrap(Session.class)
.disableFilter(TenantScopedBaseEntity.TENANT_FILTER_EXPLICT);
} }
public EntityManager getEntityManager() { public EntityManager getEntityManager() {
return entityManager; return this.entityManager;
} }
public void setEntityManager(EntityManager entityManager) { public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager; this.entityManager = entityManager;
} }
} }

View File

@ -1,44 +1,44 @@
package gr.cite.annotation.data.tenant; //package gr.cite.annotation.data.tenant;
//
import gr.cite.annotation.common.scope.tenant.TenantScope; //import gr.cite.annotation.common.scope.tenant.TenantScope;
import jakarta.persistence.EntityManager; //import jakarta.persistence.EntityManager;
import org.aspectj.lang.JoinPoint; //import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning; //import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect; //import org.aspectj.lang.annotation.Aspect;
import org.hibernate.Session; //import org.hibernate.Session;
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 javax.management.InvalidApplicationException; //import javax.management.InvalidApplicationException;
//
@Aspect //@Aspect
@Component //@Component
public class TenantFilterAspect { //public class TenantFilterAspect {
//
private final TenantScope tenantScope; // private final TenantScope tenantScope;
//
@Autowired // @Autowired
public TenantFilterAspect( // public TenantFilterAspect(
TenantScope tenantScope // TenantScope tenantScope
) { // ) {
this.tenantScope = tenantScope; // this.tenantScope = tenantScope;
} // }
//
@AfterReturning( // @AfterReturning(
pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))", // pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))",
returning = "retVal") // returning = "retVal")
public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException { // public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException {
if (retVal instanceof EntityManager && tenantScope.isSet()) { // if (retVal instanceof EntityManager && tenantScope.isSet()) {
Session session = ((EntityManager) retVal).unwrap(Session.class); // Session session = ((EntityManager) retVal).unwrap(Session.class);
if(!tenantScope.isDefaultTenant()) { // if(!tenantScope.isDefaultTenant()) {
session // session
.enableFilter(TenantScopedBaseEntity.TENANT_FILTER) // .enableFilter(TenantScopedBaseEntity.TENANT_FILTER)
.setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); // .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString());
} else { // } else {
session // session
.enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); // .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER);
} // }
} // }
} // }
//
} //}

View File

@ -16,22 +16,25 @@ import java.util.UUID;
//@Getter //@Getter
//@Setter //@Setter
//@NoArgsConstructor //@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) @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, 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) @EntityListeners(TenantListener.class)
public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable { public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String TENANT_FILTER = "tenantFilter"; public static final String TENANT_FILTER = "tenantFilter";
public static final String DEFAULT_TENANT_FILTER = "defaultTenantFilter"; 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"; public static final String TENANT_FILTER_TENANT_PARAM = "tenantId";
@Column(name = "tenant", columnDefinition = "uuid", nullable = true) @Column(name = "tenant", columnDefinition = "uuid", nullable = true)
private UUID tenantId; private UUID tenantId;
public static final String _tenantId = "tenantId"; public static final String _tenantId = "tenantId";
public UUID getTenantId() { public UUID getTenantId() {
return tenantId; return this.tenantId;
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import gr.cite.annotation.integrationevent.inbox.InboxProperties;
import gr.cite.annotation.integrationevent.inbox.InboxRepositoryImpl; import gr.cite.annotation.integrationevent.inbox.InboxRepositoryImpl;
import gr.cite.queueinbox.InboxConfigurer; import gr.cite.queueinbox.InboxConfigurer;
import gr.cite.queueinbox.repository.InboxRepository; import gr.cite.queueinbox.repository.InboxRepository;
import jakarta.persistence.EntityManagerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -15,18 +16,20 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(prefix = "queue.task.listener", name = "enable", matchIfMissing = false) @ConditionalOnProperty(prefix = "queue.task.listener", name = "enable", matchIfMissing = false)
public class InboxIntegrationEventConfigurer extends InboxConfigurer { 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.applicationContext = applicationContext;
this.inboxProperties = inboxProperties; this.inboxProperties = inboxProperties;
this.entityManagerFactory = entityManagerFactory;
} }
@Bean @Bean
public InboxRepository inboxRepositoryCreator() { public InboxRepository inboxRepositoryCreator() {
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties); return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties, this.entityManagerFactory);
} }
} }

View File

@ -9,6 +9,7 @@ import gr.cite.queueoutbox.repository.OutboxRepository;
import gr.cite.rabbitmq.IntegrationEventMessageConstants; import gr.cite.rabbitmq.IntegrationEventMessageConstants;
import gr.cite.rabbitmq.RabbitProperties; import gr.cite.rabbitmq.RabbitProperties;
import gr.cite.rabbitmq.broker.MessageHydrator; import gr.cite.rabbitmq.broker.MessageHydrator;
import jakarta.persistence.EntityManagerFactory;
import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.core.MessageProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -25,12 +26,14 @@ import java.util.UUID;
@EnableConfigurationProperties({OutboxProperties.class}) @EnableConfigurationProperties({OutboxProperties.class})
@ConditionalOnProperty(prefix = "queue.task.publisher", name = "enable", matchIfMissing = false) @ConditionalOnProperty(prefix = "queue.task.publisher", name = "enable", matchIfMissing = false)
public class OutboxIntegrationEventConfigurer extends OutboxConfigurer { public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
private ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private OutboxProperties outboxProperties; 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.applicationContext = applicationContext;
this.outboxProperties = outboxProperties; this.outboxProperties = outboxProperties;
this.entityManagerFactory = entityManagerFactory;
} }
@Bean @Bean
@ -66,7 +69,7 @@ public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
@Bean @Bean
public OutboxRepository outboxRepositoryCreator() { public OutboxRepository outboxRepositoryCreator() {
return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties); return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties, this.entityManagerFactory);
} }
} }

View File

@ -44,13 +44,15 @@ public class InboxRepositoryImpl implements InboxRepository {
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final InboxProperties inboxProperties; private final InboxProperties inboxProperties;
private final EntityManagerFactory entityManagerFactory;
public InboxRepositoryImpl( public InboxRepositoryImpl(
ApplicationContext applicationContext, ApplicationContext applicationContext,
InboxProperties inboxProperties InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory
) { ) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class); this.entityManagerFactory = entityManagerFactory;
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
this.inboxProperties = inboxProperties; this.inboxProperties = inboxProperties;
} }
@ -62,8 +64,7 @@ public class InboxRepositoryImpl implements InboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -120,9 +121,7 @@ public class InboxRepositoryImpl implements InboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -166,9 +165,7 @@ public class InboxRepositoryImpl implements InboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -214,9 +211,8 @@ public class InboxRepositoryImpl implements InboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
queueMessage = this.createQueueInboxEntity(inboxCreatorParams); queueMessage = this.createQueueInboxEntity(inboxCreatorParams);
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class);
entityManager = entityManagerFactory.createEntityManager(); entityManager = this.entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -275,9 +271,7 @@ public class InboxRepositoryImpl implements InboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class); TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);

View File

@ -22,13 +22,8 @@ import gr.cite.tools.data.query.QueryFactory;
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 gr.cite.tools.validation.ValidatorFactory; 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.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.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -80,16 +75,16 @@ public class AnnotationEntitiesRemovalIntegrationEventHandlerImpl implements Ann
EventProcessingStatus status = EventProcessingStatus.Success; EventProcessingStatus status = EventProcessingStatus.Success;
try { try {
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { 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) { if (tenant == null) {
logger.error("missing tenant from event message"); logger.error("missing tenant from event message");
return EventProcessingStatus.Error; 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()) { } else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message"); // logger.error("missing tenant from event message");
// return EventProcessingStatus.Error; // 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); logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
} finally { } finally {
currentPrincipalResolver.pop(); currentPrincipalResolver.pop();
tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager());
try { try {
this.tenantEntityManager.enableTenantFilters(); tenantScope.removeTempTenant(this.tenantEntityManager);
this.tenantEntityManager.reloadTenantFilters();
} catch (InvalidApplicationException e) { } catch (InvalidApplicationException e) {
} }
} }

View File

@ -3,7 +3,6 @@ package gr.cite.annotation.integrationevent.inbox.annotationentitiestouch;
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.enums.IsActive; 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.common.scope.tenant.TenantScope;
import gr.cite.annotation.data.EntityUserEntity; import gr.cite.annotation.data.EntityUserEntity;
import gr.cite.annotation.data.TenantEntity; 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.model.Tenant;
import gr.cite.annotation.query.EntityUserQuery; import gr.cite.annotation.query.EntityUserQuery;
import gr.cite.annotation.query.TenantQuery; 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.CurrentPrincipalResolver;
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties; import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
import gr.cite.tools.auditing.AuditService; 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.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 jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.OptimisticLockException;
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.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -81,16 +74,16 @@ public class AnnotationEntitiesTouchedIntegrationEventHandlerImpl implements Ann
EventProcessingStatus status = EventProcessingStatus.Success; EventProcessingStatus status = EventProcessingStatus.Success;
try { try {
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { 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) { if (tenant == null) {
logger.error("missing tenant from event message"); logger.error("missing tenant from event message");
return EventProcessingStatus.Error; 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()) { } else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message"); // logger.error("missing tenant from event message");
// return EventProcessingStatus.Error; // 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)); 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); logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
} finally { } finally {
currentPrincipalResolver.pop(); currentPrincipalResolver.pop();
tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager());
try { try {
this.tenantEntityManager.enableTenantFilters(); tenantScope.removeTempTenant(this.tenantEntityManager);
this.tenantEntityManager.reloadTenantFilters();
} catch (InvalidApplicationException e) { } catch (InvalidApplicationException e) {
} }
} }

View File

@ -19,7 +19,7 @@ public class TenantRemovalConsistencyHandler implements ConsistencyHandler<Tenan
@Override @Override
public Boolean isConsistent(TenantRemovalConsistencyPredicates consistencyPredicates) { public Boolean isConsistent(TenantRemovalConsistencyPredicates consistencyPredicates) {
long count = this.queryFactory.query(TenantQuery.class).ids(consistencyPredicates.getTenantId()).count(); long count = this.queryFactory.query(TenantQuery.class).disableTracking().ids(consistencyPredicates.getTenantId()).count();
return count > 0; return count > 0;
} }

View File

@ -19,7 +19,7 @@ public class UserRemovalConsistencyHandler implements ConsistencyHandler<UserRem
@Override @Override
public Boolean isConsistent(UserRemovalConsistencyPredicates consistencyPredicates) { public Boolean isConsistent(UserRemovalConsistencyPredicates consistencyPredicates) {
long count = this.queryFactory.query(UserQuery.class).ids(consistencyPredicates.getUserId()).count(); long count = this.queryFactory.query(UserQuery.class).disableTracking().ids(consistencyPredicates.getUserId()).count();
return count != 0; return count != 0;
} }
} }

View File

@ -26,6 +26,7 @@ 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;
@ -81,16 +82,16 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
EventProcessingStatus status = EventProcessingStatus.Success; EventProcessingStatus status = EventProcessingStatus.Success;
try { try {
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { 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) { if (tenant == null) {
logger.error("missing tenant from event message"); logger.error("missing tenant from event message");
return EventProcessingStatus.Error; 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()) { } else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message"); // logger.error("missing tenant from event message");
// return EventProcessingStatus.Error; // 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)); currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
@ -98,7 +99,7 @@ public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegr
if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) { if (!(userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(event.getUserId())))) {
status = EventProcessingStatus.Postponed; status = EventProcessingStatus.Postponed;
currentPrincipalResolver.pop(); currentPrincipalResolver.pop();
tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); tenantScope.removeTempTenant(this.tenantEntityManager);
return status; return status;
} }
@ -113,7 +114,11 @@ 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();
tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); try {
tenantScope.removeTempTenant(this.tenantEntityManager);
} catch (InvalidApplicationException e) {
logger.error( e.getMessage(), e);
}
} }
return status; return status;

View File

@ -15,6 +15,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -230,10 +231,10 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
@Override @Override
protected List<Specification> specifications(UserCredential item) { protected List<Specification> specifications(UserCredential item) {
return Arrays.asList( return Collections.singletonList(
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getSubjectId())) .must(() -> !this.isEmpty(item.getSubjectId()))
.failOn(UserCredential._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserCredential._subjectId}, LocaleContextHolder.getLocale())) .failOn(UserCredential._subjectId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserCredential._subjectId}, LocaleContextHolder.getLocale()))
); );
} }
} }
@ -272,10 +273,10 @@ public class UserTouchedIntegrationEvent extends TrackedEvent {
@Override @Override
protected List<Specification> specifications(TenantUser item) { protected List<Specification> specifications(TenantUser item) {
return Arrays.asList( return Collections.singletonList(
this.spec() this.spec()
.must(() -> !this.isNull(item.getTenant())) .must(() -> !this.isNull(item.getTenant()))
.failOn(TenantUser._tenant).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantUser._tenant}, LocaleContextHolder.getLocale())) .failOn(TenantUser._tenant).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantUser._tenant}, LocaleContextHolder.getLocale()))
); );
} }
} }

View File

@ -23,6 +23,7 @@ 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;
@ -71,16 +72,16 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
EventProcessingStatus status = EventProcessingStatus.Success; EventProcessingStatus status = EventProcessingStatus.Success;
try { try {
if (this.tenantScope.isMultitenant() && properties.getTenantId() != null) { 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) { if (tenant == null) {
logger.error("missing tenant from event message"); logger.error("missing tenant from event message");
return EventProcessingStatus.Error; 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()) { } else if (this.tenantScope.isMultitenant()) {
// logger.error("missing tenant from event message"); // logger.error("missing tenant from event message");
// return EventProcessingStatus.Error; // 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)); 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); logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
} finally { } finally {
currentPrincipalResolver.pop(); currentPrincipalResolver.pop();
tenantScope.removeTempTenant(this.tenantEntityManager.getEntityManager()); try {
tenantScope.removeTempTenant(this.tenantEntityManager);
} catch (InvalidApplicationException e) {
logger.error(e.getMessage(), e);
}
} }
return status; return status;

View File

@ -33,17 +33,16 @@ public class OutboxRepositoryImpl implements OutboxRepository {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class));
private final JsonHandlingService jsonHandlingService;
private final OutboxProperties outboxProperties; private final OutboxProperties outboxProperties;
private final EntityManagerFactory entityManagerFactory;
public OutboxRepositoryImpl( public OutboxRepositoryImpl(
ApplicationContext applicationContext, ApplicationContext applicationContext,
OutboxProperties outboxProperties OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory
) { ) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
this.outboxProperties = outboxProperties; this.outboxProperties = outboxProperties;
this.entityManagerFactory = entityManagerFactory;
} }
@Override @Override
@ -54,8 +53,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -115,9 +113,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -161,9 +157,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -209,9 +203,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -265,9 +257,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -309,9 +299,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); entityManager = this.entityManagerFactory.createEntityManager();
entityManager = entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();
@ -353,9 +341,8 @@ public class OutboxRepositoryImpl implements OutboxRepository {
try (FakeRequestScope ignored = new FakeRequestScope()) { try (FakeRequestScope ignored = new FakeRequestScope()) {
try { try {
queueMessage = this.mapEvent((OutboxIntegrationEvent) item); queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class);
entityManager = entityManagerFactory.createEntityManager(); entityManager = this.entityManagerFactory.createEntityManager();
transaction = entityManager.getTransaction(); transaction = entityManager.getTransaction();
transaction.begin(); transaction.begin();

View File

@ -100,7 +100,7 @@ public class AnnotationBuilder extends BaseBuilder<Annotation, AnnotationEntity>
.map(AnnotationEntity::getSubjectId) .map(AnnotationEntity::getSubjectId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
UserQuery query = this.queryFactory.query(UserQuery.class).ids(userIds); UserQuery query = this.queryFactory.query(UserQuery.class).disableTracking().ids(userIds);
Map<UUID, List<User>> users = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, User::getId); Map<UUID, List<User>> users = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, User::getId);
users.forEach((key, val) -> { users.forEach((key, val) -> {

View File

@ -33,7 +33,7 @@ public abstract class BaseBuilder<M, D> implements Builder {
M model = null; M model = null;
return null; //TODO return null; //TODO
} }
List<M> models = this.build(directives, Arrays.asList(data)); List<M> models = this.build(directives, List.of(data));
return models.stream().findFirst().orElse(null); //TODO return models.stream().findFirst().orElse(null); //TODO
} }

View File

@ -8,7 +8,6 @@ import gr.cite.annotation.common.scope.user.UserScope;
import gr.cite.annotation.data.AnnotationEntity; import gr.cite.annotation.data.AnnotationEntity;
import gr.cite.annotation.data.EntityUserEntity; import gr.cite.annotation.data.EntityUserEntity;
import gr.cite.annotation.model.Annotation; 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.BuildSubQueryInput;
import gr.cite.annotation.query.utils.QueryUtilsService; import gr.cite.annotation.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
@ -175,6 +174,16 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
return this; return this;
} }
public AnnotationQuery enableTracking() {
this.noTracking = false;
return this;
}
public AnnotationQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds); return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds);

View File

@ -29,9 +29,9 @@ public class EntityUserQuery extends QueryBase<EntityUserEntity> {
private Collection<UUID> ids, entityIds, userIds; private Collection<UUID> ids, entityIds, userIds;
private Collection<IsActive> isActives;; private Collection<IsActive> isActives;
private final AuthorizationService authService; private final AuthorizationService authService;
private final UserScope userScope; private final UserScope userScope;
@ -107,6 +107,16 @@ public class EntityUserQuery extends QueryBase<EntityUserEntity> {
return this; return this;
} }
public EntityUserQuery enableTracking() {
this.noTracking = false;
return this;
}
public EntityUserQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return false; return false;

View File

@ -120,6 +120,16 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
return this; return this;
} }
public QueueInboxQuery enableTracking() {
this.noTracking = false;
return this;
}
public QueueInboxQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Class<QueueInboxEntity> entityClass() { protected Class<QueueInboxEntity> entityClass() {
return QueueInboxEntity.class; return QueueInboxEntity.class;

View File

@ -125,6 +125,16 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
return this; return this;
} }
public QueueOutboxQuery enableTracking() {
this.noTracking = false;
return this;
}
public QueueOutboxQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Class<QueueOutboxEntity> entityClass() { protected Class<QueueOutboxEntity> entityClass() {
return QueueOutboxEntity.class; return QueueOutboxEntity.class;

View File

@ -68,6 +68,16 @@ public class TenantQuery extends QueryBase<TenantEntity> {
return this; return this;
} }
public TenantQuery enableTracking() {
this.noTracking = false;
return this;
}
public TenantQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives); return this.isEmpty(this.ids) || this.isEmpty(this.isActives);

View File

@ -114,6 +114,16 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
return this; return this;
} }
public TenantUserQuery enableTracking() {
this.noTracking = false;
return this;
}
public TenantUserQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Class<TenantUserEntity> entityClass() { protected Class<TenantUserEntity> entityClass() {
return TenantUserEntity.class; return TenantUserEntity.class;

View File

@ -125,6 +125,16 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
return this; return this;
} }
public UserCredentialQuery enableTracking() {
this.noTracking = false;
return this;
}
public UserCredentialQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return return

View File

@ -84,6 +84,16 @@ public class UserQuery extends QueryBase<UserEntity> {
return this; return this;
} }
public UserQuery enableTracking() {
this.noTracking = false;
return this;
}
public UserQuery disableTracking() {
this.noTracking = false;
return this;
}
@Override @Override
protected Class<UserEntity> entityClass() { protected Class<UserEntity> entityClass() {
return UserEntity.class; return UserEntity.class;

View File

@ -23,7 +23,6 @@ import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import jakarta.transaction.Transactional;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -69,7 +68,6 @@ public class AnnotationServiceImpl implements AnnotationService {
} }
@Override @Override
@Transactional
public Annotation persist(AnnotationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException { public Annotation persist(AnnotationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException {
logger.debug(new MapLogEntry("persisting annotation").And("model", model).And("fields", fields)); logger.debug(new MapLogEntry("persisting annotation").And("model", model).And("fields", fields));

View File

@ -30,7 +30,6 @@ import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import jakarta.transaction.Transactional;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -85,7 +84,6 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
@Transactional
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));
@ -185,7 +183,7 @@ public class UserServiceImpl implements UserService {
try { try {
TenantEntity tenant = tenantEntities.stream().filter(x -> x.getId().equals(model.getTenant())).findFirst().orElse(null); 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())); 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 = new TenantUserEntity();
data.setId(UUID.randomUUID()); data.setId(UUID.randomUUID());
data.setUserId(userId); data.setUserId(userId);
@ -195,7 +193,7 @@ public class UserServiceImpl implements UserService {
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
entityManager.persist(data); entityManager.persist(data);
} finally { } finally {
this.tenantScope.removeTempTenant(this.entityManager.getEntityManager()); this.tenantScope.removeTempTenant(this.entityManager);
} }
} }
updatedCreatedIds.add(data.getId()); updatedCreatedIds.add(data.getId());

View File

@ -13,7 +13,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version> <version>3.2.5</version>
</parent> </parent>
<modules> <modules>
@ -43,7 +43,7 @@
<groupId>org.hibernate.orm</groupId> <groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<scope>compile</scope> <scope>compile</scope>
<version>6.3.1.Final</version> <version>6.5.2.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hibernate.orm</groupId> <groupId>org.hibernate.orm</groupId>
@ -71,7 +71,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.3</version> <version>2.17.0</version>
</dependency> </dependency>
<dependency> <dependency>
@ -107,7 +107,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>data-tools</artifactId> <artifactId>data-tools</artifactId>
<version>2.1.2</version> <version>2.1.4</version>
</dependency> </dependency>
<dependency> <dependency>
@ -119,7 +119,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>validation</artifactId> <artifactId>validation</artifactId>
<version>3.0.2</version> <version>3.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
@ -149,6 +149,12 @@
<artifactId>queue-outbox</artifactId> <artifactId>queue-outbox</artifactId>
<version>2.1.1</version> <version>2.1.1</version>
</dependency> </dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>cache</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>

View File

@ -20,7 +20,7 @@ public class PageEntity {
private List<SectionEntity> sections; private List<SectionEntity> sections;
public List<SectionEntity> getSections() { public List<SectionEntity> getSections() {
return sections; return this.sections;
} }
public void setSections(List<SectionEntity> sections) { public void setSections(List<SectionEntity> sections) {
@ -28,7 +28,7 @@ public class PageEntity {
} }
public String getId() { public String getId() {
return id; return this.id;
} }
public void setId(String id) { public void setId(String id) {
@ -36,7 +36,7 @@ public class PageEntity {
} }
public int getOrdinal() { public int getOrdinal() {
return ordinal; return this.ordinal;
} }
public void setOrdinal(int ordinal) { public void setOrdinal(int ordinal) {
@ -44,7 +44,7 @@ public class PageEntity {
} }
public String getTitle() { public String getTitle() {
return title; return this.title;
} }
public void setTitle(String title) { public void setTitle(String title) {

View File

@ -76,7 +76,7 @@ public class InAppNotificationController {
this.censorFactory.censor(InAppNotificationCensor.class).censor(lookup.getProject(), userId); this.censorFactory.censor(InAppNotificationCensor.class).censor(lookup.getProject(), userId);
if (userId == null) throw new MyForbiddenException(this.errors.getNonPersonPrincipal().getCode(), this.errors.getNonPersonPrincipal().getMessage()); 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<InAppNotificationEntity> data = query.collectAs(lookup.getProject()); List<InAppNotificationEntity> data = query.collectAs(lookup.getProject());
List<InAppNotification> models = this.builderFactory.builder(InAppNotificationBuilder.class).build(lookup.getProject(), data); List<InAppNotification> models = this.builderFactory.builder(InAppNotificationBuilder.class).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
@ -88,7 +88,7 @@ public class InAppNotificationController {
@GetMapping("{id}") @GetMapping("{id}")
@Transactional @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)); logger.debug(new MapLogEntry("retrieving" + InAppNotification.class.getSimpleName()).And("id", id).And("fields", fieldSet));
UUID userId = this.userScope.getUserId(); UUID userId = this.userScope.getUserId();

View File

@ -64,7 +64,7 @@ public class NotificationController {
this.censorFactory.censor(NotificationCensor.class).censor(lookup.getProject()); 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<NotificationEntity> data = query.collectAs(lookup.getProject()); List<NotificationEntity> data = query.collectAs(lookup.getProject());
List<Notification> models = this.builderFactory.builder(NotificationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); List<Notification> 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(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();

View File

@ -65,7 +65,7 @@ public class NotificationTemplateController {
this.censorFactory.censor(NotificationTemplateCensor.class).censor(lookup.getProject()); 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<NotificationTemplateEntity> data = query.collectAs(lookup.getProject()); List<NotificationTemplateEntity> data = query.collectAs(lookup.getProject());
List<NotificationTemplate> models = this.builderFactory.builder(NotificationTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); List<NotificationTemplate> 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(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();

View File

@ -29,18 +29,15 @@ public class PrincipalController {
private final CurrentPrincipalResolver currentPrincipalResolver; private final CurrentPrincipalResolver currentPrincipalResolver;
private final AccountBuilder accountBuilder; private final AccountBuilder accountBuilder;
private final ClaimExtractor claimExtractor;
@Autowired @Autowired
public PrincipalController( public PrincipalController(
CurrentPrincipalResolver currentPrincipalResolver, CurrentPrincipalResolver currentPrincipalResolver,
AccountBuilder accountBuilder, AccountBuilder accountBuilder,
AuditService auditService, AuditService auditService) {
ClaimExtractor claimExtractor) {
this.currentPrincipalResolver = currentPrincipalResolver; this.currentPrincipalResolver = currentPrincipalResolver;
this.accountBuilder = accountBuilder; this.accountBuilder = accountBuilder;
this.auditService = auditService; this.auditService = auditService;
this.claimExtractor = claimExtractor;
} }
@GetMapping("me") @GetMapping("me")

View File

@ -86,7 +86,7 @@ public class TenantConfigurationController {
this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null); 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<TenantConfigurationEntity> data = query.collectAs(lookup.getProject()); List<TenantConfigurationEntity> data = query.collectAs(lookup.getProject());
List<TenantConfiguration> models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); List<TenantConfiguration> models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);

View File

@ -76,7 +76,7 @@ public class UserNotificationPreferenceController {
this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(lookup.getProject(), null); this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(lookup.getProject(), null);
UserNotificationPreferenceQuery query = lookup.enrich(this.queryFactory); UserNotificationPreferenceQuery query = lookup.enrich(this.queryFactory).disableTracking();
List<UserNotificationPreferenceEntity> data = query.collectAs(lookup.getProject()); List<UserNotificationPreferenceEntity> data = query.collectAs(lookup.getProject());
List<UserNotificationPreference> models = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); List<UserNotificationPreference> 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(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();

View File

@ -13,7 +13,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version> <version>3.2.5</version>
</parent> </parent>
<modules> <modules>
@ -43,7 +43,7 @@
<groupId>org.hibernate.orm</groupId> <groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<scope>compile</scope> <scope>compile</scope>
<version>6.3.1.Final</version> <version>6.5.2.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hibernate.orm</groupId> <groupId>org.hibernate.orm</groupId>
@ -71,7 +71,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.3</version> <version>2.17.0</version>
</dependency> </dependency>
<dependency> <dependency>
@ -107,7 +107,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>data-tools</artifactId> <artifactId>data-tools</artifactId>
<version>2.1.2</version> <version>2.1.4</version>
</dependency> </dependency>
<dependency> <dependency>
@ -119,7 +119,7 @@
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>
<artifactId>validation</artifactId> <artifactId>validation</artifactId>
<version>3.0.2</version> <version>3.0.3</version>
</dependency> </dependency>
<dependency> <dependency>