Search in sources :

Example 6 with TaskFormData

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

the class FormServiceTest method testFormPropertyHandling.

@Deployment
public void testFormPropertyHandling() {
    Map<String, String> properties = new HashMap<String, String>();
    // default
    properties.put("room", "5b");
    // variable name mapping
    properties.put("speaker", "Mike");
    // type conversion
    properties.put("duration", "45");
    // type conversion
    properties.put("free", "true");
    // type conversion
    properties.put("double", "45.5");
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", 45l);
    expectedVariables.put("free", Boolean.TRUE);
    expectedVariables.put("double", 45.5d);
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Address address = new Address();
    address.setStreet("broadway");
    runtimeService.setVariable(processInstanceId, "address", address);
    runtimeService.signal(runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult().getId());
    String taskId = taskService.createTaskQuery().singleResult().getId();
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    FormProperty propertyRoom = formProperties.get(0);
    assertEquals("room", propertyRoom.getId());
    assertEquals("5b", propertyRoom.getValue());
    FormProperty propertyDuration = formProperties.get(1);
    assertEquals("duration", propertyDuration.getId());
    assertEquals("45", propertyDuration.getValue());
    FormProperty propertySpeaker = formProperties.get(2);
    assertEquals("speaker", propertySpeaker.getId());
    assertEquals("Mike", propertySpeaker.getValue());
    FormProperty propertyStreet = formProperties.get(3);
    assertEquals("street", propertyStreet.getId());
    assertEquals("broadway", propertyStreet.getValue());
    FormProperty propertyFree = formProperties.get(4);
    assertEquals("free", propertyFree.getId());
    assertEquals("true", propertyFree.getValue());
    FormProperty propertyDouble = formProperties.get(5);
    assertEquals("double", propertyDouble.getId());
    assertEquals("45.5", propertyDouble.getValue());
    assertEquals(6, formProperties.size());
    try {
        formService.submitTaskFormData(taskId, new HashMap<String, String>());
        fail("expected exception about required form property 'street'");
    } catch (ActivitiException e) {
    // OK
    }
    try {
        properties = new HashMap<String, String>();
        properties.put("speaker", "its not allowed to update speaker!");
        formService.submitTaskFormData(taskId, properties);
        fail("expected exception about a non writable form property 'speaker'");
    } catch (ActivitiException e) {
    // OK
    }
    properties = new HashMap<String, String>();
    properties.put("street", "rubensstraat");
    formService.submitTaskFormData(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", 45l);
    expectedVariables.put("free", Boolean.TRUE);
    expectedVariables.put("double", 45.5d);
    variables = runtimeService.getVariables(processInstanceId);
    address = (Address) variables.remove("address");
    assertEquals("rubensstraat", address.getStreet());
    assertEquals(expectedVariables, variables);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.activiti.engine.form.FormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 7 with TaskFormData

use of org.activiti.engine.form.TaskFormData 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 8 with TaskFormData

use of org.activiti.engine.form.TaskFormData in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method toResource.

private WorkflowTaskInstanceDto toResource(Task task) {
    if (task == null) {
        return null;
    }
    WorkflowTaskInstanceDto dto = new WorkflowTaskInstanceDto();
    dto.setId(task.getId());
    dto.setCreated(task.getCreateTime());
    dto.setFormKey(task.getFormKey());
    dto.setAssignee(task.getAssignee());
    dto.setName(task.getName());
    dto.setDescription(task.getDescription());
    dto.setProcessInstanceId(task.getProcessInstanceId());
    Map<String, Object> taksVariables = task.getTaskLocalVariables();
    Map<String, Object> processVariables = task.getProcessVariables();
    // Add applicant username to task dto (for easier work)
    if (processVariables != null && processVariables.containsKey(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER)) {
        dto.setApplicant((String) processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
    }
    dto.setVariables(processVariables);
    convertToDtoVariables(dto, taksVariables);
    dto.setDefinition(workflowTaskDefinitionService.searchTaskDefinitionById(task.getProcessDefinitionId(), task.getTaskDefinitionKey()));
    if (!Strings.isNullOrEmpty(task.getProcessDefinitionId())) {
        WorkflowProcessDefinitionDto processDefinition = workflowProcessDefinitionService.get(task.getProcessDefinitionId());
        if (processDefinition != null) {
            dto.setProcessDefinitionKey(processDefinition.getKey());
        }
    }
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    // Add form data (it means form properties and value from WF)
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    // Search and add identity links to dto (It means all user
    // (assigned/candidates/group) for this task)
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    if (identityLinks != null) {
        List<IdentityLinkDto> identityLinksDtos = new ArrayList<>();
        for (IdentityLink il : identityLinks) {
            identityLinksDtos.add(toResource(il));
        }
        dto.getIdentityLinks().addAll(identityLinksDtos);
    }
    // Check if the logged user can complete this task
    boolean canExecute = this.canExecute(dto);
    if (formProperties != null && !formProperties.isEmpty()) {
        for (FormProperty property : formProperties) {
            resovleFormProperty(property, dto, canExecute);
        }
    }
    return dto;
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ArrayList(java.util.ArrayList) TaskFormData(org.activiti.engine.form.TaskFormData) IdentityLink(org.activiti.engine.task.IdentityLink) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)

Aggregations

TaskFormData (org.activiti.engine.form.TaskFormData)8 FormProperty (org.activiti.engine.form.FormProperty)6 HashMap (java.util.HashMap)4 Deployment (org.activiti.engine.test.Deployment)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)2 ActivitiException (org.activiti.engine.ActivitiException)2 StartFormData (org.activiti.engine.form.StartFormData)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 LayoutClickEvent (com.vaadin.event.LayoutEvents.LayoutClickEvent)1 LayoutClickListener (com.vaadin.event.LayoutEvents.LayoutClickListener)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 CssLayout (com.vaadin.ui.CssLayout)1 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)1 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)1 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)1 ArrayList (java.util.ArrayList)1