use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyIgnoreNegativePage.
@Test
void verifyIgnoreNegativePage() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "true");
options.put(WebOptions.PAGE, "-2");
options.put(WebOptions.PAGE_SIZE, "200");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(200));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyPaginationIsDisabled.
@Test
void verifyPaginationIsDisabled() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "false");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(0));
assertThat(paginationData.hasPagination(), is(false));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class ProgramDataElementController method getObjectList.
@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
Schema schema = schemaService.getDynamicSchema(ProgramDataElementDimensionItem.class);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<Order> orders = orderParams.getOrders(schema);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
WebOptions options = new WebOptions(rpParameters);
WebMetadata metadata = new WebMetadata();
List<ProgramDataElementDimensionItem> programDataElements;
Query query = queryService.getQueryFromUrl(ProgramDataElementDimensionItem.class, filters, orders, PaginationUtils.getPaginationData(options), options.getRootJunction());
query.setDefaultOrder();
if (options.contains("program")) {
String programUid = options.get("program");
programDataElements = programService.getGeneratedProgramDataElements(programUid);
query.setObjects(programDataElements);
}
programDataElements = (List<ProgramDataElementDimensionItem>) queryService.query(query);
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), programDataElements.size(), options.getPageSize());
programDataElements = PagerUtils.pageCollection(programDataElements, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.toCollectionNode(ProgramDataElementDimensionItem.class, new FieldFilterParams(programDataElements, fields)));
return rootNode;
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class GeoFeatureController method getGeoFeaturesJsonP.
@GetMapping(produces = "application/javascript")
public void getGeoFeaturesJsonP(@RequestParam(required = false) String ou, @RequestParam(required = false) String oug, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(required = false) String coordinateField, @RequestParam(defaultValue = "callback") String callback, @RequestParam(defaultValue = "false", value = "includeGroupSets") boolean rpIncludeGroupSets, @RequestParam Map<String, String> parameters, DhisApiVersion apiVersion, HttpServletRequest request, HttpServletResponse response) throws IOException {
WebOptions options = new WebOptions(parameters);
boolean includeGroupSets = "detailed".equals(options.getViewClass()) || rpIncludeGroupSets;
List<GeoFeature> features = geoFeatureService.getGeoFeatures(GeoFeatureService.Parameters.builder().apiVersion(apiVersion).displayProperty(displayProperty).includeGroupSets(includeGroupSets).request(request).response(response).userOrgUnit(userOrgUnit).organisationUnitGroupId(oug).relativePeriodDate(relativePeriodDate).coordinateField(coordinateField).build());
if (features == null) {
return;
}
ContextUtils.setCacheControl(response, GEOFEATURE_CACHE);
response.setContentType("application/javascript");
renderService.toJsonP(response.getOutputStream(), features, callback);
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class AbstractCrudController method getObjectInternal.
@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User user) throws Exception {
WebOptions options = new WebOptions(parameters);
List<T> entities = getEntity(uid, options);
if (entities.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(getEntityClass(), uid));
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), options.getRootJunction());
query.setUser(user);
query.setObjects(entities);
entities = (List<T>) queryService.query(query);
handleLinksAndAccess(entities, fields, true, user);
for (T entity : entities) {
postProcessEntity(entity);
postProcessEntity(entity, options, parameters);
}
CollectionNode collectionNode = fieldFilterService.filter(getEntityClass(), entities, fields);
if (options.isTrue("useWrapper") || entities.size() > 1) {
RootNode rootNode = NodeUtils.createMetadata(collectionNode);
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
} else {
List<Node> children = collectionNode.getChildren();
RootNode rootNode;
if (!children.isEmpty()) {
rootNode = NodeUtils.createRootNode(children.get(0));
} else {
rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
}
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
}
}
Aggregations