use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceAbstractDto in project CzechIdMng by bcvsolutions.
the class ManualWorkflowTaskDelegationBulkAction method getDtoById.
@Override
protected WorkflowTaskInstanceAbstractDto getDtoById(UUID id) {
WorkflowTaskInstanceDto task = workflowTaskInstanceService.get(id.toString());
if (task != null) {
WorkflowTaskInstanceAbstractDto mockTask = new WorkflowTaskInstanceAbstractDto();
mockTask.setId(task.getId());
mockTask.setIdentityLinks(task.getIdentityLinks());
mockTask.setApplicant(task.getApplicant());
return mockTask;
}
return null;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceAbstractDto in project CzechIdMng by bcvsolutions.
the class ManualWorkflowTaskDelegationBulkAction method processDto.
@Override
protected OperationResult processDto(WorkflowTaskInstanceAbstractDto task) {
IdmBulkActionDto action = this.getAction();
Assert.notNull(action, "Bulk action is required.");
IdmIdentityDto delegator = findDelegator();
if (delegator == null) {
throw new ResultCodeException(CoreResultCode.MANUAL_TASK_DELEGATION_DELEGATOR_MISSING);
}
UUID delegateId = this.getDelegateId();
UUID delegatorId = delegator.getId();
Assert.notNull(delegateId, "Delegate ID cannot be null!");
IdmIdentityDto delegate = identityService.get(delegateId);
Assert.notNull(delegate, "Delegate cannot be null!");
boolean delegatorIsCandidate = task.getIdentityLinks().stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType()) || IdentityLinkType.ASSIGNEE.equals(identityLink.getType())).filter(identityLink -> UUID.fromString(identityLink.getUserId()).equals(delegatorId)).findFirst().isPresent();
// Delegator have to be candidate or assigned task user!
if (!delegatorIsCandidate) {
throw new ResultCodeException(CoreResultCode.MANUAL_TASK_DELEGATION_DELEGATOR_IS_NOT_CANDIDATE, ImmutableMap.of("delegator", delegator.getUsername(), "task", task.getId()));
}
// Find delegation definitions for delegator and delegate.
IdmDelegationDefinitionDto delegationDefinition = findDelegationDefinition(delegateId, delegatorId);
WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
mockTask.setId(task.getId().toString());
// Create delegation for this task.
delegationManager.delegate(mockTask, delegationDefinition);
// Add delegate as task candidat.
taskService.addCandidateUser(mockTask.getId(), delegationDefinition.getDelegate().toString());
// Delete delegator form the task's candidats.
taskService.deleteCandidateUser(mockTask.getId(), delegationDefinition.getDelegator().toString());
// Add delegator as participant to this task.
taskService.addUserIdentityLink(mockTask.getId(), delegationDefinition.getDelegator().toString(), IdentityLinkType.PARTICIPANT);
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Aggregations