Search in sources :

Example 6 with DataValue

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

the class HibernateDataValueStore method getSoftDeletedDataValue.

@Override
public DataValue getSoftDeletedDataValue(DataValue dataValue) {
    Session session = sessionFactory.getCurrentSession();
    Period storedPeriod = periodStore.reloadPeriod(dataValue.getPeriod());
    if (storedPeriod == null) {
        return null;
    }
    return (DataValue) session.createCriteria(DataValue.class).add(Restrictions.eq("dataElement", dataValue.getDataElement())).add(Restrictions.eq("period", storedPeriod)).add(Restrictions.eq("source", dataValue.getSource())).add(Restrictions.eq("categoryOptionCombo", dataValue.getCategoryOptionCombo())).add(Restrictions.eq("attributeOptionCombo", dataValue.getAttributeOptionCombo())).add(Restrictions.eq("deleted", true)).uniqueResult();
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period) Session(org.hibernate.Session)

Example 7 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithCategoryOptionComboIdScheme.

@Test
public void testImportDataValuesWithCategoryOptionComboIdScheme() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetCCode.xml").getInputStream();
    ImportOptions options = new ImportOptions().setCategoryOptionComboIdScheme("CODE");
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(3, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
}
Also used : 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 8 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithAttributeOptionCombo.

@Test
public void testImportDataValuesWithAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetD.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocA)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, 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 9 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeA.

@Test
public void testImportDataValuesXmlWithCodeA() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
    assertEquals(0, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesBooleanCsv.

@Test
public void testImportDataValuesBooleanCsv() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBooleanTest.csv").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSetCsv(in, null, null);
    // False rows
    assertEquals(summary.getConflicts().toString(), 5, summary.getConflicts().size());
    List<String> expectedBools = Lists.newArrayList("true", "false");
    List<DataValue> resultBools = mockDataValueBatchHandler.getInserts();
    for (DataValue dataValue : resultBools) {
        assertTrue(expectedBools.contains(dataValue.getValue()));
    }
}
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)

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