Search in sources :

Example 26 with DataExportParams

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

the class AdxDataServiceIntegrationTest method testGetFromUrl1.

// --------------------------------------------------------------------------
// Test get data export params from URL arguments
// --------------------------------------------------------------------------
@Test
void testGetFromUrl1() {
    Date now = new Date();
    DataExportParams expected = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setPeriods(Sets.newHashSet(pe202001)).setOrganisationUnits(Sets.newHashSet(ouA)).setIncludeDescendants(true).setIncludeDeleted(false).setLastUpdated(now).setLimit(999).setOutputIdSchemes(new IdSchemes().setIdScheme("CODE"));
    DataExportParams actual = adxDataService.getFromUrl(DataValueSetQueryParams.builder().dataSet(Sets.newHashSet(dsA.getUid())).period(Sets.newHashSet("202001")).orgUnit(Sets.newHashSet(ouA.getUid())).children(true).includeDeleted(false).lastUpdated(now).limit(999).build());
    assertEquals(expected.toString(), actual.toString());
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) Date(java.util.Date) DhisTest(org.hisp.dhis.DhisTest) Test(org.junit.jupiter.api.Test)

Example 27 with DataExportParams

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

the class DataValueSetExportAccessControlTest method testExportAttributeOptionComboAccessLimitedUserA.

/**
 * User has data read sharing access to cocA and coCB through category
 * options. Verifies that only data values for those attribute option
 * combinations are returned.
 */
@Test
void testExportAttributeOptionComboAccessLimitedUserA() throws IOException {
    // User
    User user = createUser('A');
    user.setOrganisationUnits(Sets.newHashSet(ouA));
    setCurrentUser(user);
    // Sharing
    enableDataSharing(user, coA, DATA_READ);
    enableDataSharing(user, coC, DATA_READ);
    enableDataSharing(user, coD, DATA_READ);
    enableDataSharing(user, dsA, DATA_READ);
    idObjectManager.update(coA);
    idObjectManager.update(coC);
    idObjectManager.update(coD);
    idObjectManager.update(dsA);
    // Test
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setPeriods(Sets.newHashSet(peA)).setOrganisationUnits(Sets.newHashSet(ouA));
    dbmsManager.flushSession();
    dataValueSetService.exportDataValueSetJson(params, out);
    DataValueSet dvs = jsonMapper.readValue(out.toByteArray(), DataValueSet.class);
    Set<String> expectedOptionCombos = Sets.newHashSet(cocA.getUid(), cocB.getUid());
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(ouA.getUid(), dv.getOrgUnit());
        assertEquals(peA.getUid(), dv.getPeriod());
        assertTrue(expectedOptionCombos.contains(dv.getAttributeOptionCombo()));
    }
}
Also used : User(org.hisp.dhis.user.User) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with DataExportParams

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

the class DataValueSetExportAccessControlTest method testExportExplicitAttributeOptionComboAccess.

/**
 * User has no data read sharing access to cocA through category options.
 * Verifies that validation fails.
 */
@Test
void testExportExplicitAttributeOptionComboAccess() {
    // User
    User user = createUser('A');
    user.setOrganisationUnits(Sets.newHashSet(ouA));
    setCurrentUser(user);
    // Sharing
    enableDataSharing(user, coA, DATA_READ);
    enableDataSharing(user, dsA, DATA_READ);
    idObjectManager.update(coA);
    idObjectManager.update(dsA);
    dbmsManager.flushSession();
    // Test
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setPeriods(Sets.newHashSet(peA)).setOrganisationUnits(Sets.newHashSet(ouA)).setAttributeOptionCombos(Sets.newHashSet(cocA));
    assertThrows(IllegalQueryException.class, () -> dataValueSetService.exportDataValueSetJson(params, out));
}
Also used : User(org.hisp.dhis.user.User) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with DataExportParams

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

the class DataValueSetServiceExportTest method testMissingOrgUnit.

@Test
void testMissingOrgUnit() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setPeriods(Sets.newHashSet(peA));
    assertIllegalQueryEx(assertThrows(IllegalQueryException.class, () -> dataValueSetService.exportDataValueSetJson(params, out)), ErrorCode.E2006);
}
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 30 with DataExportParams

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

the class DataValueSetServiceExportTest method testExportOrgUnitChildren.

@Test
void testExportOrgUnitChildren() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouA)).setIncludeDescendants(true).setPeriods(Sets.newHashSet(peA));
    dataValueSetService.exportDataValueSetJson(params, out);
    DataValueSet dvs = jsonMapper.readValue(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(dsA.getUid(), dvs.getDataSet());
    assertEquals(8, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(peAUid, dv.getPeriod());
    }
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) 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