use of io.crnk.core.engine.information.repository.RepositoryInformationProvider in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method findRelationshipMatch.
private ResponseRelationshipEntry findRelationshipMatch(ResourceField relationshipField) {
Collection<Object> repositories = moduleRegistry.getRepositories();
RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
ResponseRelationshipEntry matchedEntry = null;
for (Object repository : repositories) {
RepositoryInformation repositoryInformation = repositoryInformationBuilder.build(repository, new DefaultRepositoryInformationProviderContext(moduleRegistry));
if (repositoryInformation instanceof RelationshipRepositoryInformation) {
RelationshipRepositoryInformation relationshipRepositoryInformation = (RelationshipRepositoryInformation) repositoryInformation;
RelationshipMatcher matcher = relationshipRepositoryInformation.getMatcher();
if (matcher.matches(relationshipField)) {
if (matchedEntry != null) {
throw new IllegalStateException("multiple repositories for " + relationshipField + ": " + repository + ", " + matchedEntry);
}
matcher.matches(relationshipField);
matchedEntry = setupRelationship(relationshipField, relationshipRepositoryInformation, repository);
}
}
}
return matchedEntry;
}
use of io.crnk.core.engine.information.repository.RepositoryInformationProvider 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.RepositoryInformationProvider in project crnk-framework by crnk-project.
the class ModuleRegistryTest method repositoryInformationBuilderAccept.
@Test
public void repositoryInformationBuilderAccept() {
RepositoryInformationProvider builder = moduleRegistry.getRepositoryInformationBuilder();
Assert.assertFalse(builder.accept("no resource"));
Assert.assertFalse(builder.accept(String.class));
Assert.assertTrue(builder.accept(TaskRepository.class));
Assert.assertTrue(builder.accept(ProjectRepository.class));
Assert.assertTrue(builder.accept(TaskToProjectRepository.class));
Assert.assertTrue(builder.accept(new TaskRepository()));
Assert.assertTrue(builder.accept(new TaskToProjectRepository()));
}
use of io.crnk.core.engine.information.repository.RepositoryInformationProvider 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.RepositoryInformationProvider 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