Search in sources :

Example 16 with WorkflowHistoricProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class WorkflowHistoricProcessInstanceController method getDiagram.

/**
 * Generate process instance diagram image
 *
 * @param historicProcessInstanceId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@ApiOperation(value = "Historic process instance diagram", nickname = "getHistoricProcessInstanceDiagram", response = WorkflowHistoricProcessInstanceDto.class, tags = { WorkflowHistoricProcessInstanceController.TAG })
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Historic process instance id.", required = true) @PathVariable @NotNull String backendId) {
    // check rights
    WorkflowHistoricProcessInstanceDto result = workflowHistoricProcessInstanceService.get(backendId);
    if (result == null) {
        throw new ResultCodeException(CoreResultCode.FORBIDDEN);
    }
    InputStream is = workflowHistoricProcessInstanceService.getDiagram(backendId);
    try {
        return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with WorkflowHistoricProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRequestItemService method toDto.

@Override
public IdmRequestItemDto toDto(IdmRequestItem entity, IdmRequestItemDto dto) {
    IdmRequestItemDto requestItemDto = super.toDto(entity, dto);
    // Load and add WF process DTO to embedded. Prevents of many requests from FE.
    if (requestItemDto != null && requestItemDto.getWfProcessId() != null) {
        if (RequestState.IN_PROGRESS == requestItemDto.getState()) {
            // Instance of process should exists only in 'IN_PROGRESS' state
            WorkflowProcessInstanceDto processInstanceDto = workflowProcessInstanceService.get(requestItemDto.getWfProcessId());
            // size
            if (processInstanceDto != null) {
                processInstanceDto.setProcessVariables(null);
            }
            requestItemDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processInstanceDto);
        } else {
            // In others states we need load historic process
            WorkflowHistoricProcessInstanceDto processHistDto = workflowHistoricProcessInstanceService.get(requestItemDto.getWfProcessId());
            // size
            if (processHistDto != null) {
                processHistDto.setProcessVariables(null);
            }
            requestItemDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processHistDto);
        }
    }
    // Load and add owner DTO to embedded. Prevents of many requests from FE.
    if (requestItemDto != null && requestItemDto.getOwnerId() != null && requestItemDto.getOwnerType() != null) {
        try {
            @SuppressWarnings("unchecked") Requestable requestable = requestManager.convertItemToDto(requestItemDto, (Class<Requestable>) Class.forName(requestItemDto.getOwnerType()));
            // Item for remove operation does not contains the JSON data, so we need load owner via lookupService
            if (requestable == null && RequestOperationType.REMOVE == requestItemDto.getOperation()) {
                requestable = (Requestable) lookupService.lookupDto(requestItemDto.getOwnerType(), requestItemDto.getOwnerId());
            }
            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}.", requestItemDto.getOwnerType(), requestItemDto.getOwnerId(), requestItemDto.getId()));
            }
            requestItemDto.getEmbedded().put(IdmRequestDto.OWNER_FIELD, requestable);
        } catch (ClassNotFoundException e) {
            // Only print warning
            LOG.warn(MessageFormat.format("Class not found for request item {0}.", requestItemDto.getId()), e);
        } catch (JsonParseException e) {
            // Only print warning
            LOG.warn(MessageFormat.format("JsonParseException for request item {0}.", requestItemDto.getId()), e);
        } catch (JsonMappingException e) {
            // Only print warning
            LOG.warn(MessageFormat.format("JsonMappingException for request item {0}.", requestItemDto.getId()), e);
        } catch (IOException e) {
            // Only print warning
            LOG.warn(MessageFormat.format("IOException for request item {0}.", requestItemDto.getId()), e);
        }
    }
    return requestItemDto;
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) JsonParseException(com.fasterxml.jackson.core.JsonParseException) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Aggregations

WorkflowHistoricProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)17 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)9 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)5 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)3 List (java.util.List)3 Test (org.junit.Test)3 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)2 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)2 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)2 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)2 IOException (java.io.IOException)2 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)1 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)1 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)1