Search in sources :

Example 1 with IdmContractPositionDto

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);
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ArrayList(java.util.ArrayList) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 2 with IdmContractPositionDto

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);
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 3 with IdmContractPositionDto

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));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 4 with IdmContractPositionDto

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();
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 5 with IdmContractPositionDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)40 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)37 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)29 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)22 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)18 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)18 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)14 Transactional (org.springframework.transaction.annotation.Transactional)14 IdmContractPositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)12 UUID (java.util.UUID)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)7 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)6 IdmIdentityContractService (eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService)6 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)6 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)5