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