Search in sources :

Example 1 with EntityEventProcessorDto

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

the class DefaultEntityEventManager method toDto.

/**
 * Convert processor to dto.
 *
 * @param processor
 * @return
 */
private EntityEventProcessorDto toDto(EntityEventProcessor<?> processor) {
    EntityEventProcessorDto dto = new EntityEventProcessorDto();
    dto.setId(processor.getId());
    dto.setName(processor.getName());
    dto.setModule(processor.getModule());
    dto.setContentClass(processor.getEntityClass());
    dto.setEntityType(processor.getEntityClass().getSimpleName());
    dto.setEventTypes(Lists.newArrayList(processor.getEventTypes()));
    dto.setClosable(processor.isClosable());
    dto.setDisabled(processor.isDisabled());
    dto.setDisableable(processor.isDisableable());
    dto.setOrder(processor.getOrder());
    // resolve documentation
    dto.setDescription(processor.getDescription());
    dto.setConfigurationProperties(processor.getConfigurationMap());
    // 
    return dto;
}
Also used : EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto)

Example 2 with EntityEventProcessorDto

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

the class EntityEventProcessorFilterUnitTest method testEventTypeFilter.

@Test
public void testEventTypeFilter() {
    Map<String, Object> registeredProcessors = new HashMap<>();
    registeredProcessors.put(IdentitySaveProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentitySaveProcessor.PROCESSOR_NAME, CoreModuleDescriptor.MODULE_ID, "description one", CoreEventType.CREATE, CoreEventType.DELETE));
    registeredProcessors.put(IdentityDeleteProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentityDeleteProcessor.PROCESSOR_NAME, "custom", "description two", CoreEventType.UPDATE, CoreEventType.DELETE));
    when(enabledEvaluator.isEnabled(any(Object.class))).thenReturn(true);
    when(context.getBeansOfType(any())).thenReturn(registeredProcessors);
    // 
    EntityEventProcessorFilter filter = new EntityEventProcessorFilter();
    filter.setEventTypes(Lists.newArrayList("wrong"));
    // 
    List<EntityEventProcessorDto> results = eventManager.find(filter);
    Assert.assertTrue(results.isEmpty());
    // 
    filter.setEventTypes(Lists.newArrayList(CoreEventType.DELETE.name()));
    results = eventManager.find(filter);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
    // 
    filter.setEventTypes(Lists.newArrayList(CoreEventType.DELETE.name(), CoreEventType.UPDATE.name()));
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
}
Also used : Mock(org.mockito.Mock) HashMap(java.util.HashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) DefaultEntityEventManager(eu.bcvsolutions.idm.core.model.service.impl.DefaultEntityEventManager) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) InjectMocks(org.mockito.InjectMocks) IdentitySaveProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentitySaveProcessor) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IdentityDeleteProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityDeleteProcessor) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Assert(org.junit.Assert) HashMap(java.util.HashMap) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 3 with EntityEventProcessorDto

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

the class EntityEventProcessorFilterUnitTest method testDescriptionFilter.

@Test
public void testDescriptionFilter() {
    Map<String, Object> registeredProcessors = new HashMap<>();
    registeredProcessors.put(IdentitySaveProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentitySaveProcessor.PROCESSOR_NAME, CoreModuleDescriptor.MODULE_ID, "description one"));
    registeredProcessors.put(IdentityDeleteProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentityDeleteProcessor.PROCESSOR_NAME, "custom", "description two"));
    when(enabledEvaluator.isEnabled(any(Object.class))).thenReturn(true);
    when(context.getBeansOfType(any())).thenReturn(registeredProcessors);
    // 
    EntityEventProcessorFilter filter = new EntityEventProcessorFilter();
    filter.setDescription("description");
    // 
    List<EntityEventProcessorDto> results = eventManager.find(filter);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
    // 
    filter.setDescription("one");
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
}
Also used : Mock(org.mockito.Mock) HashMap(java.util.HashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) DefaultEntityEventManager(eu.bcvsolutions.idm.core.model.service.impl.DefaultEntityEventManager) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) InjectMocks(org.mockito.InjectMocks) IdentitySaveProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentitySaveProcessor) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IdentityDeleteProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityDeleteProcessor) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Assert(org.junit.Assert) HashMap(java.util.HashMap) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 4 with EntityEventProcessorDto

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

the class EntityEventProcessorFilterUnitTest method testEntityTypeFilter.

