Search in sources :

Example 1 with TranslateParams

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);
}
Also used : User(org.hisp.dhis.user.User) TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with TranslateParams

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;
}
Also used : User(org.hisp.dhis.user.User) TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams)

Example 3 with TranslateParams

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());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with TranslateParams

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();
    }
}
Also used : TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with TranslateParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)9 TranslateParams (org.hisp.dhis.dxf2.common.TranslateParams)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 DataSet (org.hisp.dhis.dataset.DataSet)5 User (org.hisp.dhis.user.User)5 Pager (org.hisp.dhis.common.Pager)4 ReadAccessDeniedException (org.hisp.dhis.hibernate.exception.ReadAccessDeniedException)4 Period (org.hisp.dhis.period.Period)4 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)4 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 RootNode (org.hisp.dhis.node.types.RootNode)3 Enums (com.google.common.base.Enums)2 Joiner (com.google.common.base.Joiner)2 Optional (com.google.common.base.Optional)2 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2