Search in sources :

Example 1 with ApiVersion

use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method postCompleteRegistrationsXml.

// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_XML)
public void postCompleteRegistrationsXml(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_XML, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_XML);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsXml(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toXml(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ApiVersion

use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.

// Legacy (<= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, produces = "text/plain")
public void saveCompleteDataSetRegistration(@RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) Date cd, @RequestParam(required = false) String sb, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
    DataSet dataSet = dataSetService.getDataSet(ds);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
    }
    Period period = PeriodType.getPeriodFromIsoString(pe);
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
    }
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
    if (organisationUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
    }
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    if (attributeOptionCombo == null) {
        return;
    }
    if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
    }
    // ---------------------------------------------------------------------
    // Register as completed data set
    // ---------------------------------------------------------------------
    Set<OrganisationUnit> children = organisationUnit.getChildren();
    String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
    Date completionDate = (cd == null) ? new Date() : cd;
    List<CompleteDataSetRegistration> registrations = new ArrayList<>();
    if (!multiOu) {
        CompleteDataSetRegistration completeDataSetRegistration = registerCompleteDataSet(dataSet, period, organisationUnit, attributeOptionCombo, storedBy, completionDate);
        if (completeDataSetRegistration != null) {
            registrations.add(completeDataSetRegistration);
        }
    } else {
        addRegistrationsForOrgUnits(registrations, Sets.union(children, Sets.newHashSet(organisationUnit)), dataSet, period, attributeOptionCombo, storedBy, completionDate);
    }
    registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ApiVersion

use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrationsJson.

// Legacy (>= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getCompleteDataSetRegistrationsJson(@RequestParam Set<String> dataSet, @RequestParam(required = false) String period, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> orgUnit, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
        List<String> defaults = new ArrayList<>();
        defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id],attributeOptionCombo[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    response.setContentType(CONTENT_TYPE_JSON);
    CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations(dataSet, period, startDate, endDate, orgUnit, children);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(CompleteDataSetRegistration.class, completeDataSetRegistrations.getCompleteDataSetRegistrations(), fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ApiVersion

use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method postCompleteRegistrationsJson.

@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_JSON)
public void postCompleteRegistrationsJson(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_JSON, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_JSON);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsJson(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toJson(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ApiVersion

use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.

the class DataSetController method updateCustomDataEntryFormJson.

@PostMapping(value = "/{uid}/form", consumes = APPLICATION_JSON_VALUE)
@ApiVersion(value = DhisApiVersion.ALL)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateCustomDataEntryFormJson(@PathVariable("uid") String uid, HttpServletRequest request) throws WebMessageException {
    DataSet dataSet = dataSetService.getDataSet(uid);
    if (dataSet == null) {
        throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
    }
    DataEntryForm form = dataSet.getDataEntryForm();
    DataEntryForm newForm;
    try {
        newForm = renderService.fromJson(request.getInputStream(), DataEntryForm.class);
    } catch (IOException e) {
        throw new WebMessageException(badRequest("Failed to parse request", e.getMessage()));
    }
    if (form == null) {
        if (!newForm.hasForm()) {
            throw new WebMessageException(badRequest("Missing required parameter 'htmlCode'"));
        }
        newForm.setName(dataSet.getName());
        dataEntryFormService.addDataEntryForm(newForm);
        dataSet.setDataEntryForm(newForm);
    } else {
        if (newForm.getHtmlCode() != null) {
            form.setHtmlCode(dataEntryFormService.prepareDataEntryFormForSave(newForm.getHtmlCode()));
        }
        if (newForm.getStyle() != null) {
            form.setStyle(newForm.getStyle());
        }
        dataEntryFormService.updateDataEntryForm(form);
    }
    dataSet.increaseVersion();
    dataSetService.updateDataSet(dataSet);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) IOException(java.io.IOException) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ArrayList (java.util.ArrayList)3 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)3 DataSet (org.hisp.dhis.dataset.DataSet)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Period (org.hisp.dhis.period.Period)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 CompleteDataSetRegistrationRequest (org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest)1 DataEntryForm (org.hisp.dhis.dataentryform.DataEntryForm)1