Search in sources :

Example 1 with TaskFormData

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

the class TaskRestServiceInteractionTest method setUpRuntimeData.

@Before
public void setUpRuntimeData() {
    taskServiceMock = mock(TaskService.class);
    when(processEngine.getTaskService()).thenReturn(taskServiceMock);
    mockTask = MockProvider.createMockTask();
    mockQuery = mock(TaskQuery.class);
    when(mockQuery.initializeFormKeys()).thenReturn(mockQuery);
    when(mockQuery.taskId(anyString())).thenReturn(mockQuery);
    when(mockQuery.singleResult()).thenReturn(mockTask);
    when(taskServiceMock.createTaskQuery()).thenReturn(mockQuery);
    List<IdentityLink> identityLinks = new ArrayList<IdentityLink>();
    mockAssigneeIdentityLink = MockProvider.createMockUserAssigneeIdentityLink();
    identityLinks.add(mockAssigneeIdentityLink);
    mockOwnerIdentityLink = MockProvider.createMockUserOwnerIdentityLink();
    identityLinks.add(mockOwnerIdentityLink);
    mockCandidateGroupIdentityLink = MockProvider.createMockCandidateGroupIdentityLink();
    identityLinks.add(mockCandidateGroupIdentityLink);
    mockCandidateGroup2IdentityLink = MockProvider.createAnotherMockCandidateGroupIdentityLink();
    identityLinks.add(mockCandidateGroup2IdentityLink);
    when(taskServiceMock.getIdentityLinksForTask(EXAMPLE_TASK_ID)).thenReturn(identityLinks);
    mockTaskComment = MockProvider.createMockTaskComment();
    when(taskServiceMock.getTaskComment(EXAMPLE_TASK_ID, EXAMPLE_TASK_COMMENT_ID)).thenReturn(mockTaskComment);
    mockTaskComments = MockProvider.createMockTaskComments();
    when(taskServiceMock.getTaskComments(EXAMPLE_TASK_ID)).thenReturn(mockTaskComments);
    when(taskServiceMock.createComment(EXAMPLE_TASK_ID, null, EXAMPLE_TASK_COMMENT_FULL_MESSAGE)).thenReturn(mockTaskComment);
    mockTaskAttachment = MockProvider.createMockTaskAttachment();
    when(taskServiceMock.getTaskAttachment(EXAMPLE_TASK_ID, EXAMPLE_TASK_ATTACHMENT_ID)).thenReturn(mockTaskAttachment);
    mockTaskAttachments = MockProvider.createMockTaskAttachments();
    when(taskServiceMock.getTaskAttachments(EXAMPLE_TASK_ID)).thenReturn(mockTaskAttachments);
    when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(mockTaskAttachment);
    when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), any(InputStream.class))).thenReturn(mockTaskAttachment);
    when(taskServiceMock.getTaskAttachmentContent(EXAMPLE_TASK_ID, EXAMPLE_TASK_ATTACHMENT_ID)).thenReturn(new ByteArrayInputStream(createMockByteData()));
    formServiceMock = mock(FormService.class);
    when(processEngine.getFormService()).thenReturn(formServiceMock);
    TaskFormData mockFormData = MockProvider.createMockTaskFormData();
    when(formServiceMock.getTaskFormData(anyString())).thenReturn(mockFormData);
    VariableMap variablesMock = MockProvider.createMockFormVariables();
    when(formServiceMock.getTaskFormVariables(eq(EXAMPLE_TASK_ID), Matchers.<Collection<String>>any(), anyBoolean())).thenReturn(variablesMock);
    repositoryServiceMock = mock(RepositoryService.class);
    when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
    ProcessDefinition mockDefinition = MockProvider.createMockDefinition();
    when(repositoryServiceMock.getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(mockDefinition);
    managementServiceMock = mock(ManagementService.class);
    when(processEngine.getManagementService()).thenReturn(managementServiceMock);
    when(managementServiceMock.getProcessApplicationForDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID)).thenReturn(MockProvider.EXAMPLE_PROCESS_APPLICATION_NAME);
    when(managementServiceMock.getHistoryLevel()).thenReturn(ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL);
    HistoryService historyServiceMock = mock(HistoryService.class);
    when(processEngine.getHistoryService()).thenReturn(historyServiceMock);
    historicTaskInstanceQueryMock = mock(HistoricTaskInstanceQuery.class);
    when(historyServiceMock.createHistoricTaskInstanceQuery()).thenReturn(historicTaskInstanceQueryMock);
    when(historicTaskInstanceQueryMock.taskId(eq(EXAMPLE_TASK_ID))).thenReturn(historicTaskInstanceQueryMock);
    HistoricTaskInstance historicTaskInstanceMock = createMockHistoricTaskInstance();
    when(historicTaskInstanceQueryMock.singleResult()).thenReturn(historicTaskInstanceMock);
    // replace the runtime container delegate & process application service with a mock
    ProcessApplicationService processApplicationService = mock(ProcessApplicationService.class);
    ProcessApplicationInfo appMock = MockProvider.createMockProcessApplicationInfo();
    when(processApplicationService.getProcessApplicationInfo(MockProvider.EXAMPLE_PROCESS_APPLICATION_NAME)).thenReturn(appMock);
    RuntimeContainerDelegate delegate = mock(RuntimeContainerDelegate.class);
    when(delegate.getProcessApplicationService()).thenReturn(processApplicationService);
    RuntimeContainerDelegate.INSTANCE.set(delegate);
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) MockProvider.createMockHistoricTaskInstance(org.camunda.bpm.engine.rest.helper.MockProvider.createMockHistoricTaskInstance) TaskService(org.camunda.bpm.engine.TaskService) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProcessApplicationService(org.camunda.bpm.ProcessApplicationService) FormService(org.camunda.bpm.engine.FormService) ArrayList(java.util.ArrayList) HistoryService(org.camunda.bpm.engine.HistoryService) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) ManagementService(org.camunda.bpm.engine.ManagementService) ByteArrayInputStream(java.io.ByteArrayInputStream) VariableMap(org.camunda.bpm.engine.variable.VariableMap) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessApplicationInfo(org.camunda.bpm.application.ProcessApplicationInfo) RuntimeContainerDelegate(org.camunda.bpm.container.RuntimeContainerDelegate) RepositoryService(org.camunda.bpm.engine.RepositoryService) Before(org.junit.Before)

