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));
}
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations