use of io.crnk.meta.model.MetaAttribute 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.MetaAttribute 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;
}
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class JpaMetaEnricher method onInitialized.
@Override
public void onInitialized(MetaElement element) {
if (element instanceof MetaJsonObject) {
MetaJsonObject jsonDataObject = (MetaJsonObject) element;
Class<?> implementationClass = jsonDataObject.getImplementationClass();
if (metaProvider.hasMeta(implementationClass)) {
MetaJpaDataObject jpaDataObject = metaProvider.getMeta(implementationClass);
if (jpaDataObject.getPrimaryKey() != null && jsonDataObject.getPrimaryKey() != null) {
jsonDataObject.getPrimaryKey().setGenerated(jpaDataObject.getPrimaryKey().isGenerated());
}
List<? extends MetaAttribute> declaredAttributes = jsonDataObject.getDeclaredAttributes();
for (MetaAttribute declaredAttribute : declaredAttributes) {
String name = declaredAttribute.getName();
if (jpaDataObject.hasAttribute(name)) {
MetaAttribute jpaAttribute = jpaDataObject.getAttribute(name);
declaredAttribute.setLob(jpaAttribute.isLob());
declaredAttribute.setVersion(jpaAttribute.isVersion());
declaredAttribute.setNullable(jpaAttribute.isNullable());
declaredAttribute.setCascaded(jpaAttribute.isCascaded());
}
}
}
}
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class DtoMappingTest method testDtoMeta.
@Test
public void testDtoMeta() {
MetaLookup lookup = metaModule.getLookup();
MetaResource meta = (MetaResource) lookup.getMetaById().get("resources.testDTO");
MetaKey primaryKey = meta.getPrimaryKey();
Assert.assertNotNull(primaryKey);
Assert.assertEquals(1, primaryKey.getElements().size());
Assert.assertEquals("id", primaryKey.getElements().get(0).getName());
MetaAttribute oneRelatedAttr = meta.getAttribute("oneRelatedValue");
Assert.assertTrue(oneRelatedAttr.isAssociation());
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class JpaMetaProviderAttributeTest method testCascaded.
@Test
public void testCascaded() {
MetaEntity meta = metaProvider.discoverMeta(TestEntity.class);
MetaAttribute oneRelatedAttr = meta.getAttribute("oneRelatedValue");
MetaAttribute eagerRelatedAttr = meta.getAttribute("eagerRelatedValue");
Assert.assertTrue(oneRelatedAttr.isCascaded());
Assert.assertFalse(eagerRelatedAttr.isCascaded());
}
Aggregations