Search in sources :

Example 11 with MetaDataObject

use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testReadOnlyField.

@Test
public void testReadOnlyField() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    ResourceInformation info = builder.build(AnnotationTestEntity.class);
    ResourceField field = info.findAttributeFieldByName("readOnlyValue");
    Assert.assertFalse(field.getAccess().isPostable());
    Assert.assertFalse(field.getAccess().isPatchable());
    MetaDataObject meta = jpaMetaProvider.discoverMeta(AnnotationTestEntity.class).asDataObject();
    MetaAttribute attribute = meta.getAttribute("readOnlyValue");
    Assert.assertFalse(attribute.isInsertable());
    Assert.assertFalse(attribute.isUpdatable());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 12 with MetaDataObject

use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.

the class JpaResourceInformationProviderTest method testAttributeAnnotations.

@Test
public void testAttributeAnnotations() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    ResourceInformation info = builder.build(AnnotationTestEntity.class);
    ResourceField lobField = info.findAttributeFieldByName("lobValue");
    ResourceField fieldAnnotatedField = info.findAttributeFieldByName("fieldAnnotatedValue");
    ResourceField columnAnnotatedField = info.findAttributeFieldByName("columnAnnotatedValue");
    Assert.assertFalse(lobField.getAccess().isSortable());
    Assert.assertFalse(lobField.getAccess().isFilterable());
    Assert.assertTrue(lobField.getAccess().isPostable());
    Assert.assertTrue(lobField.getAccess().isPatchable());
    Assert.assertFalse(fieldAnnotatedField.getAccess().isSortable());
    Assert.assertFalse(fieldAnnotatedField.getAccess().isFilterable());
    Assert.assertTrue(fieldAnnotatedField.getAccess().isPostable());
    Assert.assertFalse(fieldAnnotatedField.getAccess().isPatchable());
    Assert.assertTrue(columnAnnotatedField.getAccess().isSortable());
    Assert.assertTrue(columnAnnotatedField.getAccess().isFilterable());
    Assert.assertFalse(columnAnnotatedField.getAccess().isPostable());
    Assert.assertTrue(columnAnnotatedField.getAccess().isPatchable());
    MetaDataObject meta = jpaMetaProvider.discoverMeta(AnnotationTestEntity.class).asDataObject();
    Assert.assertTrue(meta.getAttribute("lobValue").isLob());
    Assert.assertFalse(meta.getAttribute("fieldAnnotatedValue").isLob());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaDataObject(io.crnk.meta.model.MetaDataObject) Test(org.junit.Test)

Example 13 with MetaDataObject

use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.

the class QueryFilterBuilder method filterSimpleOperation.

private P filterSimpleOperation(FilterSpec fs, MetaDataObject rootMeta) {
    Object value = fs.getValue();
    if (value instanceof Set) {
        // HashSet not properly supported in ORM/JDBC, convert to
        // list
        Set<?> set = (Set<?>) value;
        value = new ArrayList<Object>(set);
    }
    MetaAttributePath path = rootMeta.resolvePath(fs.getAttributePath(), attributeFinder);
    path = enhanceAttributePath(path, value);
    return backend.buildPredicate(fs.getOperator(), path, value);
}
Also used : Set(java.util.Set) MetaDataObject(io.crnk.meta.model.MetaDataObject) AnyTypeObject(io.crnk.jpa.query.AnyTypeObject) MetaAttributePath(io.crnk.meta.model.MetaAttributePath)

Example 14 with MetaDataObject

use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.

the class MetaEntityTest method testGeneratedPrimaryKey.

@Test
public void testGeneratedPrimaryKey() {
    MetaDataObject meta = metaProvider.discoverMeta(SequenceEntity.class).asDataObject();
    MetaPrimaryKey primaryKey = meta.getPrimaryKey();
    Assert.assertNotNull(primaryKey);
    Assert.assertEquals(1, primaryKey.getElements().size());
    Assert.assertEquals("id", primaryKey.getElements().get(0).getName());
    Assert.assertTrue(primaryKey.isGenerated());
}
Also used : SequenceEntity(io.crnk.jpa.model.SequenceEntity) MetaPrimaryKey(io.crnk.meta.model.MetaPrimaryKey) MetaDataObject(io.crnk.meta.model.MetaDataObject) Test(org.junit.Test)

Example 15 with MetaDataObject

use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.

the class MetaLookupTest method testObjectArrayMeta.

@Test
public void testObjectArrayMeta() {
    MetaArrayType meta = metaProvider.discoverMeta(TestEntity[].class);
    MetaType elementType = meta.getElementType();
    Assert.assertTrue(elementType instanceof MetaDataObject);
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaArrayType(io.crnk.meta.model.MetaArrayType) MetaType(io.crnk.meta.model.MetaType) Test(org.junit.Test)

Aggregations

MetaDataObject (io.crnk.meta.model.MetaDataObject)23 MetaAttribute (io.crnk.meta.model.MetaAttribute)7 MetaElement (io.crnk.meta.model.MetaElement)6 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 TSInterfaceType (io.crnk.gen.typescript.model.TSInterfaceType)5 Test (org.junit.Test)5 MetaAttributePath (io.crnk.meta.model.MetaAttributePath)3 MetaResource (io.crnk.meta.model.resource.MetaResource)3 Type (java.lang.reflect.Type)3 MetaPrimaryKey (io.crnk.meta.model.MetaPrimaryKey)2 MetaType (io.crnk.meta.model.MetaType)2 ResourceFieldType (io.crnk.core.engine.information.resource.ResourceFieldType)1 DefaultResourceInstanceBuilder (io.crnk.core.engine.internal.information.resource.DefaultResourceInstanceBuilder)1 TypeParser (io.crnk.core.engine.parser.TypeParser)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 IncludeFieldSpec (io.crnk.core.queryspec.IncludeFieldSpec)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1 TSContainerElement (io.crnk.gen.typescript.model.TSContainerElement)1 TSElement (io.crnk.gen.typescript.model.TSElement)1