Search in sources :

Example 6 with MetaAttribute

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

the class MetaDataObjectProvider method onInitialized.

@Override
public void onInitialized(MetaElement element) {
    if (element instanceof MetaAttribute && element.getParent().getClass() == getMetaClass()) {
        MetaAttribute attr = (MetaAttribute) element;
        MetaDataObject parent = attr.getParent();
        Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());
        MetaElement metaType = context.allocate(implementationType);
        attr.setType(metaType.asType());
    }
}
Also used : Type(java.lang.reflect.Type) MetaElement(io.crnk.meta.model.MetaElement) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute)

Example 7 with MetaAttribute

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

the class MetaMetaTest method testMetaElementImmutable.

@Test
public void testMetaElementImmutable() {
    MetaResource dataMeta = resourceProvider.getMeta(MetaDataObject.class);
    Assert.assertFalse(dataMeta.isUpdatable());
    Assert.assertFalse(dataMeta.isInsertable());
    Assert.assertFalse(dataMeta.isDeletable());
    Assert.assertNotEquals(0, dataMeta.getAttributes().size());
    for (MetaAttribute attr : dataMeta.getAttributes()) {
        Assert.assertFalse(attr.isUpdatable());
        Assert.assertFalse(attr.isInsertable());
    }
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 8 with MetaAttribute

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

the class MetaMetaTest method testMetaDataObjectMeta.

@Test
public void testMetaDataObjectMeta() {
    MetaResource meta = resourceProvider.getMeta(MetaDataObject.class);
    MetaAttribute elementTypeAttr = meta.getAttribute("elementType");
    Assert.assertNotNull(elementTypeAttr);
    Assert.assertNotNull(elementTypeAttr.getType());
    Assert.assertEquals("resources.meta.type.elementType", elementTypeAttr.getId());
    MetaAttribute attrsAttr = meta.getAttribute("attributes");
    Assert.assertNotNull(attrsAttr.getType());
    MetaAttribute childrenAttr = meta.getAttribute("children");
    Assert.assertEquals("resources.meta.element.children", childrenAttr.getId());
    Assert.assertEquals("resources.meta.element$list", childrenAttr.getType().getId());
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) Test(org.junit.Test)

Example 9 with MetaAttribute

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

the class MetaMetaTest method testMetaNaming.

@Test
public void testMetaNaming() {
    MetaResource taskMeta = resourceProvider.getMeta(Task.class);
    MetaAttribute metaInformation = taskMeta.getAttribute("metaInformation");
    MetaType type = metaInformation.getType();
    Assert.assertEquals(type.getId(), "resources.tasks$meta");
    Assert.assertEquals(type.getName(), "TaskMeta");
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaType(io.crnk.meta.model.MetaType) Test(org.junit.Test)

Example 10 with MetaAttribute

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

the class MetaDataObjectProviderBase method createAttribute.

protected MetaAttribute createAttribute(T metaDataObject, String name) {
    MetaAttribute attr = new MetaAttribute();
    attr.setName(MetaUtils.firstToLower(name));
    attr.setParent(metaDataObject, true);
    attr.setFilterable(true);
    attr.setSortable(true);
    return attr;
}
Also used : MetaAttribute(io.crnk.meta.model.MetaAttribute)

Aggregations

MetaAttribute (io.crnk.meta.model.MetaAttribute)54 Test (org.junit.Test)32 MetaResource (io.crnk.meta.model.resource.MetaResource)16 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)9 MetaDataObject (io.crnk.meta.model.MetaDataObject)7 MetaKey (io.crnk.meta.model.MetaKey)7 MetaResourceBase (io.crnk.meta.model.resource.MetaResourceBase)7 FilterSpec (io.crnk.core.queryspec.FilterSpec)5 MetaType (io.crnk.meta.model.MetaType)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 MetaElement (io.crnk.meta.model.MetaElement)4 EntityManager (javax.persistence.EntityManager)4 Type (java.lang.reflect.Type)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 TSField (io.crnk.gen.typescript.model.TSField)2 MetaEntity (io.crnk.jpa.meta.MetaEntity)2 MetaJpaDataObject (io.crnk.jpa.meta.MetaJpaDataObject)2 NamingTestEntity (io.crnk.jpa.model.NamingTestEntity)2