Search in sources :

Example 41 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class MdsRestFacadeTest method shouldAppendMetadataWhenExecutingLookup.

@Test
public void shouldAppendMetadataWhenExecutingLookup() {
    when(dataService.countSupportedLookup(anyString(), anyInt())).thenReturn(81l);
    Map<String, String> lookupMap = asLookupMap(null, "44");
    QueryParams queryParams = new QueryParams(5, 20, new Order("value", Order.Direction.DESC));
    when(dataService.supportedLookup(null, 44, queryParams)).thenReturn(asList(recordOne));
    RestResponse result = (RestResponse) mdsRestFacade.executeLookup(SUPPORTED_LOOKUP_NAME, lookupMap, queryParams, false);
    assertNotNull(result.getMetadata());
    assertEquals(ENTITY_NAME, result.getMetadata().getEntity());
    assertEquals(TEST_MODULE, result.getMetadata().getModule());
    assertEquals(Record.class.getName(), result.getMetadata().getClassName());
    assertEquals(NAMESPACE, result.getMetadata().getNamespace());
    assertEquals(5, result.getMetadata().getPage());
    assertEquals(20, result.getMetadata().getPageSize());
    assertEquals(81l, result.getMetadata().getTotalCount());
}
Also used : Order(org.motechproject.mds.util.Order) QueryParams(org.motechproject.mds.query.QueryParams) Record(org.motechproject.mds.testutil.records.Record) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 42 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class MdsRestFacadeTest method shouldAppendMetadata.

@Test
public void shouldAppendMetadata() {
    setUpCrudAccess(false, true, false, false);
    when(dataService.count()).thenReturn(81l);
    QueryParams queryParams = new QueryParams(5, 20, new Order("value", Order.Direction.DESC));
    RestResponse result = mdsRestFacade.get(queryParams, false);
    assertNotNull(result.getMetadata());
    assertEquals(ENTITY_NAME, result.getMetadata().getEntity());
    assertEquals(TEST_MODULE, result.getMetadata().getModule());
    assertEquals(Record.class.getName(), result.getMetadata().getClassName());
    assertEquals(NAMESPACE, result.getMetadata().getNamespace());
    assertEquals(5, result.getMetadata().getPage());
    assertEquals(20, result.getMetadata().getPageSize());
    assertEquals(81l, result.getMetadata().getTotalCount());
}
Also used : Order(org.motechproject.mds.util.Order) QueryParams(org.motechproject.mds.query.QueryParams) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Example 43 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class ActivityController method getAllActivities.

/**
 * Returns the list of all the task activities.
 *
 * @return the list of activities
 */
@RequestMapping(value = "/activity/all", method = RequestMethod.GET)
@ResponseBody
public TaskActivityRecords getAllActivities(GridSettings settings) {
    if (settings != null) {
        QueryParams params = getParams(settings);
        Set<TaskActivityType> types = settings.getTypesFromString();
        Range<DateTime> dateTimeRange = settings.convertToDateRange(settings.getDateTimeFrom(), settings.getDateTimeTo());
        List<TaskActivityDto> activities;
        long count;
        if (dateTimeRange != null) {
            activities = taskWebService.getAllActivities(types, dateTimeRange, params, settings.isLastExecution());
            count = activityService.getAllTaskActivitiesCount(types, dateTimeRange, settings.isLastExecution());
        } else {
            activities = taskWebService.getAllActivities(types, params, settings.isLastExecution());
            count = activityService.getAllTaskActivitiesCount(types, settings.isLastExecution());
        }
        int totalPages = (int) Math.ceil((double) count / settings.getRows());
        return new TaskActivityRecords(settings.getPage(), totalPages, count, activities);
    } else {
        return null;
    }
}
Also used : TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) TaskActivityDto(org.motechproject.tasks.dto.TaskActivityDto) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 44 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class TaskActivitiesDataServiceBundleIT method shouldReturnLatestRecordsOrderedByDate.

@Test
public void shouldReturnLatestRecordsOrderedByDate() {
    setUpActivityRecords();
    List<TaskActivity> allActivities = taskActivitiesDataService.retrieveAll();
    List<TaskActivity> activities = taskActivitiesDataService.retrieveAll(new QueryParams(1, 10, new Order("date", Order.Direction.DESC)));
    // There should always be only 10 records returned
    assertEquals(10, activities.size());
    // The first activity should have the most recent one
    DateTime mostRecentDate = new DateTime(0);
    for (TaskActivity activity : allActivities) {
        if (activity.getDate().isAfter(mostRecentDate)) {
            mostRecentDate = activity.getDate();
        }
    }
    assertEquals(mostRecentDate, activities.get(0).getDate());
    // All recent activities should be sorted by date
    for (int i = 1; i < 10; i++) {
        assertTrue(activities.get(i - 1).getDate().isAfter(activities.get(i).getDate()));
    }
}
Also used : Order(org.motechproject.mds.util.Order) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) QueryParams(org.motechproject.mds.query.QueryParams) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 45 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class EmailController method prepareCriteria.

private EmailRecordSearchCriteria prepareCriteria(GridSettings filter) {
    EmailRecordSearchCriteria criteria = new EmailRecordSearchCriteria();
    DateTime from = StringUtils.isBlank(filter.getTimeFrom()) ? null : DateTimeFormat.forPattern("Y-MM-dd HH:mm:ss").parseDateTime(filter.getTimeFrom());
    DateTime to = StringUtils.isBlank(filter.getTimeTo()) ? null : DateTimeFormat.forPattern("Y-MM-dd HH:mm:ss").parseDateTime(filter.getTimeTo());
    criteria.withMessageTimeRange(new Range<>(from, to));
    if (filter.getDeliveryStatusFromSettings() != null && (!filter.getDeliveryStatusFromSettings().isEmpty())) {
        criteria = criteria.withDeliveryStatuses(filter.getDeliveryStatusFromSettings());
    }
    Order sortOrder = new Order(filter.getSidx(), filter.getSord());
    QueryParams queryParams = new QueryParams(filter.getPage(), filter.getRows(), sortOrder);
    criteria.withQueryParams(queryParams);
    criteria.withSubject(filter.getSubject());
    criteria.withToAddress(filter.getSubject());
    criteria.withFromAddress(filter.getSubject());
    criteria.withMessage(filter.getSubject());
    return criteria;
}
Also used : Order(org.motechproject.mds.util.Order) QueryParams(org.motechproject.mds.query.QueryParams) EmailRecordSearchCriteria(org.motechproject.email.builder.EmailRecordSearchCriteria) DateTime(org.joda.time.DateTime)

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