Search in sources :

Example 1 with TaskFormData

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

the class TaskDetailPanel method initTaskForm.

protected void initTaskForm() {
    // Check if task requires a form
    TaskFormData formData = formService.getTaskFormData(task.getId());
    if (formData != null && formData.getFormProperties() != null && !formData.getFormProperties().isEmpty()) {
        taskForm = new FormPropertiesForm();
        taskForm.setSubmitButtonCaption(i18nManager.getMessage(Messages.TASK_COMPLETE));
        taskForm.setCancelButtonCaption(i18nManager.getMessage(Messages.TASK_RESET_FORM));
        taskForm.setFormHelp(i18nManager.getMessage(Messages.TASK_FORM_HELP));
        taskForm.setFormProperties(formData.getFormProperties());
        taskForm.addListener(new FormPropertiesEventListener() {

            private static final long serialVersionUID = -3893467157397686736L;

            @Override
            protected void handleFormSubmit(FormPropertiesEvent event) {
                Map<String, String> properties = event.getFormProperties();
                formService.submitTaskFormData(task.getId(), properties);
                notificationManager.showInformationNotification(Messages.TASK_COMPLETED, task.getName());
                taskPage.refreshSelectNext();
            }

            @Override
            protected void handleFormCancel(FormPropertiesEvent event) {
                // Clear the form values 
                taskForm.clear();
            }
        });
        // Only if current user is task's assignee
        taskForm.setEnabled(isCurrentUserAssignee());
        // Add component to page
        centralLayout.addComponent(taskForm);
    } else {
        // Just add a button to complete the task
        // TODO: perhaps move to a better place
        CssLayout buttonLayout = new CssLayout();
        buttonLayout.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
        buttonLayout.setWidth(100, UNITS_PERCENTAGE);
        centralLayout.addComponent(buttonLayout);
        completeButton = new Button(i18nManager.getMessage(Messages.TASK_COMPLETE));
        completeButton.addListener(new ClickListener() {

            private static final long serialVersionUID = 1L;

            public void buttonClick(ClickEvent event) {
                // If no owner, make assignee owner (will go into archived then)
                if (task.getOwner() == null) {
                    task.setOwner(task.getAssignee());
                    taskService.setOwner(task.getId(), task.getAssignee());
                }
                taskService.complete(task.getId());
                notificationManager.showInformationNotification(Messages.TASK_COMPLETED, task.getName());
                taskPage.refreshSelectNext();
            }
        });
        completeButton.setEnabled(isCurrentUserAssignee() || isCurrentUserOwner());
        buttonLayout.addComponent(completeButton);
    }
}
Also used : CssLayout(com.vaadin.ui.CssLayout) FormPropertiesEventListener(org.activiti.explorer.ui.form.FormPropertiesEventListener) Button(com.vaadin.ui.Button) LayoutClickEvent(com.vaadin.event.LayoutEvents.LayoutClickEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) FormPropertiesForm(org.activiti.explorer.ui.form.FormPropertiesForm) TaskFormData(org.activiti.engine.form.TaskFormData) FormPropertiesEvent(org.activiti.explorer.ui.form.FormPropertiesForm.FormPropertiesEvent) Map(java.util.Map) ClickListener(com.vaadin.ui.Button.ClickListener) LayoutClickListener(com.vaadin.event.LayoutEvents.LayoutClickListener) ClaimTaskClickListener(org.activiti.explorer.ui.task.listener.ClaimTaskClickListener)

Example 2 with TaskFormData

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

the class RestResponseFactory method createFormDataResponse.

