use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class MetaLookup method add.
public void add(MetaElement element) {
PreconditionUtil.assertTrue("no discovering", discovering);
PreconditionUtil.assertNotNull("no name provided", element.getName());
if (!element.hasId() && element.getParent() != null) {
element.setId(element.getParent().getId() + "." + element.getName());
}
PreconditionUtil.assertNull("already exists", idElementMap.get(element.getId()));
// if (idElementMap.get(element.getId()) != element) {
LOGGER.debug("add {} of type {}", element.getId(), element.getClass().getSimpleName());
// queue for initialization
initializationQueue.add(element);
MetaElement currentElement = idElementMap.get(element.getId());
PreconditionUtil.assertNull(element.getId(), currentElement);
idElementMap.put(element.getId(), element);
// add children recursively
for (MetaElement child : element.getChildren()) {
add(child);
}
// }
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class BaseMetaPartition method doAllocateMetaElement.
protected Optional<MetaElement> doAllocateMetaElement(Type type) {
if (type instanceof Class) {
Class clazz = (Class) type;
clazz = mapPrimitiveType(clazz);
if (isPrimitiveType(clazz)) {
String id = BASE_ID_PREFIX + firstToLower(clazz.getSimpleName());
Optional<MetaElement> optPrimitiveType = context.getMetaElement(id);
if (!optPrimitiveType.isPresent()) {
MetaPrimitiveType primitiveType = new MetaPrimitiveType();
primitiveType.setElementType(primitiveType);
primitiveType.setImplementationType(clazz);
primitiveType.setName(firstToLower(clazz.getSimpleName()));
primitiveType.setId(id);
return addElement(type, primitiveType);
}
return optPrimitiveType;
}
}
return Optional.empty();
}
use of io.crnk.meta.model.MetaElement 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);
}
}
}
});
}
Aggregations