use of org.camunda.bpm.engine.rest.dto.task.FormDto 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;
}
use of org.camunda.bpm.engine.rest.dto.task.FormDto 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;
}
Aggregations