public FormDataResponse createFormDataResponse(FormData formData) {
    FormDataResponse result = new FormDataResponse();
    result.setDeploymentId(formData.getDeploymentId());
    result.setFormKey(formData.getFormKey());
    if (formData.getFormProperties() != null) {
        for (FormProperty formProp : formData.getFormProperties()) {
            RestFormProperty restFormProp = new RestFormProperty();
            restFormProp.setId(formProp.getId());
            restFormProp.setName(formProp.getName());
            if (formProp.getType() != null) {
                restFormProp.setType(formProp.getType().getName());
            }
            restFormProp.setValue(formProp.getValue());
            restFormProp.setReadable(formProp.isReadable());
            restFormProp.setRequired(formProp.isRequired());
            restFormProp.setWritable(formProp.isWritable());
            if ("enum".equals(restFormProp.getType())) {
                Object values = formProp.getType().getInformation("values");
                if (values != null) {
                    @SuppressWarnings("unchecked") Map<String, String> enumValues = (Map<String, String>) values;
                    for (String enumId : enumValues.keySet()) {
                        RestEnumFormProperty enumProperty = new RestEnumFormProperty();
                        enumProperty.setId(enumId);
                        enumProperty.setName(enumValues.get(enumId));
                        restFormProp.addEnumValue(enumProperty);
                    }
                }
            } else if ("date".equals(restFormProp.getType())) {
                restFormProp.setDatePattern((String) formProp.getType().getInformation("datePattern"));
            }
            result.addFormProperty(restFormProp);
        }
    }
    RestUrlBuilder urlBuilder = createUrlBuilder();
    if (formData instanceof StartFormData) {
        StartFormData startFormData = (StartFormData) formData;
        if (startFormData.getProcessDefinition() != null) {
            result.setProcessDefinitionId(startFormData.getProcessDefinition().getId());
            result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, startFormData.getProcessDefinition().getId()));
        }
    } else if (formData instanceof TaskFormData) {
        TaskFormData taskFormData = (TaskFormData) formData;
        if (taskFormData.getTask() != null) {
            result.setTaskId(taskFormData.getTask().getId());
            result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, taskFormData.getTask().getId()));
        }
    }
    return result;
}
Also used : RestEnumFormProperty(org.activiti.rest.service.api.form.RestEnumFormProperty) RestEnumFormProperty(org.activiti.rest.service.api.form.RestEnumFormProperty) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Map(java.util.Map) FormDataResponse(org.activiti.rest.service.api.form.FormDataResponse)

Example 3 with TaskFormData

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

the class FormPropertyDefaultValueTest method testDefaultValue.

@Deployment
public void testDefaultValue() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    TaskFormData formData = formService.getTaskFormData(task.getId());
    List<FormProperty> formProperties = formData.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);
        }
    }
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    formService.submitTaskFormData(task.getId(), 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 : Task(org.activiti.engine.task.Task) FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 4 with TaskFormData

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

the class FormServiceTest method testFormPropertyExpression.

@Deployment
public void testFormPropertyExpression() {
    Map<String, Object> varMap = new HashMap<String, Object>();
    // variable name mapping
    varMap.put("speaker", "Mike");
    Address address = new Address();
    varMap.put("address", address);
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, varMap);
    String taskId = taskService.createTaskQuery().singleResult().getId();
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    FormProperty propertySpeaker = formProperties.get(0);
    assertEquals("speaker", propertySpeaker.getId());
    assertEquals("Mike", propertySpeaker.getValue());
    assertEquals(2, formProperties.size());
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("street", "Broadway");
    formService.submitTaskFormData(taskId, properties);
    address = (Address) runtimeService.getVariable(processInstance.getId(), "address");
    assertEquals("Broadway", address.getStreet());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.activiti.engine.form.FormProperty) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 5 with TaskFormData

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

the class GetRenderedTaskFormCmd method execute.

public Object execute(CommandContext commandContext) {
    TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
    }
    if (task.getTaskDefinition() == null) {
        throw new ActivitiException("Task form definition for '" + taskId + "' not found");
    }
    TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler == null) {
        return null;
    }
    FormEngine formEngine = commandContext.getProcessEngineConfiguration().getFormEngines().get(formEngineName);
    if (formEngine == null) {
        throw new ActivitiException("No formEngine '" + formEngineName + "' defined process engine configuration");
    }
    TaskFormData taskForm = taskFormHandler.createTaskForm(task);
    return formEngine.renderTaskForm(taskForm);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) TaskFormHandler(org.activiti.engine.impl.form.TaskFormHandler) TaskFormData(org.activiti.engine.form.TaskFormData) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) FormEngine(org.activiti.engine.impl.form.FormEngine)

Aggregations

TaskFormData (org.activiti.engine.form.TaskFormData)7 FormProperty (org.activiti.engine.form.FormProperty)5 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 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)1 FormEngine (org.activiti.engine.impl.form.FormEngine)1 TaskFormHandler (org.activiti.engine.impl.form.TaskFormHandler)1