use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class RoleRequestByWfEvaluatorIntegrationTest method checkAndCompleteOneTask.
private void checkAndCompleteOneTask(WorkflowFilterDto taskFilter, String user, String decision, String userTaskId) {
IdmIdentityDto identity = identityService.getByUsername(user);
List<WorkflowTaskInstanceDto> tasks;
tasks = (List<WorkflowTaskInstanceDto>) workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
if (userTaskId != null) {
assertEquals(userTaskId, tasks.get(0).getDefinition().getId());
}
assertEquals(identity.getId().toString(), tasks.get(0).getApplicant());
workflowTaskInstanceService.completeTask(tasks.get(0).getId(), decision);
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method toResource.
private WorkflowTaskInstanceDto toResource(TaskInfo task, BasePermission[] permission) {
if (task == null) {
return null;
}
WorkflowTaskInstanceDto dto = new WorkflowTaskInstanceDto();
dto.setId(task.getId());
dto.setName(task.getName());
dto.setProcessDefinitionId(task.getProcessDefinitionId());
dto.setPriority(task.getPriority());
dto.setAssignee(task.getAssignee());
dto.setCreated(task.getCreateTime());
dto.setFormKey(task.getFormKey());
dto.setDescription(task.getDescription());
dto.setProcessInstanceId(task.getProcessInstanceId());
Map<String, Object> taskVariables = task.getTaskLocalVariables();
Map<String, Object> processVariables = task.getProcessVariables();
// Add applicant username to task dto (for easier work)
if (processVariables != null && processVariables.containsKey(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER)) {
dto.setApplicant(processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
}
dto.setVariables(processVariables);
convertToDtoVariables(dto, taskVariables);
dto.setDefinition(workflowTaskDefinitionService.searchTaskDefinitionById(task.getProcessDefinitionId(), task.getTaskDefinitionKey()));
if (!Strings.isNullOrEmpty(task.getProcessDefinitionId())) {
WorkflowProcessDefinitionDto processDefinition = workflowProcessDefinitionService.get(task.getProcessDefinitionId());
if (processDefinition != null) {
dto.setProcessDefinitionKey(processDefinition.getKey());
}
}
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
// Add form data (it means form properties and value from WF)
List<FormProperty> formProperties = taskFormData.getFormProperties();
// Search and add identity links to dto (It means all user
// (assigned/candidates/group) for this task)
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
if (identityLinks != null) {
List<IdentityLinkDto> identityLinksDtos = new ArrayList<>(identityLinks.size());
identityLinks.forEach((il) -> {
identityLinksDtos.add(toResource(il));
});
dto.getIdentityLinks().addAll(identityLinksDtos);
}
// Check if the logged user can complete this task
boolean canExecute = this.canExecute(dto, permission);
if (formProperties != null && !formProperties.isEmpty()) {
formProperties.forEach((property) -> {
resovleFormProperty(property, dto, canExecute);
});
}
return dto;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method resovleFormProperty.
/**
* Convert form property and add to result dto
*
* @param property
* @param dto
* @param canExecute
*/
@SuppressWarnings("unchecked")
private void resovleFormProperty(FormProperty property, WorkflowTaskInstanceDto dto, boolean canExecute) {
FormType formType = property.getType();
if (formType instanceof DecisionFormType) {
// task
if (!canExecute) {
return;
}
DecisionFormTypeDto decisionDto = (DecisionFormTypeDto) ((DecisionFormType) formType).convertFormValueToModelValue(property.getValue());
if (decisionDto != null) {
decisionDto.setId(property.getId());
setDecisionReasonRequired(decisionDto);
dto.getDecisions().add(decisionDto);
}
} else if (formType instanceof TaskHistoryFormType) {
WorkflowFilterDto filterDto = new WorkflowFilterDto();
filterDto.setProcessInstanceId(dto.getProcessInstanceId());
List<WorkflowHistoricTaskInstanceDto> tasks = historicTaskInstanceService.find(filterDto, PageRequest.of(0, 50)).getContent();
List<WorkflowHistoricTaskInstanceDto> history = tasks.stream().filter(workflowHistoricTaskInstanceDto -> workflowHistoricTaskInstanceDto.getEndTime() != null).sorted((o1, o2) -> {
if (o1.getEndTime().before(o2.getEndTime())) {
return -1;
} else if (o1.getEndTime().after(o2.getEndTime())) {
return 1;
}
return 0;
}).collect(Collectors.toList());
dto.getFormData().add(historyToResource(property, history));
} else if (formType instanceof AbstractFormType) {
// To rest will be add only component form type marked as "exportable to rest".
if (formType instanceof AbstractComponentFormType && !((AbstractComponentFormType) formType).isExportableToRest()) {
return;
}
Object values = formType.getInformation("values");
if (values instanceof Map<?, ?>) {
dto.getFormData().add(toResource(property, (Map<String, String>) values));
} else {
dto.getFormData().add(toResource(property, null));
}
}
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class WorkflowTaskInstanceController method getDto.
@Override
public // need call direct service with Permission.READ!
WorkflowTaskInstanceDto getDto(Serializable backendId) {
WorkflowTaskInstanceDto dto = getService().get(backendId, IdmBasePermission.READ);
// on FE will said that task was resolved. For prevent this, I try to find task instance if user has permission to the process.
if (dto == null || dto instanceof WorkflowHistoricTaskInstanceDto) {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setOnlyInvolved(Boolean.FALSE);
if (dto == null) {
// First load the task without check permission. We need ID of a process.
WorkflowTaskInstanceDto task = workflowTaskInstanceService.get(backendId, filter);
if (task == null) {
return null;
}
dto = task;
}
boolean hasUsePermissionOnProcess = processInstanceService.canReadProcessOrHistoricProcess(dto.getProcessInstanceId());
if (hasUsePermissionOnProcess) {
// User has permission to read the process. We can set filter for find all tasks (check on the user has to be involved in tasks, will be skip).
dto = getService().get(backendId, filter, IdmBasePermission.READ);
}
}
// Add delegation to a task.
addDelegationToTask(dto, IdmBasePermission.READ);
return dto;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto 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