Search in sources :

Example 41 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class ResourceMetaParitition method discoverElements.

@Override
public void discoverElements() {
    ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
    // enforce setup of meta data
    Collection<RegistryEntry> entries = resourceRegistry.getResources();
    for (RegistryEntry entry : entries) {
        ResourceInformation resourceInformation = entry.getResourceInformation();
        MetaResource metaResource = discoverResource(resourceInformation);
        ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
        ResourceRepositoryAdapter<?, Serializable> resourceRepository = entry.getResourceRepository();
        if (resourceRepository != null) {
            MetaResourceRepository repository = discoverRepository(repositoryInformation, metaResource, resourceRepository);
            context.addElement(repository);
        }
    }
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Serializable(java.io.Serializable) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 42 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class ConstraintViolationImplTest method setup.

@Before
public void setup() {
    boot = new CrnkBoot();
    boot.addModule(ValidationModule.create());
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.validation.mock.repository"));
    boot.boot();
    errorData = Mockito.spy(new ErrorDataBuilder().setDetail("testMessage").addMetaField(ConstraintViolationExceptionMapper.META_RESOURCE_TYPE, "tasks").setSourcePointer("name").build());
    ResourceRegistry resourceRegistry = boot.getResourceRegistry();
    violation = ConstraintViolationImpl.fromError(resourceRegistry, errorData);
}
Also used : ErrorDataBuilder(io.crnk.core.engine.document.ErrorDataBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) Before(org.junit.Before)

Example 43 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class ConstraintViolationExceptionMapper method getResourceId.

/**
 * @param resource to get the id from
 * @return id of the given resource
 */
protected String getResourceId(Object resource) {
    ResourceRegistry resourceRegistry = context.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
    ResourceInformation resourceInformation = entry.getResourceInformation();
    ResourceField idField = resourceInformation.getIdField();
    Object id = idField.getAccessor().getValue(resource);
    if (id != null) {
        return id.toString();
    }
    return null;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 44 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class OffsetLimitPagingBehaviorTest method testBuild.

@Test
public void testBuild() {
    PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
    OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QuerySpec spec = new QuerySpec(Task.class);
    QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
    querySpecAdapter.setPagingSpec(pagingSpec);
    PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
    when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
    DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
    pagedMetaInformation.setTotalResourceCount(30L);
    ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
    for (int i = 0; i < 30; i++) {
        resourceList.add(new Task());
    }
    PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
    pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
    assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
    assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
    assertNull(pagedLinksInformation.getPrev());
    assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 45 with ResourceRegistry

use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.

the class ResourceFilterDirectoryImplTest method setup.

@Before
public void setup() {
    requestContextProvider = new HttpRequestContextProvider();
    filter = Mockito.mock(ResourceFilter.class);
    filters.add(filter);
    resourceInformation = Mockito.mock(ResourceInformation.class);
    resourceField = Mockito.mock(ResourceField.class);
    resourceRegistry = Mockito.mock(ResourceRegistry.class);
    directory = new ResourceFilterDirectoryImpl(filters, requestContextProvider, resourceRegistry);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFilter(io.crnk.core.engine.filter.ResourceFilter) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider) Before(org.junit.Before)

Aggregations

ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)48 Test (org.junit.Test)25 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)21 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)19 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)17 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)15 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)10 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)4 ModuleRegistry (io.crnk.core.module.ModuleRegistry)4 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)4 Before (org.junit.Before)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FieldResourceGet (io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet)3 RelationshipsResourceGet (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet)3 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)3 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)2