Search in sources :

Example 6 with StartFormData

use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.

the class ReportDetailPanel method initForm.

protected void initForm() {
    // Check if a start form is defined
    final ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    StartFormData startFormData = processEngine.getFormService().getStartFormData(processDefinition.getId());
    if (startFormData != null && ((startFormData.getFormProperties() != null && !startFormData.getFormProperties().isEmpty()) || startFormData.getFormKey() != null)) {
        processDefinitionStartForm = new FormPropertiesForm();
        detailContainer.addComponent(processDefinitionStartForm);
        processDefinitionStartForm.setFormProperties(startFormData.getFormProperties());
        processDefinitionStartForm.setSubmitButtonCaption(i18nManager.getMessage(Messages.REPORTING_GENERATE_REPORT));
        processDefinitionStartForm.hideCancelButton();
        processDefinitionStartForm.addListener(new FormPropertiesEventListener() {

            private static final long serialVersionUID = 1L;

            protected void handleFormSubmit(FormPropertiesEvent event) {
                // Report is generated by running a process and storing the dataset in the history tablkes
                savedFormProperties = event.getFormProperties();
                ProcessInstance processInstance = startProcessInstanceWithFormProperties(processDefinition.getId(), event.getFormProperties());
                generateReport(processInstance);
            }

            protected void handleFormCancel(FormPropertiesEvent event) {
            // Not needed, cancel button not shown in report panels
            }
        });
    } else {
        // Just start the process-instance since it has no form.
        ProcessInstance processInstance = startProcessInstance(processDefinition.getId());
        generateReport(processInstance);
    }
}
Also used : FormPropertiesEventListener(org.activiti.explorer.ui.form.FormPropertiesEventListener) StartFormData(org.activiti.engine.form.StartFormData) FormPropertiesForm(org.activiti.explorer.ui.form.FormPropertiesForm) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) FormPropertiesEvent(org.activiti.explorer.ui.form.FormPropertiesForm.FormPropertiesEvent) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 7 with StartFormData

use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.

the class StartProcessInstanceClickListener method buttonClick.

