Search in sources :

Example 6 with MetaDataObject

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

the class AbstractEntityMetaFactory method create.

@Override
public MetaElement create(Type type) {
    Class<?> rawClazz = ClassUtils.getRawType(type);
    Class<?> superClazz = rawClazz.getSuperclass();
    MetaElement superMeta = getSuperMeta(superClazz);
    T meta = newDataObject();
    meta.setElementType(meta);
    meta.setName(rawClazz.getSimpleName());
    meta.setImplementationType(type);
    meta.setSuperType((MetaDataObject) superMeta);
    if (superMeta != null) {
        ((MetaDataObject) superMeta).addSubType(meta);
    }
    createAttributes(meta);
    setKey(meta);
    return meta;
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) MetaDataObject(io.crnk.meta.model.MetaDataObject)

Example 7 with MetaDataObject

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

the class JpaMetaFilter method onInitialized.

@Override
public void onInitialized(MetaElement element) {
    if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute) {
        MetaAttribute attr = (MetaAttribute) element;
        MetaDataObject parent = attr.getParent();
        Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());
        MetaType metaType = (MetaType) partition.allocateMetaElement(implementationType).get();
        attr.setType(metaType);
    }
    if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute && ((MetaAttribute) element).getOppositeAttribute() == null) {
        MetaAttribute attr = (MetaAttribute) element;
        String mappedBy = getMappedBy(attr);
        if (mappedBy != null) {
            MetaType attrType = attr.getType();
            MetaDataObject oppositeType = attrType.getElementType().asDataObject();
            if (!mappedBy.contains(".")) {
                MetaAttribute oppositeAttr = oppositeType.getAttribute(mappedBy);
                attr.setOppositeAttribute(oppositeAttr);
            } else {
            // references within embeddables not yet supported
            }
        }
    }
}
Also used : Type(java.lang.reflect.Type) MetaType(io.crnk.meta.model.MetaType) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaJpaDataObject(io.crnk.jpa.meta.MetaJpaDataObject) MetaType(io.crnk.meta.model.MetaType)

Example 8 with MetaDataObject

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

the class EmbeddableMetaFactory method create.

@Override
public MetaEmbeddable create(Type type) {
    Class<?> rawClazz = ClassUtils.getRawType(type);
    Class<?> superClazz = rawClazz.getSuperclass();
    MetaElement superMeta = null;
    if (superClazz != Object.class) {
        superMeta = context.allocate(superClazz);
    }
    MetaEmbeddable meta = new MetaEmbeddable();
    meta.setElementType(meta);
    meta.setName(rawClazz.getSimpleName());
    meta.setImplementationType(type);
    meta.setSuperType((MetaDataObject) superMeta);
    if (superMeta != null) {
        ((MetaDataObject) superMeta).addSubType(meta);
    }
    createAttributes(meta);
    return meta;
}
Also used : MetaEmbeddable(io.crnk.jpa.meta.MetaEmbeddable) MetaElement(io.crnk.meta.model.MetaElement) MetaDataObject(io.crnk.meta.model.MetaDataObject)

Example 9 with MetaDataObject

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

the class ComputedAttributeRegistryImpl method getForType.

@Override
public Set<String> getForType(Class<?> entityType) {
    Set<String> set = new HashSet<>();
    for (Registration reg : map.values()) {
        MetaComputedAttribute attr = reg.getAttribute();
        MetaDataObject parent = attr.getParent();
        Class<?> parentImpl = parent.getImplementationClass();
        if (parentImpl.isAssignableFrom(entityType)) {
            set.add(attr.getName());
        }
    }
    return set;
}
Also used : MetaDataObject(io.crnk.meta.model.MetaDataObject) HashSet(java.util.HashSet)

Example 10 with MetaDataObject

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

the class JpaResourceInformationProviderTest method testMappedSuperclass.

@Test
public void testMappedSuperclass() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    ResourceInformation info = builder.build(AnnotationMappedSuperclassEntity.class);
    Assert.assertNull(info.getResourceType());
    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(AnnotationMappedSuperclassEntity.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)

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