use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOrganisationUnitGroup.
/**
* @param uniqueCharacter A unique character to identify the object.
*/
public static OrganisationUnitGroup createOrganisationUnitGroup(char uniqueCharacter) {
OrganisationUnitGroup group = new OrganisationUnitGroup();
group.setAutoFields();
group.setUid(BASE_UID + uniqueCharacter);
group.setName("OrganisationUnitGroup" + uniqueCharacter);
group.setShortName("OrganisationUnitGroupShort" + uniqueCharacter);
group.setCode("OrganisationUnitGroupCode" + uniqueCharacter);
return group;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class DefaultExpressionService method getOrganisationUnitGroupsInIndicators.
@Override
public Set<OrganisationUnitGroup> getOrganisationUnitGroupsInIndicators(Collection<Indicator> indicators) {
Set<OrganisationUnitGroup> groups = new HashSet<>();
if (indicators != null) {
for (Indicator indicator : indicators) {
groups.addAll(getOrganisationUnitGroupsInExpression(indicator.getNumerator()));
groups.addAll(getOrganisationUnitGroupsInExpression(indicator.getDenominator()));
}
}
return groups;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class DefaultExpressionService method substituteExpression.
private String substituteExpression(String expression, Map<String, Constant> constants, Map<String, OrganisationUnitGroup> orgUnitGroups, Integer days) {
if (expression == null || expression.isEmpty()) {
return null;
}
// ---------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------
StringBuffer sb = new StringBuffer();
Matcher matcher = CONSTANT_PATTERN.matcher(expression);
while (matcher.find()) {
String co = matcher.group(GROUP_ID);
Constant constant = constants.get(co);
String replacement = constant != null ? String.valueOf(constant.getValue()) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Org unit groups
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = OU_GROUP_PATTERN.matcher(expression);
while (matcher.find()) {
String oug = matcher.group(GROUP_ID);
OrganisationUnitGroup group = orgUnitGroups.get(oug);
String replacement = group != null ? String.valueOf(group.getMembers().size()) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, replacement);
// TODO sub tree
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Days
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = DAYS_PATTERN.matcher(expression);
while (matcher.find()) {
String replacement = days != null ? String.valueOf(days) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, replacement);
}
return TextUtils.appendTail(matcher, sb);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class MergeServiceTest method mergeOrgUnitGroupSet.
@Test
public void mergeOrgUnitGroupSet() {
OrganisationUnit organisationUnitA = createOrganisationUnit('A');
OrganisationUnit organisationUnitB = createOrganisationUnit('B');
OrganisationUnit organisationUnitC = createOrganisationUnit('C');
OrganisationUnit organisationUnitD = createOrganisationUnit('D');
OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
organisationUnitGroupA.getMembers().add(organisationUnitA);
organisationUnitGroupA.getMembers().add(organisationUnitB);
organisationUnitGroupA.getMembers().add(organisationUnitC);
organisationUnitGroupA.getMembers().add(organisationUnitD);
OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
mergeService.merge(new MergeParams<>(organisationUnitGroupSetA, organisationUnitGroupSetB).setMergeMode(MergeMode.REPLACE));
assertFalse(organisationUnitGroupSetB.getOrganisationUnitGroups().isEmpty());
assertEquals(organisationUnitGroupSetA.getName(), organisationUnitGroupSetB.getName());
assertEquals(organisationUnitGroupSetA.getDescription(), organisationUnitGroupSetB.getDescription());
assertEquals(organisationUnitGroupSetA.isCompulsory(), organisationUnitGroupSetB.isCompulsory());
assertEquals(organisationUnitGroupSetA.isIncludeSubhierarchyInAnalytics(), organisationUnitGroupSetB.isIncludeSubhierarchyInAnalytics());
assertEquals(1, organisationUnitGroupSetB.getOrganisationUnitGroups().size());
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class AbstractDataSetCompletenessService method getRelevantSources.
private Set<Integer> getRelevantSources(DataSet dataSet, Set<Integer> sources, Set<OrganisationUnitGroup> groups) {
Set<Integer> dataSetSources = new HashSet<>(getIdentifiers(dataSet.getSources()));
if (groups != null) {
for (OrganisationUnitGroup group : groups) {
List<Integer> ids = getIdentifiers(group.getMembers());
dataSetSources.retainAll(ids);
}
}
return Sets.intersection(dataSetSources, sources);
}
Aggregations