Search in sources :

Example 66 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID 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)

Example 67 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class DataSetController method updateCustomDataEntryFormHtml.

@RequestMapping(value = { "/{uid}/customDataEntryForm", "/{uid}/form" }, method = { RequestMethod.PUT, RequestMethod.POST }, consumes = TEXT_HTML_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateCustomDataEntryFormHtml(@PathVariable("uid") String uid, @RequestBody String formContent, HttpServletResponse response) throws Exception {
    DataSet dataSet = dataSetService.getDataSet(uid);
    if (dataSet == null) {
        throw new WebMessageException(notFound("DataSet not found for uid: " + uid));
    }
    DataEntryForm form = dataSet.getDataEntryForm();
    if (form == null) {
        form = new DataEntryForm(dataSet.getName(), DisplayDensity.NORMAL, formContent);
        dataEntryFormService.addDataEntryForm(form);
        dataSet.setDataEntryForm(form);
    } else {
        form.setHtmlCode(formContent);
        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) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID 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)

Example 69 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class FileResourceController method getFileResource.

@GetMapping(value = "/{uid}")
public FileResource getFileResource(@PathVariable String uid, @RequestParam(required = false) ImageFileDimension dimension) throws WebMessageException {
    FileResource fileResource = fileResourceService.getFileResource(uid);
    if (fileResource == null) {
        throw new WebMessageException(notFound(FileResource.class, uid));
    }
    FileResourceUtils.setImageFileDimensions(fileResource, MoreObjects.firstNonNull(dimension, ImageFileDimension.ORIGINAL));
    return fileResource;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) FileResource(org.hisp.dhis.fileresource.FileResource) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 70 with UID

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.

the class ProgramStageValidationStrategyTest method createDefaultEvent.

private Event createDefaultEvent(DataValue... dataValues) {
    final String uid = CodeGenerator.generateUid();
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    event.getDataValues().addAll(Arrays.asList(dataValues));
    event.setUid(uid);
    event.setEvent(uid);
    return event;
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 Event (org.hisp.dhis.dxf2.events.event.Event)39 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)34 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)29 GetMapping (org.springframework.web.bind.annotation.GetMapping)28 User (org.hisp.dhis.user.User)23 Test (org.junit.jupiter.api.Test)21 HashMap (java.util.HashMap)19 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)19 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)19 InputStream (java.io.InputStream)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)18 ArrayList (java.util.ArrayList)17 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 List (java.util.List)16 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)15