Search in sources :

Example 6 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class ForwardingStrategyContext method findOne.

public <Q> Q findOne(RegistryEntry entry, Serializable id) {
    ResourceRepositoryAdapter targetAdapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec(entry.getResourceInformation()), resourceRegistry);
    return (Q) targetAdapter.findOne(id, queryAdapter).getEntity();
}
Also used : ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 7 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class JsonApiRequestProcessorTest method createRequestBody.

private String createRequestBody(String name) throws JsonProcessingException {
    Task task = new Task();
    task.setId(1L);
    task.setName(name);
    task.setCategory("testCategory");
    JsonApiResponse request = new JsonApiResponse();
    request.setEntity(task);
    Document requestDocument = boot.getDocumentMapper().toDocument(request, new QuerySpecAdapter(new QuerySpec(Task.class), boot.getResourceRegistry()));
    return boot.getObjectMapper().writeValueAsString(requestDocument);
}
Also used : Task(io.crnk.core.mock.models.Task) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Document(io.crnk.core.engine.document.Document) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 8 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class ResourceFilterTest method checkFilterGetOnResourceField.

@Test
public void checkFilterGetOnResourceField() {
    // setup test data
    RegistryEntry entry = resourceRegistry.getEntry(Task.class);
    ResourceRepositoryAdapter resourceRepository = entry.getResourceRepository();
    Project project = new Project();
    project.setId(13L);
    project.setName("myProject");
    Task task = new Task();
    task.setId(12L);
    task.setName("myTask");
    task.setProject(project);
    resourceRepository.create(task, new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry));
    // get information
    ResourceInformation resourceInformation = entry.getResourceInformation();
    ResourceField projectField = resourceInformation.findFieldByUnderlyingName("project");
    ResourceField nameField = resourceInformation.findFieldByUnderlyingName("name");
    String path = "/tasks/";
    String method = HttpMethod.GET.toString();
    Map<String, Set<String>> parameters = Collections.emptyMap();
    Document requestBody = null;
    // forbid field
    Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
    Response response = boot.getRequestDispatcher().dispatchRequest(path, method, parameters, null, requestBody);
    Assert.assertEquals(HttpStatus.OK_200, response.getHttpStatus().intValue());
    Resource taskResource = response.getDocument().getCollectionData().get().get(0);
    Assert.assertTrue(taskResource.getRelationships().containsKey("projects"));
    Assert.assertFalse(taskResource.getRelationships().containsKey("project"));
    Assert.assertTrue(taskResource.getAttributes().containsKey("name"));
    // allow resource
    Mockito.when(filter.filterField(Mockito.eq(nameField), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
    response = boot.getRequestDispatcher().dispatchRequest(path, method, parameters, null, requestBody);
    Assert.assertEquals(HttpStatus.OK_200, response.getHttpStatus().intValue());
    taskResource = response.getDocument().getCollectionData().get().get(0);
    Assert.assertTrue(taskResource.getRelationships().containsKey("projects"));
    Assert.assertFalse(taskResource.getRelationships().containsKey("project"));
    Assert.assertFalse(taskResource.getAttributes().containsKey("name"));
}
Also used : Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Set(java.util.Set) Resource(io.crnk.core.engine.document.Resource) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) Document(io.crnk.core.engine.document.Document) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Response(io.crnk.core.engine.dispatcher.Response) Project(io.crnk.core.mock.models.Project) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) HttpMethod(io.crnk.core.engine.http.HttpMethod) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 9 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter 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 10 with QuerySpecAdapter

use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.

the class AbstractIncludeBehaviorTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
    super.setup();
    ResourceRepositoryAdapter hierarchicalTaskRepository = resourceRegistry.findEntry(HierarchicalTask.class).getResourceRepository(null);
    h = new HierarchicalTask();
    h.setId(1L);
    h.setName("");
    h0 = new HierarchicalTask();
    h0.setId(2L);
    h0.setName("0");
    h0.setParent(h);
    h1 = new HierarchicalTask();
    h1.setId(3L);
    h1.setName("1");
    h1.setParent(h);
    h11 = new HierarchicalTask();
    h11.setId(4L);
    h11.setName("11");
    h11.setParent(h1);
    h.setChildren(Arrays.asList(h0, h1));
    h0.setChildren(new ArrayList<HierarchicalTask>());
    h1.setChildren(Arrays.asList(h11));
    h11.setChildren(new ArrayList<HierarchicalTask>());
    QueryAdapter emptyQueryAdapter = new QuerySpecAdapter(new QuerySpec(HierarchicalTask.class), resourceRegistry);
    hierarchicalTaskRepository.create(h, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h0, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h1, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h11, emptyQueryAdapter);
}
Also used : HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Before(org.junit.Before)

Aggregations

QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)48 QuerySpec (io.crnk.core.queryspec.QuerySpec)32 Test (org.junit.Test)25 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)15 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)13 Task (io.crnk.core.mock.models.Task)11 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)11 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)11 Document (io.crnk.core.engine.document.Document)10 Resource (io.crnk.core.engine.document.Resource)8 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)8 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)7 Before (org.junit.Before)7 Relationship (io.crnk.core.engine.document.Relationship)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 Project (io.crnk.core.mock.models.Project)6 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 Response (io.crnk.core.engine.dispatcher.Response)4 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4