Search in sources :

Example 1 with AnnotatedRelationshipEntryBuilder

use of io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder in project crnk-framework by crnk-project.

the class RegistryEntry method getRelationshipRepository.

@SuppressWarnings("unchecked")
public RelationshipRepositoryAdapter getRelationshipRepository(ResourceField field, RepositoryMethodParameterProvider parameterProvider) {
    ResponseRelationshipEntry relationshipEntry = relationshipEntries.get(field);
    if (relationshipEntry == null) {
        throw new RelationshipRepositoryNotFoundException(getResourceInformation().getResourceType(), field.getUnderlyingName());
    }
    Object repoInstance;
    if (relationshipEntry instanceof AnnotatedRelationshipEntryBuilder) {
        repoInstance = ((AnnotatedRelationshipEntryBuilder) relationshipEntry).build(parameterProvider);
    } else {
        repoInstance = ((DirectResponseRelationshipEntry) relationshipEntry).getRepositoryInstanceBuilder();
    }
    if (repoInstance instanceof ResourceRegistryAware) {
        ((ResourceRegistryAware) repoInstance).setResourceRegistry(moduleRegistry.getResourceRegistry());
    }
    return new RelationshipRepositoryAdapter(getResourceInformation(), moduleRegistry, repoInstance);
}
Also used : DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) RelationshipRepositoryNotFoundException(io.crnk.core.exception.RelationshipRepositoryNotFoundException) AnnotatedRelationshipEntryBuilder(io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder) RelationshipRepositoryAdapter(io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)

Example 2 with AnnotatedRelationshipEntryBuilder

use of io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder in project crnk-framework by crnk-project.

the class AnnotatedRelationshipEntryBuilderTest method onInstanceOfAnnotatedRelationshipRepositoryShouldReturnTargetClass.

@Test
public void onInstanceOfAnnotatedRelationshipRepositoryShouldReturnTargetClass() {
    // GIVEN
    final AnnotatedRelationshipEntryBuilder builder = new AnnotatedRelationshipEntryBuilder(moduleRegistry, new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), SimpleRelationshipRepository.class));
    // WHEN
    final String targetResourceType = builder.getTargetResourceType();
    // THEN
    assertThat(targetResourceType).isEqualTo("projects");
}
Also used : SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) AnnotatedRelationshipEntryBuilder(io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) Test(org.junit.Test)

Example 3 with AnnotatedRelationshipEntryBuilder

use of io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder in project crnk-framework by crnk-project.

the class AnnotatedRelationshipEntryBuilderTest method onInstanceOfAnonymousDescendantOfAnnotatedRelationshipRepositoryShouldReturnTargetClass.

@Test
public void onInstanceOfAnonymousDescendantOfAnnotatedRelationshipRepositoryShouldReturnTargetClass() {
    // GIVEN
    final AnnotatedRelationshipEntryBuilder builder = new AnnotatedRelationshipEntryBuilder(moduleRegistry, new RepositoryInstanceBuilder(new JsonServiceLocator() {

        @Override
        public <T> T getInstance(Class<T> clazz) {
            return (T) new SimpleRelationshipRepository() {
            };
        }
    }, SimpleRelationshipRepository.class));
    // WHEN
    final String targetResourceType = builder.getTargetResourceType();
    // THEN
    assertThat(targetResourceType).isEqualTo("projects");
}
Also used : AnnotatedRelationshipEntryBuilder(io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder) JsonServiceLocator(io.crnk.legacy.locator.JsonServiceLocator) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) Test(org.junit.Test)

Aggregations

AnnotatedRelationshipEntryBuilder (io.crnk.legacy.registry.AnnotatedRelationshipEntryBuilder)3 SampleJsonServiceLocator (io.crnk.legacy.locator.SampleJsonServiceLocator)2 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)2 Test (org.junit.Test)2 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 RelationshipRepositoryNotFoundException (io.crnk.core.exception.RelationshipRepositoryNotFoundException)1 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)1 JsonServiceLocator (io.crnk.legacy.locator.JsonServiceLocator)1