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;
}
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
}
}
}
}
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;
}
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;
}
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());
}
Aggregations