Search in sources :

Example 41 with DataValue

use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesXmlUpdatesOnly.

@Test
public void testImportDataValuesXmlUpdatesOnly() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setImportStrategy(ImportStrategy.UPDATES);
    IdSchemes idSchemes = new IdSchemes();
    idSchemes.setIdScheme("UID");
    idSchemes.setDataElementIdScheme("UID");
    idSchemes.setOrgUnitIdScheme("UID");
    importOptions.setIdSchemes(idSchemes);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(12, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 42 with DataValue

use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithInvalidAttributeOptionCombo.

@Test
public void testImportDataValuesWithInvalidAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetF.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(ImportStatus.ERROR, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 43 with DataValue

use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesInvalidAttributeOptionComboDates.

@Test
public void testImportDataValuesInvalidAttributeOptionComboDates() throws Exception {
    categoryOptionA.setStartDate(peB.getStartDate());
    categoryOptionA.setEndDate(peB.getEndDate());
    categoryService.updateDataElementCategoryOption(categoryOptionA);
    in = new ClassPathResource("datavalueset/dataValueSetH.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deB, peB, ouB, ocDef, ocA)));
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 44 with DataValue

use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.

the class DefaultValidationService method validateRequiredComments.

@Override
public List<DataElementOperand> validateRequiredComments(DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo) {
    List<DataElementOperand> violations = new ArrayList<>();
    if (dataSet.isNoValueRequiresComment()) {
        for (DataElement de : dataSet.getDataElements()) {
            for (DataElementCategoryOptionCombo co : de.getCategoryOptionCombos()) {
                DataValue dv = dataValueService.getDataValue(de, period, organisationUnit, co, attributeOptionCombo);
                boolean missingValue = dv == null || StringUtils.trimToNull(dv.getValue()) == null;
                boolean missingComment = dv == null || StringUtils.trimToNull(dv.getComment()) == null;
                if (missingValue && missingComment) {
                    violations.add(new DataElementOperand(de, co));
                }
            }
        }
    }
    return violations;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.datavalue.DataValue) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 45 with DataValue

use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.

the class DataValueController method deleteDataValue.

// ---------------------------------------------------------------------
// DELETE
// ---------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_DELETE')")
@RequestMapping(method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
    // ---------------------------------------------------------------------
    // Input validation
    // ---------------------------------------------------------------------
    DataElement dataElement = getAndValidateDataElement(de);
    DataElementCategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(co, false);
    DataElementCategoryOptionCombo attributeOptionCombo = getAndValidateAttributeOptionCombo(cc, cp);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrganisationUnit(ou);
    // ---------------------------------------------------------------------
    // Locking validation
    // ---------------------------------------------------------------------
    validateDataSetNotLocked(dataElement, period, organisationUnit, attributeOptionCombo);
    // ---------------------------------------------------------------------
    // Period validation
    // ---------------------------------------------------------------------
    validateDataInputPeriodForDataElementAndPeriod(dataElement, period);
    // ---------------------------------------------------------------------
    // Delete data value
    // ---------------------------------------------------------------------
    DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
    if (dataValue == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Data value cannot be deleted because it does not exist"));
    }
    dataValueService.deleteDataValue(dataValue);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValue(org.hisp.dhis.datavalue.DataValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataValue (org.hisp.dhis.datavalue.DataValue)49 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)20 Period (org.hisp.dhis.period.Period)19 Test (org.junit.Test)19 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 ClassPathResource (org.springframework.core.io.ClassPathResource)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 Date (java.util.Date)7 ArrayList (java.util.ArrayList)4 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)4 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 SMSCode (org.hisp.dhis.sms.command.code.SMSCode)3