Search in sources :

Example 1 with FormData

use of org.camunda.bpm.engine.form.FormData 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 2 with FormData

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

the class AbstractGetDeployedFormCmd method execute.

public InputStream execute(final CommandContext commandContext) {
    checkAuthorization(commandContext);
    final FormData formData = getFormData(commandContext);
    String formKey = formData.getFormKey();
    if (formKey == null) {
        throw new BadUserRequestException("The form key is not set.");
    }
    final String resourceName = getResourceName(formKey);
    try {
        return commandContext.runWithoutAuthorization(new Callable<InputStream>() {

            @Override
            public InputStream call() throws Exception {
                return new GetDeploymentResourceCmd(formData.getDeploymentId(), resourceName).execute(commandContext);
            }
        });
    } catch (DeploymentResourceNotFoundException e) {
        throw new NotFoundException("The form with the resource name '" + resourceName + "' cannot be found in deployment.", e);
    }
}
Also used : FormData(org.camunda.bpm.engine.form.FormData) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException) InputStream(java.io.InputStream) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException)

Aggregations

FormData (org.camunda.bpm.engine.form.FormData)2 InputStream (java.io.InputStream)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)1 FormService (org.camunda.bpm.engine.FormService)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 DeploymentResourceNotFoundException (org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException)1 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)1 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)1 FormDto (org.camunda.bpm.engine.rest.dto.task.FormDto)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 HalTask (org.camunda.bpm.engine.rest.hal.task.HalTask)1 Task (org.camunda.bpm.engine.task.Task)1