Search in sources :

Example 1 with FormService

use of org.camunda.bpm.engine.FormService in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method getFormVariables.

public Map<String, VariableValueDto> getFormVariables(String variableNames, boolean deserializeValues) {
    final FormService formService = engine.getFormService();
    List<String> formVariables = null;
    if (variableNames != null) {
        StringListConverter stringListConverter = new StringListConverter();
        formVariables = stringListConverter.convertQueryParameterToType(variableNames);
    }
    VariableMap startFormVariables = formService.getStartFormVariables(processDefinitionId, formVariables, deserializeValues);
    return VariableValueDto.fromVariableMap(startFormVariables);
}
Also used : StringListConverter(org.camunda.bpm.engine.rest.dto.converter.StringListConverter) VariableMap(org.camunda.bpm.engine.variable.VariableMap) FormService(org.camunda.bpm.engine.FormService)

Example 2 with FormService

use of org.camunda.bpm.engine.FormService in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method submitForm.

@Override
public ProcessInstanceDto submitForm(UriInfo context, StartProcessInstanceDto parameters) {
    FormService formService = engine.getFormService();
    ProcessInstance instance = null;
    try {
        Map<String, Object> variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        String businessKey = parameters.getBusinessKey();
        if (businessKey != null) {
            instance = formService.submitStartForm(processDefinitionId, businessKey, variables);
        } else {
            instance = formService.submitStartForm(processDefinitionId, variables);
        }
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) FormService(org.camunda.bpm.engine.FormService) RestException(org.camunda.bpm.engine.rest.exception.RestException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with FormService

use of org.camunda.bpm.engine.FormService in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method getStartForm.

@Override
public FormDto getStartForm() {
    final FormService formService = engine.getFormService();
    final StartFormData formData;
    try {
        formData = formService.getStartFormData(processDefinitionId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, "Cannot get start form data for process definition " + processDefinitionId);
    }
    FormDto dto = FormDto.fromFormData(formData);
    if (dto.getKey() == null || dto.getKey().isEmpty()) {
        if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
            dto.setKey("embedded:engine://engine/:engine/process-definition/" + processDefinitionId + "/rendered-form");
        }
    }
    dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
    return dto;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) FormService(org.camunda.bpm.engine.FormService) StartFormData(org.camunda.bpm.engine.form.StartFormData) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) FormDto(org.camunda.bpm.engine.rest.dto.task.FormDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 4 with FormService

use of org.camunda.bpm.engine.FormService in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method getForm.

@Override
public FormDto getForm() {
    FormService formService = engine.getFormService();
    Task task = getTaskById(taskId);
    FormData formData;
    try {
        formData = formService.getTaskFormData(taskId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.BAD_REQUEST, e, "Cannot get form for task " + taskId);
    }
    FormDto dto = FormDto.fromFormData(formData);
    if (dto.getKey() == null || dto.getKey().isEmpty()) {
        if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
            dto.setKey("embedded:engine://engine/:engine/task/" + taskId + "/rendered-form");
        }
    }
    // to get the application context path it is necessary to
    // execute it without authentication (tries to fetch the
    // process definition), because:
    // - user 'demo' has READ permission on a specific task resource
    // - user 'demo' does not have a READ permission on the corresponding
    // process definition
    // -> running the following lines with authorization would lead
    // to an AuthorizationException because the user 'demo' does not
    // have READ permission on the corresponding process definition
    IdentityService identityService = engine.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    try {
        identityService.clearAuthentication();
        String processDefinitionId = task.getProcessDefinitionId();
        String caseDefinitionId = task.getCaseDefinitionId();
        if (processDefinitionId != null) {
            dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
        } else if (caseDefinitionId != null) {
            dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByCaseDefinitionId(engine, caseDefinitionId));
        }
    } finally {
        identityService.setAuthentication(currentAuthentication);
    }
    return dto;
}
Also used : FormData(org.camunda.bpm.engine.form.FormData) IdentityService(org.camunda.bpm.engine.IdentityService) Task(org.camunda.bpm.engine.task.Task) HalTask(org.camunda.bpm.engine.rest.hal.task.HalTask) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) FormService(org.camunda.bpm.engine.FormService) RestException(org.camunda.bpm.engine.rest.exception.RestException) FormDto(org.camunda.bpm.engine.rest.dto.task.FormDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 5 with FormService

use of org.camunda.bpm.engine.FormService in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method getRenderedForm.

public Response getRenderedForm() {
    FormService formService = engine.getFormService();
    Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
    if (renderedTaskForm != null) {
        String content = renderedTaskForm.toString();
        InputStream stream = new ByteArrayInputStream(content.getBytes(EncodingUtil.DEFAULT_ENCODING));
        return Response.ok(stream).type(MediaType.APPLICATION_XHTML_XML).build();
    }
    throw new InvalidRequestException(Status.NOT_FOUND, "No matching rendered form for task with the id " + taskId + " found.");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FormService(org.camunda.bpm.engine.FormService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Aggregations

FormService (org.camunda.bpm.engine.FormService)9 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)5 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 RestException (org.camunda.bpm.engine.rest.exception.RestException)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 IdentityService (org.camunda.bpm.engine.IdentityService)2 StringListConverter (org.camunda.bpm.engine.rest.dto.converter.StringListConverter)2 FormDto (org.camunda.bpm.engine.rest.dto.task.FormDto)2 URI (java.net.URI)1 CaseService (org.camunda.bpm.engine.CaseService)1 ExternalTaskService (org.camunda.bpm.engine.ExternalTaskService)1 FilterService (org.camunda.bpm.engine.FilterService)1 HistoryService (org.camunda.bpm.engine.HistoryService)1 ManagementService (org.camunda.bpm.engine.ManagementService)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 TaskService (org.camunda.bpm.engine.TaskService)1