Search in sources :

Example 1 with MetaElement

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

the class TSMetaDataObjectTransformation method setupParent.

private static void setupParent(TSMetaTransformationContext context, TSInterfaceType interfaceType, MetaDataObject metaDataObject) {
    TSContainerElement parent = null;
    // move links and meta information to the resource itself
    boolean isMeta = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.meta.MetaInformation");
    boolean isLinks = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.links.LinksInformation");
    if ((isMeta || isLinks) && metaDataObject.getImplementationClass().getEnclosingClass() != null) {
        MetaElement enclosingMeta = context.getMeta(metaDataObject.getImplementationClass().getEnclosingClass());
        if (enclosingMeta instanceof MetaResource) {
            TSType enclosingType = (TSType) context.transform(enclosingMeta, TSMetaTransformationOptions.EMPTY);
            TSModule module = TypescriptUtils.getNestedTypeContainer(enclosingType, true);
            interfaceType.setName(isLinks ? "Links" : "Meta");
            parent = module;
        }
    }
    if (parent == null) {
        TSSource source = new TSSource();
        source.setName(TypescriptUtils.toFileName(metaDataObject.getName()));
        source.setNpmPackage(context.getNpmPackage(metaDataObject));
        source.setDirectory(context.getDirectory(metaDataObject));
        context.addSource(source);
        parent = source;
    }
    parent.getElements().add(interfaceType);
    interfaceType.setParent(parent);
}
Also used : TSContainerElement(io.crnk.gen.typescript.model.TSContainerElement) TSModule(io.crnk.gen.typescript.model.TSModule) MetaElement(io.crnk.meta.model.MetaElement) MetaResource(io.crnk.meta.model.resource.MetaResource) TSSource(io.crnk.gen.typescript.model.TSSource) TSType(io.crnk.gen.typescript.model.TSType)

Example 2 with MetaElement

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

the class JpaResourceInformationProvider method accept.

@Override
public boolean accept(Class<?> resourceClass) {
    // needs to be configured for being exposed
    if (resourceClass.getAnnotation(JpaResource.class) != null) {
        return true;
    }
    if (JpaMetaUtils.isJpaType(resourceClass)) {
        // needs to be an entity
        MetaElement meta = metaProvider.discoverMeta(resourceClass);
        if (meta instanceof MetaEntity) {
            MetaEntity metaEntity = (MetaEntity) meta;
            MetaKey primaryKey = metaEntity.getPrimaryKey();
            return primaryKey != null && primaryKey.getElements().size() == 1;
        } else {
            // note that DTOs cannot be handled here
            return meta instanceof MetaJpaDataObject;
        }
    }
    return false;
}
Also used : MetaKey(io.crnk.meta.model.MetaKey) MetaElement(io.crnk.meta.model.MetaElement) MetaEntity(io.crnk.jpa.meta.MetaEntity) JpaResource(io.crnk.jpa.annotations.JpaResource) MetaJpaDataObject(io.crnk.jpa.meta.MetaJpaDataObject)

Example 3 with MetaElement

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

the class TSGeneratorTest method throwExceptionWhenMetaElementNotMappedToNpmPackage.

@Test(expected = UnsupportedOperationException.class)
public void throwExceptionWhenMetaElementNotMappedToNpmPackage() {
    TSMetaTransformationContext transformationContext = generator.createMetaTransformationContext();
    MetaElement metaElement = Mockito.mock(MetaElement.class);
    metaElement.setId("does.not.exist");
    transformationContext.getNpmPackage(metaElement);
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) TSMetaTransformationContext(io.crnk.gen.typescript.transform.TSMetaTransformationContext) Test(org.junit.Test)

Example 4 with MetaElement

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

the class TSGeneratorTest method throwExceptionWhenTransformingUnknownMetaElement.

@Test(expected = IllegalStateException.class)
public void throwExceptionWhenTransformingUnknownMetaElement() {
    MetaElement metaElement = Mockito.mock(MetaElement.class);
    metaElement.setId("does.not.exist");
    TSMetaTransformationOptions options = Mockito.mock(TSMetaTransformationOptions.class);
    generator.transform(metaElement, options);
}
Also used : TSMetaTransformationOptions(io.crnk.gen.typescript.transform.TSMetaTransformationOptions) MetaElement(io.crnk.meta.model.MetaElement) Test(org.junit.Test)

Example 5 with MetaElement

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

the class TSGeneratorTest method throwExceptionWhenMetaElementNotMappedToDirectory.

@Test(expected = UnsupportedOperationException.class)
public void throwExceptionWhenMetaElementNotMappedToDirectory() {
    TSMetaTransformationContext transformationContext = generator.createMetaTransformationContext();
    MetaElement metaElement = Mockito.mock(MetaElement.class);
    metaElement.setId("does.not.exist");
    transformationContext.getDirectory(metaElement);
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) TSMetaTransformationContext(io.crnk.gen.typescript.transform.TSMetaTransformationContext) Test(org.junit.Test)

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