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());
}
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();
}
}
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());
}
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());
}
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;
}
Aggregations