use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testRemoveDuplicateEventsForTheSameOwner.
@Test
public void testRemoveDuplicateEventsForTheSameOwner() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
int count = 10;
//
// create events
MockOwner mockOwner = new MockOwner();
for (int i = 0; i < count; i++) {
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwner.getClass().getCanonicalName());
entityEvent.setEventType("empty");
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setInstanceId(configurationService.getInstanceId());
entityEvent.setResult(new OperationResultDto(OperationState.CREATED));
entityEvent.setPriority(PriorityType.NORMAL);
events.add(entityEventService.save(entityEvent));
}
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(MockOwner.class.getCanonicalName());
filter.setStates(Lists.newArrayList(OperationState.CREATED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
//
// execute
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// wait for executed events
helper.waitForResult(res -> {
return entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements() != 0;
}, 1000, Integer.MAX_VALUE);
//
// check what happened
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
Assert.assertEquals(1, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
// the last one
entityEventService.delete(events.get(9));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter in project CzechIdMng by bcvsolutions.
the class IdmEntityEventController method toFilter.
@Override
protected IdmEntityEventFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmEntityEventFilter filter = new IdmEntityEventFilter(parameters);
filter.setCreatedFrom(getParameterConverter().toDateTime(parameters, "createdFrom"));
filter.setCreatedTill(getParameterConverter().toDateTime(parameters, "createdTill"));
filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
//
String ownerId = getParameterConverter().toString(parameters, "ownerId");
if (StringUtils.isNotEmpty(filter.getOwnerType()) && StringUtils.isNotEmpty(ownerId)) {
// try to find entity owner by Codeable identifier
AbstractDto owner = manager.findOwner(filter.getOwnerType(), ownerId);
if (owner != null) {
filter.setOwnerId(owner.getId());
} else {
throw new ResultCodeException(CoreResultCode.BAD_VALUE, "Entity type [%s] with identifier [%s] does not found", ImmutableMap.of("entityClass", filter.getOwnerType(), "identifier", ownerId));
}
} else {
filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
}
filter.setStates(getParameterConverter().toEnums(parameters, "states", OperationState.class));
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testMultiThreadEventProcessing.
@Test
public void testMultiThreadEventProcessing() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
// 15s
int count = 250;
// create events
for (int i = 0; i < count; i++) {
MockOwner mockOwner = new MockOwner();
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwner.getClass().getCanonicalName());
entityEvent.setEventType("empty");
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setInstanceId(configurationService.getInstanceId());
entityEvent.setResult(new OperationResultDto(OperationState.CREATED));
entityEvent.setPriority(PriorityType.NORMAL);
events.add(entityEventService.save(entityEvent));
}
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(MockOwner.class.getCanonicalName());
filter.setStates(Lists.newArrayList(OperationState.CREATED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
//
// execute
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// wait for executed events
helper.waitForResult(res -> {
return entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements() != 0;
}, 1000, Integer.MAX_VALUE);
//
// check what happened
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
events.forEach(e -> entityEventService.delete(e));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter in project CzechIdMng by bcvsolutions.
the class IdmEntityEventFilterIntegrationTest method testFindByOwnerId.
@Test
@Transactional
public void testFindByOwnerId() {
UUID ownerOneId = UUID.randomUUID();
IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
entityEventOne.setOwnerType("mockType");
entityEventOne.setEventType("mockEvent");
entityEventOne.setOwnerId(ownerOneId);
entityEventOne.setInstanceId("mockInstance");
entityEventOne.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventOne.setPriority(PriorityType.NORMAL);
entityEventOne = service.save(entityEventOne);
//
UUID ownerTwoId = UUID.randomUUID();
IdmEntityEventDto entityEventTwo = new IdmEntityEventDto();
entityEventTwo.setOwnerType("mockType");
entityEventTwo.setEventType("mockEvent");
entityEventTwo.setOwnerId(ownerTwoId);
entityEventTwo.setInstanceId("mockInstance");
entityEventTwo.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventTwo.setPriority(PriorityType.NORMAL);
entityEventTwo = service.save(entityEventTwo);
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerId(ownerOneId);
//
List<IdmEntityEventDto> events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventOne.getId(), events.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter in project CzechIdMng by bcvsolutions.
the class IdmEntityEventFilterIntegrationTest method testFindByParentId.
@Test
@Transactional
public void testFindByParentId() {
UUID ownerId = UUID.randomUUID();
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType("mockType");
entityEvent.setEventType("mockEvent");
entityEvent.setOwnerId(ownerId);
entityEvent.setInstanceId("mockInstance");
entityEvent.setResult(new OperationResultDto(OperationState.CANCELED));
entityEvent.setPriority(PriorityType.NORMAL);
entityEvent = service.save(entityEvent);
//
UUID ownerOneId = UUID.randomUUID();
IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
entityEventOne.setOwnerType("mockType");
entityEventOne.setEventType("mockEvent");
entityEventOne.setOwnerId(ownerOneId);
entityEventOne.setInstanceId("mockInstance");
entityEventOne.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventOne.setPriority(PriorityType.NORMAL);
entityEventOne.setParent(entityEvent.getId());
entityEventOne = service.save(entityEventOne);
//
UUID ownerTwoId = UUID.randomUUID();
IdmEntityEventDto entityEventTwo = new IdmEntityEventDto();
entityEventTwo.setOwnerType("mockType");
entityEventTwo.setEventType("mockEvent");
entityEventTwo.setOwnerId(ownerTwoId);
entityEventTwo.setInstanceId("mockInstance");
entityEventTwo.setResult(new OperationResultDto(OperationState.EXCEPTION));
entityEventTwo.setPriority(PriorityType.NORMAL);
entityEventTwo.setParent(entityEventOne.getId());
entityEventTwo = service.save(entityEventTwo);
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType("mockType");
filter.setParentId(entityEventTwo.getId());
//
List<IdmEntityEventDto> events = service.find(filter, null).getContent();
Assert.assertEquals(0, events.size());
//
filter.setParentId(entityEvent.getId());
events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventOne.getId(), events.get(0).getId());
//
filter.setParentId(entityEventOne.getId());
events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventTwo.getId(), events.get(0).getId());
}
Aggregations