Search in sources :

Example 46 with Attribute

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

the class DimensionalObjectUtilsTest method testGetUidMapIsSchemeAttribute.

@Test
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.setAttributeValues(Sets.newHashSet(avA));
    deB.setAttributeValues(Sets.newHashSet(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.jupiter.api.Test)

Example 47 with Attribute

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

the class TypedIndexedObjectContainerTest method getContainerExisting.

@Test
void getContainerExisting() {
    final Attribute attribute1 = new Attribute();
    final Category category1 = new Category();
    container.mergeObjectIndex(new Attribute());
    container.mergeObjectIndex(new Category());
    container.mergeObjectIndex(attribute1);
    container.mergeObjectIndex(category1);
    IndexedObjectContainer container1 = container.getTypedContainer(Attribute.class);
    Assertions.assertSame(1, container1.mergeObjectIndex(attribute1));
    IndexedObjectContainer container2 = container.getTypedContainer(Category.class);
    Assertions.assertSame(1, container2.mergeObjectIndex(category1));
}
Also used : Category(org.hisp.dhis.category.Category) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.jupiter.api.Test)

Example 48 with Attribute

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

the class TypedIndexedObjectContainerTest method add.

@Test
void add() {
    final Attribute attribute1 = new Attribute();
    final Attribute attribute2 = new Attribute();
    final Attribute attribute3 = new Attribute();
    final Category category1 = new Category();
    final Category category2 = new Category();
    container.add(attribute1);
    container.add(attribute2);
    container.add(attribute3);
    container.add(category1);
    container.add(category2);
    Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(attribute1));
    Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(attribute2));
    Assertions.assertEquals((Integer) 2, container.mergeObjectIndex(attribute3));
    Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(category1));
    Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(category2));
}
Also used : Category(org.hisp.dhis.category.Category) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.jupiter.api.Test)

Example 49 with Attribute

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

the class OrgUnitProfileServiceTest method testGetProfileDataWithoutOrgUnitProfile.

@Test
void testGetProfileDataWithoutOrgUnitProfile() {
    Attribute attribute = createAttribute('A');
    attribute.setOrganisationUnitAttribute(true);
    manager.save(attribute);
    OrganisationUnit orgUnit = createOrganisationUnit("A");
    orgUnit.getAttributeValues().add(new AttributeValue("testAttributeValue", attribute));
    manager.save(orgUnit);
    OrganisationUnitGroup group = createOrganisationUnitGroup('A');
    group.addOrganisationUnit(orgUnit);
    manager.save(group);
    OrganisationUnitGroupSet groupSet = createOrganisationUnitGroupSet('A');
    groupSet.addOrganisationUnitGroup(group);
    manager.save(groupSet);
    DataElement dataElement = createDataElement('A');
    manager.save(dataElement);
    Period period = createPeriod("202106");
    manager.save(period);
    // Mock analytic query for data value
    Map<String, Object> mapDataItem = new HashMap<>();
    mapDataItem.put(dataElement.getUid(), "testDataValue");
    Mockito.when(mockAnalyticsService.getAggregatedDataValueMapping(any(DataQueryParams.class))).thenReturn(mapDataItem);
    OrgUnitProfileData data = mockService.getOrgUnitProfileData(orgUnit.getUid(), period.getIsoDate());
    assertEquals(0, data.getAttributes().size());
    assertEquals(0, data.getDataItems().size());
    assertEquals(0, data.getGroupSets().size());
    assertEquals(orgUnit.getCode(), data.getInfo().getCode());
    assertEquals(orgUnit.getName(), data.getInfo().getName());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Period(org.hisp.dhis.period.Period) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 50 with Attribute

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

the class AbstractSchemaStrategy method queryForIdentifiableObjects.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void queryForIdentifiableObjects(TrackerPreheat preheat, Schema schema, TrackerIdentifier identifier, List<List<String>> splitList, Class<? extends PreheatMapper> mapper) {
    TrackerIdScheme idScheme = identifier.getIdScheme();
    for (List<String> ids : splitList) {
        List<? extends IdentifiableObject> objects;
        if (TrackerIdScheme.ATTRIBUTE.equals(idScheme)) {
            Attribute attribute = new Attribute();
            attribute.setUid(identifier.getValue());
            objects = manager.getAllByAttributeAndValues((Class<? extends IdentifiableObject>) schema.getKlass(), attribute, ids);
        } else {
            objects = cacheAwareFetch(preheat.getUser(), schema, identifier, ids, mapper);
        }
        preheat.put(identifier, objects);
    }
}
Also used : Attribute(org.hisp.dhis.attribute.Attribute) TrackerIdScheme(org.hisp.dhis.tracker.TrackerIdScheme) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

Attribute (org.hisp.dhis.attribute.Attribute)56 Test (org.junit.jupiter.api.Test)28 AttributeValue (org.hisp.dhis.attribute.AttributeValue)27 HashMap (java.util.HashMap)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 ArrayList (java.util.ArrayList)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)7 Property (org.hisp.dhis.schema.Property)7 Schema (org.hisp.dhis.schema.Schema)7 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Lists (com.google.common.collect.Lists)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4