Search in sources :

Example 6 with MetaKey

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());
}
Also used : MetaKey(io.crnk.meta.model.MetaKey) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 7 with MetaKey

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());
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaKey(io.crnk.meta.model.MetaKey) MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 8 with MetaKey

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());
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaKey(io.crnk.meta.model.MetaKey) Test(org.junit.Test)

Example 9 with MetaKey

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));
}
Also used : MethodAnnotatedEntity(io.crnk.jpa.model.MethodAnnotatedEntity) MetaKey(io.crnk.meta.model.MetaKey) MetaEntity(io.crnk.jpa.meta.MetaEntity) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 10 with MetaKey

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);
    }
}
Also used : MetaKey(io.crnk.meta.model.MetaKey) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute) FilterSpec(io.crnk.core.queryspec.FilterSpec)

Aggregations

MetaKey (io.crnk.meta.model.MetaKey)12 MetaAttribute (io.crnk.meta.model.MetaAttribute)7 Test (org.junit.Test)6 MetaEntity (io.crnk.jpa.meta.MetaEntity)3 MetaResource (io.crnk.meta.model.resource.MetaResource)3 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 MetaLookup (io.crnk.meta.MetaLookup)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 TSField (io.crnk.gen.typescript.model.TSField)1 TSIndexSignature (io.crnk.gen.typescript.model.TSIndexSignature)1 TSInterfaceType (io.crnk.gen.typescript.model.TSInterfaceType)1 TSModule (io.crnk.gen.typescript.model.TSModule)1 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)1 JpaResource (io.crnk.jpa.annotations.JpaResource)1 MetaJpaDataObject (io.crnk.jpa.meta.MetaJpaDataObject)1 MethodAnnotatedEntity (io.crnk.jpa.model.MethodAnnotatedEntity)1 MetaDataObject (io.crnk.meta.model.MetaDataObject)1 MetaElement (io.crnk.meta.model.MetaElement)1