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