Search in sources :

Example 6 with IdmEntityEventDto

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

the class EntityEventDeleteProcessor method process.

@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
    IdmEntityEventDto role = event.getContent();
    // 
    service.deleteInternal(role);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 7 with IdmEntityEventDto

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

the class EntityEventExecuteProcessor method process.

@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
    IdmEntityEventDto entityEvent = event.getContent();
    // 
    EntityEvent<Identifiable> resurectedEvent;
    try {
        resurectedEvent = entityEventManager.toEvent(entityEvent);
        // execute
        EventContext<Identifiable> context = entityEventManager.process(resurectedEvent);
        entityEvent.setProcessedOrder(context.getProcessedOrder());
        entityEvent.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
    } catch (EventContentDeletedException ex) {
        // content was deleted - log state
        LOG.warn("Event content was deleted, event cannot be executed.", ex);
        entityEvent.setResult(new OperationResultDto.Builder(// it's expected ex, lower level
        OperationState.NOT_EXECUTED).setException(ex).build());
    }
    // 
    event.setContent(entityEvent);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Example 8 with IdmEntityEventDto

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

the class AsynchronousAccountManagementIntegrationTest method testAsynchronousAccountManagementError.

@Test
public void testAsynchronousAccountManagementError() {
    // add error to some script
    SysSystemDto system = helper.createTestResourceSystem(true);
    SysSystemMappingDto mapping = helper.getDefaultMapping(system);
    SysSystemAttributeMappingDto attributeHandlingUserName = schemaAttributeHandlingService.findBySystemMappingAndName(mapping.getId(), TestHelper.ATTRIBUTE_MAPPING_NAME);
    // username is transformed with error
    attributeHandlingUserName.setTransformToResourceScript("returan \"" + "error" + "\";");
    attributeHandlingUserName = schemaAttributeHandlingService.save(attributeHandlingUserName);
    IdmIdentityDto identity = helper.createIdentity();
    IdmRoleDto role = helper.createRole();
    helper.createRoleSystem(role, system);
    IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
    try {
        helper.waitForResult(res -> {
            return !(entityEventService.findByState(configurationService.getInstanceId(), OperationState.CREATED).isEmpty() && entityEventService.findByState(configurationService.getInstanceId(), OperationState.RUNNING).isEmpty());
        });
        AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
        Assert.assertNull(account);
        // 
        // find event result with exception
        IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
        eventFilter.setOwnerId(identityRole.getId());
        eventFilter.setStates(Lists.newArrayList(OperationState.EXCEPTION));
        List<IdmEntityEventDto> failedEvents = entityEventService.find(eventFilter, null).getContent();
        // 
        Assert.assertEquals(1, failedEvents.size());
        Assert.assertEquals(CoreResultCode.GROOVY_SCRIPT_EXCEPTION.getCode(), failedEvents.get(0).getResult().getCode());
    } finally {
        identityService.delete(identity);
        systemService.delete(system);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with IdmEntityEventDto

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

the class IdmEntityEventFilterIntegrationTest method testFindByOwnerType.

@Test
@Transactional
public void testFindByOwnerType() {
    UUID ownerOneId = UUID.randomUUID();
    IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
    entityEventOne.setOwnerType("mockTypeOne");
    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("mockTypeTwo");
    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.setOwnerType("mockTypeOne");
    // 
    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 IdmEntityEventDto

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

the class IdmEntityEventFilterIntegrationTest method testFindByCreated.

@Test
@Transactional
public void testFindByCreated() {
    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);
    // 
    helper.waitForResult(null, null, 1);
    // 
    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.setCreatedFrom(entityEventTwo.getCreated());
    filter.setOwnerType("mockType");
    List<IdmEntityEventDto> events = service.find(filter, null).getContent();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(entityEventTwo.getId(), events.get(0).getId());
    // 
    filter.setCreatedFrom(null);
    filter.setCreatedTill(entityEventTwo.getCreated());
    events = service.find(filter, null).getContent();
    Assert.assertEquals(2, events.size());
    // 
    filter.setCreatedTill(entityEventOne.getCreated());
    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)

Aggregations

IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)35 Test (org.junit.Test)21 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)15 Transactional (org.springframework.transaction.annotation.Transactional)13 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 UUID (java.util.UUID)12 ArrayList (java.util.ArrayList)11 DateTime (org.joda.time.DateTime)10 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)9 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)9 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)5 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 PageRequest (org.springframework.data.domain.PageRequest)4 Lists (com.google.common.collect.Lists)3 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 MockOwner (eu.bcvsolutions.idm.core.event.domain.MockOwner)3