Search in sources :

Example 21 with Attribute

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

the class DefaultFieldFilterServiceTest method toCollectionNodeSkipSharingOwner.

@Test
void toCollectionNodeSkipSharingOwner() throws Exception {
    final Attribute attribute = new Attribute();
    final Map<String, Property> propertyMap = new HashMap<>();
    addProperty(propertyMap, attribute, "dataElementAttribute");
    Property p = addProperty(propertyMap, attribute, "dataSetAttribute");
    p.setOwner(true);
    p.setPersisted(true);
    addProperty(propertyMap, attribute, "user");
    addProperty(propertyMap, attribute, "publicAccess");
    addProperty(propertyMap, attribute, "userGroupAccesses");
    addProperty(propertyMap, attribute, "userAccesses");
    addProperty(propertyMap, attribute, "externalAccess");
    final Schema rootSchema = new Schema(Attribute.class, "attribute", "attributes");
    rootSchema.setPropertyMap(propertyMap);
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(Attribute.class))).thenReturn(rootSchema);
    final Schema booleanSchema = new Schema(boolean.class, "boolean", "booleans");
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(boolean.class))).thenReturn(booleanSchema);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(attribute), Collections.singletonList(":owner"), Defaults.INCLUDE, true);
    CollectionNode node = service.toCollectionNode(Attribute.class, params);
    Assertions.assertEquals(1, node.getChildren().size());
    Set<String> names = extractNodeNames(node.getChildren().get(0).getChildren());
    Assertions.assertFalse(names.contains("dataElementAttribute"));
    Assertions.assertTrue(names.contains("dataSetAttribute"));
    Assertions.assertFalse(names.contains("user"));
    Assertions.assertFalse(names.contains("publicAccess"));
    Assertions.assertFalse(names.contains("userGroupAccesses"));
    Assertions.assertFalse(names.contains("userAccesses"));
    Assertions.assertFalse(names.contains("externalAccess"));
}
Also used : Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Test(org.junit.jupiter.api.Test)

Example 22 with Attribute

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

the class DefaultFieldFilterServiceTest method toCollectionNodeSkipSharingNoFields.

@Test
void toCollectionNodeSkipSharingNoFields() throws Exception {
    final Attribute attribute = new Attribute();
    final Map<String, Property> propertyMap = new HashMap<>();
    addProperty(propertyMap, attribute, "dataElementAttribute");
    addProperty(propertyMap, attribute, "user");
    addProperty(propertyMap, attribute, "publicAccess");
    addProperty(propertyMap, attribute, "userGroupAccesses");
    addProperty(propertyMap, attribute, "userAccesses");
    addProperty(propertyMap, attribute, "externalAccess");
    final Schema rootSchema = new Schema(Attribute.class, "attribute", "attributes");
    rootSchema.setPropertyMap(propertyMap);
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(Attribute.class))).thenReturn(rootSchema);
    final Schema booleanSchema = new Schema(boolean.class, "boolean", "booleans");
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(boolean.class))).thenReturn(booleanSchema);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(attribute), Collections.emptyList(), Defaults.INCLUDE, true);
    CollectionNode node = service.toCollectionNode(Attribute.class, params);
    Assertions.assertEquals(1, node.getChildren().size());
    Set<String> names = extractNodeNames(node.getChildren().get(0).getChildren());
    Assertions.assertTrue(names.contains("dataElementAttribute"));
    Assertions.assertFalse(names.contains("user"));
    Assertions.assertFalse(names.contains("publicAccess"));
    Assertions.assertFalse(names.contains("userGroupAccesses"));
    Assertions.assertFalse(names.contains("userAccesses"));
    Assertions.assertFalse(names.contains("externalAccess"));
}
Also used : Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Test(org.junit.jupiter.api.Test)

Example 23 with Attribute

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

the class OrgUnitProfileServiceTest method testValidator.

@Test
void testValidator() {
    Attribute attribute = createAttribute('A');
    attribute.setOrganisationUnitAttribute(true);
    OrganisationUnit orgUnit = createOrganisationUnit("A");
    orgUnit.getAttributeValues().add(new AttributeValue("testAttributeValue", attribute));
    OrganisationUnitGroup group = createOrganisationUnitGroup('A');
    group.addOrganisationUnit(orgUnit);
    OrganisationUnitGroupSet groupSet = createOrganisationUnitGroupSet('A');
    groupSet.addOrganisationUnitGroup(group);
    DataElement dataElement = createDataElement('A');
    OrgUnitProfile orgUnitProfile = new OrgUnitProfile();
    orgUnitProfile.getAttributes().add(attribute.getUid());
    orgUnitProfile.getDataItems().add(dataElement.getUid());
    orgUnitProfile.getGroupSets().add(groupSet.getUid());
    List<ErrorReport> errors = service.validateOrgUnitProfile(orgUnitProfile);
    assertEquals(3, errors.size());
    assertTrue(errorContains(errors, ErrorCode.E4014, OrganisationUnitGroupSet.class, groupSet.getUid()));
    assertTrue(errorContains(errors, ErrorCode.E4014, Attribute.class, attribute.getUid()));
    assertTrue(errorContains(errors, ErrorCode.E4014, Collection.class, dataElement.getUid()));
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ErrorReport(org.hisp.dhis.feedback.ErrorReport) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) Collection(java.util.Collection) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 24 with Attribute

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

the class OrgUnitProfileServiceTest method testGetProfileDataWithOrgUnitProfile.

@Test
void testGetProfileDataWithOrgUnitProfile() {
    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);
    OrgUnitProfile orgUnitProfile = new OrgUnitProfile();
    orgUnitProfile.getAttributes().add(attribute.getUid());
    orgUnitProfile.getDataItems().add(dataElement.getUid());
    orgUnitProfile.getGroupSets().add(groupSet.getUid());
    service.saveOrgUnitProfile(orgUnitProfile);
    // 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("testAttributeValue", data.getAttributes().get(0).getValue());
    assertEquals("testDataValue", data.getDataItems().get(0).getValue());
    assertEquals(group.getDisplayName(), data.getGroupSets().get(0).getValue());
}
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 25 with Attribute

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

the class TrackerPreheatTest method testPutAndGetByAttribute.

@Test
void testPutAndGetByAttribute() {
    TrackerPreheat preheat = new TrackerPreheat();
    Attribute attribute = new Attribute();
    attribute.setAutoFields();
    AttributeValue attributeValue = new AttributeValue("value1");
    attributeValue.setAttribute(attribute);
    DataElement de1 = new DataElement("dataElementA");
    de1.setAttributeValues(Collections.singleton(attributeValue));
    preheat.put(TrackerIdentifier.builder().idScheme(TrackerIdScheme.ATTRIBUTE).value(attribute.getUid()).build(), de1);
    assertEquals(1, preheat.getAll(DataElement.class).size());
    assertThat(preheat.get(DataElement.class, "value1"), is(notNullValue()));
}
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)

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