Search in sources :

Example 6 with FormField

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

the class MockProvider method createMockStartFormDataUsingFormFieldsWithoutFormKey.

public static StartFormData createMockStartFormDataUsingFormFieldsWithoutFormKey(ProcessDefinition definition) {
    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);
    StartFormData mockFormData = mock(StartFormData.class);
    when(mockFormData.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
    when(mockFormData.getProcessDefinition()).thenReturn(definition);
    List<FormField> mockFormFields = new ArrayList<FormField>();
    mockFormFields.add(mockFormField);
    when(mockFormData.getFormFields()).thenReturn(mockFormFields);
    return mockFormData;
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) FormType(org.camunda.bpm.engine.form.FormType) ArrayList(java.util.ArrayList) HistoricFormField(org.camunda.bpm.engine.history.HistoricFormField) FormField(org.camunda.bpm.engine.form.FormField)

Example 7 with FormField

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

the class HtmlFormEngine method renderFormData.

protected String renderFormData(FormData formData) {
    if (formData == null || (formData.getFormFields() == null || formData.getFormFields().isEmpty()) && (formData.getFormProperties() == null || formData.getFormProperties().isEmpty())) {
        return null;
    } else {
        HtmlElementWriter formElement = new HtmlElementWriter(FORM_ELEMENT).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE);
        HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement);
        // render fields
        for (FormField formField : formData.getFormFields()) {
            renderFormField(formField, documentBuilder);
        }
        // render deprecated form properties
        for (FormProperty formProperty : formData.getFormProperties()) {
            renderFormField(new FormPropertyAdapter(formProperty), documentBuilder);
        }
        // end document element
        documentBuilder.endElement();
        return documentBuilder.getHtmlString();
    }
}
Also used : FormProperty(org.camunda.bpm.engine.form.FormProperty) FormField(org.camunda.bpm.engine.form.FormField)

Example 8 with FormField

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

the class GetStartFormVariablesCmd method execute.

public VariableMap execute(final CommandContext commandContext) {
    StartFormData startFormData = commandContext.runWithoutAuthorization(new Callable<StartFormData>() {

        public StartFormData call() throws Exception {
            return new GetStartFormCmd(resourceId).execute(commandContext);
        }
    });
    ProcessDefinition definition = startFormData.getProcessDefinition();
    checkGetStartFormVariables((ProcessDefinitionEntity) definition, commandContext);
    VariableMap result = new VariableMapImpl();
    for (FormField formField : startFormData.getFormFields()) {
        if (formVariableNames == null || formVariableNames.contains(formField.getId())) {
            result.put(formField.getId(), createVariable(formField, null));
        }
    }
    return result;
}
Also used : VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) StartFormData(org.camunda.bpm.engine.form.StartFormData) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) FormField(org.camunda.bpm.engine.form.FormField)

Example 9 with FormField

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

the class AbstractRenderFormDelegate method renderFormData.

protected String renderFormData(FormData formData) {
    if (formData == null || (formData.getFormFields() == null || formData.getFormFields().isEmpty()) && (formData.getFormProperties() == null || formData.getFormProperties().isEmpty())) {
        return null;
    } else {
        HtmlElementWriter formElement = new HtmlElementWriter(FORM_ELEMENT).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE);
        HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement);
        // render fields
        for (FormField formField : formData.getFormFields()) {
            renderFormField(formField, documentBuilder);
        }
        // render deprecated form properties
        for (FormProperty formProperty : formData.getFormProperties()) {
            renderFormField(new FormPropertyAdapter(formProperty), documentBuilder);
        }
        // end document element
        documentBuilder.endElement();
        return documentBuilder.getHtmlString();
    }
}
Also used : FormProperty(org.camunda.bpm.engine.form.FormProperty) FormField(org.camunda.bpm.engine.form.FormField)

Example 10 with FormField

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

the class FormServiceTest method testGetTaskFormWithoutLabels.

@Deployment
@Test
public void testGetTaskFormWithoutLabels() {
    runtimeService.startProcessInstanceByKey("testProcess");
    Task task = taskService.createTaskQuery().singleResult();
    // form data can be retrieved
    TaskFormData formData = formService.getTaskFormData(task.getId());
    List<FormField> formFields = formData.getFormFields();
    assertEquals(3, formFields.size());
    List<String> formFieldIds = new ArrayList<String>();
    for (FormField field : formFields) {
        assertNull(field.getLabel());
        formFieldIds.add(field.getId());
    }
    assertTrue(formFieldIds.containsAll(Arrays.asList("stringField", "customField", "longField")));
    // the form can be rendered
    Object startForm = formService.getRenderedTaskForm(task.getId());
    assertNotNull(startForm);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ArrayList(java.util.ArrayList) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Test(org.junit.Test) 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