Search in sources :

Example 6 with IdmEntityEventFilter

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);
    }
}
Also used : MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 7 with IdmEntityEventFilter

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;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState)

Example 8 with IdmEntityEventFilter

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);
    }
}
Also used : MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 9 with IdmEntityEventFilter

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());
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) 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 10 with IdmEntityEventFilter

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());
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) 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)

Aggregations

IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)10 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Test (org.junit.Test)9 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)8 UUID (java.util.UUID)6 Transactional (org.springframework.transaction.annotation.Transactional)6 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 MockOwner (eu.bcvsolutions.idm.core.event.domain.MockOwner)2 ArrayList (java.util.ArrayList)2 PageRequest (org.springframework.data.domain.PageRequest)2 Lists (com.google.common.collect.Lists)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)1 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1