Search in sources :

Example 1 with AttributeValue

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

the class ObjectBundleServiceAttributesTest method defaultSetupWithAttributes.

private void defaultSetupWithAttributes() {
    Attribute attribute = new Attribute("AttributeA", ValueType.TEXT);
    attribute.setUid("d9vw7V9Mw8W");
    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 2 with AttributeValue

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

the class DataElementStoreTest method testDataElementByNonUniqueAttributeValue.

@Test
public void testDataElementByNonUniqueAttributeValue() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("cid", ValueType.TEXT);
    attribute.setDataElementAttribute(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);
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID1"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID2"));
    assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID3"));
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with AttributeValue

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

the class DataElementCategoryOptionComboServiceTest method testAddAttributeValue.

@Test
public void testAddAttributeValue() {
    categoryOptionComboA = new DataElementCategoryOptionCombo();
    Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet(categoryOptionA, categoryOptionB);
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryOptionComboA.setCategoryOptions(categoryOptions);
    int id = categoryService.addDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryOptionComboA = categoryService.getDataElementCategoryOptionCombo(id);
    Attribute attribute1 = new Attribute("attribute 1", ValueType.TEXT);
    attribute1.setCategoryOptionComboAttribute(true);
    attributeService.addAttribute(attribute1);
    AttributeValue avA = new AttributeValue("value 1");
    avA.setAttribute(attribute1);
    categoryOptionComboA.getAttributeValues().add(avA);
    categoryService.updateDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryOptionComboA = categoryService.getDataElementCategoryOptionCombo(id);
    assertFalse(categoryOptionComboA.getAttributeValues().isEmpty());
    categoryOptionComboA.getAttributeValues().clear();
    categoryService.updateDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryOptionComboA = categoryService.getDataElementCategoryOptionCombo(id);
    assertTrue(categoryOptionComboA.getAttributeValues().isEmpty());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with AttributeValue

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

the class DataElementStoreTest method testDataElementFromAttribute.

// Fails with expected:<null> but was:<{"class":"class org.hisp.dhis.dataelement.DataElement"
@Ignore
@Test
public void testDataElementFromAttribute() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("test", ValueType.TEXT);
    attribute.setDataElementAttribute(true);
    attributeService.addAttribute(attribute);
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    dataElementStore.save(dataElementA);
    dataElementStore.save(dataElementB);
    AttributeValue attributeValue = new AttributeValue("SOME VALUE", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValue);
    dataElementA.getAttributeValues().add(attributeValue);
    dataElementStore.update(dataElementA);
    DataElement dataElement = dataElementStore.getByAttribute(attribute);
    assertEquals(dataElement, dataElementA);
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Ignore(org.junit.Ignore) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with AttributeValue

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

the class DataElementStoreTest method testAttributeValueFromAttributeAndValue.

@Test
public void testAttributeValueFromAttributeAndValue() throws NonUniqueAttributeValueException {
    Attribute attribute = new Attribute("test", ValueType.TEXT);
    attribute.setDataElementAttribute(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("SOME VALUE", attribute);
    AttributeValue attributeValueB = new AttributeValue("SOME VALUE", attribute);
    AttributeValue attributeValueC = new AttributeValue("ANOTHER VALUE", attribute);
    attributeService.addAttributeValue(dataElementA, attributeValueA);
    attributeService.addAttributeValue(dataElementB, attributeValueB);
    attributeService.addAttributeValue(dataElementC, attributeValueC);
    dataElementStore.update(dataElementA);
    dataElementStore.update(dataElementB);
    dataElementStore.update(dataElementC);
    List<AttributeValue> values = dataElementStore.getAttributeValueByAttributeAndValue(attribute, "SOME VALUE");
    assertEquals(2, values.size());
    values = dataElementStore.getAttributeValueByAttributeAndValue(attribute, "ANOTHER VALUE");
    assertEquals(1, values.size());
}
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