use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class LookupExecutorTest method shouldExecuteALookupWithQueryParams.
@Test
public void shouldExecuteALookupWithQueryParams() {
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put(STR_FIELD_NAME, STR_ARG);
lookupMap.put(INT_FIELD_NAME, INT_ARG);
lookupMap.put(TEXTAREA_FIELD_NAME, TEXTAREA_ARG);
QueryParams queryParams = new QueryParams(PAGE, PAGE_SIZE, new Order(SORT_FIELD, DIRECTION));
List result = (List) lookupExecutor1.execute(lookupMap, queryParams);
assertEquals(dataService.find(STR_ARG, INT_ARG, TEXTAREA_ARG, queryParams), result);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestController method doGet.
private Object doGet(String entityName, String moduleName, String namespace, Map<String, String> requestParams, String pathLookupName) {
debugRequest("GET", entityName, moduleName, namespace);
QueryParams queryParams = ParamParser.buildQueryParams(requestParams);
Long id = ParamParser.getId(requestParams);
// we have 2 endpoints for lookups, in one the name comes from the path in the second its in the params
String lookupName = StringUtils.isNotBlank(pathLookupName) ? pathLookupName : ParamParser.getLookupName(requestParams);
MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
Boolean includeBlob = ParamParser.getIncludeBlob(requestParams);
if (lookupName != null) {
// lookup
return restFacade.executeLookup(lookupName, requestParams, queryParams, includeBlob != null && includeBlob);
} else if (id != null) {
// retrieve by id
return restFacade.get(id, includeBlob == null || includeBlob);
} else {
// get records
return restFacade.get(queryParams, includeBlob != null && includeBlob);
}
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceControllerTest method shouldExportInstancesWithAdditionalOptionsAsCsv.
@Test
public void shouldExportInstancesWithAdditionalOptionsAsCsv() throws Exception {
when(response.getWriter()).thenReturn(writer);
ArgumentCaptor<QueryParams> queryParamsCaptor = ArgumentCaptor.forClass(QueryParams.class);
ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
GridSettings gridSettings = new GridSettings();
gridSettings.setSortColumn("sortColumn");
gridSettings.setSortDirection("asc");
gridSettings.setSelectedFields(asList("id", "date"));
gridSettings.setLookup("lookup");
instanceController.exportEntityInstances(1L, gridSettings, "50", "csv", response);
verify(instanceService).verifyEntityAccess(1L);
verify(csvImportExportService).exportCsv(eq(1L), eq(writer), eq("lookup"), queryParamsCaptor.capture(), listCaptor.capture(), any(Map.class));
verify(response).setContentType("text/csv");
verify(response).setHeader("Content-Disposition", "attachment; filename=Entity_1_instances.csv");
QueryParams captorValue = queryParamsCaptor.getValue();
assertEquals(Order.Direction.ASC, captorValue.getOrderList().get(0).getDirection());
assertEquals("sortColumn", captorValue.getOrderList().get(0).getField());
assertEquals(Integer.valueOf(1), captorValue.getPage());
assertEquals(Integer.valueOf(50), captorValue.getPageSize());
assertEquals(2, listCaptor.getValue().size());
assertTrue(listCaptor.getValue().contains("id"));
assertTrue(listCaptor.getValue().contains("date"));
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class TaskActivityServiceImplTest method shouldReturnPaginatedActivitiesForGivenTask.
@Test
public void shouldReturnPaginatedActivitiesForGivenTask() {
Set<TaskActivityType> types = new HashSet<>();
types.addAll(Arrays.asList(TaskActivityType.values()));
Set<Long> activitiesIds = new HashSet<>();
QueryParams queryParams = new QueryParams((Order) null);
boolean lastExecution = false;
when(taskActivitiesDataService.byTaskAndActivityTypesAndIds(TASK_ID, types, activitiesIds, queryParams)).thenReturn(activities);
List<TaskActivity> actual = activityService.getTaskActivities(TASK_ID, types, queryParams, lastExecution);
assertNotNull(actual);
assertEquals(activities, actual);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class ActionParametersBundleIT method hasTaskExecuted.
private boolean hasTaskExecuted(Long taskID) {
Set<TaskActivityType> activityTypes = new HashSet<>();
Set<Long> activityIds = new HashSet<>();
activityTypes.add(TaskActivityType.SUCCESS);
QueryParams queryParams = new QueryParams((Order) null);
List<TaskActivity> taskActivities = taskActivitiesDataService.byTaskAndActivityTypesAndIds(taskID, activityTypes, activityIds, queryParams);
return taskActivities.size() == 1;
}
Aggregations