use of eu.bcvsolutions.idm.core.workflow.model.dto.DecisionFormTypeDto 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.DecisionFormTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmConceptRoleRequestService method cancelWF.
private void cancelWF(IdmConceptRoleRequestDto dto) {
if (!Strings.isNullOrEmpty(dto.getWfProcessId())) {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessInstanceId(dto.getWfProcessId());
List<WorkflowProcessInstanceDto> resources = workflowProcessInstanceService.find(filter, null).getContent();
if (resources.isEmpty()) {
// Process with this ID not exist ... maybe was ended
this.addToLog(dto, MessageFormat.format("Workflow process with ID [{0}] was not deleted, because was not found. Maybe was ended before.", dto.getWfProcessId()));
} else {
// Before delete/cancel process we try to finish process as disapprove. Cancel
// process does not trigger the parent process. That means without correct
// ending of process, parent process will be frozen!
// Find active task for this process.
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setProcessInstanceId(dto.getWfProcessId());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
if (tasks.size() == 1) {
WorkflowTaskInstanceDto task = tasks.get(0);
DecisionFormTypeDto disapprove = //
task.getDecisions().stream().filter(decision -> WorkflowTaskInstanceService.WORKFLOW_DECISION_DISAPPROVE.equals(decision.getId())).findFirst().orElse(null);
if (disapprove != null) {
// Active task exists and has decision for 'disapprove'. Complete task (process)
// with this decision.
workflowTaskInstanceService.completeTask(task.getId(), disapprove.getId(), null, null, null);
this.addToLog(dto, MessageFormat.format("Workflow process with ID [{0}] was disapproved, because this concept is deleted/canceled", dto.getWfProcessId()));
return;
}
}
// We wasn't able to disapprove this process, we cancel him now.
workflowProcessInstanceService.delete(dto.getWfProcessId(), "Role concept use this WF, was deleted. This WF was deleted too.");
this.addToLog(dto, MessageFormat.format("Workflow process with ID [{0}] was deleted, because this concept is deleted/canceled", dto.getWfProcessId()));
}
}
}
Aggregations