Search in sources :

Example 31 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testEventGreenLine.

@Test
public void testEventGreenLine() {
    EntityEvent<TestContent> event = new CoreEvent<>(CoreEventType.CREATE, new TestContent());
    EventContext<TestContent> context = manager.process(event);
    // 
    assertEquals(4, context.getResults().size());
    assertEquals(4, context.getProcessedOrder().intValue());
    assertEquals("4", context.getLastResult().getEvent().getContent().getText());
}
Also used : CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) TestContent(eu.bcvsolutions.idm.core.event.TestContent) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 32 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testRemoveRunningEvent.

@Test
public void testRemoveRunningEvent() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    try {
        getHelper().enableAsynchronousProcessing();
        Assert.assertFalse(manager.isRunningOwner(identity.getId()));
        // 
        // publish never ends event
        NeverEndingProcessor.wait = true;
        EntityEvent<IdmIdentityDto> event = new CoreEvent<>(NeverEndingProcessor.WAIT, identity);
        manager.processOnBackground(event);
        // 
        IdmEntityEventFilter filter = new IdmEntityEventFilter();
        filter.setOwnerId(identity.getId());
        filter.setEventType(NeverEndingProcessor.WAIT.name());
        filter.setStates(Lists.newArrayList(OperationState.RUNNING));
        // 
        // wait for executed event is running
        getHelper().waitForResult(res -> {
            return !manager.isRunningOwner(identity.getId());
        }, 500, 20);
        getHelper().waitForResult(res -> {
            return entityEventService.find(filter, PageRequest.of(0, 1)).getContent().isEmpty();
        }, 500, 20);
        Assert.assertTrue(manager.isRunningOwner(identity.getId()));
        // 
        IdmEntityEventDto entityEvent = entityEventService.find(filter, PageRequest.of(0, 1)).getContent().get(0);
        manager.deleteEvent(entityEvent);
        // 
        Assert.assertFalse(manager.isRunningOwner(identity.getId()));
        // 
        // end running event on background
        NeverEndingProcessor.wait = false;
        // just for sure
        Assert.assertFalse(manager.isRunningOwner(identity.getId()));
    } finally {
        getHelper().disableAsynchronousProcessing();
        manager.deleteAllEvents();
    }
}
Also used : CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 33 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testPersistChildEventAutomatically.

/**
 * Child event has to be persisted automatically, when parent event is persisted
 */
@Test
@Transactional
public void testPersistChildEventAutomatically() {
    MockOwner mockOwner = new MockOwner();
    // 
    // root
    IdmEntityEventDto eventDto = manager.prepareEvent(mockOwner, null);
    eventDto.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
    eventDto.setEventType(CoreEventType.CREATE.name());
    eventDto.setPriority(PriorityType.HIGH);
    final IdmEntityEventDto rootEventDto = manager.saveEvent(eventDto);
    // 
    // child
    CoreEvent<MockOwner> childEvent = new CoreEvent<MockOwner>(CoreEventType.CREATE, mockOwner);
    // 
    // process - sync
    manager.process(childEvent, manager.toEvent(rootEventDto));
    // 
    // two event should be persisted
    IdmEntityEventFilter filter = new IdmEntityEventFilter();
    filter.setOwnerType(manager.getOwnerType(mockOwner));
    filter.setOwnerId(mockOwner.getId());
    List<IdmEntityEventDto> content = entityEventService.find(filter, null).getContent();
    Assert.assertEquals(2, content.size());
    Assert.assertTrue(content.stream().allMatch(e -> e.getResult().getState() == OperationState.EXECUTED));
    Assert.assertTrue(content.stream().anyMatch(e -> e.getRootId() == null));
    Assert.assertTrue(content.stream().anyMatch(e -> rootEventDto.getId().equals(e.getRootId()) && e.getEventType().equals(CoreEventType.CREATE.name())));
    // check child event
    IdmEntityEventDto childEventDto = content.stream().filter(e -> rootEventDto.getId().equals(e.getRootId()) && e.getEventType().equals(CoreEventType.CREATE.name())).findFirst().get();
    Assert.assertEquals(rootEventDto.getId(), childEventDto.getParent());
    Assert.assertEquals(rootEventDto.getPriority(), childEventDto.getPriority());
    Assert.assertEquals(rootEventDto.getEventType(), childEventDto.getParentEventType());
}
Also used : DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AcceptedContent(eu.bcvsolutions.idm.core.event.AcceptedContent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) EntityGenerateValuesProcessor(eu.bcvsolutions.idm.core.model.event.processor.EntityGenerateValuesProcessor) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) MockDto(eu.bcvsolutions.idm.core.event.domain.MockDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) ObserveDtoProcessor(eu.bcvsolutions.idm.core.model.event.processor.ObserveDtoProcessor) TestEntityEventProcessorConfiguration(eu.bcvsolutions.idm.core.event.TestEntityEventProcessorConfiguration) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) 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) NeverEndingProcessor(eu.bcvsolutions.idm.core.model.event.processor.NeverEndingProcessor) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestContentTwo(eu.bcvsolutions.idm.core.event.TestContentTwo) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) ConditionalContent(eu.bcvsolutions.idm.core.event.ConditionalContent) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TestIdentityNotifyProcessor(eu.bcvsolutions.idm.core.model.event.processor.TestIdentityNotifyProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) TestContent(eu.bcvsolutions.idm.core.event.TestContent) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testConditionalProcessor.

