use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultSelectionTreeManager method getRootOrganisationUnitsParent.
@Override
public OrganisationUnit getRootOrganisationUnitsParent() {
Collection<OrganisationUnit> rootUnits = getCollectionFromSession(SESSION_KEY_ROOT_ORG_UNITS);
if (rootUnits == null || rootUnits.isEmpty()) {
return null;
}
OrganisationUnit randomRootUnit = rootUnits.iterator().next();
OrganisationUnit reloadedRootUnit = reloadOrganisationUnit(randomRootUnit);
return reloadedRootUnit.getParent();
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultSelectionTreeManager method reloadOrganisationUnits.
private Collection<OrganisationUnit> reloadOrganisationUnits(Collection<OrganisationUnit> units) {
int noSelected = units.size();
if (// Select all at once
noSelected > LIMIT_SELECT_ALL_ORG_UNITS) {
Set<OrganisationUnit> orgUnits = Sets.newHashSet(organisationUnitService.getAllOrganisationUnits());
orgUnits.retainAll(Sets.newHashSet(units));
return orgUnits;
} else // Select one by one
{
Set<OrganisationUnit> reloadedUnits = new HashSet<>();
for (OrganisationUnit unit : units) {
OrganisationUnit reloadedUnit = reloadOrganisationUnit(unit);
if (reloadedUnit != null) {
reloadedUnits.add(reloadedUnit);
}
}
return reloadedUnits;
}
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class AddSelectedOrganisationUnitAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
selectedUnits = new HashSet<>(selectionTreeManager.getSelectedOrganisationUnits());
if (id != null) {
OrganisationUnit unit = organisationUnitService.getOrganisationUnit(id);
selectedUnits.add(unit);
}
if (level != null) {
selectedUnits.addAll(organisationUnitService.getOrganisationUnitsAtLevel(level));
}
if (organisationUnitGroupId != null) {
selectedUnits.addAll(organisationUnitGroupService.getOrganisationUnitGroup(organisationUnitGroupId).getMembers());
}
if (children != null && children == true) {
for (OrganisationUnit selected : selectionTreeManager.getSelectedOrganisationUnits()) {
selectedUnits.addAll(organisationUnitService.getOrganisationUnitWithChildren(selected.getId()));
}
}
selectionTreeManager.setSelectedOrganisationUnits(selectedUnits);
return SUCCESS;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class GetExpandedTreeAction method findPathNodes.
private final Collection<OrganisationUnit> findPathNodes(Collection<OrganisationUnit> roots, Collection<OrganisationUnit> selected) {
Set<OrganisationUnit> pathNodes = new HashSet<>();
for (OrganisationUnit unit : selected) {
if (// Is parent => done
roots.contains(unit)) {
continue;
}
// Start with parent
OrganisationUnit tmp = unit.getParent();
while (!roots.contains(tmp)) {
// Add each parent
pathNodes.add(tmp);
if (tmp != null && tmp.getParent() != null) {
tmp = tmp.getParent();
}
}
// Add the root
pathNodes.add(tmp);
}
return pathNodes;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultOrganisationUnitSelectionManager method getRootOrganisationUnitsParent.
@Override
public OrganisationUnit getRootOrganisationUnitsParent() {
Collection<OrganisationUnit> rootUnits = getCollectionFromSession(SESSION_KEY_ROOT_ORG_UNITS);
if (rootUnits == null || rootUnits.isEmpty()) {
return null;
}
OrganisationUnit randomRootUnit = rootUnits.iterator().next();
OrganisationUnit reloadedRootUnit = reloadOrganisationUnit(randomRootUnit);
return reloadedRootUnit.getParent();
}
Aggregations