Search in sources :

Example 11 with MetaLookup

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

the class MetaEntityTest 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 12 with MetaLookup

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

the class TSGeneratorRuntimeContextImpl method generate.

@Override
public void generate(Object meta) throws IOException {
    MetaLookup metaLookup = (MetaLookup) meta;
    TSGenerator gen = new TSGenerator(outputDir, metaLookup, config);
    gen.run();
}
Also used : MetaLookup(io.crnk.meta.MetaLookup)

Example 13 with MetaLookup

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

the class MetaResourceRepositoryImpl method findOne.

@SuppressWarnings("unchecked")
@Override
public T findOne(String id, QuerySpec querySpec) {
    MetaLookup lookup = lookupSupplier.get();
    MetaElement metaElement = lookup.getMetaById().get(id);
    Class<T> resourceClass = this.getResourceClass();
    if (metaElement != null && resourceClass.isInstance(metaElement)) {
        MetaElement wrappedElement = MetaUtils.adjustForRequest(lookup, metaElement);
        if (wrappedElement != null) {
            return (T) metaElement;
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaElement(io.crnk.meta.model.MetaElement) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException)

Example 14 with MetaLookup

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

the class MetaResourceRepositoryImpl method filterByType.

@SuppressWarnings("unchecked")
private Collection<T> filterByType(Collection<MetaElement> values) {
    Collection<T> results = new ArrayList<>();
    Class<T> resourceClass = this.getResourceClass();
    MetaLookup lookup = lookupSupplier.get();
    for (MetaElement element : values) {
        if (resourceClass.isInstance(element)) {
            MetaElement wrappedElement = MetaUtils.adjustForRequest(lookup, element);
            if (wrappedElement != null) {
                results.add((T) wrappedElement);
            }
        }
    }
    return results;
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaElement(io.crnk.meta.model.MetaElement) ArrayList(java.util.ArrayList)

Example 15 with MetaLookup

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

the class AbstractJpaTest method clear.

public static void clear(final EntityManager em, JpaQueryFactory factory) {
    factory.initalize(new JpaQueryFactoryContext() {

        @Override
        public EntityManager getEntityManager() {
            return em;
        }

        @Override
        public MetaPartition getMetaPartition() {
            JpaMetaProvider jpaMetaProvider = new JpaMetaProvider(em.getEntityManagerFactory());
            MetaLookup metaLookup = new MetaLookup();
            metaLookup.addProvider(jpaMetaProvider);
            metaLookup.initialize();
            return jpaMetaProvider.getPartition();
        }
    });
    clear(em, factory.query(OneToOneTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(ManyToManyTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(ManyToManyOppositeEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(TestSubclassWithSuperclassPk.class).buildExecutor().getResultList());
    clear(em, factory.query(RelatedEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(TestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(OtherRelatedEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(CountryTranslationEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(CountryEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(LangEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(BasicAttributesTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(RenamedTestEntity.class).buildExecutor().getResultList());
    clear(em, factory.query(UuidTestEntity.class).buildExecutor().getResultList());
    em.flush();
    em.clear();
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) JpaMetaProvider(io.crnk.jpa.meta.JpaMetaProvider) EntityManager(javax.persistence.EntityManager) MetaPartition(io.crnk.meta.provider.MetaPartition)

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