use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class GeoFeatureController method getGeoFeaturesJsonP.
@RequestMapping(method = RequestMethod.GET, produces = { "application/javascript" })
public void getGeoFeaturesJsonP(@RequestParam String ou, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @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 = getGeoFeatures(ou, displayProperty, relativePeriodDate, userOrgUnit, request, response, includeGroupSets, apiVersion);
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 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, 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.filter(ProgramDataElementDimensionItem.class, programDataElements, fields));
return rootNode;
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class LockExceptionController method getLockExceptions.
// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptions(@RequestParam(required = false) String key, @RequestParam Map<String, String> rpParameters, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<LockException> lockExceptions = new ArrayList<>();
if (key != null) {
LockException lockException = dataSetService.getLockException(MathUtils.parseInt(key));
if (lockException == null) {
throw new WebMessageException(WebMessageUtils.notFound("Cannot find LockException with key: " + key));
}
lockExceptions.add(lockException);
} else if (!filters.isEmpty()) {
lockExceptions = dataSetService.filterLockExceptions(filters);
} else {
lockExceptions = dataSetService.getAllLockExceptions();
}
WebOptions options = new WebOptions(rpParameters);
WebMetadata metadata = new WebMetadata();
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), lockExceptions.size(), options.getPageSize());
lockExceptions = PagerUtils.pageCollection(lockExceptions, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(LockException.class, lockExceptions, fields));
return rootNode;
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class DataElementGroupController method getOperandsByQuery.
@RequestMapping(value = "/{uid}/operands/query/{q}", method = RequestMethod.GET)
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList();
for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
dataElementOperands.add(dataElementOperand);
}
}
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class EventController method getEvents.
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public RootNode getEvents(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
WebOptions options = new WebOptions(parameters);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, eventIds, null, null, includeDeleted);
Events events = eventService.getEvents(params);
if (hasHref(fields)) {
events.getEvents().forEach(e -> e.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + e.getEvent()));
}
if (!skipMeta && params.getProgram() != null) {
events.setMetaData(getMetaData(params.getProgram()));
}
model.addAttribute("model", events);
model.addAttribute("viewClass", options.getViewClass("detailed"));
RootNode rootNode = NodeUtils.createMetadata();
if (events.getPager() != null) {
rootNode.addChild(NodeUtils.createPager(events.getPager()));
}
if (!StringUtils.isEmpty(attachment)) {
response.addHeader(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + attachment);
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
}
rootNode.addChild(fieldFilterService.filter(Event.class, events.getEvents(), fields));
return rootNode;
}
Aggregations