Search in sources :

Example 11 with ID

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

the class EnrollmentController method updateEnrollmentJson.

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = enrollmentService.updateEnrollmentJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ID

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

the class EnrollmentController method updateEnrollmentXml.

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = enrollmentService.updateEnrollmentXml(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ID

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

the class EnrollmentController method deleteEnrollment.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteEnrollment(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    if (!programInstanceService.programInstanceExists(id)) {
        throw new WebMessageException(WebMessageUtils.notFound("Enrollment not found for ID " + id));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    ImportSummary importSummary = enrollmentService.deleteEnrollment(id);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ID

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

the class AbstractEnrollmentService method updateEnrollmentForNote.

@Override
public ImportSummary updateEnrollmentForNote(Enrollment enrollment) {
    if (enrollment == null || enrollment.getEnrollment() == null) {
        return new ImportSummary(ImportStatus.ERROR, "No enrollment or enrollment ID was supplied").incrementIgnored();
    }
    ImportSummary importSummary = new ImportSummary(enrollment.getEnrollment());
    ProgramInstance programInstance = programInstanceService.getProgramInstance(enrollment.getEnrollment());
    if (programInstance == null) {
        return new ImportSummary(ImportStatus.ERROR, "Enrollment ID was not valid.").incrementIgnored();
    }
    saveTrackedEntityComment(programInstance, enrollment, currentUserService.getCurrentUser());
    importSummary.setReference(enrollment.getEnrollment());
    importSummary.getImportCount().incrementUpdated();
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Example 15 with ID

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

the class OrganisationUnitSupplier method fetchOu.

private Map<String, OrganisationUnit> fetchOu(IdScheme idScheme, Set<String> orgUnitUids, Multimap<String, String> orgUnitToEvent) {
    String sql = "select ou.organisationunitid, ou.uid, ou.code, ou.name, ou.path, ou.hierarchylevel ";
    if (idScheme.isAttribute()) {
        // 
        // Attribute IdScheme handling: use Postgres JSONB custom clauses to
        // query the
        // "attributvalues" column
        // 
        // The column is expected to contain a JSON structure like so:
        // 
        // {"ie9wfkGw8GX": {"value": "Some value", "attribute": {"id":
        // "ie9wfkGw8GX"}}}
        // 
        // The 'ie9wfkGw8GX' uid is the attribute identifier
        // 
        final String attribute = idScheme.getAttribute();
        sql += ",attributevalues->'" + attribute + "'->>'value' as " + ATTRIBUTESCHEME_COL + " from organisationunit ou where ou.attributevalues#>>'{" + attribute + ",value}' in (:ids)";
    } else {
        sql += "from organisationunit ou where ou." + IdSchemeUtils.getColumnNameByScheme(idScheme, "organisationunitid") + " in (:ids)";
    }
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", orgUnitUids);
    return jdbcTemplate.query(sql, parameters, rs -> {
        Map<String, OrganisationUnit> results = new HashMap<>();
        while (rs.next()) {
            OrganisationUnit ou = mapFromResultSet(rs);
            try {
                for (String event : orgUnitToEvent.get(idScheme.isAttribute() ? rs.getString(ATTRIBUTESCHEME_COL) : getIdentifierBasedOnIdScheme(ou, idScheme))) {
                    results.put(event, ou);
                }
            } catch (Exception e) {
                throw new UnrecoverableImportException(e);
            }
        }
        return results;
    });
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) UnrecoverableImportException(org.hisp.dhis.dxf2.events.event.UnrecoverableImportException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) HashMap(java.util.HashMap) UnrecoverableImportException(org.hisp.dhis.dxf2.events.event.UnrecoverableImportException) SQLException(java.sql.SQLException)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)41 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)39 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 InputStream (java.io.InputStream)24 User (org.hisp.dhis.user.User)21 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)18 IOException (java.io.IOException)17 Event (org.hisp.dhis.dxf2.events.event.Event)16 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)13 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 DataElement (org.hisp.dhis.dataelement.DataElement)10 Test (org.junit.jupiter.api.Test)10 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)9 Lists (com.google.common.collect.Lists)8 Collectors (java.util.stream.Collectors)8 HashMap (java.util.HashMap)7