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