Search in sources :

Example 1 with FormField

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

the class GetTaskFormVariablesCmd method execute.

public VariableMap execute(CommandContext commandContext) {
    final TaskManager taskManager = commandContext.getTaskManager();
    TaskEntity task = taskManager.findTaskById(resourceId);
    ensureNotNull(BadUserRequestException.class, "Cannot find task with id '" + resourceId + "'.", "task", task);
    checkGetTaskFormVariables(task, commandContext);
    VariableMapImpl result = new VariableMapImpl();
    // first, evaluate form fields
    TaskDefinition taskDefinition = task.getTaskDefinition();
    if (taskDefinition != null) {
        TaskFormData taskFormData = taskDefinition.getTaskFormHandler().createTaskForm(task);
        for (FormField formField : taskFormData.getFormFields()) {
            if (formVariableNames == null || formVariableNames.contains(formField.getId())) {
                result.put(formField.getId(), createVariable(formField, task));
            }
        }
    }
    // collect remaining variables from task scope and parent scopes
    task.collectVariables(result, formVariableNames, false, deserializeObjectValues);
    return result;
}
Also used : VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) TaskManager(org.camunda.bpm.engine.impl.persistence.entity.TaskManager) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField)

Example 2 with FormField

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

the class MockProvider method createMockTaskFormDataUsingFormFieldsWithoutFormKey.

public static TaskFormData createMockTaskFormDataUsingFormFieldsWithoutFormKey() {
    FormField mockFormField = mock(FormField.class);
    when(mockFormField.getId()).thenReturn(EXAMPLE_FORM_PROPERTY_ID);
    when(mockFormField.getLabel()).thenReturn(EXAMPLE_FORM_PROPERTY_NAME);
    when(mockFormField.getDefaultValue()).thenReturn(EXAMPLE_FORM_PROPERTY_VALUE);
    FormType mockFormType = mock(FormType.class);
    when(mockFormType.getName()).thenReturn(EXAMPLE_FORM_PROPERTY_TYPE_NAME);
    when(mockFormField.getType()).thenReturn(mockFormType);
    TaskFormData mockFormData = mock(TaskFormData.class);
    when(mockFormData.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
    List<FormField> mockFormFields = new ArrayList<FormField>();
    mockFormFields.add(mockFormField);
    when(mockFormData.getFormFields()).thenReturn(mockFormFields);
    return mockFormData;
}
Also used : FormType(org.camunda.bpm.engine.form.FormType) ArrayList(java.util.ArrayList) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) HistoricFormField(org.camunda.bpm.engine.history.HistoricFormField) FormField(org.camunda.bpm.engine.form.FormField)

Example 3 with FormField

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

the class FormServiceTest method testBusinessKey.

@Deployment
@Test
public void testBusinessKey() {
    // given
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    // when
    StartFormData startFormData = formService.getStartFormData(procDefId);
    // then
    FormField formField = startFormData.getFormFields().get(0);
    assertTrue(formField.isBusinessKey());
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) FormField(org.camunda.bpm.engine.form.FormField) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with FormField

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

the class FormDataTest method testGetFormFieldValidationConstraints.

@Deployment
public void testGetFormFieldValidationConstraints() {
    runtimeService.startProcessInstanceByKey("FormDataTest.testGetFormFieldValidationConstraints");
    Task task = taskService.createTaskQuery().singleResult();
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    List<FormField> formFields = taskFormData.getFormFields();
    FormField field1 = formFields.get(0);
    List<FormFieldValidationConstraint> validationConstraints = field1.getValidationConstraints();
    FormFieldValidationConstraint constraint1 = validationConstraints.get(0);
    assertEquals("maxlength", constraint1.getName());
    assertEquals("10", constraint1.getConfiguration());
    FormFieldValidationConstraint constraint2 = validationConstraints.get(1);
    assertEquals("minlength", constraint2.getName());
    assertEquals("5", constraint2.getConfiguration());
}
Also used : Task(org.camunda.bpm.engine.task.Task) FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with FormField

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

the class FormDataTest method testGetFormFieldProperties.

@Deployment
public void testGetFormFieldProperties() {
    runtimeService.startProcessInstanceByKey("FormDataTest.testGetFormFieldProperties");
    Task task = taskService.createTaskQuery().singleResult();
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    List<FormField> formFields = taskFormData.getFormFields();
    FormField stringField = formFields.get(0);
    Map<String, String> properties = stringField.getProperties();
    assertEquals("property1", properties.get("p1"));
    assertEquals("property2", properties.get("p2"));
}
Also used : Task(org.camunda.bpm.engine.task.Task) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

FormField (org.camunda.bpm.engine.form.FormField)14 TaskFormData (org.camunda.bpm.engine.form.TaskFormData)8 Deployment (org.camunda.bpm.engine.test.Deployment)8 Task (org.camunda.bpm.engine.task.Task)6 ArrayList (java.util.ArrayList)4 StartFormData (org.camunda.bpm.engine.form.StartFormData)4 Test (org.junit.Test)3 FormProperty (org.camunda.bpm.engine.form.FormProperty)2 FormType (org.camunda.bpm.engine.form.FormType)2 HistoricFormField (org.camunda.bpm.engine.history.HistoricFormField)2 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 FormFieldValidationConstraint (org.camunda.bpm.engine.form.FormFieldValidationConstraint)1 EnumFormType (org.camunda.bpm.engine.impl.form.type.EnumFormType)1 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)1 TaskManager (org.camunda.bpm.engine.impl.persistence.entity.TaskManager)1 TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1