Search in sources :

Example 11 with TranslateParams

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);
}
Also used : 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) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with TranslateParams

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CategoryCombo(org.hisp.dhis.category.CategoryCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataSetElement(org.hisp.dhis.dataset.DataSetElement) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with TranslateParams

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

Example 14 with TranslateParams

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());
}
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 15 with TranslateParams

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

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