Search in sources :

Example 21 with QueryParams

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);
}
Also used : Order(org.motechproject.mds.util.Order) HashMap(java.util.HashMap) QueryParams(org.motechproject.mds.query.QueryParams) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 22 with QueryParams

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);
    }
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) QueryParams(org.motechproject.mds.query.QueryParams)

Example 23 with QueryParams

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"));
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) GridSettings(org.motechproject.mds.web.domain.GridSettings) Map(java.util.Map) Test(org.junit.Test)

Example 24 with QueryParams

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);
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with QueryParams

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;
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet)

Aggregations

QueryParams (org.motechproject.mds.query.QueryParams)48 Test (org.junit.Test)27 Order (org.motechproject.mds.util.Order)14 ArrayList (java.util.ArrayList)8 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DateTime (org.joda.time.DateTime)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Arrays.asList (java.util.Arrays.asList)5 List (java.util.List)5 Map (java.util.Map)4 Records (org.motechproject.mds.web.domain.Records)4 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)4 HashSet (java.util.HashSet)3 Matchers.anyString (org.mockito.Matchers.anyString)3 EntityDto (org.motechproject.mds.dto.EntityDto)3 RestResponse (org.motechproject.mds.rest.RestResponse)3 TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)3 TaskActivityDto (org.motechproject.tasks.dto.TaskActivityDto)3 JsonObject (com.google.gson.JsonObject)2