Search in sources :

Example 51 with IdmTreeNodeDto

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

the class ContractSynchronizationExecutor method findTreeNode.

private IdmTreeNodeDto findTreeNode(Object value, SynchronizationContext context) {
    if (value instanceof Serializable) {
        // Find by UUID
        context.getLogItem().addToLog(MessageFormat.format("Work position - try find directly by transformed value [{0}]!", value));
        IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, (Serializable) value);
        if (node != null) {
            IdmTreeTypeDto treeTypeDto = DtoUtils.getEmbedded(node, IdmTreeNode_.treeType, IdmTreeTypeDto.class);
            context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] (in tree type [{2}]) was found directly by transformed value [{0}]!", value, node.getCode(), treeTypeDto.getCode()));
            return node;
        }
        context.getLogItem().addToLog(MessageFormat.format("Work position - was not not found directly from transformed value [{0}]!", value));
        if (value instanceof String) {
            // Find by code in default tree type
            SysSyncContractConfigDto config = this.getConfig(context);
            if (config.getDefaultTreeType() == null) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - we cannot finding node by code [{0}], because default tree node is not set (in sync configuration)!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            }
            IdmTreeNodeFilter treeNodeFilter = new IdmTreeNodeFilter();
            IdmTreeTypeDto defaultTreeType = DtoUtils.getEmbedded(config, SysSyncContractConfig_.defaultTreeType, IdmTreeTypeDto.class);
            treeNodeFilter.setTreeTypeId(config.getDefaultTreeType());
            treeNodeFilter.setCode((String) value);
            context.getLogItem().addToLog(MessageFormat.format("Work position - try find in default tree type [{1}] with code [{0}]!", value, defaultTreeType.getCode()));
            List<IdmTreeNodeDto> nodes = treeNodeService.find(treeNodeFilter, null).getContent();
            if (nodes.isEmpty()) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - none node found for code [{0}]!", value));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            } else if (nodes.size() > 1) {
                context.getLogItem().addToLog(MessageFormat.format("Warning - Work position - more then one [{0}] node found for code [{1}]!", value, nodes.size()));
                this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
                return null;
            } else {
                context.getLogItem().addToLog(MessageFormat.format("Work position - One node [{1}] was found for code [{0}]!", value, nodes.get(0).getId()));
                return nodes.get(0);
            }
        }
    } else {
        context.getLogItem().addToLog(MessageFormat.format("Warning! - Work position cannot be found, because transformed value [{0}] is not Serializable!", value));
        this.initSyncActionLog(context.getActionType(), OperationResultType.WARNING, context.getLogItem(), context.getLog(), context.getActionLogs());
    }
    return null;
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) Serializable(java.io.Serializable) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

Example 52 with IdmTreeNodeDto

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

the class IdmIdentityController method organizationPosition.

/**
 * Get given identity's prime position in organization.
 *
 * @param backendId
 * @return Positions from root to closest parent
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/work-position", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity prime position in organization.", nickname = "getIdentityPosition", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> organizationPosition(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
    IdmIdentityDto identity = getDto(backendId);
    if (identity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
    if (primeContract == null) {
        return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
    }
    WorkPositionDto position = new WorkPositionDto(identity, primeContract);
    if (primeContract.getWorkPosition() != null) {
        IdmTreeNodeDto contractPosition = treeNodeService.get(primeContract.getWorkPosition());
        position.getPath().addAll(treeNodeService.findAllParents(contractPosition.getId(), new Sort(Direction.ASC, "forestIndex.lft")));
        position.getPath().add(contractPosition);
    }
    return new ResponseEntity<WorkPositionDto>(position, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) WorkPositionDto(eu.bcvsolutions.idm.core.model.dto.WorkPositionDto) Sort(org.springframework.data.domain.Sort) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with IdmTreeNodeDto

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

the class IdmTreeNodeController method getDefaultTreeNode.

/**
 * Returns default tree node or {@code null}, if no default tree node is defined
 *
 * @return
 */
@ResponseBody
@RequestMapping(value = "/search/default", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.TREENODE_AUTOCOMPLETE + "')" + " or hasAuthority('" + CoreGroupPermission.TREENODE_READ + "')")
@ApiOperation(value = "Get default tree node detail", nickname = "getDefaultTreeNode", response = IdmTreeNodeDto.class, tags = { IdmTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREENODE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREENODE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREENODE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREENODE_READ, description = "") }) })
public ResponseEntity<?> getDefaultTreeNode() {
    IdmTreeNodeDto defaultTreeNode = treeNodeService.getDefaultTreeNode();
    if (defaultTreeNode == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", "default tree type"));
    }
    Set<String> permissions = getService().getPermissions(defaultTreeNode.getId());
    if (!PermissionUtils.hasAnyPermission(permissions, IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ)) {
        throw new ForbiddenEntityException(defaultTreeNode.getId(), IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
    }
    return new ResponseEntity<>(toResource(defaultTreeNode), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 54 with IdmTreeNodeDto

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

the class IdmTreeNodeController method getFormValues.

/**
 * Returns filled form values
 *
 * @param backendId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.GET)
@ApiOperation(value = "Tree node form definition - read values", nickname = "getTreeNodeFormValues", tags = { IdmTreeNodeController.TAG })
public Resource<?> getFormValues(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode) {
    IdmTreeNodeDto dto = getDto(backendId);
    if (dto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(IdmTreeNode.class, definitionCode);
    // 
    return formDefinitionController.getFormValues(dto, formDefinition);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with IdmTreeNodeDto

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

the class TreeSynchronizationExecutor method doUpdateEntity.

/**
 * Fill data from IC attributes to entity (EAV and confidential storage too)
 *
 * @param account
 * @param entityType
 * @param uid
 * @param icAttributes
 * @param mappedAttributes
 * @param log
 * @param logItem
 * @param actionLogs
 */
@Override
protected void doUpdateEntity(SynchronizationContext context) {
    String uid = context.getUid();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    AccAccountDto account = context.getAccount();
    List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
    UUID entityId = getEntityByAccount(account.getId());
    IdmTreeNodeDto treeNode = null;
    if (entityId != null) {
        treeNode = treeNodeService.get(entityId);
    }
    if (treeNode != null) {
        // Update entity
        treeNode = fillEntity(mappedAttributes, uid, icAttributes, treeNode, false, context);
        treeNode = this.save(treeNode, true);
        // Update extended attribute (entity must be persisted first)
        updateExtendedAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
        // Update confidential attribute (entity must be persisted first)
        updateConfidentialAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
        // TreeNode Updated
        addToItemLog(logItem, MessageFormat.format("TreeNode with id {0} was updated", treeNode.getId()));
        if (logItem != null) {
            logItem.setDisplayName(treeNode.getName());
        }
        // Call provisioning for entity
        this.callProvisioningForEntity(treeNode, context.getEntityType(), logItem);
        return;
    } else {
        addToItemLog(logItem, "Tree - account relation (with ownership = true) was not found!");
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Aggregations

IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)79 Test (org.junit.Test)48 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)35 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)31 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)21 UUID (java.util.UUID)13 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)9 LocalDate (org.joda.time.LocalDate)9 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)7 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)6 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)5