use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class JpaMetaProviderAttributeTest method testRelationMany.
@Test
public void testRelationMany() {
MetaEntity meta = metaProvider.discoverMeta(TestEntity.class);
MetaAttribute attr = meta.getAttribute(TestEntity.ATTR_manyRelatedValues);
Assert.assertTrue(attr.isAssociation());
Assert.assertEquals(TestEntity.ATTR_manyRelatedValues, attr.getName());
Assert.assertEquals(TestEntity.class.getName() + "." + TestEntity.ATTR_manyRelatedValues, attr.getId());
Assert.assertFalse(attr.isDerived());
Assert.assertFalse(attr.isVersion());
Assert.assertTrue(attr.isLazy());
Assert.assertNotNull(attr.getOppositeAttribute());
MetaCollectionType colType = attr.getType().asCollection();
Assert.assertTrue(colType.isCollection());
Assert.assertEquals(RelatedEntity.class, colType.getElementType().getImplementationClass());
Assert.assertEquals(RelatedEntity.class, attr.getType().getElementType().getImplementationClass());
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class ValidationMetaProvider method getFilters.
@Override
public Collection<MetaFilter> getFilters() {
return Arrays.asList((MetaFilter) new MetaFilterBase() {
@Override
public void onInitialized(MetaElement element) {
if (element instanceof MetaAttribute) {
MetaAttribute attr = (MetaAttribute) element;
NotNull notNull = attr.getAnnotation(NotNull.class);
if (notNull != null) {
attr.setNullable(false);
}
}
}
});
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class ValidationMetaProviderTest method testNotNullNotDisabledWithoutValidationProvider.
@Test
public void testNotNullNotDisabledWithoutValidationProvider() {
setup(false);
MetaResourceBase meta = resourceMetaProvider.getMeta(Task.class);
MetaAttribute attr = meta.getAttribute("name");
Assert.assertTrue(attr.isNullable());
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class AnyUtils method setValue.
/**
* Sets the value of the given anytype.
*
* @param partition to use to retrieve information
* @param dataObject the anytype for which the value is set.
* @param value the new value
*/
public static void setValue(MetaPartition partition, AnyTypeObject dataObject, Object value) {
MetaDataObject meta = (MetaDataObject) partition.getMeta(dataObject.getClass());
if (value == null) {
for (MetaAttribute attr : meta.getAttributes()) {
attr.setValue(dataObject, null);
}
} else {
boolean found = false;
for (MetaAttribute attr : meta.getAttributes()) {
if (attr.getName().equals(TYPE_ATTRIBUTE)) {
continue;
}
if (attr.getType().getImplementationClass().isAssignableFrom(value.getClass())) {
attr.setValue(dataObject, value);
found = true;
} else {
attr.setValue(dataObject, null);
}
}
if (!found) {
throw new IllegalStateException("cannot assign " + value + " to " + dataObject);
}
}
}
use of io.crnk.meta.model.MetaAttribute in project crnk-framework by crnk-project.
the class JoinRegistry method getOrCreateJoin.
public F getOrCreateJoin(MetaAttributePath path) {
if (path.length() == 0)
return backend.getRoot();
MetaAttributePath subPath = new MetaAttributePath();
F from = backend.getRoot();
for (int i = 0; i < path.length(); i++) {
MetaAttribute pathElement = path.getElement(i);
from = getOrCreateJoin(subPath, pathElement);
subPath = subPath.concat(pathElement);
}
return from;
}
Aggregations