use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractPositionDeleteProcessor method process.
@Override
public EventResult<IdmContractPositionDto> process(EntityEvent<IdmContractPositionDto> event) {
IdmContractPositionDto dto = event.getContent();
Assert.notNull(dto.getId(), "Posistion id is required!");
IdmIdentityContractDto contract = DtoUtils.getEmbedded(dto, IdmContractPosition_.identityContract);
//
// delete identity roles assigned by deleted position
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
identityRoleService.findAllByContractPosition(dto.getId()).forEach(identityRole -> {
if (identityRole.getDirectRole() == null) {
// sub roles are removed different way (processor on direct identity role)
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityContract(dto.getIdentityContract());
conceptRoleRequest.setContractPosition(dto.getId());
//
concepts.add(conceptRoleRequest);
}
});
roleRequestService.executeConceptsImmediate(contract.getIdentity(), concepts);
//
contractPositionService.deleteInternal(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ContractPositionSaveProcessor method process.
@Override
public EventResult<IdmContractPositionDto> process(EntityEvent<IdmContractPositionDto> event) {
IdmContractPositionDto dto = event.getContent();
//
dto = contractPositionService.saveInternal(dto);
//
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class TreeTypeDeleteBulkActionIntegrationTest method testForceDelete.
@Test
public void testForceDelete() {
logout();
loginAsAdmin();
// create sub tree nodes, automatic roles, contract, contract positions
IdmTreeTypeDto treeType = getHelper().createTreeType();
IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null, null);
IdmTreeNodeDto subTreeNode = getHelper().createTreeNode(treeType, (String) null, treeNode);
IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode(treeType, (String) null, subTreeNode);
IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
//
// 3 manual, 2 automatic
Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
//
// remove tree type
Map<String, Object> properties = new HashMap<>();
properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
// delete by bulk action
IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeType.class, TreeTypeDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(treeType.getId()));
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, 0l, 0l);
//
Assert.assertNull(treeTypeService.get(treeType));
Assert.assertNull(treeNodeService.get(treeNode));
Assert.assertNull(treeNodeService.get(subTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNull(treeNodeService.get(subSubTreeNode));
Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
Assert.assertNull(identityContractService.get(contract).getWorkPosition());
Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
Assert.assertNull(roleTreeNodeService.get(automaticRole));
//
Assert.assertNotNull(treeNodeService.get(otherTreeNode));
Assert.assertNotNull(getHelper().getPrimeContract(identity));
Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmEntityStateDto state) {
UUID ownerId = state.getOwnerId();
if (processedOwnerIds.contains(ownerId)) {
LOG.debug("Automatic roles for owner [{}] was already processed, delete state only.", ownerId);
//
entityStateManager.deleteState(state);
// Item will be deleted only - we need some result - counter / count will match.
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
// process automatic role on state owner
if (state.getOwnerType().equals(entityStateManager.getOwnerType(IdmIdentityContractDto.class))) {
// contract
LOG.debug("Process automatic roles for contract [{}].", ownerId);
//
IdmIdentityContractDto contract = lookupService.lookupDto(IdmIdentityContractDto.class, ownerId);
if (contract == null) {
getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
} else if (!contract.isValidNowOrInFuture()) {
removeAllAutomaticRoles(contract);
//
getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
} else {
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.NOTIFY, contract);
event.setOriginalSource((IdmIdentityContractDto) state.getResult().getModel().getParameters().get(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE));
contractProcessor.process(event);
//
getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
}
} else {
// position
LOG.debug("Process automatic roles for position [{}].", ownerId);
//
IdmContractPositionDto position = lookupService.lookupDto(IdmContractPositionDto.class, ownerId);
if (position == null) {
getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
} else {
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.NOTIFY, position);
positionProcessor.process(event);
//
getItemService().createLogItem(position, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
}
}
processedOwnerIds.add(ownerId);
entityStateManager.deleteState(state);
// Log added manually above - log processed contract / position instead of deleted entity state.
return Optional.empty();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmContractPositionServiceIntegrationTest method testAssignAutomaticRole.
@Test
@Transactional
public void testAssignAutomaticRole() {
IdmRoleDto role = getHelper().createRole();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
// other
getHelper().createContractPosition(contract, getHelper().createTreeNode());
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
}
Aggregations