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