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"));
}
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);
}
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;
}
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);
}
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());
}
Aggregations