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;
}
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;
}
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;
}
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;
}
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]));
}
Aggregations