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);
}
Aggregations