Search in sources :

Example 41 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation 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 42 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testLongAttributeAccess.

@Test
public void testLongAttributeAccess() {
    ResourceInformation info = builder.build(VersionedEntity.class);
    ResourceField field = info.findAttributeFieldByName("longValue");
    Assert.assertTrue(field.getAccess().isPostable());
    Assert.assertTrue(field.getAccess().isPatchable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 43 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testStringAttributeAccess.

@Test
public void testStringAttributeAccess() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findAttributeFieldByName("stringValue");
    Assert.assertTrue(field.getAccess().isPostable());
    Assert.assertTrue(field.getAccess().isPatchable());
    Assert.assertTrue(field.getAccess().isSortable());
    Assert.assertTrue(field.getAccess().isFilterable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 44 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testPrimitiveTypesProperlyRecognized.

@Test
public void testPrimitiveTypesProperlyRecognized() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findAttributeFieldByName("longValue");
    Assert.assertNotNull(field);
    Assert.assertEquals(long.class, field.getType());
    Assert.assertEquals(long.class, field.getGenericType());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 45 with ResourceInformation

use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testManyToOneRelation.

@Test
public void testManyToOneRelation() {
    ResourceInformation info = builder.build(TestEntity.class);
    ResourceField field = info.findRelationshipFieldByName("oneRelatedValue");
    Assert.assertEquals(ResourceFieldType.RELATIONSHIP, field.getResourceFieldType());
    Assert.assertEquals("related", field.getOppositeResourceType());
    Assert.assertEquals(SerializeType.LAZY, field.getSerializeType());
    Assert.assertNull(field.getOppositeName());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Aggregations

ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)167 Test (org.junit.Test)79 ResourceField (io.crnk.core.engine.information.resource.ResourceField)76 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)60 QuerySpec (io.crnk.core.queryspec.QuerySpec)16 Resource (io.crnk.core.engine.document.Resource)15 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)15 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)9 Task (io.crnk.core.mock.models.Task)9 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)9 HashSet (java.util.HashSet)9 Collection (java.util.Collection)8 Relationship (io.crnk.core.engine.document.Relationship)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)7 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)7 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)7 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)7 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)7 Set (java.util.Set)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6