use of eu.bcvsolutions.idm.core.model.entity.IdmDelegation_ in project CzechIdMng by bcvsolutions.
the class WorkflowTaskInstanceController method addDelegationToTask.
/**
* Find and add definition of the delegation connected with this task.
*
* @param dto
*/
private void addDelegationToTask(WorkflowTaskInstanceDto dto, BasePermission... permission) {
if (dto != null && dto.getId() != null) {
// We need to create mock task, because DTO can be instance of historic task here.
WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
mockTask.setId(dto.getId());
UUID currentUserId = securityService.getCurrentId();
boolean currentUserIsCandidate = dto.getIdentityLinks().stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType()) || IdentityLinkType.ASSIGNEE.equals(identityLink.getType())).anyMatch(identityLink -> currentUserId != null && UUID.fromString(identityLink.getUserId()).equals(currentUserId));
boolean filterOnlyForCurrentUser = currentUserIsCandidate && !workflowTaskInstanceService.canReadAllTask(permission);
List<IdmDelegationDto> delegations = delegationManager.findDelegationForOwner(mockTask, permission).stream().filter(delegation -> {
// Filter only delegation where delegator or delegate is logged user (and user is not admin).
if (!filterOnlyForCurrentUser) {
return true;
}
IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
return definition.getDelegate().equals(currentUserId) || definition.getDelegator().equals(currentUserId);
}).sorted(Comparator.comparing(IdmDelegationDto::getCreated)).collect(Collectors.toList());
// TODO: ONLY first delegation definition is sets to the task!
if (!CollectionUtils.isEmpty(delegations)) {
Collections.reverse(delegations);
IdmDelegationDto delegation = delegations.get(0);
IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
dto.setDelegationDefinition(definition);
}
}
}
Aggregations