Search in sources :

Example 1 with ResourceRegistry

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

the class CrnkFeature method registerActionRepositories.

/**
 * All repositories with JAX-RS action need to be registered with JAX-RS as singletons.
 *
 * @param context of jaxrs
 * @param boot of crnk
 */
private void registerActionRepositories(FeatureContext context, CrnkBoot boot) {
    ResourceRegistry resourceRegistry = boot.getResourceRegistry();
    Collection<RegistryEntry> registryEntries = resourceRegistry.getResources();
    for (RegistryEntry registryEntry : registryEntries) {
        ResourceRepositoryInformation repositoryInformation = registryEntry.getRepositoryInformation();
        if (repositoryInformation != null && !repositoryInformation.getActions().isEmpty()) {
            ResourceRepositoryAdapter<?, Serializable> repositoryAdapter = registryEntry.getResourceRepository(null);
            Object resourceRepository = repositoryAdapter.getResourceRepository();
            context.register(resourceRepository);
        }
    }
}
Also used : 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 2 with ResourceRegistry

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

the class SecurityModule method toType.

private <T> String toType(Class<T> resourceClass) {
    ResourceRegistry resourceRegistry = context.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntryForClass(resourceClass);
    if (entry == null) {
        throw new ResourceNotFoundException("resource type not found: " + resourceClass.getName());
    }
    ResourceInformation resourceInformation = entry.getResourceInformation();
    return resourceInformation.getResourceType();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 3 with ResourceRegistry

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

the class FieldResourcePostTest method onNonRelationRequestShouldDenyIt.

@Test
public void onNonRelationRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourcePost sut = new FieldResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) FieldResourcePost(io.crnk.core.engine.internal.dispatcher.controller.FieldResourcePost) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 4 with ResourceRegistry

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

the class FieldResourcePostTest method onValidRequestShouldAcceptIt.

@Test
public void onValidRequestShouldAcceptIt() {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("tasks/1/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourcePost sut = new FieldResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isTrue();
}
Also used : ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) FieldResourcePost(io.crnk.core.engine.internal.dispatcher.controller.FieldResourcePost) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 5 with ResourceRegistry

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

the class RelationshipsResourceGetTest method onValidRequestShouldAcceptIt.

@Test
public void onValidRequestShouldAcceptIt() {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("tasks/1/relationships/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    RelationshipsResourceGet sut = new RelationshipsResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isTrue();
}
Also used : RelationshipsResourceGet(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

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