Search in sources :

Example 1 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class MetaRelationshipRepositoryImpl method getSource.

private MetaElement getSource(String sourceId) {
    MetaLookup lookup = lookupSupplier.get();
    MetaElement source = lookup.getMetaById().get(sourceId);
    if (source == null) {
        throw new ResourceNotFoundException(sourceId);
    }
    return source;
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaElement(io.crnk.meta.model.MetaElement) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException)

Example 2 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class MetaResourceRepositoryImpl method findAll.

@Override
public ResourceList<T> findAll(QuerySpec querySpec) {
    MetaLookup lookup = lookupSupplier.get();
    Collection<T> values = filterByType(lookup.getMetaById().values());
    return querySpec.apply(values);
}
Also used : MetaLookup(io.crnk.meta.MetaLookup)

Example 3 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class MetaLookupTest method setup.

@Before
public void setup() {
    metaProvider = new JpaMetaProvider(Collections.<Class>emptySet());
    MetaLookup lookup = new MetaLookup();
    lookup.addProvider(metaProvider);
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) Before(org.junit.Before)

Example 4 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class CdiRunner method run.

public void run(GeneratorTrigger context) throws IOException {
    Weld weld = new Weld();
    try {
        weld.setClassLoader(context.getClassLoader());
        weld.initialize();
        CrnkBoot boot = new CrnkBoot();
        boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://<generator>"));
        boot.boot();
        ModuleRegistry moduleRegistry = boot.getModuleRegistry();
        Optional<MetaModule> optionalModule = moduleRegistry.getModule(MetaModule.class);
        if (!optionalModule.isPresent()) {
            throw new IllegalStateException("add MetaModule to CDI setup, got: " + moduleRegistry.getModules() + " with " + boot.getServiceDiscovery());
        }
        MetaModule metaModule = optionalModule.get();
        MetaLookup lookup = metaModule.getLookup();
        context.generate(lookup);
    } finally {
        weld.shutdown();
    }
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) MetaLookup(io.crnk.meta.MetaLookup) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) MetaModule(io.crnk.meta.MetaModule) Weld(org.jboss.weld.environment.se.Weld)

Example 5 with MetaLookup

use of io.crnk.meta.MetaLookup in project crnk-framework by crnk-project.

the class SpringRunner method run.

public void run(GeneratorTrigger context) {
    SpringRuntimeConfig springConfig = context.getConfig().getRuntime().getSpring();
    if (springConfig.getConfiguration() == null) {
        throw new IllegalStateException("typescriptGen.runtime.spring.configuration not specified");
    }
    if (springConfig.getProfile() == null) {
        throw new IllegalStateException("typescriptGen.runtime.spring.profile not specified");
    }
    ConfigurableApplicationContext applicationContext = null;
    try {
        Class configurationClass = getClass().getClassLoader().loadClass(springConfig.getConfiguration());
        String initializerMethodName = springConfig.getInitializerMethod();
        if (initializerMethodName != null) {
            Method initializerMethod = configurationClass.getMethod(initializerMethodName);
            initializerMethod.invoke(configurationClass);
        }
        SpringApplication application = new SpringApplication(configurationClass);
        application.setWebEnvironment(false);
        application.setAdditionalProfiles(springConfig.getProfile());
        application.setDefaultProperties(springConfig.getDefaultProperties());
        applicationContext = application.run();
        MetaModule metaModule = applicationContext.getBean(MetaModule.class);
        MetaLookup lookup = metaModule.getLookup();
        context.generate(lookup);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    } catch (NoSuchMethodException e) {
        throw new IllegalStateException(e);
    } catch (InvocationTargetException e) {
        throw new IllegalStateException(e);
    } finally {
        if (applicationContext != null) {
            applicationContext.close();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MetaLookup(io.crnk.meta.MetaLookup) SpringApplication(org.springframework.boot.SpringApplication) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MetaModule(io.crnk.meta.MetaModule)

Aggregations

MetaLookup (io.crnk.meta.MetaLookup)19 Before (org.junit.Before)6 JpaMetaProvider (io.crnk.jpa.meta.JpaMetaProvider)5 MetaElement (io.crnk.meta.model.MetaElement)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)2 MetaModule (io.crnk.meta.MetaModule)2 MetaKey (io.crnk.meta.model.MetaKey)2 MetaPartition (io.crnk.meta.provider.MetaPartition)2 EntityManager (javax.persistence.EntityManager)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 TypeParser (io.crnk.core.engine.parser.TypeParser)1 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)1 JpaResourceInformationProvider (io.crnk.jpa.internal.JpaResourceInformationProvider)1