Search in sources :

Example 1 with ResourceList

use of io.crnk.core.resource.list.ResourceList in project crnk-framework by crnk-project.

the class ActivitiRepositoryBase method findAll.

@Override
public ResourceList<T> findAll(QuerySpec querySpec) {
    Query activitiQuery = createQuery();
    List list = ActivitiQuerySpecMapper.find(activitiQuery, querySpec, baseFilters);
    return mapToResources(list);
}
Also used : Query(org.activiti.engine.query.Query) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) ResourceList(io.crnk.core.resource.list.ResourceList) List(java.util.List)

Example 2 with ResourceList

use of io.crnk.core.resource.list.ResourceList in project crnk-framework by crnk-project.

the class TaskRelationshipRepository method findOneTarget.

@Override
public T findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
    if (relationshipName.equals(fieldName)) {
        RegistryEntry taskEntry = resourceRegistry.getEntry(taskClass);
        ResourceRepositoryV2 taskRepository = (ResourceRepositoryV2) taskEntry.getResourceRepository(null).getResourceRepository();
        QuerySpec processQuerySpec = querySpec.duplicate();
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(PROCESS_INSTANCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(TASK_DEFINITION_KEY_FIELD), FilterOperator.EQ, taskDefinitionId));
        ResourceList tasks = taskRepository.findAll(processQuerySpec);
        PreconditionUtil.assertTrue("unique result expected", tasks.size() <= 1);
        return tasks.isEmpty() ? null : (T) tasks.get(0);
    } else {
        throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
    }
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 3 with ResourceList

use of io.crnk.core.resource.list.ResourceList in project crnk-framework by crnk-project.

the class ApprovalRelationshipRepository method findOneTarget.

@Override
public P findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
    if (relationshipName.equals(fieldName)) {
        RegistryEntry resourceEntry = resourceRegistry.getEntry(resourceClass);
        RegistryEntry processEntry = resourceRegistry.getEntry(processInfoClass);
        String resourceType = resourceEntry.getResourceInformation().getResourceType();
        ResourceRepositoryV2 processRepository = (ResourceRepositoryV2) processEntry.getResourceRepository(null).getResourceRepository();
        QuerySpec processQuerySpec = querySpec.duplicate();
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_TYPE_FIELD), FilterOperator.EQ, resourceType));
        baseFilters.forEach(processQuerySpec::addFilter);
        ResourceList list = processRepository.findAll(querySpec);
        PreconditionUtil.assertTrue("unique result expected", list.size() <= 1);
        return list.isEmpty() ? null : (P) list.get(0);
    } else {
        throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
    }
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 4 with ResourceList

use of io.crnk.core.resource.list.ResourceList in project crnk-framework by crnk-project.

the class ResponseRepositoryAdapter method doGetLinksInformation.

@SuppressWarnings({ "unchecked", "rawtypes" })
private LinksInformation doGetLinksInformation(Object repository, Iterable<?> resources, RepositoryRequestSpec requestSpec) {
    if (resources instanceof ResourceList) {
        ResourceList<?> resourceList = (ResourceList<?>) resources;
        boolean createLinksInformation = resourceList instanceof DefaultResourceList;
        LinksInformation newLinksInfo = enrichLinksInformation(resourceList.getLinks(), resources, requestSpec);
        if (createLinksInformation) {
            ((DefaultResourceList) resources).setLinks(newLinksInfo);
        }
        return resourceList.getLinks();
    }
    LinksInformation linksInformation = null;
    if (repository instanceof AnnotatedRepositoryAdapter) {
        if (((AnnotatedRepositoryAdapter) repository).linksRepositoryAvailable()) {
            linksInformation = ((LinksRepository) repository).getLinksInformation(resources, requestSpec.getQueryParams());
        }
    } else if (repository instanceof LinksRepositoryV2) {
        linksInformation = ((LinksRepositoryV2) repository).getLinksInformation(resources, requestSpec.getResponseQuerySpec());
    } else if (repository instanceof LinksRepository) {
        linksInformation = ((LinksRepository) repository).getLinksInformation(resources, requestSpec.getQueryParams());
    }
    // everything deprecated anyway
    return enrichLinksInformation(linksInformation, resources, requestSpec);
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) LinksInformation(io.crnk.core.resource.links.LinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) AnnotatedRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRepositoryAdapter) LinksRepositoryV2(io.crnk.core.repository.LinksRepositoryV2) LinksRepository(io.crnk.legacy.repository.LinksRepository)

Example 5 with ResourceList

use of io.crnk.core.resource.list.ResourceList in project crnk-framework by crnk-project.

the class ResponseRepositoryAdapter method enrichLinksInformation.

private LinksInformation enrichLinksInformation(LinksInformation linksInformation, Iterable<?> resources, RepositoryRequestSpec requestSpec) {
    QueryAdapter queryAdapter = requestSpec.getQueryAdapter();
    LinksInformation enrichedLinksInformation = linksInformation;
    if (queryAdapter instanceof QuerySpecAdapter && resources instanceof ResourceList && requestSpec.getResponseResourceInformation().getPagingBehavior() != null && requestSpec.getResponseResourceInformation().getPagingBehavior().isRequired(queryAdapter.getPagingSpec())) {
        enrichedLinksInformation = enrichPageLinksInformation(enrichedLinksInformation, (ResourceList<?>) resources, queryAdapter, requestSpec);
    }
    return enrichedLinksInformation;
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) LinksInformation(io.crnk.core.resource.links.LinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter)

Aggregations

ResourceList (io.crnk.core.resource.list.ResourceList)7 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)3 DefaultPagedLinksInformation (io.crnk.core.resource.links.DefaultPagedLinksInformation)3 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)2 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)2 LinksInformation (io.crnk.core.resource.links.LinksInformation)2 Test (org.junit.Test)2 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)1 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)1 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)1 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 Task (io.crnk.core.mock.models.Task)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 LinksRepositoryV2 (io.crnk.core.repository.LinksRepositoryV2)1 DefaultPagedMetaInformation (io.crnk.core.resource.meta.DefaultPagedMetaInformation)1