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