use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ResourceDeleteTest method onNonRelationRequestShouldDenyIt.
@Test
public void onNonRelationRequestShouldDenyIt() {
// GIVEN
JsonPath jsonPath = new ResourcePath("tasks/1/relationships/project");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
ResourceDelete sut = new ResourceDelete(resourceRegistry, new ArrayList<ResourceModificationFilter>());
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isFalse();
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ResourceIdControllerTest method toQueryAdapter.
private QueryAdapter toQueryAdapter(QueryParams requestParams, Class resourceType) {
ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntry(resourceType);
ResourceInformation resourceInformation = entry.getResourceInformation();
return new QueryParamsAdapter(resourceInformation, requestParams, moduleRegistry);
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class ConstraintViolationExceptionMapper method getResourceType.
protected String getResourceType(Object resource) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class JsonApiRequestProcessor method process.
@Override
public void process(HttpRequestContext requestContext) throws IOException {
if (isJsonApiRequest(requestContext, isAcceptingPlainJson())) {
ResourceRegistry resourceRegistry = moduleContext.getResourceRegistry();
RequestDispatcher requestDispatcher = moduleContext.getRequestDispatcher();
String path = requestContext.getPath();
JsonPath jsonPath = new PathBuilder(resourceRegistry).build(path);
Map<String, Set<String>> parameters = requestContext.getRequestParameters();
String method = requestContext.getMethod();
if (jsonPath instanceof ActionPath) {
// inital implementation, has to improve
requestDispatcher.dispatchAction(path, method, parameters);
} else if (jsonPath != null) {
byte[] requestBody = requestContext.getRequestBody();
Document document = null;
if (requestBody != null && requestBody.length > 0) {
ObjectMapper objectMapper = moduleContext.getObjectMapper();
try {
document = objectMapper.readerFor(Document.class).readValue(requestBody);
} catch (JsonProcessingException e) {
final String message = "Json Parsing failed";
setResponse(requestContext, buildBadRequestResponse(message, e.getMessage()));
LOGGER.error(message, e);
return;
}
}
RepositoryMethodParameterProvider parameterProvider = requestContext.getRequestParameterProvider();
Response crnkResponse = requestDispatcher.dispatchRequest(path, method, parameters, parameterProvider, document);
setResponse(requestContext, crnkResponse);
} else {
// no repositories invoked, we do nothing
}
}
}
use of io.crnk.core.engine.registry.ResourceRegistry in project crnk-framework by crnk-project.
the class QueryParamsAdapterTest method test.
@Test
public void test() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
QueryParams params = new QueryParams();
DefaultResourceInformationProvider builder = new DefaultResourceInformationProvider(new NullPropertiesProvider(), new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
ResourceInformation info = builder.build(Task.class);
QueryParamsAdapter adapter = new QueryParamsAdapter(info, params, moduleRegistry);
Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
Assert.assertEquals(resourceRegistry, adapter.getResourceRegistry());
}
Aggregations