Search in sources :

Example 11 with OperationResultDto

use of eu.bcvsolutions.idm.core.api.dto.OperationResultDto 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)

Example 12 with OperationResultDto

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

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegrityOwnerIsDeleted.

@Test
@Ignore
@Transactional
public void testReferentialIntegrityOwnerIsDeleted() {
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = helper.createIdentity((GuardedString) null);
    // 
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType(entityEventManager.getOwnerType(identity.getClass()));
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(identity.getId());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    IdmEntityStateDto entityState = new IdmEntityStateDto(entityEvent);
    entityState.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityState = entityStateService.save(entityState);
    // 
    Assert.assertNotNull(entityState.getId());
    // 
    identityService.delete(identityTwo);
    // 
    Assert.assertNotNull(identityService.get(identity));
    Assert.assertNotNull(entityEventService.get(entityEvent));
    Assert.assertNotNull(entityStateService.get(entityState));
    // 
    identityService.delete(identity);
    // 
    Assert.assertNull(identityService.get(identity));
    Assert.assertNull(entityEventService.get(entityEvent));
    Assert.assertNull(entityStateService.get(entityState));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with OperationResultDto

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

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegrity.

@Test
@Transactional
public void testReferentialIntegrity() {
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType("empty");
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(UUID.randomUUID());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    IdmEntityStateDto entityState = new IdmEntityStateDto(entityEvent);
    entityState.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityState = entityStateService.save(entityState);
    // 
    Assert.assertNotNull(entityState.getId());
    // 
    entityEventService.delete(entityEvent);
    // 
    Assert.assertNull(entityEventService.get(entityEvent));
    Assert.assertNull(entityStateService.get(entityState));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 14 with OperationResultDto

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

the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegritParentIsDeleted.

@Test(expected = EventDeleteFailedHasChildrenException.class)
@Transactional
public void testReferentialIntegritParentIsDeleted() {
    IdmEntityEventDto parentEvent = new IdmEntityEventDto();
    parentEvent.setOwnerType("empty");
    parentEvent.setEventType("empty");
    parentEvent.setOwnerId(UUID.randomUUID());
    parentEvent.setInstanceId("empty");
    parentEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    parentEvent.setPriority(PriorityType.NORMAL);
    parentEvent = entityEventService.save(parentEvent);
    // 
    IdmEntityEventDto entityEvent = new IdmEntityEventDto();
    entityEvent.setOwnerType("empty");
    entityEvent.setEventType("empty");
    entityEvent.setOwnerId(UUID.randomUUID());
    entityEvent.setInstanceId("empty");
    entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
    entityEvent.setPriority(PriorityType.NORMAL);
    entityEvent.setParent(parentEvent.getId());
    entityEvent = entityEventService.save(entityEvent);
    // 
    Assert.assertNotNull(entityEvent.getId());
    // 
    entityEventService.delete(parentEvent);
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 15 with OperationResultDto

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

the class DefaultEntityEventManager method init.

/**
 * Cancel all previously ran events
 */
@Override
public void init() {
    LOG.info("Cancel unprocessed events - event was interrupt during instance restart");
    // 
    String instanceId = configurationService.getInstanceId();
    entityEventService.findByState(instanceId, OperationState.RUNNING).forEach(event -> {
        LOG.info("Cancel unprocessed event [{}] - event was interrupt during instance [{}] restart", event.getId(), instanceId);
        // 
        // cancel event
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.EVENT_CANCELED_BY_RESTART, ImmutableMap.of("eventId", event.getId(), "eventType", event.getEventType(), "ownerId", String.valueOf(event.getOwnerId()), "instanceId", event.getInstanceId()));
        OperationResultDto result = new OperationResultDto.Builder(OperationState.CANCELED).setModel(resultModel).build();
        event.setResult(result);
        entityEventService.saveInternal(event);
        // 
        // cancel event states
        IdmEntityStateFilter filter = new IdmEntityStateFilter();
        filter.setEventId(event.getId());
        entityStateService.find(filter, null).getContent().stream().filter(state -> {
            return OperationState.RUNNING == state.getResult().getState();
        }).forEach(state -> {
            event.setResult(result);
            entityStateService.save(state);
        });
    });
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Sort(org.springframework.data.domain.Sort) Objects(com.google.common.base.Objects) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) CreatedComparator(eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) DateTime(org.joda.time.DateTime) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Aggregations

OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)17 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)13 Transactional (org.springframework.transaction.annotation.Transactional)12 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)11 Test (org.junit.Test)11 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)8 UUID (java.util.UUID)8 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)3 ArrayList (java.util.ArrayList)3 PageRequest (org.springframework.data.domain.PageRequest)3 Lists (com.google.common.collect.Lists)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)2 Objects (com.google.common.base.Objects)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)1 Auditable (eu.bcvsolutions.idm.core.api.domain.Auditable)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1