Search in sources :

Example 36 with DataValue

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

the class DataValueBatchHandlerTest method testFindObject.

@Test
public void testFindObject() {
    dataValueService.addDataValue(dataValueA);
    dataValueService.addDataValue(dataValueC);
    DataValue retrievedDataValueA = batchHandler.findObject(dataValueA);
    DataValue retrievedDataValueB = batchHandler.findObject(dataValueB);
    assertNotNull(dataValueA.getValue());
    assertNotNull(dataValueA.getComment());
    assertNotNull(dataValueA.getStoredBy());
    assertEquals(dataValueA.getValue(), retrievedDataValueA.getValue());
    assertEquals(dataValueA.getComment(), retrievedDataValueA.getComment());
    assertEquals(dataValueA.getStoredBy(), retrievedDataValueA.getStoredBy());
    assertEquals(dataValueA.isFollowup(), retrievedDataValueA.isFollowup());
    assertNull(retrievedDataValueB);
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 37 with DataValue

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

the class DataValueSetServiceExportTest method setUpTest.

@Override
public void setUpTest() {
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    idObjectManager.save(deC);
    ccA = createCategoryCombo('A');
    categoryService.addDataElementCategoryCombo(ccA);
    cocA = createCategoryOptionCombo('A');
    cocB = createCategoryOptionCombo('B');
    cocA.setCategoryCombo(ccA);
    cocB.setCategoryCombo(ccA);
    categoryService.addDataElementCategoryOptionCombo(cocA);
    categoryService.addDataElementCategoryOptionCombo(cocB);
    atA = createAttribute('A');
    atA.setDataElementAttribute(true);
    atA.setOrganisationUnitAttribute(true);
    atA.setCategoryOptionComboAttribute(true);
    idObjectManager.save(atA);
    dsA = createDataSet('A');
    dsA.addDataSetElement(deA);
    dsA.addDataSetElement(deB);
    dsB = createDataSet('B');
    dsB.addDataSetElement(deA);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
    peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 3, 1), getDate(2016, 3, 31));
    peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 4, 1), getDate(2016, 4, 30));
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B', ouA);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    avA = new AttributeValue("AttributeValueA", atA);
    avB = new AttributeValue("AttributeValueB", atA);
    avC = new AttributeValue("AttributeValueC", atA);
    avD = new AttributeValue("AttributeValueD", atA);
    attributeService.addAttributeValue(deA, avA);
    attributeService.addAttributeValue(ouA, avB);
    attributeService.addAttributeValue(cocA, avC);
    attributeService.addAttributeValue(cocB, avD);
    // Data values
    dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocB, cocB, "1"));
    dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocB, cocB, "1"));
    dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocB, cocB, "1"));
    dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocB, cocB, "1"));
    dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocB, cocB, "1"));
    dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocA, cocA, "1"));
    dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocB, cocB, "1"));
    // Flush session to make data values visible to JDBC query
    dbmsManager.flushSession();
    // Service mocks
    user = createUser('A');
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(dataValueSetService, "currentUserService", currentUserService);
    setDependency(organisationUnitService, "currentUserService", currentUserService);
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) DataValue(org.hisp.dhis.datavalue.DataValue) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService)

Example 38 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithOrgUnitOutsideHierarchy.

@Test
public void testImportDataValuesWithOrgUnitOutsideHierarchy() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetE.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, 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 39 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithDataSetAllowsPeriods.

@Test
public void testImportDataValuesWithDataSetAllowsPeriods() throws Exception {
    Date thisMonth = DateUtils.truncate(new Date(), Calendar.MONTH);
    dsA.setExpiryDays(62);
    dsA.setOpenFuturePeriods(2);
    dataSetService.updateDataSet(dsA);
    Period tooEarly = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 4));
    Period okBefore = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 1));
    Period okAfter = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -1));
    Period tooLate = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -4));
    Period outOfRange = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 6));
    periodService.addPeriod(tooEarly);
    periodService.addPeriod(okBefore);
    periodService.addPeriod(okAfter);
    periodService.addPeriod(tooLate);
    String importData = "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0\" idScheme=\"code\" dataSet=\"DS_A\" orgUnit=\"OU_A\">\n" + "  <dataValue dataElement=\"DE_A\" period=\"" + tooEarly.getIsoDate() + "\" value=\"10001\" />\n" + "  <dataValue dataElement=\"DE_B\" period=\"" + okBefore.getIsoDate() + "\" value=\"10002\" />\n" + "  <dataValue dataElement=\"DE_C\" period=\"" + okAfter.getIsoDate() + "\" value=\"10003\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + tooLate.getIsoDate() + "\" value=\"10004\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + outOfRange.getIsoDate() + "\" value=\"10005\" />\n" + "</dataValueSet>\n";
    in = new ByteArrayInputStream(importData.getBytes(StandardCharsets.UTF_8));
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(summary.getConflicts().toString(), 3, summary.getConflicts().size());
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(2, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deB, okBefore, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, okAfter, ouA, ocDef, ocDef)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 40 with DataValue

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

the class DataValueSetServiceTest method testImportNullDataValues.

@Test
public void testImportNullDataValues() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetANull.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, 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)

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