Search in sources :

Example 1 with Supplier

use of io.crnk.core.utils.Supplier in project crnk-framework by crnk-project.

the class MetaResourceRepositoryTest method setup.

@Before
public void setup() {
    super.setup();
    ResourceMetaProvider provider = new ResourceMetaProvider();
    lookup = new MetaLookup();
    lookup.setModuleContext(boot.getModuleRegistry().getContext());
    lookup.addProvider(provider);
    lookup.initialize();
    repo = new MetaResourceRepositoryImpl(new Supplier<MetaLookup>() {

        @Override
        public MetaLookup get() {
            return lookup;
        }
    }, MetaElement.class);
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) MetaResourceRepositoryImpl(io.crnk.meta.internal.MetaResourceRepositoryImpl) Supplier(io.crnk.core.utils.Supplier) Before(org.junit.Before)

Example 2 with Supplier

use of io.crnk.core.utils.Supplier in project crnk-framework by crnk-project.

the class MetaModule method registerRepositories.

protected void registerRepositories(DefaultResourceInformationProvider informationBuilder, Set<Class<? extends MetaElement>> metaClasses) {
    Supplier<MetaLookup> lookupSupplier = new Supplier<MetaLookup>() {

        @Override
        public MetaLookup get() {
            return getLookup();
        }
    };
    for (Class<? extends MetaElement> metaClass : metaClasses) {
        context.addRepository(new MetaResourceRepositoryImpl<>(lookupSupplier, metaClass));
        HashSet<Class<? extends MetaElement>> targetResourceClasses = new HashSet<>();
        ResourceInformation information = informationBuilder.build(metaClass);
        for (ResourceField relationshipField : information.getRelationshipFields()) {
            if (!MetaElement.class.isAssignableFrom(relationshipField.getElementType())) {
                throw new IllegalStateException("only MetaElement relations supported, got " + relationshipField);
            }
            targetResourceClasses.add((Class<? extends MetaElement>) relationshipField.getElementType());
        }
        for (Class<? extends MetaElement> targetResourceClass : targetResourceClasses) {
            context.addRepository(new MetaRelationshipRepositoryImpl(lookupSupplier, metaClass, targetResourceClass));
        }
    }
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaElement(io.crnk.meta.model.MetaElement) ResourceField(io.crnk.core.engine.information.resource.ResourceField) MetaRelationshipRepositoryImpl(io.crnk.meta.internal.MetaRelationshipRepositoryImpl) Supplier(io.crnk.core.utils.Supplier) HashSet(java.util.HashSet)

Example 3 with Supplier

use of io.crnk.core.utils.Supplier in project crnk-framework by crnk-project.

the class MetaRelationshipRepositoryImplTest method setup.

@Before
public void setup() {
    super.setup();
    resourceProvider = new ResourceMetaProvider();
    lookup = new MetaLookup();
    lookup.setModuleContext(boot.getModuleRegistry().getContext());
    lookup.addProvider(resourceProvider);
    lookup.initialize();
    repo = new MetaRelationshipRepositoryImpl(new Supplier<MetaLookup>() {

        @Override
        public MetaLookup get() {
            return lookup;
        }
    }, MetaElement.class, MetaElement.class);
}
Also used : MetaRelationshipRepositoryImpl(io.crnk.meta.internal.MetaRelationshipRepositoryImpl) MetaElement(io.crnk.meta.model.MetaElement) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) Supplier(io.crnk.core.utils.Supplier) Before(org.junit.Before)

Aggregations

Supplier (io.crnk.core.utils.Supplier)3 MetaElement (io.crnk.meta.model.MetaElement)3 MetaRelationshipRepositoryImpl (io.crnk.meta.internal.MetaRelationshipRepositoryImpl)2 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)2 Before (org.junit.Before)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 MetaResourceRepositoryImpl (io.crnk.meta.internal.MetaResourceRepositoryImpl)1 HashSet (java.util.HashSet)1