use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class AbstractCrudController method getObjectProperty.
@RequestMapping(value = "/{uid}/{property}", method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectProperty(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @RequestParam Map<String, String> rpParameters, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
if (!"translations".equals(pvProperty)) {
setUserContext(user, translateParams);
} else {
setUserContext(null, new TranslateParams(false));
}
if (!aclService.canRead(user, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
String fieldFilter = "[" + Joiner.on(',').join(fields) + "]";
return getObjectInternal(pvUid, rpParameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + fieldFilter), user);
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class TranslationInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
boolean translate = !"false".equals(request.getParameter(PARAM_TRANSLATE));
String locale = request.getParameter(PARAM_LOCALE);
User user = currentUserService.getCurrentUser();
setUserContext(user, new TranslateParams(translate, locale));
return true;
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataElementGroupController method getOperands.
@GetMapping("/{uid}/operands")
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, 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(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
Collections.sort(dataElementOperands);
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 AbstractFullReadOnlyController method getObjectProperty.
@GetMapping("/{uid}/{property}")
@ResponseBody
public RootNode getObjectProperty(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @RequestParam Map<String, String> rpParameters, TranslateParams translateParams, @CurrentUser User currentUser, HttpServletResponse response) throws Exception {
if (!"translations".equals(pvProperty)) {
setUserContext(currentUser, translateParams);
} else {
setUserContext(null, new TranslateParams(false));
}
try {
if (!aclService.canRead(currentUser, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
String fieldFilter = "[" + Joiner.on(',').join(fields) + "]";
cachePrivate(response);
return getObjectInternal(pvUid, rpParameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + fieldFilter), currentUser);
} finally {
UserContext.reset();
}
}
use of org.hisp.dhis.dxf2.common.TranslateParams in project dhis2-core by dhis2.
the class DataSetController method getFormJson.
@GetMapping(value = "/{uid}/form", produces = APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Form getFormJson(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnit, @RequestParam(value = "pe", required = false) String period, @RequestParam(value = "categoryOptions", required = false) String categoryOptions, @RequestParam(required = false) boolean metaData, TranslateParams translateParams) 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);
return getForm(dataSets, ou, pe, categoryOptions, metaData);
}
Aggregations