Search in sources :

Example 1 with DataValueContextBuilder

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext.DataValueContextBuilder in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method createDataValueContext.

private DataValueContextBuilder createDataValueContext(DataValue dataValue) {
    DataValueContextBuilder builder = DataValueContext.builder();
    String deId = dataValue.getDataElement();
    String period = dataValue.getPeriod();
    String ouId = dataValue.getOrgUnit();
    String coId = dataValue.getCategoryOptionCombo();
    String aoId = dataValue.getAttributeOptionCombo();
    if (deId != null) {
        DataElement de = new DataElement();
        de.setUid(deId);
        de.setValueType(ValueType.BOOLEAN);
        builder.dataElement(de);
    }
    if (period != null) {
        Period p = PeriodType.getPeriodFromIsoString("2021-01");
        builder.period(p);
    }
    if (ouId != null) {
        OrganisationUnit ou = new OrganisationUnit();
        ou.setUid(ouId);
        builder.orgUnit(ou);
    }
    if (coId != null) {
        builder.categoryOptionCombo(createMinimalOptionCombo(coId));
    }
    if (aoId != null) {
        builder.attrOptionCombo(createMinimalOptionCombo(aoId));
    }
    return builder;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValueContextBuilder(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext.DataValueContextBuilder) DataInputPeriod(org.hisp.dhis.dataset.DataInputPeriod) Period(org.hisp.dhis.period.Period) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

DataElement (org.hisp.dhis.dataelement.DataElement)1 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)1 DataValueContextBuilder (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext.DataValueContextBuilder)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1