Search in sources :

Example 11 with MetaElement

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

Example 12 with MetaElement

use of io.crnk.meta.model.MetaElement 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;
}
Also used : MetaEmbeddable(io.crnk.jpa.meta.MetaEmbeddable) MetaElement(io.crnk.meta.model.MetaElement) MetaDataObject(io.crnk.meta.model.MetaDataObject)

Example 13 with MetaElement

use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.

the class TSGenerator method transformMetaToTypescript.

public void transformMetaToTypescript() {
    Collection<MetaElement> elements = lookup.getMetaById().values();
    LOGGER.debug("transforming {} elements", elements.size());
    for (MetaElement element : elements) {
        boolean isRoot = isRoot(element);
        boolean isGenerated = isGenerated(element);
        if (isRoot && isGenerated) {
            LOGGER.debug("transforming {}", element.getId());
            transform(element, TSMetaTransformationOptions.EMPTY);
        } else {
            LOGGER.debug("ignoring {}, root={}, generated={}", element.getId(), isRoot, isGenerated);
        }
    }
    try {
        postProcessing = true;
        for (TSElement transformedElement : new ArrayList<>(transformedElements)) {
            for (TSMetaTransformation transformation : transformations) {
                transformation.postTransform(transformedElement, createMetaTransformationContext());
            }
        }
    } finally {
        postProcessing = false;
    }
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) ArrayList(java.util.ArrayList) TSMetaTransformation(io.crnk.gen.typescript.transform.TSMetaTransformation) TSElement(io.crnk.gen.typescript.model.TSElement)

Example 14 with MetaElement

use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.

the class MetaModule method registerRepositories.

protected void registerRepositories(DefaultResourceInformationProvider informationBuilder, Set<Class<? extends MetaElement>> metaClasses) {
    Supplier<MetaLookup> lookupSupplier = new Supplier<MetaLookup>() {

        @Override
        public MetaLookup get() {
            return getLookup();
        }
    };
    for (Class<? extends MetaElement> metaClass : metaClasses) {
        context.addRepository(new MetaResourceRepositoryImpl<>(lookupSupplier, metaClass));
        HashSet<Class<? extends MetaElement>> targetResourceClasses = new HashSet<>();
        ResourceInformation information = informationBuilder.build(metaClass);
        for (ResourceField relationshipField : information.getRelationshipFields()) {
            if (!MetaElement.class.isAssignableFrom(relationshipField.getElementType())) {
                throw new IllegalStateException("only MetaElement relations supported, got " + relationshipField);
            }
            targetResourceClasses.add((Class<? extends MetaElement>) relationshipField.getElementType());
        }
        for (Class<? extends MetaElement> targetResourceClass : targetResourceClasses) {
            context.addRepository(new MetaRelationshipRepositoryImpl(lookupSupplier, metaClass, targetResourceClass));
        }
    }
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaElement(io.crnk.meta.model.MetaElement) ResourceField(io.crnk.core.engine.information.resource.ResourceField) MetaRelationshipRepositoryImpl(io.crnk.meta.internal.MetaRelationshipRepositoryImpl) Supplier(io.crnk.core.utils.Supplier) HashSet(java.util.HashSet)

Example 15 with MetaElement

use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.

the class TSMetaDataObjectTransformation method postTransform.

@Override
public void postTransform(TSElement element, TSMetaTransformationContext context) {
    if (element instanceof TSInterfaceType) {
        TSInterfaceType interfaceType = (TSInterfaceType) element;
        String metaId = interfaceType.getPrivateData(TSMetaDataObjectTransformation.PRIVATE_DATA_META_ELEMENT_ID, String.class);
        MetaElement metaElement = context.getMeta(metaId);
        if (metaElement instanceof MetaDataObject) {
            MetaDataObject metaDataObject = (MetaDataObject) metaElement;
            if (generateAsResource(metaDataObject)) {
                // link to super type, only available once all fields are initialized
                MetaDataObject superType = metaDataObject.getSuperType();
                if (superType != null) {
                    setAttributeSuperType(interfaceType, metaDataObject, context);
                    setRelationshipsSuperType(interfaceType, metaDataObject, context);
                }
            }
        }
    }
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) MetaDataObject(io.crnk.meta.model.MetaDataObject) TSInterfaceType(io.crnk.gen.typescript.model.TSInterfaceType)

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