use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.
the class ResourceListTest method testListConstructor.
@Test
public void testListConstructor() {
LinkedList<Task> linkedList = new LinkedList<Task>();
DefaultResourceList<Task> list = new DefaultResourceList<Task>(linkedList, new TestMeta(), new TestLinks());
Assert.assertNotNull(list.getMeta());
Assert.assertNotNull(list.getLinks());
list.add(new Task());
Assert.assertEquals(1, list.size());
Assert.assertEquals(1, linkedList.size());
}
use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findManyTargets.
@Override
public ResourceList<Project> findManyTargets(ObjectId objectId, String fieldName, QuerySpec requestParams) {
Task task = taskRepository.findOne(objectId, requestParams);
try {
DefaultResourceList<Project> result = new DefaultResourceList<>();
result.addAll((Collection<Project>) PropertyUtils.getProperty(task, fieldName));
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.
the class HistoryRelationshipRepository method findManyTargets.
@Override
public ResourceList<History> findManyTargets(Serializable sourceId, String fieldName, QuerySpec querySpec) {
DefaultResourceList list = new DefaultResourceList();
for (int i = 0; i < 10; i++) {
History history = new History();
history.setId(UUID.nameUUIDFromBytes(("historyElement" + i).getBytes()));
history.setName("historyElement" + i);
list.add(history);
}
return list;
}
use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findManyTargets.
@Override
public ResourceList<Project> findManyTargets(Long sourceId, String fieldName, QuerySpec queryParams) {
DefaultResourceList<Project> projects = new DefaultResourceList<>();
for (Relation<Task> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
project.setId((Long) relation.getTargetId());
projects.add(project);
}
}
return projects;
}
use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.
the class ClientStubInvocationHandler method invokeInterfaceMethod.
private Object invokeInterfaceMethod(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException {
Method stubMethod = interfaceStubMethodMap.get(method);
Object result = stubMethod.invoke(repositoryStub, args);
Class<?> returnType = method.getReturnType();
if (result == null || returnType.isInstance(result)) {
return result;
} else if (result instanceof DefaultResourceList) {
return createTypesafeList(result, returnType);
} else {
throw new IllegalStateException("cannot cast return type " + result + " to " + returnType.getName());
}
}
Aggregations