use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.
the class HistoryProcessAndTaskTest method completeTasksAndCheckHistory.
private void completeTasksAndCheckHistory() {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessDefinitionKey(PROCESS_KEY);
List<WorkflowTaskInstanceDto> tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(1, tasks.size());
assertEquals("userTaskFirst", tasks.get(0).getName());
String taskId = tasks.get(0).getId();
String processId = tasks.get(0).getProcessInstanceId();
taskInstanceService.completeTask(taskId, null);
// Check task history
checkTaskHistory(taskId, InitTestDataProcessor.TEST_USER_1);
// Second task is for testUser2 (is candidate) for testUser1 must be null
filter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_1);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(0, tasks.size());
this.logout();
this.loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
filter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(1, tasks.size());
assertEquals("userTaskSecond", tasks.get(0).getName());
taskId = tasks.get(0).getId();
taskInstanceService.completeTask(taskId, null);
// Check task history
checkTaskHistory(taskId, InitTestDataProcessor.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(0, tasks.size());
// Find history of process. Historic process must exist and must be ended.
WorkflowHistoricProcessInstanceDto historicProcess = historicProcessService.get(processId);
assertNotNull(historicProcess);
assertNotNull(historicProcess.getEndTime());
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestService method toDto.
@Override
public IdmRequestDto toDto(IdmRequest entity, IdmRequestDto dto) {
IdmRequestDto requestDto = super.toDto(entity, dto);
// Load and add WF process DTO to embedded. Prevents of many requests from FE.
if (requestDto != null && requestDto.getWfProcessId() != null) {
if (RequestState.IN_PROGRESS == requestDto.getState()) {
// Instance of process should exists only in 'IN_PROGRESS' state
WorkflowProcessInstanceDto processInstanceDto = workflowProcessInstanceService.get(requestDto.getWfProcessId());
// size
if (processInstanceDto != null) {
processInstanceDto.setProcessVariables(null);
}
requestDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processInstanceDto);
} else {
// In others states we need load historic process
WorkflowHistoricProcessInstanceDto processHistDto = workflowHistoricProcessInstanceService.get(requestDto.getWfProcessId());
// size
if (processHistDto != null) {
processHistDto.setProcessVariables(null);
}
requestDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processHistDto);
}
}
// Load and add owner DTO to embedded. Prevents of many requests from FE.
if (requestDto != null && requestDto.getOwnerId() != null && requestDto.getOwnerType() != null) {
try {
@SuppressWarnings("unchecked") Requestable requestable = requestManager.get(requestDto.getId(), requestDto.getOwnerId(), (Class<Requestable>) Class.forName(requestDto.getOwnerType()));
if (requestable instanceof AbstractDto) {
// If is requestable realized REMOVE, then requestable DTO does not contains
// data (only ID). In this case we don't want send this DTO to FE.
AbstractDto requestableDto = (AbstractDto) requestable;
IdmRequestItemDto itemDto = DtoUtils.getEmbedded(requestableDto, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class, null);
if (itemDto != null && RequestOperationType.REMOVE == itemDto.getOperation() && itemDto.getState().isTerminatedState()) {
requestable = null;
}
// Minimise response size
requestableDto.setEmbedded(null);
}
if (requestable == null) {
// Entity was not found ... maybe was deleted or not exists yet
LOG.debug(MessageFormat.format("Owner [{0}, {1}] not found for request {2}.", requestDto.getOwnerType(), requestDto.getOwnerId(), requestDto.getId()));
}
requestDto.getEmbedded().put(IdmRequestDto.OWNER_FIELD, requestable);
} catch (ClassNotFoundException e) {
// Only print warning
LOG.warn(MessageFormat.format("Class not found for request {0}.", requestDto.getId()), e);
}
}
return requestDto;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowProcessInstanceService method canReadProcessOrHistoricProcess.
@Override
public boolean canReadProcessOrHistoricProcess(String id) {
// Try to get the process. Process will returned only if user has permission to read that process (or history of that process).
WorkflowProcessInstanceDto processInstance = this.get(id, true);
if (processInstance != null) {
return true;
}
// Ok, process was not returned, but we need to check historic process (on involved user) too.
WorkflowHistoricProcessInstanceDto historicProcess = historicProcessInstanceService.get(id);
return historicProcess != null;
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricProcessInstanceService method find.
@Override
public Page<WorkflowHistoricProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
HistoricProcessInstanceQuery query = this.getQuery(filter, pageable, permission);
if (pageable == null) {
pageable = PageRequest.of(0, Integer.MAX_VALUE);
}
long count = query.count();
List<HistoricProcessInstance> processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
String processInstanceId = filter.getProcessInstanceId();
boolean trimmed = true;
if (processInstanceId != null) {
// Process variables will be included only for get by instance ID
trimmed = false;
query.includeProcessVariables();
query.processInstanceId(processInstanceId);
}
List<WorkflowHistoricProcessInstanceDto> dtos = new ArrayList<>();
if (processInstances != null) {
for (HistoricProcessInstance instance : processInstances) {
dtos.add(toDto(instance, trimmed));
}
}
return new PageImpl<>(dtos, pageable, count);
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricProcessInstanceService method get.
/**
* Rights on involved user are evolved here!
*/
@Override
public WorkflowHistoricProcessInstanceDto get(String historicProcessInstanceId) {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessInstanceId(historicProcessInstanceId);
List<WorkflowHistoricProcessInstanceDto> resources = this.find(filter, PageRequest.of(0, 1)).getContent();
return !resources.isEmpty() ? resources.get(0) : null;
}
Aggregations