use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class TriggerEventServiceImplTest method shouldGetStaticTriggers.
@Test
public void shouldGetStaticTriggers() throws Exception {
int page = 1;
int pageSize = 10;
List<TriggerEvent> expectedTriggers = prepareTriggers();
QueryParams params = new QueryParams(page, pageSize);
when(triggerEventsDataService.byChannelModuleName(MODULE_NAME, params)).thenReturn(expectedTriggers);
List<TriggerEvent> triggers = triggerEventService.getStaticTriggers(MODULE_NAME, page, pageSize);
verify(triggerEventsDataService, times(1)).byChannelModuleName(eq(MODULE_NAME), eq(params));
assertEquals(expectedTriggers, triggers);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class ActivityControllerTest method setup.
@Before
public void setup() throws Exception {
initMocks(this);
controller = new ActivityController(activityService, taskTriggerHandler, taskWebService);
params = new HashMap<String, Object>();
params.put("errorKey", "errorValue");
expected = new ArrayList<>();
expected.add(new TaskActivityDto(SUCCESS.getValue(), TASK_ID, SUCCESS));
expected.add(new TaskActivityDto(WARNING.getValue(), TASK_ID, WARNING));
expected.add(new TaskActivityDto(ERROR.getValue(), TASK_ID, ERROR));
expected.add(new TaskActivityDto(ACTIVITY_ID, ERROR.getValue(), TASK_ID, new ArrayList<>(), null, ERROR, null, params));
activityTypes = new HashSet<>();
activityTypes.addAll(Arrays.asList(TaskActivityType.values()));
queryParams = new QueryParams(page, pageSize);
task = new Task();
task.setId(TASK_ID);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestFacadeImpl method executeLookup.
@Override
@Transactional
public Object executeLookup(String lookupName, Map<String, String> lookupMap, QueryParams queryParams, boolean includeBlob) {
if (lookupExecutors.containsKey(lookupName)) {
LookupExecutor executor = lookupExecutors.get(lookupName);
Object result = executor.execute(lookupMap, queryParams);
if (result instanceof Collection) {
if (includeBlob) {
for (T value : ((Collection<T>) result)) {
getBlobs(value);
}
}
return new RestResponse(entityName, entityClass.getName(), moduleName, namespace, executor.executeCount(lookupMap), queryParams, RestProjection.createProjectionCollection((Collection) result, restFields, blobFields));
} else {
if (result == null) {
throw new RestNoLookupResultException("No result for lookup:" + lookupName);
}
if (includeBlob) {
getBlobs((T) result);
}
return new RestResponse(entityName, entityClass.getName(), moduleName, namespace, 1l, new QueryParams(1, 1), RestProjection.createProjection(result, restFields, blobFields));
}
} else if (forbiddenLookupMethodNames.contains(lookupName)) {
throw new RestLookupExecutionForbiddenException(lookupName);
} else {
throw new RestLookupNotFoundException(lookupName);
}
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class ParamParser method buildQueryParams.
public static QueryParams buildQueryParams(Map<String, String> requestParams) {
Integer page;
Integer pageSize;
String sortBy;
String orderDir;
Order order;
try {
page = getInteger(requestParams, PAGE, 1);
} catch (NumberFormatException e) {
throw new InvalidParameterException("Given page is not a number!", e);
}
try {
pageSize = getInteger(requestParams, PAGE_SIZE, 20);
} catch (NumberFormatException e) {
throw new InvalidParameterException("Given page size is not a number!", e);
}
sortBy = requestParams.get(SORT_BY);
orderDir = requestParams.get(ORDER_DIR);
order = buildOrder(sortBy, orderDir);
return new QueryParams(page, pageSize, order);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceController method exportEntityInstances.
@RequestMapping(value = "/entities/{entityId}/exportInstances", method = RequestMethod.GET)
public void exportEntityInstances(@PathVariable Long entityId, GridSettings settings, @RequestParam String exportRecords, @RequestParam String outputFormat, HttpServletResponse response) throws IOException {
if (!Constants.ExportFormat.isValidFormat(outputFormat)) {
throw new IllegalArgumentException("Invalid export format: " + outputFormat);
}
instanceService.verifyEntityAccess(entityId);
final String fileName = "Entity_" + entityId + "_instances";
response.setContentType("text/csv");
response.setCharacterEncoding(UTF_8);
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + "." + outputFormat.toLowerCase());
final Integer pageSize = StringUtils.equalsIgnoreCase(exportRecords, "all") ? null : Integer.valueOf(exportRecords);
final Map<String, Object> fieldMap = getFields(settings);
QueryParams queryParams = new QueryParams(1, pageSize, QueryParamsBuilder.buildOrderList(settings, fieldMap));
if (Constants.ExportFormat.PDF.equals(outputFormat)) {
csvImportExportService.exportPdf(entityId, response.getOutputStream(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap);
} else {
csvImportExportService.exportCsv(entityId, response.getWriter(), settings.getLookup(), queryParams, settings.getSelectedFields(), fieldMap);
}
}
Aggregations