Search in sources :

Example 1 with WorkPositionDto

use of eu.bcvsolutions.idm.core.model.dto.WorkPositionDto 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)

Aggregations

IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 WorkPositionDto (eu.bcvsolutions.idm.core.model.dto.WorkPositionDto)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Sort (org.springframework.data.domain.Sort)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1