use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class IdmEntityStateController method find.
@Override
public Page<IdmEntityStateDto> find(IdmEntityStateFilter filter, Pageable pageable, BasePermission permission) {
Page<IdmEntityStateDto> results = super.find(filter, pageable, permission);
// fill entity embedded for FE
Map<UUID, BaseDto> loadedDtos = new HashMap<>();
results.getContent().forEach(dto -> {
UUID ownerId = dto.getOwnerId();
if (!loadedDtos.containsKey(ownerId)) {
try {
loadedDtos.put(ownerId, getLookupService().lookupDto(dto.getOwnerType(), ownerId));
} catch (IllegalArgumentException ex) {
LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getOwnerType(), ex);
}
}
dto.getEmbedded().put("ownerId", loadedDtos.get(ownerId));
});
return results;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnContractAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnContractAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
contract.setWorkPosition(node.getId());
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
contract = service.publish(event).getContent();
UUID contractId = contract.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.isEmpty());
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmEntityEventServiceIntegrationTest method testDeleteAll.
@Test
@Transactional
public void testDeleteAll() {
String mockOwnerType = getHelper().createName();
//
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwnerType);
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);
IdmEntityStateDto otherState = new IdmEntityStateDto();
otherState.setInstanceId("mock");
otherState.setOwnerId(UUID.randomUUID());
otherState.setOwnerType(mockOwnerType);
otherState.setResult(new OperationResultDto(OperationState.BLOCKED));
otherState = entityStateService.save(otherState);
//
Assert.assertNotNull(entityState.getId());
Assert.assertNotNull(otherState.getId());
//
//
IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
eventFilter.setOwnerType(mockOwnerType);
Assert.assertEquals(1, entityEventService.find(eventFilter, null).getTotalElements());
IdmEntityStateFilter stateFilter = new IdmEntityStateFilter();
stateFilter.setOwnerType(mockOwnerType);
Assert.assertEquals(2, entityStateService.find(stateFilter, null).getTotalElements());
//
entityEventService.deleteAll();
Assert.assertEquals(0, entityEventService.find(eventFilter, null).getTotalElements());
List<IdmEntityStateDto> states = entityStateService.find(stateFilter, null).getContent();
Assert.assertEquals(1, states.size());
Assert.assertEquals(otherState.getId(), states.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(node.getId());
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
position = contractPositionService.publish(event).getContent();
UUID positionId = position.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManager method createEntityState.
@Override
@Transactional
public IdmEntityStateDto createEntityState(AbstractDto entityDto) {
Assert.notNull(entityDto, "Entity cannot be null!");
Assert.notNull(entityDto.getId(), "Entity ID cannot be null!");
UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
IdmEntityStateDto entityState = this.getEntityState(entityDto.getId(), entityDto.getClass(), transactionId);
if (entityState == null) {
String entityString = entityDto.toString();
Map<String, Serializable> properties = new HashMap<>();
properties.put("entity", entityString);
entityState = entityStateManager.createState(entityDto, OperationState.BLOCKED, CoreResultCode.IDENTITY_UNIFORM_PASSWORD, properties);
LOG.debug("Uniform password entity state for entity [{}] and transaction [{}] created.", entityString, transactionId);
}
return entityState;
}
Aggregations