Search in sources :

Example 1 with RepositoryDecoratorFactory

use of io.crnk.core.repository.decorate.RepositoryDecoratorFactory in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method decorateRepository.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object decorateRepository(Object repository) {
    Object decoratedRepository = repository;
    List<RepositoryDecoratorFactory> repositoryDecorators = moduleRegistry.getRepositoryDecoratorFactories();
    for (RepositoryDecoratorFactory repositoryDecorator : repositoryDecorators) {
        Decorator decorator = null;
        if (decoratedRepository instanceof RelationshipRepositoryV2) {
            decorator = repositoryDecorator.decorateRepository((RelationshipRepositoryV2) decoratedRepository);
        } else if (decoratedRepository instanceof ResourceRepositoryV2) {
            decorator = repositoryDecorator.decorateRepository((ResourceRepositoryV2) decoratedRepository);
        }
        if (decorator != null) {
            decorator.setDecoratedObject(decoratedRepository);
            decoratedRepository = decorator;
        }
    }
    return decoratedRepository;
}
Also used : Decorator(io.crnk.core.engine.internal.utils.Decorator) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) RepositoryDecoratorFactory(io.crnk.core.repository.decorate.RepositoryDecoratorFactory) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2)

Example 2 with RepositoryDecoratorFactory

use of io.crnk.core.repository.decorate.RepositoryDecoratorFactory in project crnk-framework by crnk-project.

the class ModuleRegistryTest method testDecorators.

@Test
public void testDecorators() throws Exception {
    List<RepositoryDecoratorFactory> decorators = moduleRegistry.getRepositoryDecoratorFactories();
    Assert.assertEquals(2, decorators.size());
    RegistryEntry entry = this.resourceRegistry.getEntry(Schedule.class);
    Object resourceRepository = entry.getResourceRepository(null).getResourceRepository();
    Assert.assertNotNull(resourceRepository);
    Assert.assertTrue(resourceRepository instanceof ScheduleRepository);
    Assert.assertTrue(resourceRepository instanceof DecoratedScheduleRepository);
}
Also used : DecoratedScheduleRepository(io.crnk.core.engine.internal.dispatcher.filter.TestRepositoryDecorator.DecoratedScheduleRepository) DecoratedScheduleRepository(io.crnk.core.engine.internal.dispatcher.filter.TestRepositoryDecorator.DecoratedScheduleRepository) RepositoryDecoratorFactory(io.crnk.core.repository.decorate.RepositoryDecoratorFactory) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Aggregations

RepositoryDecoratorFactory (io.crnk.core.repository.decorate.RepositoryDecoratorFactory)2 DecoratedScheduleRepository (io.crnk.core.engine.internal.dispatcher.filter.TestRepositoryDecorator.DecoratedScheduleRepository)1 Decorator (io.crnk.core.engine.internal.utils.Decorator)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 RelationshipRepositoryV2 (io.crnk.core.repository.RelationshipRepositoryV2)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 Test (org.junit.Test)1