use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class EntityEventProcessorUnitTest method testSupportAllIdentityEvents.
@Test
public void testSupportAllIdentityEvents() {
EntityEventProcessor<?> processor = new EventProcessorIdentity();
assertTrue(processor.supports(new IdentityEvent(IdentityEventType.CREATE, new IdmIdentityDto())));
assertTrue(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
assertTrue(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
assertFalse(processor.supports(new RoleEvent(RoleEventType.DELETE, new IdmRoleDto())));
assertTrue(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
assertTrue(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class EntityEventProcessorUnitTest method testSuppotsAll.
@Test
public void testSuppotsAll() {
EntityEventProcessor<?> processor = new EventProcessorBase();
assertTrue(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
assertTrue(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
assertTrue(processor.supports(new IdentityContractEvent(IdentityContractEventType.DELETE, new IdmIdentityContractDto())));
assertTrue(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
assertTrue(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
assertTrue(processor.supports(new CoreEvent<IdmIdentityContractDto>(IdentityContractEventType.UPDATE, new IdmIdentityContractDto())));
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method startRequestInternal.
@Override
public IdmRoleRequestDto startRequestInternal(IdmRoleRequestDto roleRequest, boolean checkRight, boolean immediate) {
Map<String, Serializable> properties = new HashMap<>();
properties.put(RoleRequestProcessor.CHECK_RIGHT_PROPERTY, checkRight);
CoreEvent<IdmRoleRequestDto> event = new CoreEvent<IdmRoleRequestDto>((EventType) () -> "EXCECUTE", roleRequest, properties);
if (immediate) {
event.setPriority(PriorityType.IMMEDIATE);
}
//
roleRequestService.startRequestInternal(event);
//
return roleRequestService.get(roleRequest.getId(), new IdmRoleRequestFilter(true));
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class IdentityContractUpdateByAutomaticRoleProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
IdmIdentityContractDto previous = event.getOriginalSource();
UUID previousPosition = previous == null ? null : previous.getWorkPosition();
UUID newPosition = contract.getWorkPosition();
boolean validityChangedToValid = previous == null ? false : contract.isValidNowOrInFuture() && previous.isValidNowOrInFuture() != contract.isValidNowOrInFuture();
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
// flag can be processed afterwards
if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
LOG.debug("Automatic roles are skipped for contract [{}], state [{}] " + "for position will be created only.", contract.getId(), CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
//
Map<String, Serializable> properties = new HashMap<>();
// original contract as property
properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, event.getOriginalSource());
entityStateManager.createState(contract, OperationState.BLOCKED, contract.isValidNowOrInFuture() ? CoreResultCode.AUTOMATIC_ROLE_SKIPPED : CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
//
return new DefaultEventResult<>(event, this);
}
if (!contract.isValidNowOrInFuture()) {
// but we need to add skipped flag above, even when invalid contract is updated
return new DefaultEventResult<>(event, this);
}
//
if (previous == null || !Objects.equals(newPosition, previousPosition) || validityChangedToValid) {
// work positions has some difference or validity changes
List<IdmIdentityRoleDto> assignedRoles = getAssignedAutomaticRoles(contract.getId());
// remove all automatic roles by attribute and by other contract position
if (!assignedRoles.isEmpty()) {
assignedRoles = assignedRoles.stream().filter(autoRole -> {
// remove automatic roles by attribute - solved by different process
AbstractIdmAutomaticRoleDto automaticRoleDto = DtoUtils.getEmbedded(autoRole, IdmIdentityRole_.automaticRole, (AbstractIdmAutomaticRoleDto) null);
if (automaticRoleDto instanceof IdmRoleTreeNodeDto) {
return true;
}
return false;
}).filter(identityRole -> {
// remove automatic roles by attribute - solved by different process
return identityRole.getContractPosition() == null;
}).collect(Collectors.toList());
}
//
Set<UUID> previousAutomaticRoles = assignedRoles.stream().filter(identityRole -> {
return identityRole.getAutomaticRole() != null;
}).map(identityRole -> {
return identityRole.getAutomaticRole();
}).collect(Collectors.toSet());
Set<IdmRoleTreeNodeDto> addedAutomaticRoles = new HashSet<>();
if (newPosition != null && contract.isValidNowOrInFuture()) {
addedAutomaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(newPosition);
}
// prevent to remove newly added or still exists roles
Set<UUID> removedAutomaticRoles = new HashSet<>(previousAutomaticRoles);
removedAutomaticRoles.removeAll(addedAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toList()));
addedAutomaticRoles.removeIf(a -> {
return previousAutomaticRoles.contains(a.getId());
});
//
for (UUID removedAutomaticRole : removedAutomaticRoles) {
Iterator<IdmIdentityRoleDto> iter = assignedRoles.iterator();
while (iter.hasNext()) {
IdmIdentityRoleDto identityRole = iter.next();
if (Objects.equals(identityRole.getAutomaticRole(), removedAutomaticRole)) {
// check, if role will be added by new automatic roles and prevent removing
IdmRoleTreeNodeDto addedAutomaticRole = getByRole(identityRole.getRole(), addedAutomaticRoles);
if (addedAutomaticRole == null) {
// remove assigned role
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
iter.remove();
} else {
// change relation only
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setAutomaticRole(addedAutomaticRole.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
//
// new automatic role is not needed
addedAutomaticRoles.remove(addedAutomaticRole);
}
}
}
}
// change date - for unchanged assigned roles only
if (previous != null && EntityUtils.validableChanged(previous, contract)) {
roleRequest.getConceptRoles().addAll(changeValidable(contract, assignedRoles));
}
// add identity roles
for (AbstractIdmAutomaticRoleDto autoRole : addedAutomaticRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(autoRole.getRole());
conceptRoleRequest.setAutomaticRole(autoRole.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
//
roleRequest.getConceptRoles().add(conceptRoleRequest);
}
// contract is enabled => process all contract positions
if (validityChangedToValid) {
IdmContractPositionFilter filter = new IdmContractPositionFilter();
filter.setIdentityContractId(contract.getId());
//
for (IdmContractPositionDto position : contractPositionService.find(filter, null).getContent()) {
CoreEvent<IdmContractPositionDto> positionEvent = new CoreEvent<>(CoreEventType.NOTIFY, position);
// we don't need the second asynchronicity
positionEvent.setPriority(PriorityType.IMMEDIATE);
positionEvent.getProperties().put(EVENT_PROPERTY_REQUEST, roleRequest);
// recount automatic roles for given position
EventContext<IdmContractPositionDto> context = contractPositionService.publish(positionEvent, event);
// get modified prepared request
if (context.getLastResult() != null) {
roleRequest = (IdmRoleRequestDto) context.getLastResult().getEvent().getProperties().get(EVENT_PROPERTY_REQUEST);
}
}
}
} else if (previous != null && EntityUtils.validableChanged(previous, contract)) {
// process validable change only
roleRequest.getConceptRoles().addAll(changeValidable(contract, getAssignedAutomaticRoles(contract.getId())));
}
// start request at end asynchronously
roleRequest.setApplicant(contract.getIdentity());
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
roleRequestService.startConcepts(requestEvent, event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testGetEvent.
@Test
@Transactional
public void testGetEvent() {
MockOwner mockOwner = new MockOwner();
//
IdmEntityEventDto entityEventDto = manager.prepareEvent(mockOwner, null);
entityEventDto.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
entityEventDto.setEventType(CoreEventType.CREATE.name());
entityEventDto.setPriority(PriorityType.HIGH);
entityEventDto = manager.saveEvent(entityEventDto);
//
CoreEvent<MockOwner> event = new CoreEvent<MockOwner>(CoreEventType.CREATE, mockOwner);
event.setId(entityEventDto.getId());
IdmEntityEventDto persistedEventDto = manager.getEvent(event);
//
Assert.assertNotNull(persistedEventDto);
Assert.assertEquals(OperationState.RUNNING, persistedEventDto.getResult().getState());
Assert.assertEquals(PriorityType.HIGH, persistedEventDto.getPriority());
Assert.assertEquals(mockOwner.getId(), persistedEventDto.getOwnerId());
Assert.assertEquals(manager.getOwnerType(mockOwner), persistedEventDto.getOwnerType());
Assert.assertEquals(CoreEventType.CREATE.name(), persistedEventDto.getEventType());
}
Aggregations