use of io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext 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.module.internal.DefaultRepositoryInformationProviderContext 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.module.internal.DefaultRepositoryInformationProviderContext in project crnk-framework by crnk-project.
the class CrnkClient method getRepositoryForInterface.
@SuppressWarnings("unchecked")
public <R extends ResourceRepositoryV2<?, ?>> R getRepositoryForInterface(Class<R> repositoryInterfaceClass) {
init();
RepositoryInformationProvider informationBuilder = moduleRegistry.getRepositoryInformationBuilder();
PreconditionUtil.assertTrue("no a valid repository interface", informationBuilder.accept(repositoryInterfaceClass));
ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) informationBuilder.build(repositoryInterfaceClass, new DefaultRepositoryInformationProviderContext(moduleRegistry));
Class<?> resourceClass = repositoryInformation.getResourceInformation().get().getResourceClass();
Object actionStub = actionStubFactory != null ? actionStubFactory.createStub(repositoryInterfaceClass) : null;
ResourceRepositoryV2<?, Serializable> repositoryStub = getQuerySpecRepository(resourceClass);
ClassLoader classLoader = repositoryInterfaceClass.getClassLoader();
InvocationHandler invocationHandler = new ClientStubInvocationHandler(repositoryInterfaceClass, repositoryStub, actionStub);
return (R) Proxy.newProxyInstance(classLoader, new Class[] { repositoryInterfaceClass, ResourceRepositoryV2.class }, invocationHandler);
}
Aggregations