use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class HttpRequestProcessorImpl method dispatchRequest.
/**
* Dispatch the request from a client
*
* @param path built represents the URI sent in the request
* @param method type of the request e.g. POST, GET, PATCH
* @param parameterProvider repository method legacy provider
* @param requestBody deserialized body of the client request
* @return the response form the Crnk
*/
@Override
public Response dispatchRequest(String path, String method, Map<String, Set<String>> parameters, RepositoryMethodParameterProvider parameterProvider, Document requestBody) {
JsonPath jsonPath = new PathBuilder(moduleRegistry.getResourceRegistry()).build(path);
try {
BaseController controller = controllerRegistry.getController(jsonPath, method);
ResourceInformation resourceInformation = getRequestedResource(jsonPath);
QueryAdapter queryAdapter = queryAdapterBuilder.build(resourceInformation, parameters);
DefaultFilterRequestContext context = new DefaultFilterRequestContext(jsonPath, queryAdapter, parameterProvider, requestBody, method);
DefaultFilterChain chain = new DefaultFilterChain(controller);
return chain.doFilter(context);
} catch (Exception e) {
Optional<JsonApiExceptionMapper> exceptionMapper = exceptionMapperRegistry.findMapperFor(e.getClass());
if (exceptionMapper.isPresent()) {
// noinspection unchecked
logger.debug("dispatching exception to mapper", e);
return exceptionMapper.get().toErrorResponse(e).toResponse();
} else {
logger.error("failed to process request", e);
throw e;
}
}
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DocumentMapperUtil method toResourceId.
public ResourceIdentifier toResourceId(Object entity) {
if (entity == null) {
return null;
}
RegistryEntry entry = resourceRegistry.findEntry(entity.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.toResourceIdentifier(entity);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class IncludeLookupUtil method isInclusionRequestedForQueryParams.
private boolean isInclusionRequestedForQueryParams(QueryAdapter queryAdapter, List<ResourceField> fieldPath) {
Map<String, IncludedRelationsParams> params = queryAdapter.getIncludedRelations().getParams();
// we have to possibilities for inclusion: by type or dot notation
for (int i = fieldPath.size() - 1; i >= 0; i--) {
String path = toPath(fieldPath, i);
ResourceInformation rootInformation = fieldPath.get(i).getParentResourceInformation();
IncludedRelationsParams includedRelationsParams = params.get(rootInformation.getResourceType());
if (includedRelationsParams != null && contains(includedRelationsParams, path)) {
return true;
}
}
return false;
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class IncludeLookupUtil method process.
private void process(String type, Set<String> processedTypes, Set<ResourceField> fields) {
if (!processedTypes.contains(type)) {
processedTypes.add(type);
RegistryEntry entry = resourceRegistry.getEntry(type);
ResourceInformation information = entry.getResourceInformation();
ResourceInformation superInformation = getSuperInformation(information);
if (superInformation != null) {
process(superInformation.getResourceType(), processedTypes, fields);
}
// TODO same relationship on multiple children
for (ResourceField field : information.getRelationshipFields()) {
boolean existsOnSuperType = superInformation != null && superInformation.findRelationshipFieldByName(field.getJsonName()) != null;
if (!existsOnSuperType) {
fields.add(field);
}
}
}
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class RegistryEntryTest method newRepositoryInformation.
private <T> ResourceRepositoryInformation newRepositoryInformation(Class<T> repositoryClass, String path) {
ModuleRegistry moduleRegistry = new ModuleRegistry();
TypeParser typeParser = moduleRegistry.getTypeParser();
return new ResourceRepositoryInformationImpl(path, new ResourceInformation(typeParser, Task.class, path, null, null, null, null), RepositoryMethodAccess.ALL);
}
Aggregations