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);
}
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 + "'");
}
}
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 + "'");
}
}
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);
}
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;
}
Aggregations