Search in sources :

Example 6 with ResourceRegistryImpl

use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.

the class AbstractJpaTest method setup.

@Before
public void setup() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:1234"));
    resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    module = JpaModule.newServerModule(emFactory, em, transactionRunner);
    setupModule(module);
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper()));
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.addModule(module);
    moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
    moduleRegistry.init(new ObjectMapper());
    queryFactory = createQueryFactory(em);
    module.setQueryFactory(queryFactory);
    clear();
    for (int i = 0; i < numTestEntities; i++) {
        TestEmbeddedIdEntity idEntity = new TestEmbeddedIdEntity();
        idEntity.setId(new TestIdEmbeddable(i, "test" + i));
        idEntity.setLongValue(100L + i);
        em.persist(idEntity);
        RelatedEntity related = new RelatedEntity();
        related.setId(100L + i);
        related.setStringValue("related" + i);
        em.persist(related);
        TestAnyType anyValue = new TestAnyType();
        if (i == 0)
            anyValue.setValue("first");
        else
            anyValue.setValue(i);
        TestEmbeddable embValue = new TestEmbeddable();
        embValue.setEmbIntValue(i);
        embValue.setEmbStringValue("emb" + i);
        embValue.setNestedValue(new TestNestedEmbeddable(i == 0));
        embValue.setAnyValue(anyValue);
        TestEntity test = new TestEntity();
        test.setStringValue("test" + i);
        test.setId((long) i);
        test.setLongValue(i);
        test.setEmbValue(embValue);
        // left join sorting
        if (i != numTestEntities - 1) {
            test.setOneRelatedValue(related);
            test.getMapValue().put("a", "a" + i);
            test.getMapValue().put("b", "b" + i);
            test.getMapValue().put("c", "c" + i);
        }
        em.persist(test);
        // inheritance
        SingleTableBaseEntity singleTableBase = new SingleTableBaseEntity();
        singleTableBase.setId((long) i);
        singleTableBase.setStringValue("base" + i);
        em.persist(singleTableBase);
        SingleTableChildEntity singleTableChild = new SingleTableChildEntity();
        singleTableChild.setId((long) i + numTestEntities);
        singleTableChild.setStringValue("child" + i);
        singleTableChild.setIntValue(i);
        em.persist(singleTableChild);
        JoinedTableBaseEntity joinedTableBase = new JoinedTableBaseEntity();
        joinedTableBase.setId((long) i);
        joinedTableBase.setStringValue("base" + i);
        em.persist(joinedTableBase);
        JoinedTableChildEntity joinedTableChild = new JoinedTableChildEntity();
        joinedTableChild.setId((long) i + numTestEntities);
        joinedTableChild.setStringValue("child" + i);
        joinedTableChild.setIntValue(i);
        em.persist(joinedTableChild);
        TablePerClassBaseEntity tablePerClassBase = new TablePerClassBaseEntity();
        tablePerClassBase.setId((long) i);
        tablePerClassBase.setStringValue("base" + i);
        em.persist(tablePerClassBase);
        TablePerClassChildEntity tablePerClassChild = new TablePerClassChildEntity();
        tablePerClassChild.setId((long) i + numTestEntities);
        tablePerClassChild.setStringValue("child" + i);
        tablePerClassChild.setIntValue(i);
        em.persist(tablePerClassChild);
    }
    em.flush();
    em.clear();
    queryFactory = createQueryFactory(em);
    module.setQueryFactory(queryFactory);
}
Also used : ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) CoreModule(io.crnk.core.engine.internal.CoreModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) Before(org.junit.Before)

Example 7 with ResourceRegistryImpl

use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.

the class CrnkBoot method setupResourceRegistry.

private ResourceRegistryPart setupResourceRegistry() {
    Map<String, ResourceRegistryPart> registryParts = moduleRegistry.getRegistryParts();
    ResourceRegistryPart rootPart;
    if (registryParts.isEmpty()) {
        rootPart = new DefaultResourceRegistryPart();
    } else {
        HierarchicalResourceRegistryPart hierarchialPart = new HierarchicalResourceRegistryPart();
        for (Map.Entry<String, ResourceRegistryPart> entry : registryParts.entrySet()) {
            hierarchialPart.putPart(entry.getKey(), entry.getValue());
        }
        if (!registryParts.containsKey("")) {
            moduleRegistry.getContext().addRegistryPart("", new DefaultResourceRegistryPart());
        }
        rootPart = hierarchialPart;
    }
    resourceRegistry = new ResourceRegistryImpl(rootPart, moduleRegistry);
    return rootPart;
}
Also used : ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) Map(java.util.Map)

Example 8 with ResourceRegistryImpl

use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.

the class OffsetLimitPagingBehaviorTest method testBuild.

@Test
public void testBuild() {
    PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
    OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QuerySpec spec = new QuerySpec(Task.class);
    QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
    querySpecAdapter.setPagingSpec(pagingSpec);
    PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
    when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
    DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
    pagedMetaInformation.setTotalResourceCount(30L);
    ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
    for (int i = 0; i < 30; i++) {
        resourceList.add(new Task());
    }
    PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
    pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
    assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
    assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
    assertNull(pagedLinksInformation.getPrev());
    assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)8 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)7 ModuleRegistry (io.crnk.core.module.ModuleRegistry)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)4 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)4 Before (org.junit.Before)4 CoreModule (io.crnk.core.engine.internal.CoreModule)3 JacksonModule (io.crnk.core.engine.internal.jackson.JacksonModule)3 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)3 Test (org.junit.Test)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 EmptyServiceDiscovery (io.crnk.core.module.discovery.EmptyServiceDiscovery)2 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)1 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)1 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)1 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)1 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)1