use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricTaskInstanceService method getTaskByProcessId.
@Override
public WorkflowHistoricTaskInstanceDto getTaskByProcessId(String processId) {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessInstanceId(processId);
List<WorkflowHistoricTaskInstanceDto> resources = (List<WorkflowHistoricTaskInstanceDto>) this.find(filter, PageRequest.of(0, 1)).getContent();
return !resources.isEmpty() ? resources.get(0) : null;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricTaskInstanceService method toResource.
private WorkflowHistoricTaskInstanceDto toResource(HistoricTaskInstance task) {
if (task == null) {
return null;
}
WorkflowHistoricTaskInstanceDto dto = new WorkflowHistoricTaskInstanceDto();
// TODO can be slow
if (task.getTaskLocalVariables() != null) {
if (task.getTaskLocalVariables().containsKey(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_DECISION)) {
dto.setCompleteTaskDecision((String) task.getTaskLocalVariables().get(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_DECISION));
}
if (task.getTaskLocalVariables().containsKey(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_MESSAGE)) {
dto.setCompleteTaskMessage((String) task.getTaskLocalVariables().get(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_MESSAGE));
}
}
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.setDescription(task.getDescription());
dto.setProcessInstanceId(task.getProcessInstanceId());
dto.setDeleteReason(task.getDeleteReason());
dto.setDurationInMillis(task.getDurationInMillis());
dto.setEndTime(task.getEndTime());
dto.setStartTime(task.getStartTime());
dto.setCreateTime(task.getCreateTime());
dto.setDueDate(task.getDueDate());
dto.setFormKey(task.getFormKey());
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((String) processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
}
dto.setVariables(processVariables);
workflowTaskInstanceService.convertToDtoVariables(dto, taskVariables);
// TODO: Prevent selection of the definition here (performance).
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());
}
}
// Search and add identity links to dto (It means all user
// (assigned/candidates/group) for this task)
List<HistoricIdentityLink> identityLinks = historyService.getHistoricIdentityLinksForTask(task.getId());
if (identityLinks != null) {
List<IdentityLinkDto> identityLinksDtos = new ArrayList<>(identityLinks.size());
identityLinks.forEach((identityLink) -> {
identityLinksDtos.add(this.convertHistoricIdentityLink(identityLink));
});
dto.getIdentityLinks().addAll(identityLinksDtos);
}
return dto;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricTaskInstanceService method get.
@Override
public WorkflowHistoricTaskInstanceDto get(Serializable id, WorkflowFilterDto context, BasePermission... permission) {
Assert.notNull(id, "Identifier is required.");
if (context == null) {
context = new WorkflowFilterDto();
}
context.setId(UUID.fromString(String.valueOf(id)));
List<WorkflowHistoricTaskInstanceDto> resources = this.find(context, PageRequest.of(0, 1)).getContent();
return !resources.isEmpty() ? resources.get(0) : null;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto 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.WorkflowHistoricTaskInstanceDto 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;
}
Aggregations