Search in sources :

Example 26 with MetaElement

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);
    }
// }
}
Also used : MetaElement(io.crnk.meta.model.MetaElement)

Example 27 with MetaElement

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();
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) MetaPrimitiveType(io.crnk.meta.model.MetaPrimitiveType)

Example 28 with MetaElement

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);
                }
            }
        }
    });
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaFilterBase(io.crnk.meta.provider.MetaFilterBase) NotNull(javax.validation.constraints.NotNull)

Aggregations

MetaElement (io.crnk.meta.model.MetaElement)28 MetaDataObject (io.crnk.meta.model.MetaDataObject)6 Test (org.junit.Test)6 MetaResource (io.crnk.meta.model.resource.MetaResource)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)3 MetaLookup (io.crnk.meta.MetaLookup)3 MetaAttribute (io.crnk.meta.model.MetaAttribute)3 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 TSMetaTransformationContext (io.crnk.gen.typescript.transform.TSMetaTransformationContext)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 ResourceFieldType (io.crnk.core.engine.information.resource.ResourceFieldType)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 ReadOnlyResourceRepositoryBase (io.crnk.core.repository.ReadOnlyResourceRepositoryBase)1 Supplier (io.crnk.core.utils.Supplier)1 TSContainerElement (io.crnk.gen.typescript.model.TSContainerElement)1