Search in sources :

Example 1 with QuerySpecAdapter

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

the class FormRelationshipRepository method findOneTarget.

@Override
public F findOneTarget(String taskId, String fieldName, QuerySpec querySpec) {
    if (RELATIONSHIP_NAME.equals(fieldName)) {
        ResourceRepositoryAdapter resourceRepository = resourceRegistry.getEntry(formClass).getResourceRepository();
        QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(querySpec, resourceRegistry);
        return (F) resourceRepository.findOne(taskId, querySpecAdapter).getEntity();
    } else {
        throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
    }
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter)

Example 2 with QuerySpecAdapter

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

the class RelationshipRepositoryBase method getTargets.

@SuppressWarnings("unchecked")
protected Iterable<D> getTargets(RegistryEntry entry, Iterable<J> targetIds) {
    ResourceRepositoryAdapter<D, J> targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Iterable<D>) targetAdapter.findAll(targetIds, queryAdapter).getEntity();
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 3 with QuerySpecAdapter

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

the class RelationshipRepositoryBase method getSaveQueryAdapter.

protected QueryAdapter getSaveQueryAdapter(String fieldName) {
    QuerySpec querySpec = newSourceQuerySpec();
    querySpec.includeRelation(Arrays.asList(fieldName));
    return new QuerySpecAdapter(querySpec, resourceRegistry);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter)

Example 4 with QuerySpecAdapter

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

the class RelationshipRepositoryBase method findTargets.

@SuppressWarnings("unchecked")
public MultivaluedMap<I, D> findTargets(Iterable<I> sourceIds, String fieldName, QuerySpec querySpec) {
    RegistryEntry sourceEntry = resourceRegistry.findEntry(sourceResourceClass);
    ResourceInformation sourceInformation = sourceEntry.getResourceInformation();
    ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
    RegistryEntry targetEntry = getTargetEntry(field);
    String oppositeName = getOppositeName(fieldName);
    QuerySpec idQuerySpec = querySpec.duplicate();
    idQuerySpec.addFilter(new FilterSpec(Arrays.asList(oppositeName, sourceInformation.getIdField().getUnderlyingName()), FilterOperator.EQ, sourceIds));
    idQuerySpec.includeRelation(Arrays.asList(oppositeName));
    ResourceRepositoryAdapter<D, J> targetAdapter = targetEntry.getResourceRepository();
    JsonApiResponse response = targetAdapter.findAll(new QuerySpecAdapter(idQuerySpec, resourceRegistry));
    List<D> results = (List<D>) response.getEntity();
    MultivaluedMap<I, D> bulkResult = new MultivaluedMap<I, D>() {

        @Override
        protected List<D> newList() {
            return new DefaultResourceList<>();
        }
    };
    Set<I> sourceIdSet = new HashSet<>();
    for (I sourceId : sourceIds) {
        sourceIdSet.add(sourceId);
    }
    for (D result : results) {
        handleTarget(bulkResult, result, sourceIdSet, oppositeName, sourceInformation);
    }
    return bulkResult;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) FilterSpec(io.crnk.core.queryspec.FilterSpec) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceField(io.crnk.core.engine.information.resource.ResourceField) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) ResourceList(io.crnk.core.resource.list.ResourceList) ArrayList(java.util.ArrayList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) List(java.util.List) QuerySpec(io.crnk.core.queryspec.QuerySpec) MultivaluedMap(io.crnk.core.engine.internal.utils.MultivaluedMap) HashSet(java.util.HashSet)

Example 5 with QuerySpecAdapter

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

the class ForwardingStrategyContext method findAll.

public <Q> Iterable<Q> findAll(RegistryEntry entry, Iterable<?> targetIds) {
    ResourceRepositoryAdapter targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Iterable) targetAdapter.findAll(targetIds, queryAdapter).getEntity();
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

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