68 lines
2.7 KiB
Java
68 lines
2.7 KiB
Java
package eu.eudat.integrationevent.outbox.annotationentityremoval;
|
|
|
|
import eu.eudat.commons.enums.IsActive;
|
|
import eu.eudat.data.DescriptionEntity;
|
|
import eu.eudat.data.DmpUserEntity;
|
|
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
|
|
import eu.eudat.integrationevent.outbox.OutboxService;
|
|
import eu.eudat.model.Description;
|
|
import eu.eudat.model.DmpUser;
|
|
import eu.eudat.query.DescriptionQuery;
|
|
import eu.eudat.query.DmpUserQuery;
|
|
import gr.cite.tools.data.query.QueryFactory;
|
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
|
import gr.cite.tools.logging.LoggerService;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@Component
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public class AnnotationEntityRemovalIntegrationEventHandlerImpl implements AnnotationEntityRemovalIntegrationEventHandler {
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(AnnotationEntityRemovalIntegrationEventHandlerImpl.class));
|
|
|
|
private final OutboxService outboxService;
|
|
|
|
private final QueryFactory queryFactory;
|
|
|
|
public AnnotationEntityRemovalIntegrationEventHandlerImpl(OutboxService outboxService, QueryFactory queryFactory) {
|
|
this.outboxService = outboxService;
|
|
this.queryFactory = queryFactory;
|
|
}
|
|
|
|
private void handle(AnnotationEntitiesRemovalIntegrationEvent event) {
|
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
|
message.setMessageId(UUID.randomUUID());
|
|
message.setType(OutboxIntegrationEvent.ANNOTATION_ENTITY_REMOVE);
|
|
message.setEvent(event);
|
|
this.outboxService.publish(message);
|
|
}
|
|
|
|
@Override
|
|
public void handleDescription(UUID descriptionId) {
|
|
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
|
event.setEntityIds(List.of(descriptionId));
|
|
|
|
this.handle(event);
|
|
}
|
|
|
|
@Override
|
|
public void handleDmp(UUID dmpId) {
|
|
List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).dmpIds(dmpId).collectAs(new BaseFieldSet().ensure(Description._id));
|
|
|
|
AnnotationEntitiesRemovalIntegrationEvent event = new AnnotationEntitiesRemovalIntegrationEvent();
|
|
event.setEntityIds(new ArrayList<>());
|
|
event.getEntityIds().add(dmpId);
|
|
|
|
for (DescriptionEntity description : descriptionEntities) event.getEntityIds().add(description.getId());
|
|
|
|
this.handle(event);
|
|
}
|
|
}
|