Search in sources :

Example 1 with RelationshipRepositoryStubImpl

use of io.crnk.client.internal.RelationshipRepositoryStubImpl in project crnk-framework by crnk-project.

the class CrnkClient method allocateRepositoryRelation.

private RelationshipRepositoryAdapter allocateRepositoryRelation(Class sourceClass, Class targetClass) {
    // allocate relations as well
    ClientResourceRegistry clientResourceRegistry = (ClientResourceRegistry) resourceRegistry;
    if (!clientResourceRegistry.isInitialized(sourceClass)) {
        allocateRepository(sourceClass);
    }
    if (!clientResourceRegistry.isInitialized(targetClass)) {
        allocateRepository(targetClass);
    }
    RegistryEntry sourceEntry = resourceRegistry.getEntry(sourceClass);
    final RegistryEntry targetEntry = resourceRegistry.getEntry(targetClass);
    String targetResourceType = targetEntry.getResourceInformation().getResourceType();
    Map relationshipEntries = sourceEntry.getRelationshipEntries();
    DirectResponseRelationshipEntry relationshipEntry = (DirectResponseRelationshipEntry) relationshipEntries.get(targetResourceType);
    if (!relationshipEntries.containsKey(targetResourceType)) {
        final RelationshipRepositoryStubImpl relationshipRepositoryStub = new RelationshipRepositoryStubImpl(this, sourceClass, targetClass, sourceEntry.getResourceInformation(), urlBuilder);
        RepositoryInstanceBuilder<RelationshipRepository> relationshipRepositoryInstanceBuilder = new RepositoryInstanceBuilder<RelationshipRepository>(null, null) {

            @Override
            public RelationshipRepository buildRepository() {
                return relationshipRepositoryStub;
            }
        };
        relationshipEntry = new DirectResponseRelationshipEntry(relationshipRepositoryInstanceBuilder) {

            @Override
            public String getTargetResourceType() {
                return targetEntry.getResourceInformation().getResourceType();
            }
        };
        relationshipEntries.put(targetResourceType, relationshipEntry);
    }
    Object repoInstance = relationshipEntry.getRepositoryInstanceBuilder();
    return new RelationshipRepositoryAdapter(sourceEntry.getResourceInformation(), moduleRegistry, repoInstance);
}
Also used : DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) RelationshipRepository(io.crnk.legacy.repository.RelationshipRepository) RelationshipRepositoryStubImpl(io.crnk.client.internal.RelationshipRepositoryStubImpl) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RelationshipRepositoryAdapter(io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)

Aggregations

RelationshipRepositoryStubImpl (io.crnk.client.internal.RelationshipRepositoryStubImpl)1 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)1 RepositoryInstanceBuilder (io.crnk.legacy.registry.RepositoryInstanceBuilder)1 RelationshipRepository (io.crnk.legacy.repository.RelationshipRepository)1