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