Search in sources :

Example 16 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class AbstractQuerySpecTest method setup.

@Before
public void setup() {
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), ImmutableList.of(new OffsetLimitPagingBehavior(), new CustomOffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider()) {

        @Override
        protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
            List<ResourceField> fields = super.getResourceFields(resourceClass);
            if (resourceClass == Task.class) {
                // add additional field that is not defined on the class
                String name = "computedAttribute";
                ResourceFieldAccess access = new ResourceFieldAccess(true, true, true, true, true);
                InformationBuilder informationBuilder = new DefaultInformationBuilder(new TypeParser());
                InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
                fieldBuilder.type(Integer.class);
                fieldBuilder.jsonName(name);
                fieldBuilder.underlyingName(name);
                fieldBuilder.access(access);
                fieldBuilder.accessor(new ResourceFieldAccessor() {

                    public Object getValue(Object resource) {
                        return 13;
                    }

                    public void setValue(Object resource, Object fieldValue) {
                    }
                });
                fields.add(fieldBuilder.build());
            }
            return fields;
        }
    };
    SimpleModule testModule = new SimpleModule("test");
    testModule.addResourceInformationProvider(resourceInformationProvider);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
    boot.addModule(testModule);
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(getResourceSearchPackage()));
    boot.boot();
    moduleRegistry = boot.getModuleRegistry();
    querySpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
    resourceRegistry = boot.getResourceRegistry();
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) TypeParser(io.crnk.core.engine.parser.TypeParser) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter) ResourceFieldAccess(io.crnk.core.engine.information.resource.ResourceFieldAccess) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldAccessor(io.crnk.core.engine.information.resource.ResourceFieldAccessor) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) SimpleModule(io.crnk.core.module.SimpleModule) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Example 17 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class MetaModuleProducer method createRepositoryModule.

@Produces
@ApplicationScoped
public Module createRepositoryModule() {
    SimpleModule module = new SimpleModule("mock");
    module.addRepository(new ScheduleRepositoryImpl());
    module.addRepository(new ProjectRepository());
    module.addRepository(new TaskRepository());
    module.addRepository(new ProjectToTaskRepository());
    module.addRepository(new ScheduleToTaskRepository());
    module.addRepository(new TaskSubtypeRepository());
    module.addRepository(new TaskToProjectRepository());
    module.addRepository(new TaskToScheduleRepo());
    return module;
}
Also used : ScheduleRepositoryImpl(io.crnk.test.mock.repository.ScheduleRepositoryImpl) ProjectRepository(io.crnk.test.mock.repository.ProjectRepository) TaskToProjectRepository(io.crnk.test.mock.repository.TaskToProjectRepository) TaskSubtypeRepository(io.crnk.test.mock.repository.TaskSubtypeRepository) ProjectToTaskRepository(io.crnk.test.mock.repository.ProjectToTaskRepository) TaskToProjectRepository(io.crnk.test.mock.repository.TaskToProjectRepository) TaskToScheduleRepo(io.crnk.test.mock.repository.TaskToScheduleRepo) TaskRepository(io.crnk.test.mock.repository.TaskRepository) ProjectToTaskRepository(io.crnk.test.mock.repository.ProjectToTaskRepository) ScheduleToTaskRepository(io.crnk.test.mock.repository.ScheduleToTaskRepository) ScheduleToTaskRepository(io.crnk.test.mock.repository.ScheduleToTaskRepository) SimpleModule(io.crnk.core.module.SimpleModule) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 18 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class MetaFilteringTest method setupFeature.

@Override
protected void setupFeature(CrnkFeature feature) {
    filter = Mockito.spy(ResourceFilterBase.class);
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addResourceFilter(filter);
    feature.addModule(filterModule);
}
Also used : ResourceFilterBase(io.crnk.core.engine.filter.ResourceFilterBase) SimpleModule(io.crnk.core.module.SimpleModule)

Aggregations

SimpleModule (io.crnk.core.module.SimpleModule)18 Before (org.junit.Before)9 CrnkBoot (io.crnk.core.boot.CrnkBoot)7 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)6 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)5 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)2 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)2 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)2 CoreModule (io.crnk.core.engine.internal.CoreModule)2 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)2 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)2 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 DefaultQuerySpecConverter (io.crnk.legacy.internal.DefaultQuerySpecConverter)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApprovalRelationshipRepository (io.crnk.activiti.example.approval.ApprovalRelationshipRepository)1