Search in sources :

Example 31 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class ClientResourceUpsert method setRelations.

public void setRelations(List<Resource> resources) {
    for (Resource resource : resources) {
        String uid = getUID(resource);
        Object object = resourceMap.get(uid);
        RegistryEntry registryEntry = resourceRegistry.getEntry(resource.getType());
        // no need for any query parameters when doing POST/PATCH
        QueryAdapter queryAdapter = null;
        // no in use on the client side
        RepositoryMethodParameterProvider parameterProvider = null;
        setRelations(object, registryEntry, resource, queryAdapter, parameterProvider, true);
    }
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) Resource(io.crnk.core.engine.document.Resource) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) RepositoryMethodParameterProvider(io.crnk.legacy.internal.RepositoryMethodParameterProvider)

Example 32 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class RelationshipRepositoryBase method getTarget.

@SuppressWarnings("unchecked")
protected D getTarget(RegistryEntry entry, J targetId) {
    if (targetId == null) {
        return null;
    }
    ResourceRepositoryAdapter<D, J> targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    D target = (D) targetAdapter.findOne(targetId, queryAdapter).getEntity();
    if (target == null) {
        throw new IllegalStateException(targetId + " not found");
    }
    return target;
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 33 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter in project crnk-framework by crnk-project.

the class CustomResourceRegistryTest method test.

@Test
public void test() {
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(new CustomRegistryPartModule());
    boot.setServiceDiscovery(new TestServiceDiscovery());
    boot.boot();
    ResourceRegistry resourceRegistry = boot.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntry("somePrefix/custom");
    Assert.assertNotNull(entry);
    ResourceRepositoryAdapter adapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec("somePrefix/custom"), resourceRegistry);
    JsonApiResponse response = adapter.findAll(queryAdapter);
    Assert.assertNotNull(response.getEntity());
    List<Resource> resources = (List<Resource>) response.getEntity();
    Assert.assertEquals(1, resources.size());
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) Resource(io.crnk.core.engine.document.Resource) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) CrnkBoot(io.crnk.core.boot.CrnkBoot) TestServiceDiscovery(io.crnk.core.module.discovery.TestServiceDiscovery) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) List(java.util.List) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 34 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter 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 35 with QueryAdapter

use of io.crnk.core.engine.query.QueryAdapter 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

QueryAdapter (io.crnk.core.engine.query.QueryAdapter)35 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)15 QuerySpec (io.crnk.core.queryspec.QuerySpec)14 ResourceField (io.crnk.core.engine.information.resource.ResourceField)13 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)12 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)12 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)10 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)9 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)7 RelationshipRepositoryV2 (io.crnk.core.repository.RelationshipRepositoryV2)6 Resource (io.crnk.core.engine.document.Resource)5 Task (io.crnk.core.mock.models.Task)5 Serializable (java.io.Serializable)5 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)4 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)4 Before (org.junit.Before)4 Test (org.junit.Test)4 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3