use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class JpaNullabilityMetaTest method testPrimaryKeyNotNullable.
@Test
public void testPrimaryKeyNotNullable() {
MetaEntity meta = metaProvider.discoverMeta(TestEntity.class);
MetaKey primaryKey = meta.getPrimaryKey();
MetaAttribute idField = primaryKey.getElements().get(0);
Assert.assertFalse(idField.isNullable());
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class DtoMappingTest method testDtoMeta.
@Test
public void testDtoMeta() {
MetaLookup lookup = metaModule.getLookup();
MetaResource meta = (MetaResource) lookup.getMetaById().get("resources.testDTO");
MetaKey primaryKey = meta.getPrimaryKey();
Assert.assertNotNull(primaryKey);
Assert.assertEquals(1, primaryKey.getElements().size());
Assert.assertEquals("id", primaryKey.getElements().get(0).getName());
MetaAttribute oneRelatedAttr = meta.getAttribute("oneRelatedValue");
Assert.assertTrue(oneRelatedAttr.isAssociation());
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class MetaKeyImplTest method test.
@Test
public void test() {
JpaMetaProvider metaProvider = new JpaMetaProvider((Set) Collections.emptySet());
MetaLookup lookup = new MetaLookup();
lookup.addProvider(metaProvider);
MetaEntity meta = metaProvider.discoverMeta(TestEntity.class);
MetaKey primaryKey = meta.getPrimaryKey();
Assert.assertTrue(primaryKey.isUnique());
Assert.assertEquals("TestEntity$primaryKey", primaryKey.getName());
Assert.assertEquals(1, primaryKey.getElements().size());
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class MethodAnnotatedEntityTest method testMeta.
@Test
public void testMeta() {
MethodAnnotatedEntity entity = new MethodAnnotatedEntity();
entity.setId(13L);
entity.setStringValue("test");
MetaEntity meta = jpaMetaProvider.getMeta(MethodAnnotatedEntity.class);
MetaKey primaryKey = meta.getPrimaryKey();
Assert.assertNotNull(primaryKey);
Assert.assertEquals(1, primaryKey.getElements().size());
MetaAttribute stringValueAttr = meta.getAttribute("stringValue");
Assert.assertNotNull(stringValueAttr);
Assert.assertEquals("stringValue", stringValueAttr.getName());
Assert.assertEquals("test", stringValueAttr.getValue(entity));
MetaAttribute idAttr = meta.getAttribute("id");
Assert.assertNotNull(idAttr);
Assert.assertEquals("id", idAttr.getName());
Assert.assertEquals(13L, idAttr.getValue(entity));
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class QueryBuilder method applyFilterSpec.
protected void applyFilterSpec() {
QueryFilterBuilder<P, F> predicateBuilder = new QueryFilterBuilder<>(backend, attributeFinder);
MetaDataObject meta = query.getMeta();
List<FilterSpec> filters = query.getFilterSpecs();
List<P> predicates = predicateBuilder.filterSpecListToPredicateArray(meta, backend.getRoot(), filters);
if (predicates != null && !predicates.isEmpty()) {
backend.addPredicate(backend.and(predicates));
}
MetaAttribute parentAttr = query.getParentAttr();
if (parentAttr != null) {
MetaDataObject parentMeta = query.getParentMeta();
MetaKey primaryKey = parentMeta.getPrimaryKey();
if (primaryKey == null) {
throw new IllegalStateException("primary key not found for " + parentAttr.getId());
}
MetaAttribute primaryKeyAttr = primaryKey.getUniqueElement();
backend.addParentPredicate(primaryKeyAttr);
}
}
Aggregations