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;
}
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);
}
}
}
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);
}
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());
}
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());
}
Aggregations