Search in sources :

Example 31 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegrityOwnerIsDeleted.

@Test
@Ignore
@Transactional
public void testReferentialIntegrityOwnerIsDeleted() {
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = helper.createIdentity((GuardedString) null);
    // 
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType(entityEventManager.getOwnerType(identity.getClass()));
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(identity.getId());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    IdmEntityStateDto entityState = new IdmEntityStateDto(entityEvent);
    entityState.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityState = entityStateService.save(entityState);
    // 
    Assert.assertNotNull(entityState.getId());
    // 
    identityService.delete(identityTwo);
    // 
    Assert.assertNotNull(identityService.get(identity));
    Assert.assertNotNull(entityEventService.get(entityEvent));
    Assert.assertNotNull(entityStateService.get(entityState));
    // 
    identityService.delete(identity);
    // 
    Assert.assertNull(identityService.get(identity));
    Assert.assertNull(entityEventService.get(entityEvent));
    Assert.assertNull(entityStateService.get(entityState));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegrity.

@Test
@Transactional
public void testReferentialIntegrity() {
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType("empty");
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(UUID.randomUUID());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    IdmEntityStateDto entityState = new IdmEntityStateDto(entityEvent);
    entityState.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityState = entityStateService.save(entityState);
    // 
    Assert.assertNotNull(entityState.getId());
    // 
    entityEventService.delete(entityEvent);
    // 
    Assert.assertNull(entityEventService.get(entityEvent));
    Assert.assertNull(entityStateService.get(entityState));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegritParentIsDeleted.

@Test(expected = EventDeleteFailedHasChildrenException.class)
@Transactional
public void testReferentialIntegritParentIsDeleted() {
    IdmEntityEventDto parentEvent = new IdmEntityEventDto();
    parentEvent.setOwnerType("empty");
    parentEvent.setEventType("empty");
    parentEvent.setOwnerId(UUID.randomUUID());
    parentEvent.setInstanceId("empty");
    parentEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    parentEvent.setPriority(PriorityType.NORMAL);
    parentEvent = entityEventService.save(parentEvent);
    // 
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType("empty");
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(UUID.randomUUID());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent.setParent(parentEvent.getId());
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    entityEventService.delete(parentEvent);
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method putToQueue.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void putToQueue(IdmEntityEventDto entityEvent) {
    if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
        executeEvent(entityEvent);
        return;
    }
    if (!eventConfiguration.isAsynchronous()) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously, asynchronous event processing [{}] is disabled.", entityEvent.getEventType(), entityEvent.getOwnerId(), EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED);
        executeEvent(entityEvent);
        return;
    }
    // 
    // get enabled processors
    final EntityEvent<Identifiable> event = toEvent(entityEvent);
    List<EntityEventProcessor> registeredProcessors = context.getBeansOfType(EntityEventProcessor.class).values().stream().filter(enabledEvaluator::isEnabled).filter(processor -> !processor.isDisabled()).filter(processor -> processor.supports(event)).filter(processor -> processor.conditional(event)).sorted(new AnnotationAwareOrderComparator()).collect(Collectors.toList());
    if (registeredProcessors.isEmpty()) {
        LOG.debug("Event type [{}] for owner with id [{}] will not be executed, no enabled processor is registered.", entityEvent.getEventType(), entityEvent.getOwnerId());
        return;
    }
    // 
    // evaluate event priority by registered processors
    PriorityType priority = evaluatePriority(event, registeredProcessors);
    if (priority != null && priority.getPriority() < entityEvent.getPriority().getPriority()) {
        entityEvent.setPriority(priority);
    }
    // registered processors voted about event will be processed synchronously
    if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
        executeEvent(entityEvent);
        return;
    }
    // 
    // notification - info about registered (asynchronous) processors
    Map<String, Object> parameters = new LinkedHashMap<>();
    parameters.put("eventType", entityEvent.getEventType());
    parameters.put("ownerId", entityEvent.getOwnerId());
    parameters.put("instanceId", entityEvent.getInstanceId());
    parameters.put("processors", registeredProcessors.stream().map(DefaultEntityEventManager.this::toDto).collect(Collectors.toList()));
    notificationManager.send(CoreModuleDescriptor.TOPIC_EVENT, new IdmMessageDto.Builder().setLevel(NotificationLevel.INFO).setModel(new DefaultResultModel(CoreResultCode.EVENT_ACCEPTED, parameters)).build());
    // 
    // persist event - asynchronous processing
    entityEventService.save(entityEvent);
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Sort(org.springframework.data.domain.Sort) Objects(com.google.common.base.Objects) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) CreatedComparator(eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) DateTime(org.joda.time.DateTime) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) LinkedHashMap(java.util.LinkedHashMap) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor)

Example 35 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method scheduleProcessCreated.

/**
 * Spring schedule new task after previous task ended (don't run concurrently)
 */
@Scheduled(fixedDelayString = "${" + SchedulerConfiguration.PROPERTY_EVENT_QUEUE_PROCESS + ":" + SchedulerConfiguration.DEFAULT_EVENT_QUEUE_PROCESS + "}")
public void scheduleProcessCreated() {
    if (!eventConfiguration.isAsynchronous()) {
        // prevent to debug some messages into log - usable for devs
        return;
    }
    // run as system - called from scheduler internally
    securityService.setSystemAuthentication();
    // 
    // calculate events to process
    String instanceId = configurationService.getInstanceId();
    List<IdmEntityEventDto> events = getCreatedEvents(instanceId);
    LOG.trace("Events to process [{}] on instance [{}].", events.size(), instanceId);
    for (IdmEntityEventDto event : events) {
        // @Transactional
        context.getBean(this.getClass()).executeEvent(event);
        ;
    }
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)35 Test (org.junit.Test)21 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)15 Transactional (org.springframework.transaction.annotation.Transactional)13 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 UUID (java.util.UUID)12 ArrayList (java.util.ArrayList)11 DateTime (org.joda.time.DateTime)10 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)9 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)9 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)5 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 PageRequest (org.springframework.data.domain.PageRequest)4 Lists (com.google.common.collect.Lists)3 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 MockOwner (eu.bcvsolutions.idm.core.event.domain.MockOwner)3