Search in sources :

Example 31 with DataSetContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueIsValid.

@Test
void testValidateDataValueIsValid() {
    DataValue dataValue = createRandomDataValue();
    dataValue.setValue("not-a-bool");
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7619, "Value must match data element's `<object1>` type constraints: value_not_bool", context, dataValue.getDataElement(), "value_not_bool");
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 32 with DataSetContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueIsDefined.

@Test
void testValidateDataValueIsDefined() {
    DataValue dataValue = createRandomDataValue();
    dataValue.setComment(null);
    dataValue.setValue(null);
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7618, "Data value or comment not specified for data element: `" + dataValue.getDataElement() + "`", context, dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 33 with DataSetContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueConformsToOpenPeriodsOfAssociatedDataSets.

@Test
void testCheckDataValueConformsToOpenPeriodsOfAssociatedDataSets() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
    String key = valueContext.getDataElement().getUid() + valueContext.getPeriod().getIsoDate();
    context.getPeriodOpenForDataElement().put(key, false);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7644, "Period: `<object1>` does not conform to the open periods of associated data sets", context, dataValue.getPeriod());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 34 with DataSetContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueCategoryOptionComboAccess.

@Test
void testValidateDataValueCategoryOptionComboAccess() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    setupUserCanWriteCategoryOptions(false);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7614, "Category option combo: `<object1>` option not accessible: `<object2>`", context, dataValue.getCategoryOptionCombo(), valueContext.getCategoryOptionCombo().getCategoryOptions().iterator().next().getUid());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 35 with DataSetContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueFileResourceExists.

@Test
void testCheckDataValueFileResourceExists() {
    DataValue dataValue = createRandomDataValue();
    dataValue.setValue(CodeGenerator.generateUid());
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    valueContext.getDataElement().setValueType(ValueType.FILE_RESOURCE);
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).strategy(ImportStrategy.DELETE).build();
    when(dataValueService.getDataValue(any(DataElement.class), any(Period.class), any(OrganisationUnit.class), any(CategoryOptionCombo.class), any(CategoryOptionCombo.class))).thenReturn(null);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7645, "No data value for file resource exist for the given combination for data element: `<object1>`", context, dataValue.getDataElement());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataInputPeriod(org.hisp.dhis.dataset.DataInputPeriod) Period(org.hisp.dhis.period.Period) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Aggregations

DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)34 Test (org.junit.jupiter.api.Test)33 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)28 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Date (java.util.Date)2 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)2 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DateRange (org.hisp.dhis.common.DateRange)1 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 NotificationLevel (org.hisp.dhis.system.notification.NotificationLevel)1 Clock (org.hisp.dhis.system.util.Clock)1 DateUtils.parseDate (org.hisp.dhis.util.DateUtils.parseDate)1