use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceController method getTrash.
@RequestMapping(value = "/entities/{entityId}/trash", method = RequestMethod.GET)
@ResponseBody
public Records<BasicEntityRecord> getTrash(@PathVariable Long entityId, GridSettings settings) {
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(settings);
List<BasicEntityRecord> trashRecordsList = instanceService.getTrashRecords(entityId, queryParams);
long recordCount = instanceService.countTrashRecords(entityId);
int rowCount = (int) Math.ceil(recordCount / (double) queryParams.getPageSize());
Records<BasicEntityRecord> records = new Records<>(queryParams.getPage(), rowCount, (int) recordCount, trashRecordsList);
processFieldsForUI(records);
return records;
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceController method getHistory.
@RequestMapping(value = "/instances/{entityId}/{instanceId}/history", method = RequestMethod.GET)
@ResponseBody
public Records<BasicHistoryRecord> getHistory(@PathVariable Long entityId, @PathVariable Long instanceId, GridSettings settings) {
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(settings);
List<BasicHistoryRecord> historyRecordsList = instanceService.getInstanceHistory(entityId, instanceId, queryParams);
long recordCount = instanceService.countHistoryRecords(entityId, instanceId);
int rowCount = (int) Math.ceil(recordCount / (double) queryParams.getPageSize());
Records<BasicHistoryRecord> records = new Records<>(queryParams.getPage(), rowCount, (int) recordCount, historyRecordsList);
processFieldsForUIinHistoryRecords(records);
return records;
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestControllerTest method verifyLookupExecution.
private void verifyLookupExecution() {
ArgumentCaptor<Map> lookupMapCaptor = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<QueryParams> queryParamsCaptor = ArgumentCaptor.forClass(QueryParams.class);
verify(restFacade).executeLookup(eq(LOOKUP_NAME), lookupMapCaptor.capture(), queryParamsCaptor.capture(), anyBoolean());
Map lookupMap = lookupMapCaptor.getValue();
assertEquals("something", lookupMap.get("strField"));
assertEquals("3", lookupMap.get("intField"));
verifyQueryParams(queryParamsCaptor.getValue());
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestControllerTest method testListReturnLookup.
private void testListReturnLookup(String entityName, String moduleName, String namespace, boolean lookupNameInPath) throws Exception {
final TestRecord record1 = new TestRecord("T1", 5);
final TestRecord record2 = new TestRecord("T2", 5);
final List<TestRecord> records = asList(record1, record2);
List<String> fields = new ArrayList<>();
fields.add(NAME_FIELD);
fields.add(VAL_FIELD);
final RestResponse response = new RestResponse(entityName, CLASSNAME, moduleName, namespace, 2l, new QueryParams(5, 14), RestProjection.createProjectionCollection(records, fields, new ArrayList<String>()));
when(restFacadeRetriever.getRestFacade(entityName, moduleName, namespace)).thenReturn(restFacade);
when(restFacade.executeLookup(eq(LOOKUP_NAME), any(Map.class), any(QueryParams.class), anyBoolean())).thenReturn(response);
String url;
if (lookupNameInPath) {
url = buildUrl(entityName, moduleName, namespace, LOOKUP_NAME) + "?" + LOOKUP_PAGINATION_STR;
} else {
url = buildUrl(entityName, moduleName, namespace) + "?lookup=" + LOOKUP_NAME + "&" + LOOKUP_PAGINATION_STR;
}
mockMvc.perform(get(url)).andExpect(status().isOk()).andExpect(content().string(objectMapper.writeValueAsString(response)));
verifyLookupExecution();
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class ParamParserTest method shouldBuildQueryParams.
@Test
public void shouldBuildQueryParams() {
Map<String, String> requestParams = new HashMap<>();
requestParams.put("page", "14");
requestParams.put("pageSize", "120");
requestParams.put("sort", "someColumn");
requestParams.put("order", "desc");
QueryParams queryParams = ParamParser.buildQueryParams(requestParams);
assertEquals(Integer.valueOf(14), queryParams.getPage());
assertEquals(Integer.valueOf(120), queryParams.getPageSize());
assertNotNull(queryParams.getOrderList());
assertEquals(1, queryParams.getOrderList().size());
assertEquals("someColumn", queryParams.getOrderList().get(0).getField());
assertEquals(Order.Direction.DESC, queryParams.getOrderList().get(0).getDirection());
// null order
requestParams.remove("sort");
requestParams.remove("order");
queryParams = ParamParser.buildQueryParams(requestParams);
assertTrue(queryParams.getOrderList().isEmpty());
// default order direction
requestParams.put("sort", "anotherColumn");
queryParams = ParamParser.buildQueryParams(requestParams);
assertNotNull(queryParams.getOrderList());
assertEquals(1, queryParams.getOrderList().size());
assertEquals("anotherColumn", queryParams.getOrderList().get(0).getField());
assertEquals(Order.Direction.ASC, queryParams.getOrderList().get(0).getDirection());
}
Aggregations