fix injection of entity manger for tasks
This commit is contained in:
parent
b3258e35eb
commit
afde6fa221
|
@ -52,7 +52,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -71,6 +71,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
public static final String _createdAt = "createdAt";
|
||||
|
||||
@Column(name = "\"updated_at\"", nullable = false)
|
||||
@Version
|
||||
private Instant updatedAt;
|
||||
|
||||
public static final String _updatedAt = "updatedAt";
|
||||
|
|
|
@ -21,7 +21,7 @@ public class TenantEntityManager {
|
|||
private EntityManager entityManager;
|
||||
private final TenantScope tenantScope;
|
||||
private final ErrorThesaurusProperties errors;
|
||||
|
||||
|
||||
boolean tenantFiltersDisabled;
|
||||
|
||||
public TenantEntityManager(TenantScope tenantScope, ErrorThesaurusProperties errors) {
|
||||
|
@ -95,6 +95,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void reloadTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -113,6 +115,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void loadExplictTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -131,6 +135,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void disableTenantFilters() {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.entityManager
|
||||
.unwrap(Session.class)
|
||||
.disableFilter(TenantScopedBaseEntity.TENANT_FILTER);
|
||||
|
@ -146,7 +152,7 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public boolean isTenantFiltersDisabled() {
|
||||
return tenantFiltersDisabled;
|
||||
return this.tenantFiltersDisabled;
|
||||
}
|
||||
|
||||
public EntityManager getEntityManager() {
|
||||
|
|
|
@ -4,7 +4,6 @@ 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;
|
||||
|
@ -20,16 +19,14 @@ public class InboxIntegrationEventConfigurer extends InboxConfigurer {
|
|||
|
||||
private final InboxProperties inboxProperties;
|
||||
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.inboxProperties = inboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public InboxRepository inboxRepositoryCreator() {
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties, this.entityManagerFactory);
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -27,13 +26,9 @@ import java.util.UUID;
|
|||
@ConditionalOnProperty(prefix = "queue.task.publisher", name = "enable", matchIfMissing = false)
|
||||
public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.outboxProperties = outboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -69,7 +64,7 @@ public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
|||
|
||||
@Bean
|
||||
public OutboxRepository outboxRepositoryCreator() {
|
||||
return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties, this.entityManagerFactory);
|
||||
return new OutboxRepositoryImpl(this.applicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package gr.cite.annotation.integrationevent.inbox;
|
||||
|
||||
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.data.QueueInboxEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.integrationevent.TrackedEvent;
|
||||
import gr.cite.annotation.integrationevent.inbox.annotationentitiesremoval.AnnotationEntitiesRemovalIntegrationEventHandler;
|
||||
import gr.cite.annotation.integrationevent.inbox.annotationentitiestouch.AnnotationEntitiesTouchedIntegrationEventHandler;
|
||||
import gr.cite.annotation.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler;
|
||||
|
@ -23,10 +21,7 @@ import gr.cite.rabbitmq.consumer.InboxCreatorParams;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
@ -40,31 +35,30 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(InboxRepositoryImpl.class));
|
||||
|
||||
protected final ApplicationContext applicationContext;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final InboxProperties inboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public InboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory
|
||||
ApplicationContext applicationContext,
|
||||
InboxProperties inboxProperties
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
|
||||
this.inboxProperties = inboxProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions options) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
@ -103,8 +97,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue inbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -116,12 +109,14 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueInbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -148,8 +143,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -160,12 +154,14 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public boolean shouldWait(CandidateInfo candidate, Function<QueueInbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -193,8 +189,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -205,14 +200,16 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public QueueInbox create(InboxCreatorParams inboxCreatorParams) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
boolean success;
|
||||
QueueInboxEntity queueMessage = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
queueMessage = this.createQueueInboxEntity(inboxCreatorParams);
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -221,23 +218,22 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueInboxEntity createQueueInboxEntity(InboxCreatorParams inboxCreatorParams) {
|
||||
|
||||
QueueInboxEntity queueMessage = new QueueInboxEntity();
|
||||
queueMessage.setId(UUID.randomUUID());
|
||||
Object tenantId = inboxCreatorParams.getHeaders() != null ? inboxCreatorParams.getHeaders().getOrDefault(IntegrationEventMessageConstants.TENANT, null) : null;
|
||||
|
@ -246,6 +242,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
try {
|
||||
queueMessage.setTenantId(UUID.fromString((String) tenantId));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
queueMessage.setExchange(this.inboxProperties.getExchange());
|
||||
|
@ -265,28 +262,26 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public Boolean emit(CandidateInfo candidateInfo) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
QueueInboxEntity queueInboxMessage;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
}
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
EventProcessingStatus status = this.emitQueueInboxEntity(queueInboxMessage);
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction.begin();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueInboxEntity queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
transaction.begin();
|
||||
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
|
||||
EventProcessingStatus status = this.processMessage(queueInboxMessage);
|
||||
switch (status) {
|
||||
case Success: {
|
||||
queueInboxMessage.setStatus(QueueInboxStatus.SUCCESSFUL);
|
||||
|
@ -311,24 +306,59 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
|
||||
entityManager.merge(queueInboxMessage);
|
||||
entityManager.flush();
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
transaction.commit();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public EventProcessingStatus emitQueueInboxEntity(QueueInboxEntity queueInboxMessage) {
|
||||
EntityTransaction transaction = null;
|
||||
EventProcessingStatus status = EventProcessingStatus.Discard;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
||||
status = this.processMessage(queueInboxMessage);
|
||||
|
||||
entityManager.flush();
|
||||
|
||||
switch (status) {
|
||||
case Error: transaction.rollback(); break;
|
||||
case Success:
|
||||
case Postponed:
|
||||
case Discard:
|
||||
default: transaction.commit(); break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return success;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
private EventProcessingStatus processMessage(QueueInboxEntity queueInboxMessage) {
|
||||
IntegrationEventHandler handler;
|
||||
logger.debug("Processing message with routing key '{}'", queueInboxMessage.getRoute());
|
||||
|
@ -357,7 +387,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
properties.setMessageId(queueInboxMessage.getMessageId().toString());
|
||||
properties.setTenantId(queueInboxMessage.getTenantId());
|
||||
|
||||
TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// using (LogContext.PushProperty(this._logTrackingConfig.LogTrackingContextName, @event.TrackingContextTag))
|
||||
// {
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,7 @@ 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.data.QueueOutboxEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.query.QueueOutboxQuery;
|
||||
import gr.cite.queueoutbox.entity.QueueOutbox;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
|
@ -14,10 +15,7 @@ import gr.cite.rabbitmq.IntegrationEvent;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
@ -33,31 +31,30 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class));
|
||||
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
|
||||
public OutboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory
|
||||
ApplicationContext applicationContext
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.outboxProperties = outboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions messageOptions, Function<QueueOutbox, Boolean> onConfirmTimeout) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueOutboxEntity item = queryFactory.query(QueueOutboxQuery.class)
|
||||
.isActives(IsActive.Active)
|
||||
.notifyStatus(QueueOutboxNotifyStatus.PENDING, QueueOutboxNotifyStatus.WAITING_CONFIRMATION, QueueOutboxNotifyStatus.ERROR)
|
||||
|
@ -95,8 +92,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -108,12 +104,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueOutbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -140,8 +138,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -152,12 +149,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldWait(CandidateInfo candidate, Function<QueueOutbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -185,8 +184,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -197,13 +195,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean process(CandidateInfo candidateInfo, Boolean isAutoconfirmOnPublish, Function<QueueOutbox, Boolean> publish) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
Boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -240,8 +239,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -252,12 +250,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleConfirm(List<UUID> confirmedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -283,8 +282,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -294,12 +292,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleNack(List<UUID> nackedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -325,8 +324,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -336,13 +334,15 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public QueueOutbox create(IntegrationEvent item) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
QueueOutboxEntity queueMessage = null;
|
||||
boolean success;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -351,18 +351,20 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueOutboxEntity mapEvent(OutboxIntegrationEvent event) {
|
||||
|
@ -373,26 +375,5 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// UUID correlationId = UUID.randomUUID();
|
||||
// if (event.getEvent() != null)
|
||||
// event.getEvent().setTrackingContextTag(correlationId.toString());
|
||||
// event.setMessage(this.jsonHandlingService.toJsonSafe(event.getEvent()));
|
||||
// //this._logTrackingService.Trace(correlationId.ToString(), $"Correlating current tracking context with new correlationId {correlationId}");
|
||||
//
|
||||
// QueueOutboxEntity queueMessage = new QueueOutboxEntity();
|
||||
// queueMessage.setId(UUID.randomUUID());
|
||||
// queueMessage.setTenantId(event.getTenantId());
|
||||
// queueMessage.setExchange(this.outboxProperties.getExchange());
|
||||
// queueMessage.setRoute(routingKey);
|
||||
// queueMessage.setMessageId(event.getMessageId());
|
||||
// queueMessage.setMessage(this.jsonHandlingService.toJsonSafe(event));
|
||||
// queueMessage.setIsActive(IsActive.Active);
|
||||
// queueMessage.setNotifyStatus(QueueOutboxNotifyStatus.PENDING);
|
||||
// queueMessage.setRetryCount(0);
|
||||
// queueMessage.setCreatedAt(Instant.now());
|
||||
// queueMessage.setUpdatedAt(Instant.now());
|
||||
//
|
||||
// return queueMessage;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import gr.cite.annotation.common.enums.IsActive;
|
|||
import gr.cite.annotation.common.scope.user.UserScope;
|
||||
import gr.cite.annotation.data.AnnotationEntity;
|
||||
import gr.cite.annotation.data.EntityUserEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.model.Annotation;
|
||||
import gr.cite.annotation.query.utils.BuildSubQueryInput;
|
||||
import gr.cite.annotation.query.utils.QueryUtilsService;
|
||||
|
@ -14,6 +15,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -53,10 +55,12 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
public AnnotationQuery(UserScope userScope, QueryUtilsService queryUtilsService, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public AnnotationQuery(UserScope userScope, QueryUtilsService queryUtilsService, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public AnnotationQuery like(String value) {
|
||||
|
@ -184,6 +188,11 @@ public class AnnotationQuery extends QueryBase<AnnotationEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.entityIds);
|
||||
|
|
|
@ -7,6 +7,7 @@ import gr.cite.annotation.common.enums.IsActive;
|
|||
import gr.cite.annotation.common.scope.user.UserScope;
|
||||
import gr.cite.annotation.data.AnnotationEntity;
|
||||
import gr.cite.annotation.data.EntityUserEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.model.EntityUser;
|
||||
import gr.cite.annotation.query.utils.BuildSubQueryInput;
|
||||
import gr.cite.annotation.query.utils.QueryUtilsService;
|
||||
|
@ -14,6 +15,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -37,10 +39,12 @@ public class EntityUserQuery extends QueryBase<EntityUserEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public EntityUserQuery(AuthorizationService authService, UserScope userScope) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public EntityUserQuery(AuthorizationService authService, UserScope userScope, TenantEntityManager tenantEntityManager) {
|
||||
this.authService = authService;
|
||||
this.userScope = userScope;
|
||||
}
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public EntityUserQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
|
@ -117,6 +121,11 @@ public class EntityUserQuery extends QueryBase<EntityUserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
|
|
|
@ -2,11 +2,13 @@ package gr.cite.annotation.query;
|
|||
|
||||
import gr.cite.annotation.common.enums.IsActive;
|
||||
import gr.cite.annotation.data.QueueInboxEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.queueinbox.entity.QueueInboxStatus;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -30,6 +32,12 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
private Collection<QueueInboxStatus> status;
|
||||
private Integer retryThreshold;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueInboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueInboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -130,6 +138,11 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueInboxEntity> entityClass() {
|
||||
return QueueInboxEntity.class;
|
||||
|
|
|
@ -2,11 +2,13 @@ package gr.cite.annotation.query;
|
|||
|
||||
import gr.cite.annotation.common.enums.IsActive;
|
||||
import gr.cite.annotation.data.QueueOutboxEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -30,6 +32,12 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
private Integer retryThreshold;
|
||||
private Integer confirmTimeout;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueOutboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueOutboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -135,6 +143,11 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueOutboxEntity> entityClass() {
|
||||
return QueueOutboxEntity.class;
|
||||
|
|
|
@ -3,10 +3,12 @@ package gr.cite.annotation.query;
|
|||
import gr.cite.annotation.authorization.AuthorizationFlags;
|
||||
import gr.cite.annotation.common.enums.IsActive;
|
||||
import gr.cite.annotation.data.TenantEntity;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.model.Tenant;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -28,7 +30,13 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public TenantQuery like(String value) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantQuery like(String value) {
|
||||
this.like = value;
|
||||
return this;
|
||||
}
|
||||
|
@ -78,6 +86,11 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.isActives);
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.annotation.authorization.AuthorizationFlags;
|
|||
import gr.cite.annotation.authorization.Permission;
|
||||
import gr.cite.annotation.common.enums.IsActive;
|
||||
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.model.Tenant;
|
||||
|
@ -12,6 +13,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -36,12 +38,14 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public TenantUserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantUserQuery ids(UUID value) {
|
||||
|
@ -124,6 +128,11 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<TenantUserEntity> entityClass() {
|
||||
return TenantUserEntity.class;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package gr.cite.annotation.query;
|
||||
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.annotation.authorization.AuthorizationFlags;
|
||||
import gr.cite.annotation.authorization.Permission;
|
||||
|
@ -10,6 +11,7 @@ import gr.cite.annotation.model.UserCredential;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -40,9 +42,11 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserCredentialQuery ids(UUID value) {
|
||||
|
@ -135,6 +139,11 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.annotation.authorization.AuthorizationFlags;
|
|||
import gr.cite.annotation.authorization.Permission;
|
||||
import gr.cite.annotation.common.enums.IsActive;
|
||||
import gr.cite.annotation.common.scope.user.UserScope;
|
||||
import gr.cite.annotation.data.TenantEntityManager;
|
||||
import gr.cite.annotation.data.UserEntity;
|
||||
import gr.cite.annotation.model.User;
|
||||
import gr.cite.annotation.model.user.PublicUser;
|
||||
|
@ -11,6 +12,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -36,12 +38,14 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
UserScope userScope,
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserQuery like(String value) {
|
||||
|
@ -94,6 +98,11 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<UserEntity> entityClass() {
|
||||
return UserEntity.class;
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.opencdmp</groupId>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.opencdmp.data;
|
||||
|
||||
import gr.cite.queueoutbox.entity.QueueOutbox;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
import jakarta.persistence.*;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.converters.enums.IsActiveConverter;
|
||||
import org.opencdmp.data.converters.enums.QueueOutboxNotifyStatusConverter;
|
||||
import gr.cite.queueoutbox.entity.QueueOutbox;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -65,11 +65,12 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
public final static String _createdAt = "createdAt";
|
||||
|
||||
@Column(name = "\"updated_at\"", nullable = false)
|
||||
@Version
|
||||
private Instant updatedAt;
|
||||
public final static String _updatedAt = "updatedAt";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
|
@ -77,7 +78,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public String getExchange() {
|
||||
return exchange;
|
||||
return this.exchange;
|
||||
}
|
||||
|
||||
public void setExchange(String exchange) {
|
||||
|
@ -85,7 +86,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public String getRoute() {
|
||||
return route;
|
||||
return this.route;
|
||||
}
|
||||
|
||||
public void setRoute(String route) {
|
||||
|
@ -93,7 +94,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public UUID getMessageId() {
|
||||
return messageId;
|
||||
return this.messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(UUID messageId) {
|
||||
|
@ -101,7 +102,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
|
@ -109,7 +110,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public QueueOutboxNotifyStatus getNotifyStatus() {
|
||||
return notifyStatus;
|
||||
return this.notifyStatus;
|
||||
}
|
||||
|
||||
public void setNotifyStatus(QueueOutboxNotifyStatus notifyStatus) {
|
||||
|
@ -117,7 +118,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public Integer getRetryCount() {
|
||||
return retryCount;
|
||||
return this.retryCount;
|
||||
}
|
||||
|
||||
public void setRetryCount(Integer retryCount) {
|
||||
|
@ -125,7 +126,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public Instant getPublishedAt() {
|
||||
return publishedAt;
|
||||
return this.publishedAt;
|
||||
}
|
||||
|
||||
public void setPublishedAt(Instant publishedAt) {
|
||||
|
@ -133,7 +134,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public Instant getConfirmedAt() {
|
||||
return confirmedAt;
|
||||
return this.confirmedAt;
|
||||
}
|
||||
|
||||
public void setConfirmedAt(Instant confirmedAt) {
|
||||
|
@ -141,7 +142,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public UUID getTenantId() {
|
||||
return tenantId;
|
||||
return this.tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(UUID tenantId) {
|
||||
|
@ -149,7 +150,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public IsActive getIsActive() {
|
||||
return isActive;
|
||||
return this.isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(IsActive isActive) {
|
||||
|
@ -157,7 +158,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
return this.createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Instant createdAt) {
|
||||
|
@ -165,7 +166,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
}
|
||||
|
||||
public Instant getUpdatedAt() {
|
||||
return updatedAt;
|
||||
return this.updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Instant updatedAt) {
|
||||
|
|
|
@ -95,6 +95,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void reloadTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -113,6 +115,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void loadExplictTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -131,6 +135,8 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void disableTenantFilters() {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
|
||||
this.entityManager
|
||||
.unwrap(Session.class)
|
||||
.disableFilter(TenantScopedBaseEntity.TENANT_FILTER);
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.opencdmp.commons.enums.DmpStatus;
|
|||
import org.opencdmp.commons.enums.DmpVersionStatus;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.elastic.data.DescriptionElasticEntity;
|
||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
||||
import org.opencdmp.elastic.data.nested.NestedDescriptionElasticEntity;
|
||||
import org.opencdmp.service.elastic.AppElasticProperties;
|
||||
|
@ -250,7 +249,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
|||
if (!predicates.isEmpty()) {
|
||||
return this.applyTenant(predicates);
|
||||
} else {
|
||||
return this.equals(this.elasticFieldOf(DescriptionElasticEntity._id), UUID.randomUUID());
|
||||
return this.equals(this.elasticFieldOf(DmpElasticEntity._id), UUID.randomUUID());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.opencdmp.integrationevent;
|
|||
|
||||
import gr.cite.queueinbox.InboxConfigurer;
|
||||
import gr.cite.queueinbox.repository.InboxRepository;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import org.opencdmp.integrationevent.inbox.InboxProperties;
|
||||
import org.opencdmp.integrationevent.inbox.InboxRepositoryImpl;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
@ -17,17 +16,15 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class InboxIntegrationEventConfigurer extends InboxConfigurer {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final InboxProperties inboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.inboxProperties = inboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public InboxRepository inboxRepositoryCreator() {
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties, this.entityManagerFactory);
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ 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.opencdmp.data.QueueOutboxEntity;
|
||||
import org.opencdmp.integrationevent.outbox.OutboxProperties;
|
||||
import org.opencdmp.integrationevent.outbox.OutboxRepositoryImpl;
|
||||
|
@ -29,12 +28,10 @@ import java.util.UUID;
|
|||
public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.outboxProperties = outboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -70,7 +67,7 @@ public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
|||
|
||||
@Bean
|
||||
public OutboxRepository outboxRepositoryCreator() {
|
||||
return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties, this.entityManagerFactory);
|
||||
return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,16 +10,11 @@ import gr.cite.rabbitmq.consumer.InboxCreatorParams;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import org.opencdmp.commons.JsonHandlingService;
|
||||
import jakarta.persistence.*;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.fake.FakeRequestScope;
|
||||
import org.opencdmp.data.QueueInboxEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.integrationevent.TrackedEvent;
|
||||
import org.opencdmp.query.QueueInboxQuery;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -29,34 +24,35 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class InboxRepositoryImpl implements InboxRepository { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(InboxRepositoryImpl.class));
|
||||
public class InboxRepositoryImpl implements InboxRepository {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(InboxRepositoryImpl.class));
|
||||
|
||||
protected final ApplicationContext applicationContext;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final InboxProperties inboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public InboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory
|
||||
ApplicationContext applicationContext,
|
||||
InboxProperties inboxProperties
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
|
||||
this.inboxProperties = inboxProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions options) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
@ -95,8 +91,7 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue inbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -108,12 +103,14 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueInbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -140,8 +137,7 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -152,12 +148,14 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
@Override
|
||||
public boolean shouldWait(CandidateInfo candidate, Function<QueueInbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -185,8 +183,7 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -197,13 +194,16 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
@Override
|
||||
public QueueInbox create(InboxCreatorParams inboxCreatorParams) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
boolean success;
|
||||
QueueInboxEntity queueMessage = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
queueMessage = this.createQueueInboxEntity(inboxCreatorParams);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -212,23 +212,22 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueInboxEntity createQueueInboxEntity(InboxCreatorParams inboxCreatorParams) {
|
||||
|
||||
QueueInboxEntity queueMessage = new QueueInboxEntity();
|
||||
queueMessage.setId(UUID.randomUUID());
|
||||
Object tenantId = inboxCreatorParams.getHeaders() != null ? inboxCreatorParams.getHeaders().getOrDefault(IntegrationEventMessageConstants.TENANT, null) : null;
|
||||
|
@ -237,6 +236,7 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
try {
|
||||
queueMessage.setTenantId(UUID.fromString((String) tenantId));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
queueMessage.setExchange(this.inboxProperties.getExchange());
|
||||
|
@ -256,27 +256,26 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
@Override
|
||||
public Boolean emit(CandidateInfo candidateInfo) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
QueueInboxEntity queueInboxMessage;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
}
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
EventProcessingStatus status = this.emitQueueInboxEntity(queueInboxMessage);
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction.begin();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueInboxEntity queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
transaction.begin();
|
||||
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
|
||||
EventProcessingStatus status = this.processMessage(queueInboxMessage);
|
||||
switch (status) {
|
||||
case Success: {
|
||||
queueInboxMessage.setStatus(QueueInboxStatus.SUCCESSFUL);
|
||||
|
@ -301,25 +300,57 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
|
||||
entityManager.merge(queueInboxMessage);
|
||||
entityManager.flush();
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
transaction.commit();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public EventProcessingStatus emitQueueInboxEntity(QueueInboxEntity queueInboxMessage) {
|
||||
EntityTransaction transaction = null;
|
||||
EventProcessingStatus status = EventProcessingStatus.Discard;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
||||
status = this.processMessage(queueInboxMessage);
|
||||
|
||||
entityManager.flush();
|
||||
|
||||
switch (status) {
|
||||
case Error: transaction.rollback(); break;
|
||||
case Success:
|
||||
case Postponed:
|
||||
case Discard:
|
||||
default: transaction.commit(); break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private EventProcessingStatus processMessage(QueueInboxEntity queueInboxMessage) {
|
||||
IntegrationEventHandler handler = null;
|
||||
|
@ -339,13 +370,13 @@ public class InboxRepositoryImpl implements InboxRepository { private static fin
|
|||
properties.setMessageId(queueInboxMessage.getMessageId().toString());
|
||||
properties.setTenantId(queueInboxMessage.getTenantId());
|
||||
|
||||
TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// using (LogContext.PushProperty(this._logTrackingConfig.LogTrackingContextName, @event.TrackingContextTag))
|
||||
// {
|
||||
try {
|
||||
return handler.handle(properties, queueInboxMessage.getMessage());
|
||||
} catch (Exception ex) {
|
||||
logger.error("problem handling event from routing key " + queueInboxMessage.getRoute() + ". Setting nack and continuing...", ex);
|
||||
logger.error("problem handling event from routing key {}. Setting nack and continuing...", queueInboxMessage.getRoute(), ex);
|
||||
return EventProcessingStatus.Error;
|
||||
}
|
||||
// }
|
||||
|
|
|
@ -9,14 +9,12 @@ import gr.cite.rabbitmq.IntegrationEvent;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.opencdmp.commons.JsonHandlingService;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.fake.FakeRequestScope;
|
||||
import org.opencdmp.data.QueueOutboxEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.query.QueueOutboxQuery;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -33,17 +31,16 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class));
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public OutboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory
|
||||
ApplicationContext applicationContext, OutboxProperties outboxProperties
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
|
||||
this.outboxProperties = outboxProperties;
|
||||
}
|
||||
|
@ -51,16 +48,17 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions messageOptions, Function<QueueOutbox, Boolean> onConfirmTimeout) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueOutboxEntity item = queryFactory.query(QueueOutboxQuery.class)
|
||||
.isActives(IsActive.Active)
|
||||
.notifyStatus(QueueOutboxNotifyStatus.PENDING, QueueOutboxNotifyStatus.WAITING_CONFIRMATION, QueueOutboxNotifyStatus.ERROR)
|
||||
|
@ -98,8 +96,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -111,13 +108,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueOutbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -144,8 +142,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -156,12 +153,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldWait(CandidateInfo candidate, Function<QueueOutbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -189,8 +188,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -201,12 +199,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean process(CandidateInfo candidateInfo, Boolean isAutoconfirmOnPublish, Function<QueueOutbox, Boolean> publish) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
Boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -243,8 +243,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -255,11 +254,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleConfirm(List<UUID> confirmedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -285,8 +286,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -296,11 +296,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleNack(List<UUID> nackedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -326,8 +328,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -337,13 +338,15 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public QueueOutbox create(IntegrationEvent item) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
QueueOutboxEntity queueMessage = null;
|
||||
boolean success;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -352,18 +355,20 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueOutboxEntity mapEvent(OutboxIntegrationEvent event) {
|
||||
|
|
|
@ -8,8 +8,6 @@ import gr.cite.tools.fieldset.BaseFieldSet;
|
|||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import org.opencdmp.authorization.AffiliatedResource;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
|
||||
|
@ -35,7 +33,6 @@ import org.opencdmp.model.dmpblueprint.DmpBlueprint;
|
|||
import org.opencdmp.model.dmpreference.DmpReference;
|
||||
import org.opencdmp.model.user.User;
|
||||
import org.opencdmp.query.*;
|
||||
import org.opencdmp.service.externalfetcher.config.entities.SourceBaseConfiguration;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -49,8 +46,6 @@ import java.util.stream.Collectors;
|
|||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -11,6 +12,7 @@ import org.opencdmp.commons.enums.ActionConfirmationStatus;
|
|||
import org.opencdmp.commons.enums.ActionConfirmationType;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.ActionConfirmationEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.actionconfirmation.ActionConfirmation;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -44,8 +46,10 @@ public class ActionConfirmationQuery extends QueryBase<ActionConfirmationEntity>
|
|||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
public ActionConfirmationQuery(QueryUtilsService queryUtilsService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public ActionConfirmationQuery(QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public ActionConfirmationQuery like(String value) {
|
||||
|
@ -174,6 +178,11 @@ public class ActionConfirmationQuery extends QueryBase<ActionConfirmationEntity>
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -15,6 +16,7 @@ import org.opencdmp.commons.scope.user.UserScope;
|
|||
import org.opencdmp.data.DescriptionEntity;
|
||||
import org.opencdmp.data.DmpDescriptionTemplateEntity;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.PublicDescription;
|
||||
import org.opencdmp.model.description.Description;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -65,10 +67,12 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
|
||||
private Collection<UUID> dmpDescriptionTemplateIds;
|
||||
|
||||
public DescriptionQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public DescriptionQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public DescriptionQuery like(String value) {
|
||||
|
@ -221,6 +225,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -12,6 +13,7 @@ import org.opencdmp.authorization.Permission;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DescriptionReferenceEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.descriptionreference.DescriptionReference;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -40,10 +42,12 @@ public class DescriptionReferenceQuery extends QueryBase<DescriptionReferenceEnt
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
public DescriptionReferenceQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public DescriptionReferenceQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public DescriptionReferenceQuery ids(UUID value) {
|
||||
|
@ -136,6 +140,11 @@ public class DescriptionReferenceQuery extends QueryBase<DescriptionReferenceEnt
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -10,6 +11,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.DescriptionEntity;
|
||||
import org.opencdmp.data.DescriptionTagEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.DescriptionTag;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
@ -124,9 +126,16 @@ public class DescriptionTagQuery extends QueryBase<DescriptionTagEntity> {
|
|||
this.noTracking = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public DescriptionTagQuery() {
|
||||
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public DescriptionTagQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -17,6 +18,7 @@ import org.opencdmp.commons.scope.user.UserScope;
|
|||
import org.opencdmp.data.DescriptionTemplateEntity;
|
||||
import org.opencdmp.data.DmpDescriptionTemplateEntity;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.descriptiontemplate.DescriptionTemplate;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -227,12 +229,19 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
|
|||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public DescriptionTemplateQuery(
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -10,6 +11,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.DescriptionTemplateTypeStatus;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.DescriptionTemplateTypeEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.DescriptionTemplateType;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -116,11 +118,18 @@ public class DescriptionTemplateTypeQuery extends QueryBase<DescriptionTemplateT
|
|||
}
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public DescriptionTemplateTypeQuery(
|
||||
QueryUtilsService queryUtilsService) {
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DescriptionTemplateTypeEntity> entityClass() {
|
||||
return DescriptionTemplateTypeEntity.class;
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -12,6 +13,7 @@ import org.opencdmp.commons.enums.DmpBlueprintStatus;
|
|||
import org.opencdmp.commons.enums.DmpBlueprintVersionStatus;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.DmpBlueprintEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.dmpblueprint.DmpBlueprint;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -168,11 +170,18 @@ public class DmpBlueprintQuery extends QueryBase<DmpBlueprintEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public DmpBlueprintQuery(
|
||||
AuthorizationService authService, QueryUtilsService queryUtilsService
|
||||
AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -13,6 +14,7 @@ import org.opencdmp.commons.enums.IsActive;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DescriptionTemplateEntity;
|
||||
import org.opencdmp.data.DmpDescriptionTemplateEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.DmpDescriptionTemplate;
|
||||
import org.opencdmp.model.PublicDmpDescriptionTemplate;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -160,17 +162,24 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
private final UserScope userScope;
|
||||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public DmpDescriptionTemplateQuery(
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -63,11 +64,13 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
|||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public DmpQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
public DmpQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public DmpQuery like(String value) {
|
||||
|
@ -251,6 +254,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.creatorIds) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes) || this.isEmpty(this.statuses) || this.isFalseQuery(this.dmpDescriptionTemplateQuery) || this.isFalseQuery(this.dmpUserQuery);
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -14,6 +15,7 @@ import org.opencdmp.commons.scope.user.UserScope;
|
|||
import org.opencdmp.data.DmpEntity;
|
||||
import org.opencdmp.data.DmpReferenceEntity;
|
||||
import org.opencdmp.data.ReferenceEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.PublicDmpReference;
|
||||
import org.opencdmp.model.dmpreference.DmpReference;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -130,14 +132,21 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public DmpReferenceQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService,
|
||||
QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope,
|
||||
AuthorizationService authService,
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -15,6 +16,7 @@ import org.opencdmp.commons.enums.IsActive;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DescriptionEntity;
|
||||
import org.opencdmp.data.DmpUserEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.DmpUser;
|
||||
import org.opencdmp.model.PublicDmpUser;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
|
@ -177,14 +179,21 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
|
|||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public DmpUserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService,
|
||||
QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope,
|
||||
AuthorizationService authService,
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -14,6 +15,7 @@ import org.opencdmp.commons.enums.IsActive;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
import org.opencdmp.data.EntityDoiEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.EntityDoi;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -175,12 +177,19 @@ public class EntityDoiQuery extends QueryBase<EntityDoiEntity> {
|
|||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public EntityDoiQuery(
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,12 +3,14 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.LanguageEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.Language;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -115,9 +117,16 @@ public class LanguageQuery extends QueryBase<LanguageEntity> {
|
|||
}
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public LanguageQuery(
|
||||
QueryUtilsService queryUtilsService) {
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -10,6 +11,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.LockTargetType;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.data.LockEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.Lock;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
@ -148,8 +150,15 @@ public class LockQuery extends QueryBase<LockEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public LockQuery(ConventionService conventionService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public LockQuery(ConventionService conventionService, TenantEntityManager tenantEntityManager) {
|
||||
this.conventionService = conventionService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,12 +3,14 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.PrefillingSourceEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.prefillingsource.PrefillingSource;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -32,6 +34,7 @@ public class PrefillingSourceQuery extends QueryBase<PrefillingSourceEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
|
||||
public PrefillingSourceQuery like(String value) {
|
||||
this.like = value;
|
||||
return this;
|
||||
|
@ -99,11 +102,18 @@ public class PrefillingSourceQuery extends QueryBase<PrefillingSourceEntity> {
|
|||
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public PrefillingSourceQuery(
|
||||
QueryUtilsService queryUtilsService) {
|
||||
TenantEntityManager tenantEntityManager, QueryUtilsService queryUtilsService) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<PrefillingSourceEntity> entityClass() {
|
||||
return PrefillingSourceEntity.class;
|
||||
|
|
|
@ -6,11 +6,13 @@ import gr.cite.tools.data.query.FieldResolver;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.QueueInboxEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -29,6 +31,12 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
private Collection<String> routes;
|
||||
private Collection<QueueInboxStatus> status;
|
||||
private Integer retryThreshold;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueInboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueInboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
|
@ -130,6 +138,11 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueInboxEntity> entityClass() {
|
||||
return QueueInboxEntity.class;
|
||||
|
|
|
@ -6,11 +6,13 @@ import gr.cite.tools.data.query.FieldResolver;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.QueueOutboxEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -31,6 +33,12 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
private Integer retryThreshold;
|
||||
private Integer confirmTimeout;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueOutboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueOutboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -136,6 +144,11 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueOutboxEntity> entityClass() {
|
||||
return QueueOutboxEntity.class;
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -12,10 +13,7 @@ import org.opencdmp.authorization.Permission;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.enums.ReferenceSourceType;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DescriptionReferenceEntity;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
import org.opencdmp.data.DmpReferenceEntity;
|
||||
import org.opencdmp.data.ReferenceEntity;
|
||||
import org.opencdmp.data.*;
|
||||
import org.opencdmp.model.PublicReference;
|
||||
import org.opencdmp.model.reference.Reference;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
|
@ -193,12 +191,19 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
|
|||
private final AuthorizationService authService;
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public ReferenceQuery(
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -10,6 +11,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.ReferenceEntity;
|
||||
import org.opencdmp.data.ReferenceTypeEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.referencetype.ReferenceType;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -117,9 +119,16 @@ public class ReferenceTypeQuery extends QueryBase<ReferenceTypeEntity> {
|
|||
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public ReferenceTypeQuery(
|
||||
QueryUtilsService queryUtilsService) {
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -12,6 +13,7 @@ import org.opencdmp.authorization.Permission;
|
|||
import org.opencdmp.commons.enums.StorageType;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.StorageFileEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.StorageFile;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -36,10 +38,12 @@ public class StorageFileQuery extends QueryBase<StorageFileEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
public StorageFileQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public StorageFileQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public StorageFileQuery like(String value) {
|
||||
|
@ -122,6 +126,11 @@ public class StorageFileQuery extends QueryBase<StorageFileEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -10,6 +11,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.enums.SupportiveMaterialFieldType;
|
||||
import org.opencdmp.data.SupportiveMaterialEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.SupportiveMaterial;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -133,9 +135,16 @@ public class SupportiveMaterialQuery extends QueryBase<SupportiveMaterialEntity>
|
|||
}
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public SupportiveMaterialQuery(
|
||||
QueryUtilsService queryUtilsService) {
|
||||
QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -13,6 +14,7 @@ import org.opencdmp.commons.enums.IsActive;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DescriptionTagEntity;
|
||||
import org.opencdmp.data.TagEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.Tag;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -46,11 +48,13 @@ public class TagQuery extends QueryBase<TagEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TagQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
public TagQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TagQuery like(String value) {
|
||||
|
@ -168,6 +172,11 @@ public class TagQuery extends QueryBase<TagEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -11,6 +12,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.enums.TenantConfigurationType;
|
||||
import org.opencdmp.data.TenantConfigurationEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.tenantconfiguration.TenantConfiguration;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
@ -32,7 +34,9 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
|
|||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
|
||||
public TenantConfigurationQuery() {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public TenantConfigurationQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantConfigurationQuery ids(UUID value) {
|
||||
|
@ -130,6 +134,11 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) ||this.isEmpty(this.isActives) ||this.isEmpty(this.types) || this.isEmpty(this.tenantIds);
|
||||
|
|
|
@ -4,12 +4,14 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.data.TenantEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.model.Tenant;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -32,9 +34,11 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
|
||||
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantQuery(QueryUtilsService queryUtilsService) {
|
||||
public TenantQuery(QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantQuery like(String value) {
|
||||
|
@ -117,6 +121,11 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.codes) ||this.isEmpty(this.isActives);
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -11,6 +12,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.TenantUserEntity;
|
||||
import org.opencdmp.data.UserEntity;
|
||||
import org.opencdmp.model.TenantUser;
|
||||
|
@ -33,13 +35,15 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantUserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantUserQuery ids(UUID value) {
|
||||
|
@ -122,6 +126,11 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<TenantUserEntity> entityClass() {
|
||||
return TenantUserEntity.class;
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -12,6 +13,7 @@ import org.opencdmp.authorization.Permission;
|
|||
import org.opencdmp.commons.enums.ContactInfoType;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DmpUserEntity;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.UserContactInfoEntity;
|
||||
import org.opencdmp.model.UserContactInfo;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
|
@ -37,10 +39,12 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
private final QueryUtilsService queryUtilsService;
|
||||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
public UserContactInfoQuery(QueryUtilsService queryUtilsService, UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserContactInfoQuery(QueryUtilsService queryUtilsService, UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserContactInfoQuery ids(UUID value) {
|
||||
|
@ -147,6 +151,11 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,12 +4,14 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.UserCredentialEntity;
|
||||
import org.opencdmp.model.usercredential.UserCredential;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -31,9 +33,11 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
|
||||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserCredentialQuery ids(UUID value) {
|
||||
|
@ -111,6 +115,11 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -3,12 +3,14 @@ package org.opencdmp.query;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.enums.UserDescriptionTemplateRole;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.UserDescriptionTemplateEntity;
|
||||
import org.opencdmp.model.UserDescriptionTemplate;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -136,9 +138,16 @@ public class UserDescriptionTemplateQuery extends QueryBase<UserDescriptionTempl
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserDescriptionTemplateQuery(
|
||||
) {
|
||||
TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import gr.cite.tools.data.query.FieldResolver;
|
|||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import gr.cite.tools.exception.MyNotFoundException;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -13,10 +14,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.DmpUserEntity;
|
||||
import org.opencdmp.data.UserContactInfoEntity;
|
||||
import org.opencdmp.data.UserEntity;
|
||||
import org.opencdmp.data.UserRoleEntity;
|
||||
import org.opencdmp.data.*;
|
||||
import org.opencdmp.model.PublicUser;
|
||||
import org.opencdmp.model.user.User;
|
||||
import org.opencdmp.query.utils.BuildSubQueryInput;
|
||||
|
@ -44,10 +42,12 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
public UserQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserQuery(UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserQuery like(String value) {
|
||||
|
@ -140,6 +140,11 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,12 +4,14 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.UserRoleEntity;
|
||||
import org.opencdmp.model.UserRole;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -33,9 +35,11 @@ public class UserRoleQuery extends QueryBase<UserRoleEntity> {
|
|||
|
||||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
public UserRoleQuery(UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserRoleQuery(UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserRoleQuery ids(UUID value) {
|
||||
|
@ -133,6 +137,11 @@ public class UserRoleQuery extends QueryBase<UserRoleEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.commons.web.authz.service.AuthorizationService;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -11,6 +12,7 @@ import org.opencdmp.authorization.AuthorizationFlags;
|
|||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commons.enums.UserSettingsType;
|
||||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.opencdmp.data.UserSettingsEntity;
|
||||
import org.opencdmp.model.UserSettings;
|
||||
import org.opencdmp.query.utils.QueryUtilsService;
|
||||
|
@ -37,13 +39,15 @@ public class UserSettingsQuery extends QueryBase<UserSettingsEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
public UserSettingsQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService, QueryUtilsService queryUtilsService
|
||||
AuthorizationService authService, QueryUtilsService queryUtilsService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserSettingsQuery like(String like) {
|
||||
|
@ -142,6 +146,11 @@ public class UserSettingsQuery extends QueryBase<UserSettingsEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.keys) || this.isEmpty(this.types) || this.isEmpty(this.entityIds);
|
||||
|
|
|
@ -1138,7 +1138,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
|||
DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().ids(data.getDmpDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActive(IsActive.Active).first();
|
||||
if (dmpDescriptionTemplateEntity != null) xml.setSectionId(dmpDescriptionTemplateEntity.getSectionId());
|
||||
|
||||
DescriptionTagQuery descriptionTagQuery = new DescriptionTagQuery();
|
||||
DescriptionTagQuery descriptionTagQuery = this.queryFactory.query(DescriptionTagQuery.class);
|
||||
descriptionTagQuery.descriptionIds(data.getId());
|
||||
descriptionTagQuery.isActive(IsActive.Active);
|
||||
|
||||
|
|
|
@ -129,7 +129,8 @@ public class LockServiceImpl implements LockService {
|
|||
else {
|
||||
if (new Date().getTime() - Date.from(lock.getTouchedAt()).getTime() > this.lockProperties.getLockInterval()) {
|
||||
lockStatus.setStatus(false);
|
||||
this.deleteAndSave(lock.getId(), lock.getTarget());
|
||||
this.deleterFactory.deleter(LockDeleter.class).deleteAndSaveByIds(List.of(lock.getId()));
|
||||
//this.deleteAndSave(lock.getId(), lock.getTarget());
|
||||
} else lockStatus.setStatus(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.tools.logging.LoggerService;
|
|||
import io.prometheus.client.Gauge;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.PersistenceUnit;
|
||||
import org.opencdmp.commons.fake.FakeRequestScope;
|
||||
import org.opencdmp.data.TenantEntityManager;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -28,16 +29,17 @@ public class UpdateMetricsTask implements Closeable, ApplicationListener<Applica
|
|||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UpdateMetricsTask.class));
|
||||
private final UpdateMetricsTaskProperties _config;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
private ScheduledExecutorService scheduler;
|
||||
private Map<String, Gauge> gauges;
|
||||
|
||||
public UpdateMetricsTask(
|
||||
UpdateMetricsTaskProperties config,
|
||||
ApplicationContext applicationContext, EntityManagerFactory entityManagerFactory) {
|
||||
ApplicationContext applicationContext) {
|
||||
this._config = config;
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.gauges = null;
|
||||
}
|
||||
|
||||
|
@ -71,29 +73,34 @@ public class UpdateMetricsTask implements Closeable, ApplicationListener<Applica
|
|||
|
||||
private void ensureGauges() {
|
||||
if (this.gauges != null) return;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
MetricsService metricsService = this.applicationContext.getBean(MetricsService.class);
|
||||
this.gauges = metricsService.gaugesBuild();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
MetricsService metricsService = this.applicationContext.getBean(MetricsService.class);
|
||||
this.gauges = metricsService.gaugesBuild();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculate() {
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
MetricsService metricsService = this.applicationContext.getBean(MetricsService.class);
|
||||
|
||||
metricsService.calculate(this.gauges);
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
|
|
@ -3,10 +3,7 @@ package org.opencdmp.service.storage;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.opencdmp.commons.fake.FakeRequestScope;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
|
@ -60,6 +57,7 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(StorageFileCleanupTask.class));
|
||||
private final StorageFileCleanupProperties _config;
|
||||
private final ApplicationContext applicationContext;
|
||||
@PersistenceUnit
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
|
@ -115,26 +113,23 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
|
||||
private boolean processStorageFile(UUID fileId) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
try {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
StorageFileEntity item = queryFactory.query(StorageFileQuery.class).ids(fileId).isPurged(false).first();
|
||||
success = true;
|
||||
|
||||
if (item != null) {
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
StorageFileService storageFileService = this.applicationContext.getBean(StorageFileService.class);
|
||||
try {
|
||||
if (item.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(item.getTenantId()).first();
|
||||
|
@ -142,6 +137,8 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
StorageFileService storageFileService = this.applicationContext.getBean(StorageFileService.class);
|
||||
storageFileService.purgeSafe(fileId);
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
|
@ -159,8 +156,9 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
if (transaction != null) transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of file. Skipping: {}", ex.getMessage(), ex);
|
||||
}
|
||||
|
@ -170,16 +168,18 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
|
||||
private CandidateInfo candidate(Instant lastCandidateCreationTimestamp) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
try {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
|
||||
StorageFileQuery query = queryFactory.query(StorageFileQuery.class)
|
||||
.canPurge(true)
|
||||
.isPurged(false)
|
||||
|
@ -206,7 +206,7 @@ public class StorageFileCleanupTask implements Closeable, ApplicationListener<A
|
|||
if (transaction != null) transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of file. Skipping: {}", ex.getMessage(), ex);
|
||||
|
|
|
@ -215,7 +215,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package org.opencdmp.interceptors.tenant;
|
||||
|
||||
|
||||
import org.opencdmp.authorization.ClaimNames;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.data.TenantEntity;
|
||||
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
||||
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorContext;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.opencdmp.authorization.ClaimNames;
|
||||
import org.opencdmp.commons.enums.IsActive;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.data.TenantEntity;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -5,15 +5,12 @@ import gr.cite.notification.schedule.NotificationScheduleTask;
|
|||
import gr.cite.notification.service.message.common.MessageBuilderBase;
|
||||
import gr.cite.notification.service.notificationscheduling.NotificationSchedulingService;
|
||||
import gr.cite.notification.service.notificationscheduling.NotificationSchedulingServiceImpl;
|
||||
import gr.cite.queueinbox.task.rabbitmq.QueueListenerProperties;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -34,13 +31,11 @@ public class NotificationConfig {
|
|||
}
|
||||
private final ApplicationContext applicationContext;
|
||||
private final NotificationProperties properties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Autowired
|
||||
public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties, EntityManagerFactory entityManagerFactory) {
|
||||
public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.properties = properties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean(BeanQualifier.GLOBAL_POLICIES_MAP)
|
||||
|
@ -74,7 +69,7 @@ public class NotificationConfig {
|
|||
|
||||
@Bean
|
||||
public NotificationSchedulingService notificationSchedulingService() {
|
||||
return new NotificationSchedulingServiceImpl(this.applicationContext, this.properties, this.entityManagerFactory);
|
||||
return new NotificationSchedulingServiceImpl(this.applicationContext, this.properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -96,6 +96,7 @@ public class NotificationEntity extends TenantScopedBaseEntity {
|
|||
public static final String _createdAt = "createdAt";
|
||||
|
||||
@Column(name = "\"updated_at\"", nullable = false)
|
||||
@Version
|
||||
private Instant updatedAt;
|
||||
|
||||
public static final String _updatedAt = "updatedAt";
|
||||
|
|
|
@ -71,6 +71,7 @@ public class QueueOutboxEntity implements QueueOutbox {
|
|||
public static final String _createdAt = "createdAt";
|
||||
|
||||
@Column(name = "\"updated_at\"", nullable = false)
|
||||
@Version
|
||||
private Instant updatedAt;
|
||||
|
||||
public static final String _updatedAt = "updatedAt";
|
||||
|
|
|
@ -95,6 +95,7 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void reloadTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -113,6 +114,7 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void loadExplictTenantFilters() throws InvalidApplicationException {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
this.disableTenantFilters();
|
||||
|
||||
if (!this.tenantScope.isSet()) return;
|
||||
|
@ -131,6 +133,7 @@ public class TenantEntityManager {
|
|||
}
|
||||
|
||||
public void disableTenantFilters() {
|
||||
if (!this.entityManager.isOpen()) return;
|
||||
this.entityManager
|
||||
.unwrap(Session.class)
|
||||
.disableFilter(TenantScopedBaseEntity.TENANT_FILTER);
|
||||
|
|
|
@ -4,7 +4,6 @@ import gr.cite.notification.integrationevent.inbox.InboxProperties;
|
|||
import gr.cite.notification.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;
|
||||
|
@ -19,17 +18,15 @@ public class InboxIntegrationEventConfigurer extends InboxConfigurer {
|
|||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final InboxProperties inboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.inboxProperties = inboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public InboxRepository inboxRepositoryCreator() {
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties, this.entityManagerFactory);
|
||||
return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -27,13 +26,9 @@ import java.util.UUID;
|
|||
@ConditionalOnProperty(prefix = "queue.task.publisher", name = "enable", matchIfMissing = false)
|
||||
public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final OutboxProperties outboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext, OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory) {
|
||||
public OutboxIntegrationEventConfigurer(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.outboxProperties = outboxProperties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -69,7 +64,7 @@ public class OutboxIntegrationEventConfigurer extends OutboxConfigurer {
|
|||
|
||||
@Bean
|
||||
public OutboxRepository outboxRepositoryCreator() {
|
||||
return new OutboxRepositoryImpl(this.applicationContext, this.outboxProperties, this.entityManagerFactory);
|
||||
return new OutboxRepositoryImpl(this.applicationContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package gr.cite.notification.integrationevent.inbox;
|
||||
|
||||
import gr.cite.notification.common.JsonHandlingService;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.fake.FakeRequestScope;
|
||||
import gr.cite.notification.data.QueueInboxEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.integrationevent.TrackedEvent;
|
||||
import gr.cite.notification.integrationevent.inbox.notify.NotifyIntegrationEventHandler;
|
||||
import gr.cite.notification.integrationevent.inbox.tenantdefaultlocaleremoval.TenantDefaultLocaleRemovalIntegrationEventHandler;
|
||||
import gr.cite.notification.integrationevent.inbox.tenantdefaultlocaletouched.TenantDefaultLocaleTouchedIntegrationEventHandler;
|
||||
|
@ -24,10 +22,7 @@ import gr.cite.rabbitmq.consumer.InboxCreatorParams;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
@ -41,29 +36,30 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(InboxRepositoryImpl.class));
|
||||
|
||||
protected final ApplicationContext applicationContext;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private final InboxProperties inboxProperties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
|
||||
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public InboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
InboxProperties inboxProperties, EntityManagerFactory entityManagerFactory
|
||||
InboxProperties inboxProperties
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.jsonHandlingService = this.applicationContext.getBean(JsonHandlingService.class);
|
||||
this.inboxProperties = inboxProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions options) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
@ -102,8 +98,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue inbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -115,12 +110,14 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueInbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -147,8 +144,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -159,12 +155,14 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public boolean shouldWait(CandidateInfo candidate, Function<QueueInbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -192,8 +190,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -204,14 +201,16 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public QueueInbox create(InboxCreatorParams inboxCreatorParams) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
boolean success;
|
||||
QueueInboxEntity queueMessage = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
queueMessage = this.createQueueInboxEntity(inboxCreatorParams);
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -220,23 +219,22 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueInboxEntity createQueueInboxEntity(InboxCreatorParams inboxCreatorParams) {
|
||||
|
||||
QueueInboxEntity queueMessage = new QueueInboxEntity();
|
||||
queueMessage.setId(UUID.randomUUID());
|
||||
Object tenantId = inboxCreatorParams.getHeaders() != null ? inboxCreatorParams.getHeaders().getOrDefault(IntegrationEventMessageConstants.TENANT, null) : null;
|
||||
|
@ -245,6 +243,7 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
try {
|
||||
queueMessage.setTenantId(UUID.fromString((String) tenantId));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
queueMessage.setExchange(this.inboxProperties.getExchange());
|
||||
|
@ -264,28 +263,26 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
@Override
|
||||
public Boolean emit(CandidateInfo candidateInfo) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
QueueInboxEntity queueInboxMessage;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
}
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
EventProcessingStatus status = this.emitQueueInboxEntity(queueInboxMessage);
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
transaction.begin();
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueInboxEntity queueInboxMessage = queryFactory.query(QueueInboxQuery.class).ids(candidateInfo.getId()).first();
|
||||
transaction.begin();
|
||||
|
||||
if (queueInboxMessage == null) {
|
||||
logger.warn("Could not lookup queue inbox {} to process. Continuing...", candidateInfo.getId());
|
||||
} else {
|
||||
|
||||
EventProcessingStatus status = this.processMessage(queueInboxMessage);
|
||||
switch (status) {
|
||||
case Success: {
|
||||
queueInboxMessage.setStatus(QueueInboxStatus.SUCCESSFUL);
|
||||
|
@ -310,22 +307,56 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
|
||||
entityManager.merge(queueInboxMessage);
|
||||
entityManager.flush();
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
transaction.commit();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public EventProcessingStatus emitQueueInboxEntity(QueueInboxEntity queueInboxMessage) {
|
||||
EntityTransaction transaction = null;
|
||||
EventProcessingStatus status = EventProcessingStatus.Discard;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
||||
status = this.processMessage(queueInboxMessage);
|
||||
|
||||
entityManager.flush();
|
||||
|
||||
switch (status) {
|
||||
case Error: transaction.rollback(); break;
|
||||
case Success:
|
||||
case Postponed:
|
||||
case Discard:
|
||||
default: transaction.commit(); break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return success;
|
||||
return status;
|
||||
}
|
||||
|
||||
private EventProcessingStatus processMessage(QueueInboxEntity queueInboxMessage) {
|
||||
|
@ -358,13 +389,13 @@ public class InboxRepositoryImpl implements InboxRepository {
|
|||
properties.setMessageId(queueInboxMessage.getMessageId().toString());
|
||||
properties.setTenantId(queueInboxMessage.getTenantId());
|
||||
|
||||
TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// TrackedEvent event = this.jsonHandlingService.fromJsonSafe(TrackedEvent.class, queueInboxMessage.getMessage());
|
||||
// using (LogContext.PushProperty(this._logTrackingConfig.LogTrackingContextName, @event.TrackingContextTag))
|
||||
// {
|
||||
try {
|
||||
return handler.handle(properties, queueInboxMessage.getMessage());
|
||||
} catch (Exception ex) {
|
||||
logger.error("problem handling event from routing key " + queueInboxMessage.getRoute() + ". Setting nack and continuing...", ex);
|
||||
logger.error("problem handling event from routing key {}. Setting nack and continuing...", queueInboxMessage.getRoute(), ex);
|
||||
return EventProcessingStatus.Error;
|
||||
}
|
||||
// }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package gr.cite.notification.integrationevent.outbox;
|
||||
|
||||
import gr.cite.notification.common.JsonHandlingService;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.fake.FakeRequestScope;
|
||||
import gr.cite.notification.data.QueueOutboxEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.query.QueueOutboxQuery;
|
||||
import gr.cite.queueoutbox.entity.QueueOutbox;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
|
@ -14,10 +14,7 @@ import gr.cite.rabbitmq.IntegrationEvent;
|
|||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import jakarta.persistence.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
|
@ -33,32 +30,30 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OutboxRepositoryImpl.class));
|
||||
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private final OutboxProperties outboxProperties;
|
||||
|
||||
public OutboxRepositoryImpl(
|
||||
ApplicationContext applicationContext,
|
||||
OutboxProperties outboxProperties, EntityManagerFactory entityManagerFactory
|
||||
ApplicationContext applicationContext
|
||||
) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
this.outboxProperties = outboxProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidate(Instant lastCandidateCreationTimestamp, MessageOptions messageOptions, Function<QueueOutbox, Boolean> onConfirmTimeout) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
CandidateInfo candidate = null;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
QueueOutboxEntity item = queryFactory.query(QueueOutboxQuery.class)
|
||||
.isActives(IsActive.Active)
|
||||
.notifyStatus(QueueOutboxNotifyStatus.PENDING, QueueOutboxNotifyStatus.WAITING_CONFIRMATION, QueueOutboxNotifyStatus.ERROR)
|
||||
|
@ -96,8 +91,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
candidate = null;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
||||
|
@ -109,12 +103,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldOmit(CandidateInfo candidate, Function<QueueOutbox, Boolean> shouldOmit) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -141,8 +137,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -153,12 +148,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean shouldWait(CandidateInfo candidate, Function<QueueOutbox, Boolean> itIsTimeFunc) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -186,8 +183,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -198,12 +194,14 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public Boolean process(CandidateInfo candidateInfo, Boolean isAutoconfirmOnPublish, Function<QueueOutbox, Boolean> publish) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
Boolean success = false;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -240,8 +238,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
transaction.rollback();
|
||||
success = false;
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -252,11 +249,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleConfirm(List<UUID> confirmedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -282,8 +281,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -293,11 +291,13 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public void handleNack(List<UUID> nackedMessages) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
|
@ -323,8 +323,7 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
|
@ -334,12 +333,15 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
@Override
|
||||
public QueueOutbox create(IntegrationEvent item) {
|
||||
EntityTransaction transaction = null;
|
||||
EntityManager entityManager = null;
|
||||
QueueOutboxEntity queueMessage = null;
|
||||
boolean success;
|
||||
try (FakeRequestScope ignored = new FakeRequestScope()) {
|
||||
try {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
queueMessage = this.mapEvent((OutboxIntegrationEvent) item);
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
|
||||
transaction.begin();
|
||||
|
@ -348,18 +350,20 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
entityManager.flush();
|
||||
|
||||
transaction.commit();
|
||||
success = true;
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
if (transaction != null)
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null)
|
||||
entityManager.close();
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
success = false;
|
||||
logger.error("Problem executing purge. rolling back any db changes and marking error. Continuing...", ex);
|
||||
}
|
||||
return queueMessage;
|
||||
return success ? queueMessage : null;
|
||||
}
|
||||
|
||||
private QueueOutboxEntity mapEvent(OutboxIntegrationEvent event) {
|
||||
|
@ -370,26 +374,5 @@ public class OutboxRepositoryImpl implements OutboxRepository {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// UUID correlationId = UUID.randomUUID();
|
||||
// if (event.getEvent() != null)
|
||||
// event.getEvent().setTrackingContextTag(correlationId.toString());
|
||||
// event.setMessage(this.jsonHandlingService.toJsonSafe(event.getEvent()));
|
||||
// //this._logTrackingService.Trace(correlationId.ToString(), $"Correlating current tracking context with new correlationId {correlationId}");
|
||||
//
|
||||
// QueueOutboxEntity queueMessage = new QueueOutboxEntity();
|
||||
// queueMessage.setId(UUID.randomUUID());
|
||||
// queueMessage.setTenantId(event.getTenantId());
|
||||
// queueMessage.setExchange(this.outboxProperties.getExchange());
|
||||
// queueMessage.setRoute(routingKey);
|
||||
// queueMessage.setMessageId(event.getMessageId());
|
||||
// queueMessage.setMessage(this.jsonHandlingService.toJsonSafe(event));
|
||||
// queueMessage.setIsActive(IsActive.Active);
|
||||
// queueMessage.setNotifyStatus(QueueOutboxNotifyStatus.PENDING);
|
||||
// queueMessage.setRetryCount(0);
|
||||
// queueMessage.setCreatedAt(Instant.now());
|
||||
// queueMessage.setUpdatedAt(Instant.now());
|
||||
//
|
||||
// return queueMessage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ public class NotificationDeleter implements Deleter {
|
|||
for (NotificationEntity item : datas) {
|
||||
logger.trace("deleting item {}", item.getId());
|
||||
item.setIsActive(IsActive.Inactive);
|
||||
item.setUpdatedAt(now);
|
||||
logger.trace("updating item");
|
||||
this.entityManager.merge(item);
|
||||
logger.trace("updated item");
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package gr.cite.notification.model.deleter;
|
||||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserCredentialEntity;
|
||||
import gr.cite.notification.query.UserCredentialQuery;
|
||||
|
@ -26,7 +25,7 @@ public class UserCredentialDeleter implements Deleter {
|
|||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCredentialDeleter.class));
|
||||
|
||||
private final TenantEntityManager entityManager;
|
||||
private final TenantEntityManager entityManager;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
|
@ -59,8 +58,6 @@ public class UserCredentialDeleter implements Deleter {
|
|||
if (data == null || data.isEmpty())
|
||||
return;
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
||||
for (UserCredentialEntity item : data) {
|
||||
logger.trace("deleting item {}", item.getId());
|
||||
logger.trace("deleting item");
|
||||
|
|
|
@ -5,10 +5,12 @@ import gr.cite.notification.common.enums.InAppNotificationPriority;
|
|||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.enums.NotificationInAppTracking;
|
||||
import gr.cite.notification.data.InAppNotificationEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.model.InAppNotification;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -46,7 +48,13 @@ public class InAppNotificationQuery extends QueryBase<InAppNotificationEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public InAppNotificationQuery like(String value) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public InAppNotificationQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public InAppNotificationQuery like(String value) {
|
||||
this.like = value;
|
||||
return this;
|
||||
}
|
||||
|
@ -166,6 +174,11 @@ public class InAppNotificationQuery extends QueryBase<InAppNotificationEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isNullOrEmpty(this.ids)
|
||||
|
|
|
@ -3,11 +3,13 @@ package gr.cite.notification.query;
|
|||
import gr.cite.notification.authorization.AuthorizationFlags;
|
||||
import gr.cite.notification.common.enums.*;
|
||||
import gr.cite.notification.data.NotificationEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.model.Notification;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -51,7 +53,13 @@ public class NotificationQuery extends QueryBase<NotificationEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public NotificationQuery ids(UUID value) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public NotificationQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public NotificationQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
@ -216,6 +224,11 @@ public class NotificationQuery extends QueryBase<NotificationEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isNullOrEmpty(this.ids)
|
||||
|
|
|
@ -3,10 +3,12 @@ package gr.cite.notification.query;
|
|||
import gr.cite.notification.authorization.AuthorizationFlags;
|
||||
import gr.cite.notification.common.enums.*;
|
||||
import gr.cite.notification.data.NotificationTemplateEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.model.NotificationTemplate;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -33,6 +35,12 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
private List<NotificationTemplateKind> kinds;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public NotificationTemplateQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public NotificationTemplateQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -155,6 +163,11 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isNullOrEmpty(this.ids)
|
||||
|
|
|
@ -2,11 +2,13 @@ package gr.cite.notification.query;
|
|||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.QueueInboxEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.queueinbox.entity.QueueInboxStatus;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -30,6 +32,12 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
private Collection<QueueInboxStatus> status;
|
||||
private Integer retryThreshold;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueInboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueInboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -130,6 +138,11 @@ public class QueueInboxQuery extends QueryBase<QueueInboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueInboxEntity> entityClass() {
|
||||
return QueueInboxEntity.class;
|
||||
|
|
|
@ -3,11 +3,13 @@ package gr.cite.notification.query;
|
|||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.QueueOutboxEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -31,6 +33,12 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
private Integer retryThreshold;
|
||||
private Integer confirmTimeout;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public QueueOutboxQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public QueueOutboxQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
|
@ -136,6 +144,11 @@ public class QueueOutboxQuery extends QueryBase<QueueOutboxEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<QueueOutboxEntity> entityClass() {
|
||||
return QueueOutboxEntity.class;
|
||||
|
|
|
@ -4,10 +4,12 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.enums.TenantConfigurationType;
|
||||
import gr.cite.notification.data.TenantConfigurationEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -30,11 +32,13 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
|
|||
private Collection<UUID> excludedIds;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantConfigurationQuery() {
|
||||
}
|
||||
public TenantConfigurationQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantConfigurationQuery ids(UUID value) {
|
||||
public TenantConfigurationQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
@ -129,6 +133,11 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) ||this.isEmpty(this.isActives) ||this.isEmpty(this.types) || this.isEmpty(this.tenantIds);
|
||||
|
|
|
@ -3,10 +3,12 @@ package gr.cite.notification.query;
|
|||
import gr.cite.notification.authorization.AuthorizationFlags;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.TenantEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.model.Tenant;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -28,7 +30,13 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public TenantQuery like(String value) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantQuery like(String value) {
|
||||
this.like = value;
|
||||
return this;
|
||||
}
|
||||
|
@ -78,6 +86,11 @@ public class TenantQuery extends QueryBase<TenantEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.isActives);
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.authorization.Permission;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.user.UserScope;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserEntity;
|
||||
import gr.cite.notification.model.Tenant;
|
||||
import gr.cite.notification.model.TenantUser;
|
||||
|
@ -12,6 +13,7 @@ import gr.cite.notification.data.TenantUserEntity;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -36,12 +38,15 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public TenantUserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public TenantUserQuery ids(UUID value) {
|
||||
|
@ -124,6 +129,11 @@ public class TenantUserQuery extends QueryBase<TenantUserEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<TenantUserEntity> entityClass() {
|
||||
return TenantUserEntity.class;
|
||||
|
|
|
@ -6,6 +6,7 @@ import gr.cite.notification.authorization.Permission;
|
|||
import gr.cite.notification.common.enums.ContactInfoType;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.user.UserScope;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserContactInfoEntity;
|
||||
import gr.cite.notification.data.UserEntity;
|
||||
import gr.cite.notification.model.User;
|
||||
|
@ -13,6 +14,7 @@ import gr.cite.notification.model.UserContactInfo;
|
|||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -46,12 +48,15 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public UserContactInfoQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
UserScope userScope,
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserContactInfoQuery ids(UUID value) {
|
||||
|
@ -164,6 +169,11 @@ public class UserContactInfoQuery extends QueryBase<UserContactInfoEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.userIds) || this.isEmpty(this.excludedUserIds) || this.isEmpty(this.isActives)
|
||||
|
|
|
@ -5,11 +5,13 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.authorization.Permission;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.user.UserScope;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserCredentialEntity;
|
||||
import gr.cite.notification.model.UserCredential;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -38,9 +40,12 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public UserCredentialQuery(UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserCredentialQuery ids(UUID value) {
|
||||
|
@ -118,6 +123,11 @@ public class UserCredentialQuery extends QueryBase<UserCredentialEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -3,12 +3,14 @@ package gr.cite.notification.query;
|
|||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.enums.NotificationContactType;
|
||||
import gr.cite.notification.data.TenantConfigurationEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserCredentialEntity;
|
||||
import gr.cite.notification.data.UserNotificationPreferenceEntity;
|
||||
import gr.cite.notification.model.UserNotificationPreference;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -37,7 +39,14 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
|
|||
|
||||
private Collection<UUID> tenantIds;
|
||||
private Boolean tenantIsSet;
|
||||
public UserNotificationPreferenceQuery ids(UUID value) {
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public UserNotificationPreferenceQuery(TenantEntityManager tenantEntityManager) {
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserNotificationPreferenceQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
@ -137,6 +146,11 @@ public class UserNotificationPreferenceQuery extends QueryBase<UserNotificationP
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.tenantIds) ||this.isEmpty(this.excludedIds) ||this.isNullOrEmpty(this.userId) && this.isNullOrEmpty(this.type) && this.isNullOrEmpty(this.channel);
|
||||
|
|
|
@ -5,12 +5,14 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.authorization.Permission;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.user.UserScope;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserEntity;
|
||||
import gr.cite.notification.model.user.PublicUser;
|
||||
import gr.cite.notification.model.User;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.annotation.RequestScope;
|
||||
|
||||
|
@ -33,12 +35,15 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
private final UserScope userScope;
|
||||
private final AuthorizationService authService;
|
||||
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public UserQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
AuthorizationService authService, TenantEntityManager tenantEntityManager
|
||||
) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserQuery like(String value) {
|
||||
|
@ -91,6 +96,11 @@ public class UserQuery extends QueryBase<UserEntity> {
|
|||
this.noTracking = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
@Override
|
||||
protected Class<UserEntity> entityClass() {
|
||||
return UserEntity.class;
|
||||
|
|
|
@ -5,11 +5,13 @@ import gr.cite.notification.authorization.AuthorizationFlags;
|
|||
import gr.cite.notification.authorization.Permission;
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.common.scope.user.UserScope;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.data.UserRoleEntity;
|
||||
import gr.cite.notification.model.UserRole;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.data.query.QueryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
@ -40,9 +42,12 @@ public class UserRoleQuery extends QueryBase<UserRoleEntity> {
|
|||
|
||||
private final AuthorizationService authService;
|
||||
|
||||
public UserRoleQuery(UserScope userScope, AuthorizationService authService) {
|
||||
private final TenantEntityManager tenantEntityManager;
|
||||
|
||||
public UserRoleQuery(UserScope userScope, AuthorizationService authService, TenantEntityManager tenantEntityManager) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.tenantEntityManager = tenantEntityManager;
|
||||
}
|
||||
|
||||
public UserRoleQuery ids(UUID value) {
|
||||
|
@ -135,6 +140,11 @@ public class UserRoleQuery extends QueryBase<UserRoleEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityManager entityManager(){
|
||||
return this.tenantEntityManager.getEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return
|
||||
|
|
|
@ -14,206 +14,167 @@ import gr.cite.notification.model.SendNotificationResult;
|
|||
import gr.cite.notification.query.NotificationQuery;
|
||||
import gr.cite.notification.query.TenantQuery;
|
||||
import gr.cite.notification.schedule.model.CandidateInfo;
|
||||
import gr.cite.notification.schedule.model.MiniTenant;
|
||||
import gr.cite.notification.service.notification.NotificationService;
|
||||
import gr.cite.notification.service.track.TrackingFactory;
|
||||
import gr.cite.notification.service.track.model.TrackerResponse;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.OptimisticLockException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NotificationSchedulingServiceImpl implements NotificationSchedulingService {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationSchedulingServiceImpl.class));
|
||||
private final ApplicationContext applicationContext;
|
||||
private final NotificationProperties properties;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
public NotificationSchedulingServiceImpl(ApplicationContext applicationContext, NotificationProperties properties, EntityManagerFactory entityManagerFactory) {
|
||||
public NotificationSchedulingServiceImpl(ApplicationContext applicationContext, NotificationProperties properties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.properties = properties;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidateToNotify(Instant lastCandidateNotificationCreationTimestamp) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
CandidateInfo candidateInfo = null;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity candidates;
|
||||
|
||||
notificationQuery = notificationQuery
|
||||
.isActive(IsActive.Active)
|
||||
.notifyState(NotificationNotifyState.PENDING, NotificationNotifyState.ERROR)
|
||||
.retryThreshold(Math.toIntExact(this.properties.getTask().getProcessor().getOptions().getRetryThreshold()))
|
||||
.createdAfter(lastCandidateNotificationCreationTimestamp)
|
||||
.ordering(new Ordering().addAscending(NotificationEntity._createdAt));
|
||||
candidates = notificationQuery.first();
|
||||
if (candidates != null) {
|
||||
NotificationNotifyState previousState = candidates.getNotifyState();
|
||||
candidates.setNotifyState(NotificationNotifyState.PROCESSING);
|
||||
//candidates.setUpdatedAt(Instant.now());
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
try {
|
||||
if (candidates.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(candidates.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity candidates;
|
||||
|
||||
notificationQuery = notificationQuery
|
||||
.isActive(IsActive.Active)
|
||||
.notifyState(NotificationNotifyState.PENDING, NotificationNotifyState.ERROR)
|
||||
.retryThreshold(Math.toIntExact(this.properties.getTask().getProcessor().getOptions().getRetryThreshold()))
|
||||
.createdAfter(lastCandidateNotificationCreationTimestamp)
|
||||
.ordering(new Ordering().addAscending(NotificationEntity._createdAt));
|
||||
candidates = notificationQuery.first();
|
||||
if (candidates != null) {
|
||||
NotificationNotifyState previousState = candidates.getNotifyState();
|
||||
candidates.setNotifyState(NotificationNotifyState.PROCESSING);
|
||||
//candidates.setUpdatedAt(Instant.now());
|
||||
candidates = entityManager.merge(candidates);
|
||||
entityManager.persist(candidates);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
}
|
||||
|
||||
candidateInfo = new CandidateInfo(candidates.getId(), previousState, candidates.getCreatedAt());
|
||||
candidateInfo = new CandidateInfo(candidates.getId(), previousState, candidates.getCreatedAt());
|
||||
}
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return candidateInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean shouldWait(CandidateInfo candidateInfo) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
Boolean shouldWait = false;
|
||||
boolean shouldWait = false;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, candidateInfo.getNotificationId());
|
||||
if (notification.getRetryCount() != null && notification.getRetryCount() >= 1) {
|
||||
int accumulatedRetry = 0;
|
||||
int pastAccumulateRetry = 0;
|
||||
NotificationProperties.Task.Processor.Options options = properties.getTask().getProcessor().getOptions();
|
||||
for (int i = 1; i <= notification.getRetryCount() + 1; i += 1)
|
||||
accumulatedRetry += (i * options.getRetryThreshold());
|
||||
for (int i = 1; i <= notification.getRetryCount(); i += 1)
|
||||
pastAccumulateRetry += (i * options.getRetryThreshold());
|
||||
int randAccumulatedRetry = ThreadLocalRandom.current().nextInt(accumulatedRetry / 2, accumulatedRetry + 1);
|
||||
long additionalTime = randAccumulatedRetry > options.getMaxRetryDelaySeconds() ? options.getMaxRetryDelaySeconds() : randAccumulatedRetry;
|
||||
long retry = pastAccumulateRetry + additionalTime;
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, candidateInfo.getNotificationId());
|
||||
if (notification.getRetryCount() != null && notification.getRetryCount() >= 1) {
|
||||
int accumulatedRetry = 0;
|
||||
int pastAccumulateRetry = 0;
|
||||
NotificationProperties.Task.Processor.Options options = properties.getTask().getProcessor().getOptions();
|
||||
for (int i = 1; i <= notification.getRetryCount() + 1; i += 1)
|
||||
accumulatedRetry += (int) (i * options.getRetryThreshold());
|
||||
for (int i = 1; i <= notification.getRetryCount(); i += 1)
|
||||
pastAccumulateRetry += (int) (i * options.getRetryThreshold());
|
||||
int randAccumulatedRetry = ThreadLocalRandom.current().nextInt(accumulatedRetry / 2, accumulatedRetry + 1);
|
||||
long additionalTime = randAccumulatedRetry > options.getMaxRetryDelaySeconds() ? options.getMaxRetryDelaySeconds() : randAccumulatedRetry;
|
||||
long retry = pastAccumulateRetry + additionalTime;
|
||||
|
||||
Instant retryOn = notification.getCreatedAt().plusSeconds(retry);
|
||||
boolean itIsTime = retryOn.isBefore(Instant.now());
|
||||
Instant retryOn = notification.getCreatedAt().plusSeconds(retry);
|
||||
boolean itIsTime = retryOn.isBefore(Instant.now());
|
||||
|
||||
if (!itIsTime) {
|
||||
notification.setNotifyState(candidateInfo.getPreviousState());
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
if (!itIsTime) {
|
||||
notification.setNotifyState(candidateInfo.getPreviousState());
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
// notification = entityManager.merge(notification);
|
||||
entityManager.merge(notification);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
}
|
||||
|
||||
shouldWait = !itIsTime;
|
||||
}
|
||||
shouldWait = !itIsTime;
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return shouldWait;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean shouldOmitNotify(UUID notificationId) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
Boolean shouldOmit = false;
|
||||
boolean shouldOmit = false;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, notificationId);
|
||||
long age = Instant.now().getEpochSecond() - notification.getCreatedAt().getEpochSecond();
|
||||
long omitSeconds = properties.getTask().getProcessor().getOptions().getTooOldToSendSeconds();
|
||||
if (age >= omitSeconds) {
|
||||
notification.setNotifyState(NotificationNotifyState.OMITTED);
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, notificationId);
|
||||
long age = Instant.now().getEpochSecond() - notification.getCreatedAt().getEpochSecond();
|
||||
long omitSeconds = properties.getTask().getProcessor().getOptions().getTooOldToSendSeconds();
|
||||
if (age >= omitSeconds) {
|
||||
notification.setNotifyState(NotificationNotifyState.OMITTED);
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
notification = entityManager.merge(notification);
|
||||
entityManager.persist(notification);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
|
||||
shouldOmit = true;
|
||||
}
|
||||
shouldOmit = true;
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return shouldOmit;
|
||||
|
||||
|
@ -221,177 +182,163 @@ public class NotificationSchedulingServiceImpl implements NotificationScheduling
|
|||
|
||||
@Override
|
||||
public Boolean notify(UUID notificationId) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
Boolean success = null;
|
||||
boolean success;
|
||||
NotificationEntity notification;
|
||||
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
EntityTransaction transaction = null;
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
NotificationQuery notificationQuery = applicationContext.getBean(NotificationQuery.class);
|
||||
NotificationEntity notification = notificationQuery.ids(notificationId).first();
|
||||
if (notification == null) throw new IllegalArgumentException("notification is null");
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
notification = queryFactory.query(NotificationQuery.class).ids(notificationId).first();
|
||||
if (notification == null) throw new IllegalArgumentException("notification is null");
|
||||
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
|
||||
SendNotificationResult result;
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
|
||||
NotificationService notificationService = this.applicationContext.getBean(NotificationService.class);
|
||||
result = notificationService.doNotify(notification);
|
||||
|
||||
SendNotificationResult result = null;
|
||||
NotificationService notificationService = this.applicationContext.getBean(NotificationService.class);
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
if (result != null && result.getSuccess()) {
|
||||
notification.setNotifyState(NotificationNotifyState.SUCCESSFUL);
|
||||
notification.setTrackingData(result.getTrackingData());
|
||||
notification.setNotifiedWith(result.getContactType());
|
||||
notification.setNotifiedAt(Instant.now());
|
||||
} else {
|
||||
notification.setNotifyState(NotificationNotifyState.ERROR);
|
||||
notification.setRetryCount(notification.getRetryCount() != null ? notification.getRetryCount() + 1 : 0);
|
||||
notification.setNotifiedWith(null);
|
||||
notification.setNotifiedAt(null);
|
||||
}
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
NotificationEntity notification1 = entityManager.merge(notification);
|
||||
entityManager.persist(notification1);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
result = notificationService.doNotify(notification);
|
||||
|
||||
if (result != null && result.getSuccess()) {
|
||||
notification.setNotifyState(NotificationNotifyState.SUCCESSFUL);
|
||||
notification.setTrackingData(result.getTrackingData());
|
||||
notification.setNotifiedWith(result.getContactType());
|
||||
notification.setNotifiedAt(Instant.now());
|
||||
} else {
|
||||
notification.setNotifyState(NotificationNotifyState.ERROR);
|
||||
notification.setRetryCount(notification.getRetryCount() != null ? notification.getRetryCount() + 1 : 0);
|
||||
notification.setNotifiedWith(null);
|
||||
notification.setNotifiedAt(null);
|
||||
}
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
NotificationEntity notification1 = entityManager.merge(notification);
|
||||
entityManager.persist(notification1);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//we want to return false for notification we want to add in the skip bag
|
||||
success = result != null && result.getSuccess();
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
//we want to return false for notification we want to add in the skip bag
|
||||
success = result != null && result.getSuccess();
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
success = false;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CandidateInfo candidateToTrack(Instant lastCandidateNotificationCreationTimestamp) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
CandidateInfo candidateInfo = null;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity candidates;
|
||||
|
||||
notificationQuery = notificationQuery
|
||||
.isActive(IsActive.Active)
|
||||
.notifyState(NotificationNotifyState.SUCCESSFUL)
|
||||
.notifiedWithHasValue()
|
||||
.notifiedWithHasValue()
|
||||
.createdAfter(lastCandidateNotificationCreationTimestamp)
|
||||
.trackingState(NotificationTrackingState.QUEUED, NotificationTrackingState.SENT, NotificationTrackingState.UNDEFINED)
|
||||
.trackingProgress(NotificationTrackingProcess.PENDING);
|
||||
candidates = notificationQuery.first();
|
||||
if (candidates != null) {
|
||||
NotificationNotifyState previousState = candidates.getNotifyState();
|
||||
candidates.setTrackingProcess(NotificationTrackingProcess.PROCESSING);
|
||||
//candidates.setUpdatedAt(Instant.now());
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try {
|
||||
if (candidates.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(candidates.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity candidates;
|
||||
|
||||
notificationQuery = notificationQuery
|
||||
.isActive(IsActive.Active)
|
||||
.notifyState(NotificationNotifyState.SUCCESSFUL)
|
||||
.notifiedWithHasValue()
|
||||
.notifiedWithHasValue()
|
||||
.createdAfter(lastCandidateNotificationCreationTimestamp)
|
||||
.trackingState(NotificationTrackingState.QUEUED, NotificationTrackingState.SENT, NotificationTrackingState.UNDEFINED)
|
||||
.trackingProgress(NotificationTrackingProcess.PENDING);
|
||||
candidates = notificationQuery.first();
|
||||
if (candidates != null) {
|
||||
NotificationNotifyState previousState = candidates.getNotifyState();
|
||||
candidates.setTrackingProcess(NotificationTrackingProcess.PROCESSING);
|
||||
//candidates.setUpdatedAt(Instant.now());
|
||||
|
||||
candidates = entityManager.merge(candidates);
|
||||
entityManager.persist(candidates);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
|
||||
candidateInfo = new CandidateInfo(candidates.getId(), previousState, candidates.getCreatedAt());
|
||||
}
|
||||
candidateInfo = new CandidateInfo(candidates.getId(), previousState, candidates.getCreatedAt());
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return candidateInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean shouldOmitTracking(UUID notificationId) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
Boolean shouldOmit = false;
|
||||
boolean shouldOmit = false;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, notificationId);
|
||||
long age = Instant.now().getEpochSecond() - notification.getNotifiedAt().getEpochSecond();
|
||||
long omitSeconds = properties.getTask().getProcessor().getOptions().getTooOldToTrackSeconds();
|
||||
if (age >= omitSeconds) {
|
||||
notification.setTrackingProcess(NotificationTrackingProcess.OMITTED);
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
NotificationEntity notification = entityManager.find(NotificationEntity.class, notificationId);
|
||||
long age = Instant.now().getEpochSecond() - notification.getNotifiedAt().getEpochSecond();
|
||||
long omitSeconds = properties.getTask().getProcessor().getOptions().getTooOldToTrackSeconds();
|
||||
if (age >= omitSeconds) {
|
||||
notification.setTrackingProcess(NotificationTrackingProcess.OMITTED);
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
notification = entityManager.merge(notification);
|
||||
entityManager.persist(notification);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
|
||||
shouldOmit = true;
|
||||
}
|
||||
shouldOmit = true;
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return shouldOmit;
|
||||
|
||||
|
@ -399,75 +346,73 @@ public class NotificationSchedulingServiceImpl implements NotificationScheduling
|
|||
|
||||
@Override
|
||||
public Boolean track(UUID notificationId) {
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
Boolean success = null;
|
||||
try (FakeRequestScope fakeRequestScope = new FakeRequestScope()) {
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity notification = notificationQuery.ids(notificationId).first();
|
||||
if (notification == null) throw new IllegalArgumentException("notification is null");
|
||||
if (notification.getNotifiedWith() == null) throw new IllegalArgumentException("Notification's Notified With is null");
|
||||
if (notification.getNotifiedAt() == null) throw new IllegalArgumentException("Notification's Notified At is null");
|
||||
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
|
||||
TrackerResponse result = null;
|
||||
try {
|
||||
if (notification.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
|
||||
QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class);
|
||||
NotificationQuery notificationQuery = queryFactory.query(NotificationQuery.class);
|
||||
NotificationEntity notification = notificationQuery.ids(notificationId).first();
|
||||
if (notification == null) throw new IllegalArgumentException("notification is null");
|
||||
if (notification.getNotifiedWith() == null) throw new IllegalArgumentException("Notification's Notified With is null");
|
||||
if (notification.getNotifiedAt() == null) throw new IllegalArgumentException("Notification's Notified At is null");
|
||||
|
||||
TenantScope tenantScope = this.applicationContext.getBean(TenantScope.class);
|
||||
TrackerResponse result = null;
|
||||
try {
|
||||
TrackingFactory trackingFactory = applicationContext.getBean(TrackingFactory.class);
|
||||
result = trackingFactory.fromContactType(notification.getNotifiedWith()).track(notification);
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not complete track for notification " + notification.getId(), e);
|
||||
}
|
||||
if (notification.getTenantId() != null) {
|
||||
TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(notification.getTenantId()).first();
|
||||
tenantScope.setTempTenant(tenantEntityManager, tenant.getId(), tenant.getCode());
|
||||
} else {
|
||||
tenantScope.setTempTenant(tenantEntityManager, null, tenantScope.getDefaultTenantCode());
|
||||
}
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
|
||||
try {
|
||||
TrackingFactory trackingFactory = applicationContext.getBean(TrackingFactory.class);
|
||||
result = trackingFactory.fromContactType(notification.getNotifiedWith()).track(notification);
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not complete track for notification {}", notification.getId(), e);
|
||||
}
|
||||
|
||||
if (result != null && notification.getTrackingProcess().equals(result.getTrackingProgress()) && notification.getTrackingState().equals(result.getTrackingState())) {
|
||||
return false;
|
||||
}
|
||||
if (result != null && notification.getTrackingProcess().equals(result.getTrackingProgress()) && notification.getTrackingState().equals(result.getTrackingState())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
notification.setTrackingState(result.getTrackingState());
|
||||
notification.setTrackingProcess(result.getTrackingProgress());
|
||||
notification.setTrackingData(result.getTrackingData());
|
||||
} else {
|
||||
notification.setTrackingProcess(NotificationTrackingProcess.ERROR);
|
||||
}
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
if (result != null) {
|
||||
notification.setTrackingState(result.getTrackingState());
|
||||
notification.setTrackingProcess(result.getTrackingProgress());
|
||||
notification.setTrackingData(result.getTrackingData());
|
||||
} else {
|
||||
notification.setTrackingProcess(NotificationTrackingProcess.ERROR);
|
||||
}
|
||||
//notification.setUpdatedAt(Instant.now());
|
||||
|
||||
NotificationEntity notification1 = entityManager.merge(notification);
|
||||
entityManager.persist(notification1);
|
||||
entityManager.flush();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
NotificationEntity notification1 = entityManager.merge(notification);
|
||||
entityManager.persist(notification1);
|
||||
entityManager.flush();
|
||||
|
||||
//we want to return false for notification we want to add in the skip bag
|
||||
success = result != null && !notification.getTrackingProcess().equals(NotificationTrackingProcess.ERROR);
|
||||
transaction.commit();
|
||||
} finally {
|
||||
tenantScope.removeTempTenant(tenantEntityManager);
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//we want to return false for notification we want to add in the skip bag
|
||||
success = result != null && !notification.getTrackingProcess().equals(NotificationTrackingProcess.ERROR);
|
||||
transaction.commit();
|
||||
} catch (OptimisticLockException e) {
|
||||
logger.error("Optimistic Lock Error occurred on Notification persist");
|
||||
if (transaction != null) transaction.rollback();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
if (transaction != null) transaction.rollback();
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import gr.cite.notification.common.enums.NotificationInAppTracking;
|
|||
import gr.cite.notification.common.scope.tenant.TenantScope;
|
||||
import gr.cite.notification.common.types.notification.InAppTrackingData;
|
||||
import gr.cite.notification.data.InAppNotificationEntity;
|
||||
import gr.cite.notification.data.TenantEntityManager;
|
||||
import gr.cite.notification.service.contact.model.Contact;
|
||||
import gr.cite.notification.service.contact.model.InAppContact;
|
||||
import gr.cite.notification.service.message.model.InAppMessage;
|
||||
import gr.cite.notification.service.message.model.Message;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.PersistenceUnit;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -20,6 +22,8 @@ import org.springframework.stereotype.Component;
|
|||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -28,59 +32,65 @@ public class InAppNotifier implements Notify{
|
|||
private final static LoggerService logger = new LoggerService(LoggerFactory.getLogger(InAppNotifier.class));
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final EntityManagerFactory entityManagerFactory;
|
||||
private final ApplicationContext applicationContext;
|
||||
@PersistenceUnit
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Autowired
|
||||
public InAppNotifier(JsonHandlingService jsonHandlingService, ApplicationContext applicationContext, EntityManagerFactory entityManagerFactory) {
|
||||
public InAppNotifier(JsonHandlingService jsonHandlingService, ApplicationContext applicationContext) {
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.applicationContext = applicationContext;
|
||||
this.entityManagerFactory = entityManagerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String notify(Contact contact, Message message) {
|
||||
String data = null;
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction transaction = null;
|
||||
try {
|
||||
entityManager = this.entityManagerFactory.createEntityManager();
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
InAppContact inAppContact = (InAppContact) contact;
|
||||
if (inAppContact == null) throw new IllegalArgumentException("contact not provided");
|
||||
EntityTransaction transaction = null;
|
||||
TenantEntityManager tenantEntityManager = this.applicationContext.getBean(TenantEntityManager.class);
|
||||
try (EntityManager entityManager = this.entityManagerFactory.createEntityManager()) {
|
||||
tenantEntityManager.setEntityManager(entityManager);
|
||||
tenantEntityManager.disableTenantFilters();
|
||||
|
||||
transaction = entityManager.getTransaction();
|
||||
transaction.begin();
|
||||
InAppContact inAppContact = (InAppContact) contact;
|
||||
if (inAppContact == null) throw new IllegalArgumentException("contact not provided");
|
||||
|
||||
InAppMessage inAppMessage = (InAppMessage) message;
|
||||
if (inAppMessage == null) throw new IllegalArgumentException("message not provided");
|
||||
InAppMessage inAppMessage = (InAppMessage) message;
|
||||
if (inAppMessage == null) throw new IllegalArgumentException("message not provided");
|
||||
|
||||
TenantScope tenantScope = applicationContext.getBean(TenantScope.class);
|
||||
InAppNotificationEntity inApp = new InAppNotificationEntity();
|
||||
TenantScope tenantScope = applicationContext.getBean(TenantScope.class);
|
||||
InAppNotificationEntity inApp = new InAppNotificationEntity();
|
||||
|
||||
inApp.setId(UUID.randomUUID());
|
||||
inApp.setUserId(inAppContact.getUserId());
|
||||
inApp.setIsActive(IsActive.Active);
|
||||
inApp.setType(inAppMessage.getType());
|
||||
inApp.setTrackingState(NotificationInAppTracking.STORED);
|
||||
inApp.setPriority(inAppMessage.getPriority());
|
||||
inApp.setSubject(inAppMessage.getSubject());
|
||||
inApp.setBody(inAppMessage.getBody());
|
||||
inApp.setExtraData(inAppMessage.getExtraData() != null ? this.jsonHandlingService.toJsonSafe(inAppMessage.getExtraData()) : null);
|
||||
inApp.setCreatedAt(Instant.now());
|
||||
inApp.setUpdatedAt(Instant.now());
|
||||
inApp.setTenantId(tenantScope.getTenant());
|
||||
inApp.setId(UUID.randomUUID());
|
||||
inApp.setUserId(inAppContact.getUserId());
|
||||
inApp.setIsActive(IsActive.Active);
|
||||
inApp.setType(inAppMessage.getType());
|
||||
inApp.setTrackingState(NotificationInAppTracking.STORED);
|
||||
inApp.setPriority(inAppMessage.getPriority());
|
||||
inApp.setSubject(inAppMessage.getSubject());
|
||||
inApp.setBody(inAppMessage.getBody());
|
||||
inApp.setExtraData(inAppMessage.getExtraData() != null ? this.jsonHandlingService.toJsonSafe(inAppMessage.getExtraData()) : null);
|
||||
inApp.setCreatedAt(Instant.now());
|
||||
inApp.setUpdatedAt(Instant.now());
|
||||
inApp.setTenantId(tenantScope.getTenant());
|
||||
|
||||
entityManager.persist(inApp);
|
||||
entityManager.flush();
|
||||
entityManager.persist(inApp);
|
||||
entityManager.flush();
|
||||
|
||||
InAppTrackingData trackingData = new InAppTrackingData(inApp.getId());
|
||||
data = this.jsonHandlingService.toJsonSafe(trackingData);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaction != null) transaction.rollback();
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (entityManager != null) entityManager.close();
|
||||
}
|
||||
InAppTrackingData trackingData = new InAppTrackingData(inApp.getId());
|
||||
data = this.jsonHandlingService.toJsonSafe(trackingData);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
if (transaction != null) transaction.rollback();
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
tenantEntityManager.reloadTenantFilters();
|
||||
} catch (InvalidApplicationException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>data-tools</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue