Search in sources :

Example 6 with DataValueContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueAttrOptionComboAccess.

@Test
void testValidateDataValueAttrOptionComboAccess() {
    DataValue dataValue = createRandomDataValue();
    // so that we got to later validation
    dataValue.setCategoryOptionCombo(null);
    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.E7616, "Attribute option combo: `<object1>` option not accessible: `<object2>`", context, dataValue.getAttributeOptionCombo(), valueContext.getAttrOptionCombo().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 7 with DataValueContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueOptionsExist.

@Test
void testValidateDataValueOptionsExist() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    valueContext.getDataElement().setOptionSet(new OptionSet());
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7621, "Data value is not a valid option of the data element option set: `<object1>`", context, dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) OptionSet(org.hisp.dhis.option.OptionSet) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 8 with DataValueContext

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

the class DataValueSetImportValidatorTest method testValidateDataValueOrgUnitExists.

@Test
void testValidateDataValueOrgUnitExists() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).orgUnit(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7612, "Organisation unit not found or not accessible: `<object1>`", context, dataValue.getOrgUnit());
}
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 9 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueTodayNotPastPeriodExpiry.

@Test
void testCheckDataValueTodayNotPastPeriodExpiry() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
    String key = dataSetContext.getDataSet().getUid() + valueContext.getPeriod().getUid() + valueContext.getOrgUnit().getUid();
    context.getDataSetLockedMap().put(key, true);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7640, "Current date is past expiry days for period: `<object1>`  and data set: `<object2>`", context, dataValue.getPeriod(), dataSetContext.getDataSet().getUid());
}
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 10 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueStrictDataElement.

@Test
void testCheckDataValueStrictDataElement() {
    DataValue dataValue = createRandomDataValue();
    DataValueSet dataValueSet = createEmptyDataValueSet();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(dataValueSet).build();
    ImportContext context = createMinimalImportContext(valueContext).strictDataElements(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7633, "Data element: `<object1>` is not part of dataset: `<object2>`", context, dataValue.getDataElement(), dataValueSet.getDataSet());
}
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)

Aggregations

DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)28 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)28 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 Test (org.junit.jupiter.api.Test)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 Date (java.util.Date)1 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 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 User (org.hisp.dhis.user.User)1