Search in sources :

Example 1 with PathBuilder

use of io.crnk.core.engine.internal.dispatcher.path.PathBuilder in project crnk-framework by crnk-project.

the class BaseControllerTest method prepare.

@Before
public void prepare() {
    modificationFilter = Mockito.spy(new ResourceModificationFilterBase());
    modificationFilters = Arrays.asList(modificationFilter);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.boot();
    objectMapper = boot.getObjectMapper();
    resourceRegistry = boot.getResourceRegistry();
    moduleRegistry = boot.getModuleRegistry();
    pathBuilder = new PathBuilder(resourceRegistry);
    typeParser = moduleRegistry.getTypeParser();
    documentMapper = boot.getDocumentMapper();
    MockRepositoryUtil.clear();
    emptyTaskQuery = new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry);
    emptyProjectQuery = new QuerySpecAdapter(new QuerySpec(Project.class), resourceRegistry);
    emptyUserQuery = new QuerySpecAdapter(new QuerySpec(User.class), resourceRegistry);
    emptyComplexPojoQuery = new QuerySpecAdapter(new QuerySpec(ComplexPojo.class), resourceRegistry);
    emptyMemorandumQuery = new QuerySpecAdapter(new QuerySpec(Memorandum.class), resourceRegistry);
}
Also used : PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ResourceModificationFilterBase(io.crnk.core.engine.filter.ResourceModificationFilterBase) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Before(org.junit.Before)

Example 2 with PathBuilder

use of io.crnk.core.engine.internal.dispatcher.path.PathBuilder in project crnk-framework by crnk-project.

the class FilterTest method prepare.

@Before
public void prepare() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    // GIVEN
    filter = mock(TestFilter.class);
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addFilter(filter);
    boot.addModule(filterModule);
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    moduleRegistry = boot.getModuleRegistry();
    pathBuilder = new PathBuilder(resourceRegistry);
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    collectionGet = mock(CollectionGet.class);
    controllerRegistry.addController(collectionGet);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    dispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Before(org.junit.Before)

Example 3 with PathBuilder

use of io.crnk.core.engine.internal.dispatcher.path.PathBuilder in project crnk-framework by crnk-project.

the class ControllerRegistryTest method onUnsupportedRequestRegisterShouldThrowError.

@Test
public void onUnsupportedRequestRegisterShouldThrowError() {
    // GIVEN
    PathBuilder pathBuilder = new PathBuilder(resourceRegistry);
    JsonPath jsonPath = pathBuilder.build("/tasks/");
    String requestType = "PATCH";
    ControllerRegistry sut = new ControllerRegistry(null);
    // THEN
    expectedException.expect(MethodNotFoundException.class);
    // WHEN
    sut.getController(jsonPath, requestType);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 4 with PathBuilder

use of io.crnk.core.engine.internal.dispatcher.path.PathBuilder in project crnk-framework by crnk-project.

the class OperationsModule method enrichTypeIdInformation.

private void enrichTypeIdInformation(List<Operation> operations) {
    ResourceRegistry resourceRegistry = moduleContext.getResourceRegistry();
    for (Operation operation : operations) {
        if (operation.getOp().equalsIgnoreCase(HttpMethod.DELETE.toString())) {
            String path = OperationParameterUtils.parsePath(operation.getPath());
            JsonPath jsonPath = (new PathBuilder(resourceRegistry)).build(path);
            Resource resource = new Resource();
            resource.setType(jsonPath.getResourceType());
            resource.setId(jsonPath.getIds().getIds().get(0));
            operation.setValue(resource);
        }
    }
}
Also used : PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) Resource(io.crnk.core.engine.document.Resource) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) OrderedOperation(io.crnk.operations.server.order.OrderedOperation) Operation(io.crnk.operations.Operation) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath)

Example 5 with PathBuilder

use of io.crnk.core.engine.internal.dispatcher.path.PathBuilder in project crnk-framework by crnk-project.

the class HttpRequestProcessorImpl method dispatchAction.

@Override
public void dispatchAction(String path, String method, Map<String, Set<String>> parameters) {
    JsonPath jsonPath = new PathBuilder(moduleRegistry.getResourceRegistry()).build(path);
    // preliminary implementation, more to come in the future
    ActionFilterChain chain = new ActionFilterChain();
    DefaultFilterRequestContext context = new DefaultFilterRequestContext(jsonPath, null, null, null, method);
    chain.doFilter(context);
}
Also used : PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath)

Aggregations

PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)8 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)6 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)2 ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)2 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)2 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)2 Before (org.junit.Before)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)1 Response (io.crnk.core.engine.dispatcher.Response)1 Document (io.crnk.core.engine.document.Document)1 Resource (io.crnk.core.engine.document.Resource)1 ResourceModificationFilterBase (io.crnk.core.engine.filter.ResourceModificationFilterBase)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 BaseController (io.crnk.core.engine.internal.dispatcher.controller.BaseController)1 CollectionGet (io.crnk.core.engine.internal.dispatcher.controller.CollectionGet)1 ActionPath (io.crnk.core.engine.internal.dispatcher.path.ActionPath)1 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)1