@Test
public void testEntityTypeFilter() {
    Map<String, Object> registeredProcessors = new HashMap<>();
    registeredProcessors.put(IdentitySaveProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentitySaveProcessor.PROCESSOR_NAME, CoreModuleDescriptor.MODULE_ID, "description one", CoreEventType.CREATE, CoreEventType.DELETE));
    registeredProcessors.put(IdentityDeleteProcessor.PROCESSOR_NAME, new MockRoleProcessor(IdentityDeleteProcessor.PROCESSOR_NAME, "custom", "description two", CoreEventType.UPDATE, CoreEventType.DELETE));
    when(enabledEvaluator.isEnabled(any(Object.class))).thenReturn(true);
    when(context.getBeansOfType(any())).thenReturn(registeredProcessors);
    // 
    EntityEventProcessorFilter filter = new EntityEventProcessorFilter();
    filter.setEntityType("wrong");
    // 
    List<EntityEventProcessorDto> results = eventManager.find(filter);
    Assert.assertTrue(results.isEmpty());
    // 
    filter.setEntityType(IdmIdentityDto.class.getSimpleName());
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
    // 
    filter.setEntityType(IdmRoleDto.class.getSimpleName());
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
}
Also used : Mock(org.mockito.Mock) HashMap(java.util.HashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) DefaultEntityEventManager(eu.bcvsolutions.idm.core.model.service.impl.DefaultEntityEventManager) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) InjectMocks(org.mockito.InjectMocks) IdentitySaveProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentitySaveProcessor) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IdentityDeleteProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityDeleteProcessor) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Assert(org.junit.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) HashMap(java.util.HashMap) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with EntityEventProcessorDto

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

the class EntityEventProcessorFilterUnitTest method testContentTypeFilter.

@Test
public void testContentTypeFilter() {
    Map<String, Object> registeredProcessors = new HashMap<>();
    registeredProcessors.put(IdentitySaveProcessor.PROCESSOR_NAME, new MockIdentityProcessor(IdentitySaveProcessor.PROCESSOR_NAME, CoreModuleDescriptor.MODULE_ID, "description one", CoreEventType.CREATE, CoreEventType.DELETE));
    registeredProcessors.put(IdentityDeleteProcessor.PROCESSOR_NAME, new MockRoleProcessor(IdentityDeleteProcessor.PROCESSOR_NAME, "custom", "description two", CoreEventType.UPDATE, CoreEventType.DELETE));
    when(enabledEvaluator.isEnabled(any(Object.class))).thenReturn(true);
    when(context.getBeansOfType(any())).thenReturn(registeredProcessors);
    // 
    EntityEventProcessorFilter filter = new EntityEventProcessorFilter();
    filter.setContentClass(IdmIdentityContractDto.class);
    // 
    List<EntityEventProcessorDto> results = eventManager.find(filter);
    Assert.assertTrue(results.isEmpty());
    // 
    filter.setContentClass(IdmIdentityDto.class);
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
    // 
    filter.setContentClass(IdmRoleDto.class);
    results = eventManager.find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
    // 
    filter.setContentClass(AbstractDto.class);
    results = eventManager.find(filter);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentitySaveProcessor.PROCESSOR_NAME)));
    Assert.assertTrue(results.stream().anyMatch(e -> e.getName().equals(IdentityDeleteProcessor.PROCESSOR_NAME)));
}
Also used : Mock(org.mockito.Mock) HashMap(java.util.HashMap) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) DefaultEntityEventManager(eu.bcvsolutions.idm.core.model.service.impl.DefaultEntityEventManager) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) InjectMocks(org.mockito.InjectMocks) IdentitySaveProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentitySaveProcessor) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) Matchers.any(org.mockito.Matchers.any) List(java.util.List) IdentityDeleteProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityDeleteProcessor) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Assert(org.junit.Assert) HashMap(java.util.HashMap) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

EntityEventProcessorDto (eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto)11 EntityEventProcessorFilter (eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter)8 Test (org.junit.Test)8 Lists (com.google.common.collect.Lists)7 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)7 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)7 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 AbstractEntityEventProcessor (eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor)7 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)7 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)7 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)7 EventType (eu.bcvsolutions.idm.core.api.event.EventType)7 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)7 IdentityDeleteProcessor (eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityDeleteProcessor)7 IdentitySaveProcessor (eu.bcvsolutions.idm.core.model.event.processor.identity.IdentitySaveProcessor)7 DefaultEntityEventManager (eu.bcvsolutions.idm.core.model.service.impl.DefaultEntityEventManager)7 EnabledEvaluator (eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator)7 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)7