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