use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getDvs.
@GetMapping("/{uid}/dataValueSet")
@ResponseBody
public RootNode getDvs(@PathVariable("uid") String uid, @RequestParam(value = "orgUnitIdScheme", defaultValue = "ID", required = false) String orgUnitIdScheme, @RequestParam(value = "dataElementIdScheme", defaultValue = "ID", required = false) String dataElementIdScheme, @RequestParam(value = "period", defaultValue = "", required = false) String period, @RequestParam(value = "orgUnit", defaultValue = "", required = false) List<String> orgUnits, @RequestParam(value = "comment", defaultValue = "true", required = false) boolean comment, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
}
Period pe = periodService.getPeriod(period);
return dataValueSetService.getDataValueSetTemplate(dataSets.get(0), pe, orgUnits, comment, orgUnitIdScheme, dataElementIdScheme);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getCategoryCombinations.
@GetMapping("/{uid}/categoryCombos")
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
setUserContext(translateParams);
DataSet dataSet = manager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(conflict("Data set does not exist: " + uid));
}
List<CategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
Collections.sort(categoryCombos);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
return rootNode;
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getFormXml.
@GetMapping(value = "/{uid}/form", produces = { APPLICATION_XML_VALUE, TEXT_XML_VALUE })
public void getFormXml(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "catOpts", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams, HttpServletResponse response) throws IOException, WebMessageException {
setUserContext(translateParams);
List<DataSet> dataSets = getEntity(uid, NO_WEB_OPTIONS);
if (dataSets.isEmpty()) {
throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
}
OrganisationUnit ou = manager.get(OrganisationUnit.class, orgUnit);
if (ou == null) {
throw new WebMessageException(notFound("Organisation unit does not exist: " + orgUnit));
}
Period pe = PeriodType.getPeriodFromIsoString(period);
Form form = getForm(dataSets, ou, pe, categoryOptions, metaData);
renderService.toXml(response.getOutputStream(), form);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataElementGroupController method getOperandsByQuery.
@GetMapping("/{uid}/operands/query/{q}")
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(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.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class UserContextInterceptor method preHandle.
@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
boolean translate = !"false".equals(request.getParameter(PARAM_TRANSLATE));
String locale = request.getParameter(PARAM_LOCALE);
User user = currentUserService.getCurrentUser();
if (user != null) {
configureUserContext(user, new TranslateParams(translate, locale));
}
return true;
}
Aggregations