Search in sources :

Example 11 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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)

Example 12 with DataSetContext

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

the class DataValueSetImportValidatorTest method testValidateDataSetExistsStrictDataElements.

@Test
void testValidateDataSetExistsStrictDataElements() {
    when(aclService.canDataRead(any(), any())).thenReturn(true);
    DataValueSet dataValueSet = new DataValueSet();
    ImportContext context = createMinimalImportContext(null).strictDataElements(true).build();
    DataSetContext dataSetContext = createMinimalDataSetContext(dataValueSet).build();
    assertTrue(validator.abortDataSetImport(dataValueSet, context, dataSetContext));
    assertConflict(ErrorCode.E7602, "A valid dataset is required", context);
}
Also used : DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) Test(org.junit.jupiter.api.Test)

Example 13 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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 14 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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 15 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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)

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