Search in sources :

Example 31 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportOutputIdSchemeAttribute.

@Test
void testExportOutputIdSchemeAttribute() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String attributeIdScheme = IdScheme.ATTR_ID_SCHEME_PREFIX + atA.getUid();
    IdSchemes idSchemes = new IdSchemes().setDataElementIdScheme(attributeIdScheme).setOrgUnitIdScheme(attributeIdScheme).setCategoryOptionComboIdScheme(attributeIdScheme);
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsB)).setOrganisationUnits(Sets.newHashSet(ouA)).setPeriods(Sets.newHashSet(peB)).setOutputIdSchemes(idSchemes);
    dataValueSetService.exportDataValueSetJson(params, out);
    DataValueSet dvs = jsonMapper.readValue(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(dsB.getUid(), dvs.getDataSet());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(avA.getValue(), dv.getDataElement());
        assertEquals(avB.getValue(), dv.getOrgUnit());
    }
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 32 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testMissingDataSetElementGroup.

@Test
void testMissingDataSetElementGroup() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setOrganisationUnits(Sets.newHashSet(ouB)).setPeriods(Sets.newHashSet(peA));
    assertIllegalQueryEx(assertThrows(IllegalQueryException.class, () -> dataValueSetService.exportDataValueSetJson(params, out)), ErrorCode.E2001);
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 33 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testAccessOutsideOrgUnitHierarchy.

@Test
void testAccessOutsideOrgUnitHierarchy() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouC)).setPeriods(Sets.newHashSet(peA));
    assertIllegalQueryEx(assertThrows(IllegalQueryException.class, () -> dataValueSetService.exportDataValueSetJson(params, out)), ErrorCode.E2012);
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 34 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportAttributeOptionCombo.

@Test
void testExportAttributeOptionCombo() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouB)).setPeriods(Sets.newHashSet(peA)).setAttributeOptionCombos(Sets.newHashSet(cocA));
    dataValueSetService.exportDataValueSetJson(params, out);
    DataValueSet dvs = jsonMapper.readValue(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(ouB.getUid(), dv.getOrgUnit());
        assertEquals(peAUid, dv.getPeriod());
    }
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 35 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testPeriodAndStartEndDate.

@Test
void testPeriodAndStartEndDate() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouB)).setPeriods(Sets.newHashSet(peA)).setStartDate(getDate(2019, 1, 1)).setEndDate(getDate(2019, 1, 31));
    assertIllegalQueryEx(assertThrows(IllegalQueryException.class, () -> dataValueSetService.exportDataValueSetJson(params, out)), ErrorCode.E2003);
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

DataExportParams (org.hisp.dhis.datavalue.DataExportParams)40 Test (org.junit.jupiter.api.Test)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IdSchemes (org.hisp.dhis.common.IdSchemes)8 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 ArrayList (java.util.ArrayList)6 DataSet (org.hisp.dhis.dataset.DataSet)6 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)6 User (org.hisp.dhis.user.User)6 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)5 DataValue (org.hisp.dhis.datavalue.DataValue)5 Period (org.hisp.dhis.period.Period)5 Date (java.util.Date)4 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)4 TextUtils.getCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 List (java.util.List)2