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());
}
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));
}
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));
}
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);
}
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);
});
});
}
Aggregations