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);
}
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);
}
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);
}
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;
}
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;
});
}
Aggregations