Example 2 with TaskFormData

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

the class GetRenderedTaskFormCmd method execute.

public Object execute(CommandContext commandContext) {
    TaskManager taskManager = commandContext.getTaskManager();
    TaskEntity task = taskManager.findTaskById(taskId);
    ensureNotNull("Task '" + taskId + "' not found", "task", task);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadTask(task);
    }
    ensureNotNull("Task form definition for '" + taskId + "' not found", "task.getTaskDefinition()", task.getTaskDefinition());
    TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler == null) {
        return null;
    }
    FormEngine formEngine = Context.getProcessEngineConfiguration().getFormEngines().get(formEngineName);
    ensureNotNull("No formEngine '" + formEngineName + "' defined process engine configuration", "formEngine", formEngine);
    TaskFormData taskForm = taskFormHandler.createTaskForm(task);
    return formEngine.renderTaskForm(taskForm);
}
Also used : TaskManager(org.camunda.bpm.engine.impl.persistence.entity.TaskManager) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) TaskFormHandler(org.camunda.bpm.engine.impl.form.handler.TaskFormHandler) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) FormEngine(org.camunda.bpm.engine.impl.form.engine.FormEngine)

Example 3 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData 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 4 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData 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 5 with TaskFormData

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

the class FormAuthorizationTest method testCaseTaskGetTaskFormData.

// get task form data (case task) /////////////////////////////////
public void testCaseTaskGetTaskFormData() {
    // given
    createCaseInstanceByKey(CASE_KEY);
    String taskId = selectSingleTask().getId();
    // when
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    // then
    assertNotNull(taskFormData);
}
Also used : TaskFormData(org.camunda.bpm.engine.form.TaskFormData)

Aggregations

TaskFormData (org.camunda.bpm.engine.form.TaskFormData)26 Task (org.camunda.bpm.engine.task.Task)10 Deployment (org.camunda.bpm.engine.test.Deployment)10 Test (org.junit.Test)9 FormField (org.camunda.bpm.engine.form.FormField)8 FormProperty (org.camunda.bpm.engine.form.FormProperty)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)4 LinkedHashMap (java.util.LinkedHashMap)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 FormType (org.camunda.bpm.engine.form.FormType)2 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)2 TaskManager (org.camunda.bpm.engine.impl.persistence.entity.TaskManager)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 ProcessApplicationService (org.camunda.bpm.ProcessApplicationService)1