Search in sources :

Example 1 with MetaMapType

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

the class QueryFilterBuilder method enhanceAttributePath.

public MetaAttributePath enhanceAttributePath(MetaAttributePath attrPath, Object value) {
    MetaAttribute attr = attrPath.getLast();
    MetaType valueType = attr.getType();
    if (valueType instanceof MetaMapType) {
        valueType = valueType.getElementType();
    }
    boolean anyType = AnyTypeObject.class.isAssignableFrom(valueType.getImplementationClass());
    if (anyType) {
        // we have and AnyType and do need to select the proper attribute of
        // the embeddable
        MetaAttribute anyAttr = AnyUtils.findAttribute((MetaDataObject) valueType, value);
        return attrPath.concat(anyAttr);
    } else {
        return attrPath;
    }
}
Also used : MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaMapType(io.crnk.meta.model.MetaMapType) MetaType(io.crnk.meta.model.MetaType)

Example 2 with MetaMapType

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

the class JpaMetaProviderAttributeTest method testMapAttr.

@Test
public void testMapAttr() {
    MetaEntity meta = metaProvider.discoverMeta(TestEntity.class);
    MetaAttribute attr = meta.getAttribute(TestEntity.ATTR_mapValue);
    Assert.assertFalse(attr.isAssociation());
    Assert.assertEquals(TestEntity.ATTR_mapValue, attr.getName());
    Assert.assertEquals(TestEntity.class.getName() + "." + TestEntity.ATTR_mapValue, attr.getId());
    Assert.assertFalse(attr.isDerived());
    Assert.assertFalse(attr.isVersion());
    Assert.assertFalse(attr.isLazy());
    Assert.assertNull(attr.getOppositeAttribute());
    MetaMapType mapType = attr.getType().asMap();
    Assert.assertTrue(mapType.isMap());
    Assert.assertEquals(String.class, mapType.getKeyType().getImplementationClass());
    Assert.assertEquals(String.class, mapType.getElementType().getImplementationClass());
    Assert.assertEquals(String.class, attr.getType().getElementType().getImplementationClass());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) WriteOnlyAttributeTestEntity(io.crnk.jpa.model.WriteOnlyAttributeTestEntity) NamingTestEntity(io.crnk.jpa.model.NamingTestEntity) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaMapType(io.crnk.meta.model.MetaMapType) Test(org.junit.Test)

Aggregations

MetaAttribute (io.crnk.meta.model.MetaAttribute)2 MetaMapType (io.crnk.meta.model.MetaMapType)2 NamingTestEntity (io.crnk.jpa.model.NamingTestEntity)1 TestEntity (io.crnk.jpa.model.TestEntity)1 WriteOnlyAttributeTestEntity (io.crnk.jpa.model.WriteOnlyAttributeTestEntity)1 MetaType (io.crnk.meta.model.MetaType)1 Test (org.junit.Test)1