Search in sources :

Example 6 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method buildResourceRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ResourceEntry buildResourceRepository(ResourceInformation resourceInformation) {
    resourceRepository.information().setResourceInformation(resourceInformation);
    ResourceRepositoryInformation repositoryInformation = resourceRepository.information().build();
    Object instance = resourceRepository.instance;
    final Object decoratedRepository = decorateRepository(instance);
    RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, instance.getClass()) {

        @Override
        public Object buildRepository() {
            return decoratedRepository;
        }
    };
    if (ClassUtils.getAnnotation(decoratedRepository.getClass(), JsonApiResourceRepository.class).isPresent()) {
        return new AnnotatedResourceEntry(repositoryInstanceBuilder, repositoryInformation);
    } else {
        return new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
    }
}
Also used : AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder)

Example 7 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.

@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
    // GIVEN
    ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
    ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
    Map relRepos = new HashMap<>();
    relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
    RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
    // THEN
    expectedException.expect(ResourceFieldNotFoundException.class);
    // WHEN
    sut.getRelationshipRepository("users", null);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) HashMap(java.util.HashMap) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) HashMap(java.util.HashMap) Map(java.util.Map) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 8 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class JaxrsModuleTest method testActionDetection.

@Test
public void testActionDetection() {
    ResourceRepositoryInformation information = (ResourceRepositoryInformation) builder.build(TaskRepository.class, context);
    Map<String, RepositoryAction> actions = information.getActions();
    Assert.assertEquals(5, actions.size());
    RepositoryAction action = actions.get("repositoryAction");
    Assert.assertNotNull(actions.get("repositoryPostAction"));
    Assert.assertNotNull(actions.get("repositoryDeleteAction"));
    Assert.assertNotNull(actions.get("repositoryPutAction"));
    Assert.assertNull(actions.get("notAnAction"));
    Assert.assertNotNull(action);
    Assert.assertEquals("repositoryAction", action.getName());
    Assert.assertEquals(RepositoryActionType.REPOSITORY, action.getActionType());
    Assert.assertEquals(RepositoryActionType.RESOURCE, actions.get("resourceAction").getActionType());
}
Also used : ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryAction(io.crnk.core.engine.information.repository.RepositoryAction) Test(org.junit.Test)

Example 9 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation in project crnk-framework by crnk-project.

the class PathBuilderTest method prepare.

@Before
public void prepare() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.boot();
    pathBuilder = new PathBuilder(boot.getResourceRegistry());
    RegistryEntry entry = boot.getResourceRegistry().findEntry(Task.class);
    ResourceRepositoryInformation repositoryInformation = entry.getRepositoryInformation();
    repositoryInformation.getActions().put("someRepositoryAction", Mockito.mock(RepositoryAction.class));
    repositoryInformation.getActions().put("someResourceAction", Mockito.mock(RepositoryAction.class));
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) RepositoryAction(io.crnk.core.engine.information.repository.RepositoryAction) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Before(org.junit.Before)

Example 10 with ResourceRepositoryInformation

use of io.crnk.core.engine.information.repository.ResourceRepositoryInformation 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)

Aggregations

ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)12 Test (org.junit.Test)5 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)3 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)3 Serializable (java.io.Serializable)3 RepositoryAction (io.crnk.core.engine.information.repository.RepositoryAction)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)2 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)2 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)2 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)2 ClientStubInvocationHandler (io.crnk.client.internal.ClientStubInvocationHandler)1 ResourceRepositoryStubImpl (io.crnk.client.internal.ResourceRepositoryStubImpl)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 RepositoryInformationProviderContext (io.crnk.core.engine.information.repository.RepositoryInformationProviderContext)1 RepositoryMethodAccess (io.crnk.core.engine.information.repository.RepositoryMethodAccess)1 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)1