@Test
public void testConditionalProcessor() {
    EntityEvent<ConditionalContent> event = new CoreEvent<>(CoreEventType.CREATE, new ConditionalContent(false));
    EventContext<ConditionalContent> context = manager.process(event);
    // 
    assertEquals(0, context.getResults().size());
    // 
    event = new CoreEvent<>(CoreEventType.CREATE, new ConditionalContent(true));
    context = manager.process(event);
    // 
    assertEquals(1, context.getResults().size());
}
Also used : ConditionalContent(eu.bcvsolutions.idm.core.event.ConditionalContent) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 35 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method toEvent.

@Override
public EntityEvent<? extends Identifiable> toEvent(IdmEntityEventDto entityEvent) {
    Identifiable content = null;
    // only if type and id is the same as owner can be used
    if (entityEvent.getContent() != null && Objects.equal(getOwnerType(entityEvent.getContent().getClass()), entityEvent.getOwnerType()) && Objects.equal(entityEvent.getContent().getId(), entityEvent.getOwnerId())) {
        content = entityEvent.getContent();
    }
    if (content == null) {
        // content is not persisted - try to find actual entity
        content = findOwner(entityEvent);
    }
    if (content == null) {
        throw new EventContentDeletedException(entityEvent);
    }
    // 
    Map<String, Serializable> eventProperties = entityEvent.getProperties().toMap();
    eventProperties.put(EntityEvent.EVENT_PROPERTY_EVENT_ID, entityEvent.getId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PRIORITY, entityEvent.getPriority());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_EXECUTE_DATE, entityEvent.getExecuteDate());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_TYPE, entityEvent.getParentEventType());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_ID, entityEvent.getParent());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_ROOT_EVENT_ID, entityEvent.getRootId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_SUPER_OWNER_ID, entityEvent.getSuperOwnerId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_TRANSACTION_ID, entityEvent.getTransactionId());
    final String type = entityEvent.getEventType();
    DefaultEventContext<Identifiable> initContext = new DefaultEventContext<>();
    initContext.setProcessedOrder(entityEvent.getProcessedOrder());
    EventType eventType = (EventType) () -> type;
    EntityEvent<Identifiable> resurectedEvent = new CoreEvent<>(eventType, content, eventProperties, initContext);
    // 
    // prevent to mix content and original source types between new and parent event
    Identifiable originalSource = entityEvent.getOriginalSource();
    if (originalSource != null && !originalSource.getClass().equals(content.getClass())) {
        // preset original source by current content -> content is already persisted in NOFIFY event
        resurectedEvent.setOriginalSource(content);
    } else {
        resurectedEvent.setOriginalSource(originalSource);
    }
    // 
    return resurectedEvent;
}
Also used : Serializable(java.io.Serializable) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Aggregations

CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)46 Test (org.junit.Test)27 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 UUID (java.util.UUID)9 Transactional (org.springframework.transaction.annotation.Transactional)8 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)7 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)7 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)7 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)7 Serializable (java.io.Serializable)7 RoleCodeEnvironmentProcessor (eu.bcvsolutions.idm.core.model.event.processor.role.RoleCodeEnvironmentProcessor)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)5 TestContent (eu.bcvsolutions.idm.core.event.TestContent)5 ArrayList (java.util.ArrayList)5 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)4