Search in sources :

Example 1 with ResourceRepositoryInformation

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

the class CrnkClient method allocateRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <T, I extends Serializable> RegistryEntry allocateRepository(Class<T> resourceClass) {
    ResourceInformationProvider resourceInformationProvider = moduleRegistry.getResourceInformationBuilder();
    ResourceInformation resourceInformation = resourceInformationProvider.build(resourceClass);
    final ResourceRepositoryStub<T, I> repositoryStub = new ResourceRepositoryStubImpl<>(this, resourceClass, resourceInformation, urlBuilder);
    // create interface for it!
    RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, null) {

        @Override
        public Object buildRepository() {
            return repositoryStub;
        }
    };
    ResourceRepositoryInformation repositoryInformation = new ResourceRepositoryInformationImpl(resourceInformation.getResourceType(), resourceInformation, RepositoryMethodAccess.ALL);
    ResourceEntry resourceEntry = new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
    Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = new HashMap<>();
    RegistryEntry registryEntry = new RegistryEntry(resourceEntry, relationshipEntries);
    registryEntry.initialize(moduleRegistry);
    resourceRegistry.addEntry(resourceClass, registryEntry);
    allocateRepositoryRelations(registryEntry);
    return registryEntry;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryStubImpl(io.crnk.client.internal.ResourceRepositoryStubImpl) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder)

Example 2 with ResourceRepositoryInformation

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

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

the class DefaultRegistryEntryBuilder method fromImplementation.

@Override
public void fromImplementation(Object repository) {
    RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    RepositoryInformationProviderContext builderContext = new DefaultRepositoryInformationProviderContext(moduleRegistry);
    ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) repositoryInformationBuilder.build(repository, builderContext);
    ResourceInformation resourceInformation = repositoryInformation.getResourceInformation().get();
    resource().from(resourceInformation);
    resourceRepository().information().from(repositoryInformation);
    resourceRepository().instance(repository);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProviderContext(io.crnk.core.engine.information.repository.RepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider)

Example 4 with ResourceRepositoryInformation

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

the class ModuleRegistryTest method buildResourceRepositoryInformationFromInstance.

@Test
public void buildResourceRepositoryInformationFromInstance() {
    RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
    ResourceRepositoryInformation info = (ResourceRepositoryInformation) builder.build(new TaskRepository(), newRepositoryInformationBuilderContext());
    Assert.assertEquals(Task.class, info.getResourceInformation().get().getResourceClass());
    Assert.assertEquals("tasks", info.getPath());
}
Also used : ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) Test(org.junit.Test)

Example 5 with ResourceRepositoryInformation

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

the class ModuleRegistryTest method buildResourceRepositoryInformationFromClass.

@Test
public void buildResourceRepositoryInformationFromClass() {
    RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
    ResourceRepositoryInformation info = (ResourceRepositoryInformation) builder.build(TaskRepository.class, newRepositoryInformationBuilderContext());
    Assert.assertEquals(Task.class, info.getResourceInformation().get().getResourceClass());
    Assert.assertEquals("tasks", info.getPath());
}
Also used : ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) Test(org.junit.Test)

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