Search in sources :

Example 11 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueStoredByIsValid.

@Test
void testCheckDataValueStoredByIsValid() {
    DataValue dataValue = createRandomDataValue();
    char[] chars = new char[300];
    Arrays.fill(chars, 'x');
    String storedBy = new String(chars);
    dataValue.setStoredBy(storedBy);
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7637, "Invalid storedBy: stored_by_length_greater_than_max_length", context, "stored_by_length_greater_than_max_length");
}
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 12 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueStrictOrgUnits.

@Test
void testCheckDataValueStrictOrgUnits() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).strictOrgUnits(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7636, "Data element: `<object2>` must be assigned through data sets to organisation unit: `<object1>`", context, dataValue.getOrgUnit(), 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 13 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueNotAlreadyApproved.

@Test
void testCheckDataValueNotAlreadyApproved() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
    DataApprovalWorkflow workflow = new DataApprovalWorkflow();
    workflow.setUid(CodeGenerator.generateUid());
    dataSetContext.getDataSet().setWorkflow(workflow);
    ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
    final String workflowPeriodAoc = workflow.getUid() + valueContext.getPeriod().getUid() + valueContext.getAttrOptionCombo().getUid();
    String key = valueContext.getOrgUnit().getUid() + workflowPeriodAoc;
    // already approved
    context.getApprovalMap().put(key, true);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7642, "Data is already approved for data set: `<object4>` period: `<object2>` organisation unit: `<object1>` attribute option combo: `<object3>`", context, dataValue.getOrgUnit(), dataValue.getPeriod(), dataValue.getAttributeOptionCombo(), dataSetContext.getDataSet().getUid());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 14 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueAttrOptionCombo.

@Test
void testCheckDataValueAttrOptionCombo() {
    DataValue dataValue = createRandomDataValue();
    dataValue.setAttributeOptionCombo(null);
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).requireAttrOptionCombo(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7631, "Attribute option combo is required but is not specified", context);
}
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 15 with DataValueContext

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

the class DataValueSetImportValidatorTest method testCheckDataValueStrictCategoryOptionCombos.

@Test
void testCheckDataValueStrictCategoryOptionCombos() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    valueContext.getDataElement().setCategoryCombo(new CategoryCombo());
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).strictCategoryOptionCombos(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7634, "Category option combo: `<object1>` must be part of category combo of data element: `<object2>`", context, dataValue.getCategoryOptionCombo(), dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) CategoryCombo(org.hisp.dhis.category.CategoryCombo) 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