public void buttonClick(ClickEvent event) {
    // Check if process-definition defines a start-form
    StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
    if (startFormData != null && ((startFormData.getFormProperties() != null && !startFormData.getFormProperties().isEmpty()) || startFormData.getFormKey() != null)) {
        parentPage.showStartForm(processDefinition, startFormData);
    } else {
        // Just start the process-instance since it has no form.
        // TODO: Error handling
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
        // Show notification of success
        notificationManager.showInformationNotification(Messages.PROCESS_STARTED_NOTIFICATION, getProcessDisplayName(processDefinition));
        // Switch to inbox page in case a task of this process was created
        List<Task> loggedInUsersTasks = taskService.createTaskQuery().taskAssignee(ExplorerApp.get().getLoggedInUser().getId()).processInstanceId(processInstance.getId()).list();
        if (!loggedInUsersTasks.isEmpty()) {
            ExplorerApp.get().getViewManager().showInboxPage(loggedInUsersTasks.get(0).getId());
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) StartFormData(org.activiti.engine.form.StartFormData) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 8 with StartFormData

use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.

the class FormPropertyDefaultValueTest method testStartFormDefaultValue.

@Deployment
public void testStartFormDefaultValue() throws Exception {
    String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("FormPropertyDefaultValueTest.testDefaultValue").latestVersion().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(processDefinitionId);
    List<FormProperty> formProperties = startForm.getFormProperties();
    assertEquals(4, formProperties.size());
    for (FormProperty prop : formProperties) {
        if ("booleanProperty".equals(prop.getId())) {
            assertEquals("true", prop.getValue());
        } else if ("stringProperty".equals(prop.getId())) {
            assertEquals("someString", prop.getValue());
        } else if ("longProperty".equals(prop.getId())) {
            assertEquals("42", prop.getValue());
        } else if ("longExpressionProperty".equals(prop.getId())) {
            assertEquals("23", prop.getValue());
        } else {
            assertTrue("Invalid form property: " + prop.getId(), false);
        }
    }
    // Override 2 properties. The others should pe posted as the default-value
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    ProcessInstance processInstance = formService.submitStartFormData(processDefinitionId, formDataUpdate);
    assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
    assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
    assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
    assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) StartFormData(org.activiti.engine.form.StartFormData) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 9 with StartFormData

use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.

the class FormServiceTest method testTaskFormPropertyDefaultsAndFormRendering.

@Deployment(resources = { "org/activiti/engine/test/api/form/FormsProcess.bpmn20.xml", "org/activiti/engine/test/api/form/start.form", "org/activiti/engine/test/api/form/task.form" })
public void testTaskFormPropertyDefaultsAndFormRendering() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(procDefId);
    assertNotNull(startForm);
    assertEquals(deploymentIdFromDeploymentAnnotation, startForm.getDeploymentId());
    assertEquals("org/activiti/engine/test/api/form/start.form", startForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
    assertEquals(procDefId, startForm.getProcessDefinition().getId());
    Object renderedStartForm = formService.getRenderedStartForm(procDefId);
    assertEquals("start form content", renderedStartForm);
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("room", "5b");
    properties.put("speaker", "Mike");
    String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("speaker", "Mike");
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Task task = taskService.createTaskQuery().singleResult();
    String taskId = task.getId();
    TaskFormData taskForm = formService.getTaskFormData(taskId);
    assertEquals(deploymentIdFromDeploymentAnnotation, taskForm.getDeploymentId());
    assertEquals("org/activiti/engine/test/api/form/task.form", taskForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
    assertEquals(taskId, taskForm.getTask().getId());
    assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId));
    properties = new HashMap<String, String>();
    properties.put("room", "3f");
    formService.submitTaskFormData(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "3f");
    expectedVariables.put("speaker", "Mike");
    variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
}
Also used : Task(org.activiti.engine.task.Task) FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StartFormData(org.activiti.engine.form.StartFormData) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 10 with StartFormData

use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.

the class ProcessDefinitionPropertiesResource method getStartFormProperties.

@RequestMapping(value = "/process-definition/{processDefinitionId}/properties", method = RequestMethod.GET, produces = "application/json")
public ObjectNode getStartFormProperties(@PathVariable String processDefinitionId) {
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    ObjectNode responseJSON = objectMapper.createObjectNode();
    ArrayNode propertiesJSON = objectMapper.createArrayNode();
    if (startFormData != null) {
        List<FormProperty> properties = startFormData.getFormProperties();
        for (FormProperty property : properties) {
            ObjectNode propertyJSON = objectMapper.createObjectNode();
            propertyJSON.put("id", property.getId());
            propertyJSON.put("name", property.getName());
            if (property.getValue() != null) {
                propertyJSON.put("value", property.getValue());
            } else {
                propertyJSON.putNull("value");
            }
            if (property.getType() != null) {
                propertyJSON.put("type", property.getType().getName());
                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked") Map<String, String> valuesMap = (Map<String, String>) property.getType().getInformation("values");
                    if (valuesMap != null) {
                        ArrayNode valuesArray = objectMapper.createArrayNode();
                        propertyJSON.put("enumValues", valuesArray);
                        for (String key : valuesMap.keySet()) {
                            ObjectNode valueJSON = objectMapper.createObjectNode();
                            valueJSON.put("id", key);
                            valueJSON.put("name", valuesMap.get(key));
                            valuesArray.add(valueJSON);
                        }
                    }
                }
            } else {
                propertyJSON.put("type", "String");
            }
            propertyJSON.put("required", property.isRequired());
            propertyJSON.put("readable", property.isReadable());
            propertyJSON.put("writable", property.isWritable());
            propertiesJSON.add(propertyJSON);
        }
    }
    responseJSON.put("data", propertiesJSON);
    return responseJSON;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) EnumFormType(org.activiti.engine.impl.form.EnumFormType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StartFormData (org.activiti.engine.form.StartFormData)23 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)8 HashMap (java.util.HashMap)7 FormProperty (org.activiti.engine.form.FormProperty)7 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 Map (java.util.Map)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 QName (org.alfresco.service.namespace.QName)4 ArrayList (java.util.ArrayList)3 TaskFormData (org.activiti.engine.form.TaskFormData)3 ReadOnlyProcessDefinition (org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 Deployment (org.activiti.engine.test.Deployment)3 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)3 InvalidQNameException (org.alfresco.service.namespace.InvalidQNameException)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2