Search in sources :

Example 16 with DefaultResourceList

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());
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 17 with DefaultResourceList

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);
    }
}
Also used : Project(io.crnk.example.dropwizard.mongo.domain.model.Project) Task(io.crnk.example.dropwizard.mongo.domain.model.Task) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList)

Example 18 with DefaultResourceList

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;
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) History(io.crnk.example.springboot.domain.model.History)

Example 19 with DefaultResourceList

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;
}
Also used : Project(io.crnk.test.mock.models.Project) Task(io.crnk.test.mock.models.Task) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList)

Example 20 with DefaultResourceList

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());
    }
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) Method(java.lang.reflect.Method)

Aggregations

DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)26 Task (io.crnk.core.mock.models.Task)7 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)4 DefaultHasMoreResourcesMetaInformation (io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Test (org.junit.Test)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)3 ResourceList (io.crnk.core.resource.list.ResourceList)3 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)2 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)2 Resource (io.crnk.core.engine.document.Resource)2 ModuleRegistry (io.crnk.core.module.ModuleRegistry)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2