Search in sources :

Example 1 with HalResource

use of org.camunda.bpm.engine.rest.hal.HalResource 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 HalResource

use of org.camunda.bpm.engine.rest.hal.HalResource in project camunda-bpm-platform by camunda.

the class HalTenantResolver method resolveNotCachedLinks.

@Override
protected List<HalResource<?>> resolveNotCachedLinks(String[] linkedIds, ProcessEngine processEngine) {
    IdentityService identityService = processEngine.getIdentityService();
    List<Tenant> tenants = identityService.createTenantQuery().tenantIdIn(linkedIds).list();
    List<HalResource<?>> resolvedTenants = new ArrayList<HalResource<?>>();
    for (Tenant tenant : tenants) {
        resolvedTenants.add(HalTenant.fromTenant(tenant));
    }
    return resolvedTenants;
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Tenant(org.camunda.bpm.engine.identity.Tenant) ArrayList(java.util.ArrayList) HalResource(org.camunda.bpm.engine.rest.hal.HalResource)

Example 3 with HalResource

use of org.camunda.bpm.engine.rest.hal.HalResource in project camunda-bpm-platform by camunda.

the class HalUserList method fromUserList.

public static HalUserList fromUserList(List<User> users) {
    HalUserList result = new HalUserList();
    List<HalResource<?>> halUsers = new ArrayList<HalResource<?>>();
    for (User user : users) {
        halUsers.add(HalUser.fromUser(user));
    }
    // embedd the user list
    result.addEmbedded("users", halUsers);
    // self link
    result.addLink("self", UriBuilder.fromResource(UserRestService.class).build());
    return result;
}
Also used : User(org.camunda.bpm.engine.identity.User) ArrayList(java.util.ArrayList) HalResource(org.camunda.bpm.engine.rest.hal.HalResource)

Example 4 with HalResource

use of org.camunda.bpm.engine.rest.hal.HalResource in project camunda-bpm-platform by camunda.

the class HalUserResolver method resolveNotCachedLinks.

protected List<HalResource<?>> resolveNotCachedLinks(String[] linkedIds, ProcessEngine processEngine) {
    IdentityService identityService = processEngine.getIdentityService();
    List<User> users = identityService.createUserQuery().userIdIn(linkedIds).listPage(0, linkedIds.length);
    List<HalResource<?>> resolvedUsers = new ArrayList<HalResource<?>>();
    for (User user : users) {
        resolvedUsers.add(HalUser.fromUser(user));
    }
    return resolvedUsers;
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) User(org.camunda.bpm.engine.identity.User) ArrayList(java.util.ArrayList) HalResource(org.camunda.bpm.engine.rest.hal.HalResource)

Example 5 with HalResource

use of org.camunda.bpm.engine.rest.hal.HalResource 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

HalResource (org.camunda.bpm.engine.rest.hal.HalResource)11 ArrayList (java.util.ArrayList)9 IdentityService (org.camunda.bpm.engine.IdentityService)3 User (org.camunda.bpm.engine.identity.User)3 HashMap (java.util.HashMap)2 RepositoryService (org.camunda.bpm.engine.RepositoryService)2 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)2 HalLinkResolver (org.camunda.bpm.engine.rest.hal.HalLinkResolver)2 DefaultHalResourceCache (org.camunda.bpm.engine.rest.hal.cache.DefaultHalResourceCache)2 HalRelationCacheConfiguration (org.camunda.bpm.engine.rest.hal.cache.HalRelationCacheConfiguration)2 IdentityLink (org.camunda.bpm.engine.task.IdentityLink)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 TaskService (org.camunda.bpm.engine.TaskService)1 Group (org.camunda.bpm.engine.identity.Group)1 Tenant (org.camunda.bpm.engine.identity.Tenant)1 UserQuery (org.camunda.bpm.engine.identity.UserQuery)1 CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)1 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)1 Cache (org.camunda.bpm.engine.rest.cache.Cache)1