Search in sources :

Example 1 with DefaultQuerySpecConverter

use of io.crnk.legacy.internal.DefaultQuerySpecConverter in project crnk-framework by crnk-project.

the class RepositoryRequestSpecImpl method getQuerySpec.

@Override
public QuerySpec getQuerySpec(ResourceInformation targetResourceInformation) {
    if (queryAdapter instanceof QuerySpecAdapter) {
        QuerySpec querySpec = ((QuerySpecAdapter) queryAdapter).getQuerySpec();
        return querySpec.getOrCreateQuerySpec(targetResourceInformation);
    }
    Class<?> targetResourceClass = targetResourceInformation.getResourceClass();
    QueryParams queryParams = getQueryParams();
    DefaultQuerySpecConverter converter = new DefaultQuerySpecConverter(moduleRegistry);
    return converter.fromParams(targetResourceClass, queryParams);
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter)

Example 2 with DefaultQuerySpecConverter

use of io.crnk.legacy.internal.DefaultQuerySpecConverter in project crnk-framework by crnk-project.

the class AbstractQueryParamsTest method setup.

@Before
public void setup() {
    JsonServiceLocator jsonServiceLocator = new SampleJsonServiceLocator();
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), (PagingBehavior) null, new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    SimpleModule testModule = new SimpleModule("test");
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(testModule);
    boot.boot();
    moduleRegistry = boot.getModuleRegistry();
    resourceRegistry = boot.getResourceRegistry();
    converter = new DefaultQueryParamsConverter(resourceRegistry);
    paramsToSpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JsonServiceLocator(io.crnk.legacy.locator.JsonServiceLocator) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter) SimpleModule(io.crnk.core.module.SimpleModule) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Example 3 with DefaultQuerySpecConverter

use of io.crnk.legacy.internal.DefaultQuerySpecConverter 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)

Aggregations

DefaultQuerySpecConverter (io.crnk.legacy.internal.DefaultQuerySpecConverter)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)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 SimpleModule (io.crnk.core.module.SimpleModule)2 Before (org.junit.Before)2 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceFieldAccess (io.crnk.core.engine.information.resource.ResourceFieldAccess)1 ResourceFieldAccessor (io.crnk.core.engine.information.resource.ResourceFieldAccessor)1 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 TypeParser (io.crnk.core.engine.parser.TypeParser)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1