use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class DataValidator method validateAndSetAssigned.
/**
* Validates if the given file resource uid has a valid FileResource
* associated with.
*
* @param fileResourceUid the uid of the FileResource.
* @param valueType
* @param valueTypeOptions
* @return a valid FileResource.
* @throws WebMessageException if any validation fails.
*/
public FileResource validateAndSetAssigned(final String fileResourceUid, ValueType valueType, ValueTypeOptions valueTypeOptions) throws WebMessageException {
Preconditions.checkNotNull(fileResourceUid);
final FileResource fileResource = fileResourceService.getFileResource(fileResourceUid);
if (fileResource == null || fileResource.getDomain() != DATA_VALUE) {
throw new WebMessageException(notFound(FileResource.class, fileResourceUid));
}
if (fileResource.isAssigned()) {
throw new IllegalQueryException(ErrorCode.E2026);
}
if (valueType != null && valueTypeOptions != null) {
String validationResult = dataValueIsValid(fileResource, valueType, valueTypeOptions);
if (validationResult != null) {
fileResourceService.deleteFileResource(fileResource);
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2027, validationResult));
}
}
fileResource.setAssigned(true);
return fileResource;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class VisualizationDataController method getVisualizationData.
@GetMapping(value = { "/visualizations/{uid}/data", "/visualizations/{uid}/data.png" })
public void getVisualizationData(@PathVariable("uid") String uid, @RequestParam(value = "date", required = false) Date date, @RequestParam(value = "ou", required = false) String ou, @RequestParam(value = "width", defaultValue = "800", required = false) int width, @RequestParam(value = "height", defaultValue = "500", required = false) int height, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws IOException, WebMessageException {
final Visualization visualization = visualizationService.getVisualizationNoAcl(uid);
if (visualization == null) {
throw new WebMessageException(notFound("Visualization does not exist: " + uid));
}
if (visualization.isChart() && isChartSupported(visualization.getType())) {
OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(visualization), date, unit, i18nManager.getI18nFormat(), currentUserService.getCurrentUser());
String filename = CodecUtils.filenameEncode(visualization.getName()) + ".png";
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment);
ChartUtils.writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
} else {
response.setContentType(CONTENT_TYPE_JSON);
renderService.toJson(response.getOutputStream(), getReportTableGrid(uid, ou, date));
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class PushAnalysisController method renderPushAnalytics.
@GetMapping("/{uid}/render")
public void renderPushAnalytics(@PathVariable() String uid, HttpServletResponse response) throws WebMessageException, IOException {
PushAnalysis pushAnalysis = pushAnalysisService.getByUid(uid);
if (pushAnalysis == null) {
throw new WebMessageException(notFound("Push analysis with uid " + uid + " was not found"));
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE);
log.info("User '" + currentUserService.getCurrentUser().getUsername() + "' started PushAnalysis for 'rendering'");
String result = pushAnalysisService.generateHtmlReport(pushAnalysis, currentUserService.getCurrentUser(), null);
response.getWriter().write(result);
response.getWriter().close();
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithExplicitUid.
@Test
void testFetchTrackedEntityInstancesWithExplicitUid() {
final String[] teiUid = new String[2];
doInTransaction(() -> {
org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstance();
teiUid[0] = t1.getUid();
teiUid[1] = t2.getUid();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.getTrackedEntityInstanceUids().add(teiUid[0]);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(1));
assertThat(trackedEntityInstances.get(0).getTrackedEntityInstance(), is(teiUid[0]));
// Query 2 tei uid explicitly
queryParams.getTrackedEntityInstanceUids().add(teiUid[1]);
final List<TrackedEntityInstance> multiTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(multiTrackedEntityInstances, hasSize(2));
Set<String> teis = multiTrackedEntityInstances.stream().map(t -> t.getTrackedEntityInstance()).collect(Collectors.toSet());
assertTrue(teis.contains(teiUid[0]));
assertTrue(teis.contains(teiUid[1]));
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testEnrollmentMapping.
@Test
void testEnrollmentMapping() {
final Date currentTime = new Date();
doInTransaction(this::persistTrackedEntityInstanceWithEnrollmentAndEvents);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeEnrollments(true);
params.setIncludeEvents(false);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
Enrollment enrollment = trackedEntityInstances.get(0).getEnrollments().get(0);
assertThat("Tracked Entity Type does not match", enrollment.getTrackedEntityType(), is(trackedEntityTypeA.getUid()));
assertThat("Tracked Entity Instance UID does not match", enrollment.getTrackedEntityInstance(), is(trackedEntityInstances.get(0).getTrackedEntityInstance()));
assertThat("Org Unit UID does not match", enrollment.getOrgUnit(), is(organisationUnitA.getUid()));
assertThat("Org Unit Name does not match", enrollment.getOrgUnitName(), is(organisationUnitA.getName()));
assertTrue(CodeGenerator.isValidUid(enrollment.getEnrollment()));
assertThat(enrollment.getProgram(), is(programA.getUid()));
assertThat(enrollment.getStatus(), is(EnrollmentStatus.COMPLETED));
assertThat(enrollment.isDeleted(), is(false));
assertThat(enrollment.getStoredBy(), is("system-process"));
assertThat(enrollment.getFollowup(), is(nullValue()));
// Dates
checkDate(currentTime, enrollment.getCreated(), 200L);
checkDate(currentTime, enrollment.getCreatedAtClient(), 200L);
checkDate(currentTime, enrollment.getLastUpdatedAtClient(), 200L);
checkDate(currentTime, enrollment.getLastUpdated(), 300L);
checkDate(currentTime, enrollment.getEnrollmentDate(), 300L);
checkDate(currentTime, enrollment.getIncidentDate(), 300L);
checkDate(currentTime, enrollment.getCompletedDate(), 200L);
assertThat(enrollment.getCompletedBy(), is("hello-world"));
// The Enrollment ID is not serialized to JSON
assertThat(enrollment.getId(), is(notNullValue()));
}
Aggregations