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