Search in sources :

Example 81 with IdmTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.

the class IdentityByTreeNodeEvaluatorIntegrationTest method testSubpositionMoreContract.

@Test
public void testSubpositionMoreContract() {
    IdmTreeNodeDto parent = getHelper().createTreeNode();
    IdmTreeNodeDto parentTwo = getHelper().createTreeNode(getHelper().createName(), parent);
    IdmTreeNodeDto position = getHelper().createTreeNode(getHelper().createName(), parentTwo);
    // Evaluator is on parentTwo
    IdmRoleDto role = prepareRoleWithEvaluator(parentTwo);
    // Position is sub child
    IdmIdentityDto identity = prepareIdentityOnWorkPosition(parent);
    IdmIdentityDto administrator = getHelper().createIdentity();
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        // only myself
        assertEquals(0, users.size());
        checkIdentityInList(identity, users, false);
    } finally {
        getHelper().logout();
    }
    getHelper().assignRoles(getHelper().getPrimeContract(administrator), role);
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        assertEquals(0, users.size());
        checkIdentityInList(identity, users, false);
    } finally {
        getHelper().logout();
    }
    IdmIdentityContractDto newContract = getHelper().createContract(identity, position);
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        assertEquals(1, users.size());
        checkIdentityInList(identity, users, true);
    } finally {
        getHelper().logout();
    }
    identityContractService.delete(newContract);
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        assertEquals(0, users.size());
        checkIdentityInList(identity, users, false);
    } finally {
        getHelper().logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 82 with IdmTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.

the class IdentityByTreeNodeEvaluatorIntegrationTest method testSubpositionOnContract.

@Test
public void testSubpositionOnContract() {
    IdmTreeNodeDto parent = getHelper().createTreeNode();
    IdmTreeNodeDto parentTwo = getHelper().createTreeNode(getHelper().createName(), parent);
    IdmTreeNodeDto position = getHelper().createTreeNode(getHelper().createName(), parentTwo);
    // Evaluator is on parent
    IdmRoleDto role = prepareRoleWithEvaluator(parent);
    // Position is sub child
    IdmIdentityDto identity = prepareIdentityOnWorkPosition(position);
    IdmIdentityDto administrator = getHelper().createIdentity();
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        // only myself
        assertEquals(0, users.size());
        checkIdentityInList(identity, users, false);
    } finally {
        getHelper().logout();
    }
    getHelper().assignRoles(getHelper().getPrimeContract(administrator), role);
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        assertEquals(1, users.size());
        checkIdentityInList(identity, users, true);
    } finally {
        getHelper().logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 83 with IdmTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.

the class IdentityByTreeNodeEvaluatorIntegrationTest method testOneContract.

@Test
public void testOneContract() {
    IdmTreeNodeDto position = getHelper().createTreeNode();
    IdmRoleDto role = prepareRoleWithEvaluator(position);
    IdmIdentityDto identity = prepareIdentityOnWorkPosition(position);
    IdmIdentityDto administrator = getHelper().createIdentity();
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        // only myself
        assertEquals(0, users.size());
        checkIdentityInList(identity, users, false);
    } finally {
        getHelper().logout();
    }
    getHelper().assignRoles(getHelper().getPrimeContract(administrator), role);
    try {
        getHelper().login(administrator);
        List<IdmIdentityDto> users = identityService.find(null, IdmBasePermission.READ).getContent();
        assertEquals(1, users.size());
        checkIdentityInList(identity, users, true);
    } finally {
        getHelper().logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 84 with IdmTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.

the class TreeSynchronizationExecutor method doDeleteEntity.

/**
 * Delete entity linked with given account
 *
 * @param account
 * @param entityType
 * @param log
 * @param logItem
 * @param actionLogs
 */
@Override
protected void doDeleteEntity(AccAccountDto account, SystemEntityType entityType, SysSyncLogDto log, SysSyncItemLogDto logItem, List<SysSyncActionLogDto> actionLogs) {
    IdmTreeNodeDto treeNode = this.getDtoByAccount(null, account);
    if (treeNode == null) {
        addToItemLog(logItem, "Warning! - Tree node was not found and cannot be deleted (maybe was deleted  within deleting of parent node).");
        initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
    logItem.setDisplayName(treeNode.getName());
    // Delete entity (recursively)
    deleteChildrenRecursively(treeNode, logItem);
}
Also used : IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

Example 85 with IdmTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto in project CzechIdMng by bcvsolutions.

the class TreeSynchronizationExecutor method getValueByMappedAttribute.

@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
    if (transformedValue != null && PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
        String parentUid = transformedValue.toString();
        SysSystemMappingDto systemMapping = systemMappingService.get(((SysSystemAttributeMappingDto) attribute).getSystemMapping());
        try {
            UUID parentUUID = UUID.fromString(parentUid);
            IdmTreeNodeDto parentNode = treeNodeService.get(parentUUID);
            if (parentNode != null) {
                if (!systemMapping.getTreeType().equals(parentNode.getTreeType())) {
                    throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_NODE_IS_NOT_FROM_SAME_TREE_TYPE, ImmutableMap.of("parentNode", parentNode.getCode(), "systemId", context.getSystem().getName()));
                }
                addToItemLog(context.getLogItem(), MessageFormat.format("Transformed value from the parent attribute contains the UUID of idmTreeNode [{0}].", parentNode.getCode()));
                return parentNode.getId();
            }
        } catch (IllegalArgumentException ex) {
            // OK this is not UUID of tree node
            addToItemLog(context.getLogItem(), MessageFormat.format("Parent value [{0}] is not UUID of a tree node.", parentUid));
        }
        SysSchemaObjectClassDto schemaObjectClass = schemaObjectClassService.get(systemMapping.getObjectClass());
        UUID systemId = schemaObjectClass.getSystem();
        // Find account by UID from parent field
        AccAccountFilter accountFilter = new AccAccountFilter();
        accountFilter.setUid(parentUid);
        accountFilter.setSystemId(systemId);
        List<AccAccountDto> parentAccounts = accountService.find(accountFilter, null).getContent();
        if (!parentAccounts.isEmpty()) {
            UUID parentAccount = parentAccounts.get(0).getId();
            // Find relation between tree and account
            AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
            treeAccountFilter.setAccountId(parentAccount);
            List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
            if (!treeAccounts.isEmpty()) {
                // Find parent tree node by ID
                // TODO: resolve more treeAccounts situations
                // parent uuid - we are working with dtos
                transformedValue = treeAccounts.get(0).getTreeNode();
            } else {
                LOG.warn("For parent UID: [{}] on system ID [{}] and acc account: [{}], was not found tree accounts! Return null value in parent!!", parentUid, systemId, parentAccount);
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_TREE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId, "parentAccount", parentAccount));
            }
        } else {
            LOG.warn("For parent UID: [{}] on system ID [{}], was not found parents account! Return null value in parent!!", parentUid, systemId);
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId));
        }
    }
    return transformedValue;
}
Also used : SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccTreeAccountDto(eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto) AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID)

Aggregations

IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)231 Test (org.junit.Test)172 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)130 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)122 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)102 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)102 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)92 UUID (java.util.UUID)56 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)44 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)44 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)42 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)39 Transactional (org.springframework.transaction.annotation.Transactional)38 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)33 List (java.util.List)31 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)27 LocalDate (java.time.LocalDate)26 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)25 Autowired (org.springframework.beans.factory.annotation.Autowired)25 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)23