Search in sources :

Example 46 with UID

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;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) FileResource(org.hisp.dhis.fileresource.FileResource) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 47 with UID

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));
    }
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 48 with UID

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();
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PushAnalysis(org.hisp.dhis.pushanalysis.PushAnalysis) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 49 with UID

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]));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) QueryItem(org.hisp.dhis.common.QueryItem) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) DateTimeFormatMatcher.hasDateTimeFormat(org.hisp.dhis.matchers.DateTimeFormatMatcher.hasDateTimeFormat) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EnrollmentStatus(org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) User(org.hisp.dhis.user.User) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) TrackedEntityProgramOwnerService(org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerService) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) SessionFactory(org.hibernate.SessionFactory) QueryOperator(org.hisp.dhis.common.QueryOperator) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Set(java.util.Set) AggregationType(org.hisp.dhis.analytics.AggregationType) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) EventStatus(org.hisp.dhis.event.EventStatus) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Event(org.hisp.dhis.dxf2.events.event.Event) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) FeatureType(org.hisp.dhis.organisationunit.FeatureType) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackerTest(org.hisp.dhis.dxf2.TrackerTest) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 50 with UID

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()));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

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