Search in sources :

Example 11 with AttributeValue

use of org.hisp.dhis.attribute.AttributeValue in project dhis2-core by dhis2.

the class DimensionalObjectUtilsTest method testGetUidMapIsSchemeAttribute.

@Test
public void testGetUidMapIsSchemeAttribute() {
    DataElement deA = new DataElement("DataElementA");
    DataElement deB = new DataElement("DataElementB");
    DataElement deC = new DataElement("DataElementC");
    deA.setUid("A123456789A");
    deB.setUid("A123456789B");
    deC.setUid("A123456789C");
    Attribute atA = new Attribute("AttributeA", ValueType.INTEGER);
    atA.setUid("ATTR123456A");
    AttributeValue avA = new AttributeValue("AttributeValueA", atA);
    AttributeValue avB = new AttributeValue("AttributeValueB", atA);
    deA.getAttributeValues().add(avA);
    deB.getAttributeValues().add(avB);
    List<DataElement> elements = Lists.newArrayList(deA, deB, deC);
    String scheme = IdScheme.ATTR_ID_SCHEME_PREFIX + atA.getUid();
    IdScheme idScheme = IdScheme.from(scheme);
    Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap(elements, idScheme);
    assertEquals(3, map.size());
    assertEquals("AttributeValueA", map.get("A123456789A"));
    assertEquals("AttributeValueB", map.get("A123456789B"));
    assertEquals(null, map.get("A123456789C"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test)

Example 12 with AttributeValue

use of org.hisp.dhis.attribute.AttributeValue in project dhis2-core by dhis2.

the class PreheatServiceTest method defaultSetupWithAttributes.

private void defaultSetupWithAttributes() {
    Attribute attribute = new Attribute("AttributeA", ValueType.TEXT);
    attribute.setUnique(true);
    attribute.setMandatory(true);
    attribute.setDataElementAttribute(true);
    manager.save(attribute);
    AttributeValue attributeValue1 = new AttributeValue("Value1", attribute);
    AttributeValue attributeValue2 = new AttributeValue("Value2", attribute);
    AttributeValue attributeValue3 = new AttributeValue("Value3", attribute);
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    attributeService.addAttributeValue(de1, attributeValue1);
    attributeService.addAttributeValue(de2, attributeValue2);
    attributeService.addAttributeValue(de3, attributeValue3);
    manager.save(de1);
    manager.save(de2);
    manager.save(de3);
    User user = createUser('A');
    manager.save(user);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) AttributeValue(org.hisp.dhis.attribute.AttributeValue) User(org.hisp.dhis.user.User) Attribute(org.hisp.dhis.attribute.Attribute)

Example 13 with AttributeValue

use of org.hisp.dhis.attribute.AttributeValue in project dhis2-core by dhis2.

the class DhisConvenienceTest method createAttributeValue.

public static AttributeValue createAttributeValue(Attribute attribute, String value) {
    AttributeValue attributeValue = new AttributeValue(value, attribute);
    attributeValue.setAutoFields();
    return attributeValue;
}
Also used : TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) AttributeValue(org.hisp.dhis.attribute.AttributeValue)

Example 14 with AttributeValue

use of org.hisp.dhis.attribute.AttributeValue 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 15 with AttributeValue

use of org.hisp.dhis.attribute.AttributeValue in project dhis2-core by dhis2.

the class DataElementStoreTest method testDataElementByUniqueAttributeValue.

@Test
public void testDataElementByUniqueAttributeValue() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("cid", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attribute.setUnique(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    dataElementStore.save(dataElementC);
    AttributeValue attributeValueA = new AttributeValue("CID1", attribute);
    AttributeValue attributeValueB = new AttributeValue("CID2", attribute);
    AttributeValue attributeValueC = new AttributeValue("CID3", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID1"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID2"));
    assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID3"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID4"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID5"));
    assertEquals("DataElementA", dataElementStore.getByUniqueAttributeValue(attribute, "CID1").getName());
    assertEquals("DataElementB", dataElementStore.getByUniqueAttributeValue(attribute, "CID2").getName());
    assertEquals("DataElementC", dataElementStore.getByUniqueAttributeValue(attribute, "CID3").getName());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

AttributeValue (org.hisp.dhis.attribute.AttributeValue)17 Attribute (org.hisp.dhis.attribute.Attribute)13 Test (org.junit.Test)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 ArrayList (java.util.ArrayList)5 DataElement (org.hisp.dhis.dataelement.DataElement)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 User (org.hisp.dhis.user.User)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ErrorReport (org.hisp.dhis.feedback.ErrorReport)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1