Search in sources :

Example 1 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class HalIdentityLinkResolver method resolveNotCachedLinks.

protected List<HalResource<?>> resolveNotCachedLinks(String[] linkedIds, ProcessEngine processEngine) {
    TaskService taskService = processEngine.getTaskService();
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(linkedIds[0]);
    List<HalResource<?>> resolvedIdentityLinks = new ArrayList<HalResource<?>>();
    for (IdentityLink identityLink : identityLinks) {
        resolvedIdentityLinks.add(HalIdentityLink.fromIdentityLink(identityLink));
    }
    return resolvedIdentityLinks;
}
Also used : TaskService(org.camunda.bpm.engine.TaskService) ArrayList(java.util.ArrayList) HalResource(org.camunda.bpm.engine.rest.hal.HalResource) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 2 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink 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 3 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class MockProvider method createAnotherMockCandidateGroupIdentityLink.

public static IdentityLink createAnotherMockCandidateGroupIdentityLink() {
    IdentityLink identityLink = mock(IdentityLink.class);
    when(identityLink.getTaskId()).thenReturn(EXAMPLE_TASK_ID);
    when(identityLink.getType()).thenReturn(IdentityLinkType.CANDIDATE);
    when(identityLink.getGroupId()).thenReturn(EXAMPLE_GROUP_ID2);
    return identityLink;
}
Also used : IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 4 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method getIdentityLinks.

@Override
public List<IdentityLinkDto> getIdentityLinks(String type) {
    TaskService taskService = engine.getTaskService();
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
    List<IdentityLinkDto> result = new ArrayList<IdentityLinkDto>();
    for (IdentityLink link : identityLinks) {
        if (type == null || type.equals(link.getType())) {
            result.add(IdentityLinkDto.fromIdentityLink(link));
        }
    }
    return result;
}
Also used : TaskService(org.camunda.bpm.engine.TaskService) IdentityLinkDto(org.camunda.bpm.engine.rest.dto.task.IdentityLinkDto) ArrayList(java.util.ArrayList) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Example 5 with IdentityLink

use of org.camunda.bpm.engine.task.IdentityLink in project camunda-bpm-platform by camunda.

the class HalResourceCacheTest method testIdentityLinkCaching.

@Test
public void testIdentityLinkCaching() {
    String[] taskIds = new String[] { "test" };
    // mock identityLinks and query
    IdentityLink link1 = mock(IdentityLink.class);
    when(link1.getTaskId()).thenReturn(taskIds[0]);
    IdentityLink link2 = mock(IdentityLink.class);
    when(link2.getTaskId()).thenReturn(taskIds[0]);
    when(processEngine.getTaskService().getIdentityLinksForTask(anyString())).thenReturn(Arrays.asList(link1, link2));
    // configure cache
    HalRelationCacheConfiguration configuration = new HalRelationCacheConfiguration();
    configuration.setCacheImplementationClass(DefaultHalResourceCache.class);
    Map<String, Object> halIdentityLinkConfig = new HashMap<String, Object>();
    halIdentityLinkConfig.put("capacity", 100);
    halIdentityLinkConfig.put("secondsToLive", 10000);
    configuration.addCacheConfiguration(HalIdentityLink.class, halIdentityLinkConfig);
    contextListener.configureCaches(configuration);
    // cache exists and is empty
    DefaultHalResourceCache cache = (DefaultHalResourceCache) Hal.getInstance().getHalRelationCache(HalIdentityLink.class);
    assertNotNull(cache);
    assertEquals(0, cache.size());
    // get link resolver and resolve identity link
    HalLinkResolver linkResolver = Hal.getInstance().getLinkResolver(IdentityRestService.class);
    List<HalResource<?>> halIdentityLinks = linkResolver.resolveLinks(taskIds, processEngine);
    assertEquals(2, halIdentityLinks.size());
    assertEquals(1, cache.size());
    assertEquals(halIdentityLinks, cache.get(taskIds[0]));
}
Also used : HalIdentityLink(org.camunda.bpm.engine.rest.hal.identitylink.HalIdentityLink) DefaultHalResourceCache(org.camunda.bpm.engine.rest.hal.cache.DefaultHalResourceCache) HashMap(java.util.HashMap) HalLinkResolver(org.camunda.bpm.engine.rest.hal.HalLinkResolver) HalResource(org.camunda.bpm.engine.rest.hal.HalResource) Matchers.anyString(org.mockito.Matchers.anyString) HalRelationCacheConfiguration(org.camunda.bpm.engine.rest.hal.cache.HalRelationCacheConfiguration) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) HalIdentityLink(org.camunda.bpm.engine.rest.hal.identitylink.HalIdentityLink) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Aggregations

IdentityLink (org.camunda.bpm.engine.task.IdentityLink)81 Task (org.camunda.bpm.engine.task.Task)13 Deployment (org.camunda.bpm.engine.test.Deployment)13 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)7 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 Expression (org.camunda.bpm.engine.delegate.Expression)4 HistoricIdentityLinkLog (org.camunda.bpm.engine.history.HistoricIdentityLinkLog)4 DeploymentBuilder (org.camunda.bpm.engine.repository.DeploymentBuilder)4 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 TaskService (org.camunda.bpm.engine.TaskService)3 HistoricIdentityLinkLogQuery (org.camunda.bpm.engine.history.HistoricIdentityLinkLogQuery)3 List (java.util.List)2 HalResource (org.camunda.bpm.engine.rest.hal.HalResource)2 Job (org.camunda.bpm.engine.runtime.Job)2 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)2 Matchers.anyString (org.mockito.Matchers.anyString)2