Search in sources :

Example 46 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class BraveResponseFilterTest method setup.

@Before
public void setup() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery("io.crnk.test.mock.repository", new SampleJsonServiceLocator()));
    boot.boot();
    span = Mockito.mock(Span.class);
    tracing = Mockito.mock(Tracing.class);
    tracer = Mockito.mock(Tracer.class);
    Mockito.when(tracing.tracer()).thenReturn(tracer);
    Mockito.when(tracer.nextSpan()).thenReturn(span);
    moduleContext = Mockito.mock(Module.ModuleContext.class);
    Mockito.when(moduleContext.getResourceRegistry()).thenReturn(boot.getResourceRegistry());
    QuerySpec querySpec = new QuerySpec(Task.class);
    queryAdapter = new QuerySpecAdapter(querySpec, boot.getResourceRegistry());
    ResourceInformation taskResourceInformation = boot.getResourceRegistry().getEntry(Task.class).getResourceInformation();
    requestSpec = Mockito.mock(RepositoryRequestSpec.class);
    Mockito.when(requestSpec.getMethod()).thenReturn(HttpMethod.GET);
    Mockito.when(requestSpec.getQueryAdapter()).thenReturn(queryAdapter);
    Mockito.when(requestSpec.getQuerySpec(taskResourceInformation)).thenReturn(querySpec);
    filter = new BraveRepositoryFilter(tracing, moduleContext);
    filterContext = Mockito.mock(RepositoryFilterContext.class);
    Mockito.when(filterContext.getRequest()).thenReturn(requestSpec);
    filterChain = Mockito.mock(RepositoryRequestFilterChain.class);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.test.mock.models.Task) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) Tracer(brave.Tracer) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) BraveRepositoryFilter(io.crnk.monitor.brave.internal.BraveRepositoryFilter) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) Span(brave.Span) CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Tracing(brave.Tracing) QuerySpec(io.crnk.core.queryspec.QuerySpec) RepositoryRequestFilterChain(io.crnk.core.engine.filter.RepositoryRequestFilterChain) Before(org.junit.Before)

Example 47 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class OperationsCall method toResource.

protected Resource toResource(Object object) {
    JsonApiResponse response = new JsonApiResponse();
    response.setEntity(object);
    QuerySpec querySpec = new QuerySpec(object.getClass());
    QueryAdapter queryAdapter = new QuerySpecAdapter(querySpec, client.getCrnk().getRegistry());
    CrnkClient crnk = client.getCrnk();
    DocumentMapper documentMapper = crnk.getDocumentMapper();
    Document document = documentMapper.toDocument(response, queryAdapter);
    return document.getSingleData().get();
}
Also used : CrnkClient(io.crnk.client.CrnkClient) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) ClientDocumentMapper(io.crnk.client.internal.ClientDocumentMapper) DocumentMapper(io.crnk.core.engine.internal.document.mapper.DocumentMapper) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpec(io.crnk.core.queryspec.QuerySpec) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) Document(io.crnk.core.engine.document.Document)

Example 48 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class BraveUtil method getQuery.

public static String getQuery(RepositoryRequestSpec request, ResourceRegistry resourceRegistry) {
    QueryAdapter queryAdapter = request.getQueryAdapter();
    StringBuilder builder = new StringBuilder();
    builder.append("?");
    if (queryAdapter instanceof QuerySpecAdapter) {
        QuerySpec querySpec = request.getQuerySpec(queryAdapter.getResourceInformation());
        DefaultQuerySpecSerializer serializer = new DefaultQuerySpecSerializer(resourceRegistry);
        Map<String, Set<String>> parameters = serializer.serialize(querySpec);
        for (Map.Entry<String, Set<String>> entry : parameters.entrySet()) {
            if (builder.length() > 1) {
                builder.append("&");
            }
            builder.append(entry.getKey());
            builder.append("=");
            builder.append(StringUtils.join(",", entry.getValue()));
        }
        return builder.toString();
    }
    return null;
}
Also used : Set(java.util.Set) DefaultQuerySpecSerializer(io.crnk.core.queryspec.DefaultQuerySpecSerializer) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Map(java.util.Map)

Aggregations

QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)48 QuerySpec (io.crnk.core.queryspec.QuerySpec)32 Test (org.junit.Test)25 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)15 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)13 Task (io.crnk.core.mock.models.Task)11 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)11 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)11 Document (io.crnk.core.engine.document.Document)10 Resource (io.crnk.core.engine.document.Resource)8 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)8 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)7 Before (org.junit.Before)7 Relationship (io.crnk.core.engine.document.Relationship)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 Project (io.crnk.core.mock.models.Project)6 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 Response (io.crnk.core.engine.dispatcher.Response)4 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4