Search in sources :

Example 1 with MetaRelationshipRepositoryImpl

use of io.crnk.meta.internal.MetaRelationshipRepositoryImpl 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 2 with MetaRelationshipRepositoryImpl

use of io.crnk.meta.internal.MetaRelationshipRepositoryImpl 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)2 MetaRelationshipRepositoryImpl (io.crnk.meta.internal.MetaRelationshipRepositoryImpl)2 MetaElement (io.crnk.meta.model.MetaElement)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1