Search in sources :

Example 91 with OrganisationUnit

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();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 92 with OrganisationUnit

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;
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HashSet(java.util.HashSet)

Example 93 with OrganisationUnit

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 94 with OrganisationUnit

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HashSet(java.util.HashSet)

Example 95 with OrganisationUnit

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();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)321 Period (org.hisp.dhis.period.Period)74 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)62 User (org.hisp.dhis.user.User)57 Date (java.util.Date)53 HashSet (java.util.HashSet)53 DataSet (org.hisp.dhis.dataset.DataSet)53 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 DataElement (org.hisp.dhis.dataelement.DataElement)50 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)37 List (java.util.List)36 CurrentUserService (org.hisp.dhis.user.CurrentUserService)29 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)23 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)23 Program (org.hisp.dhis.program.Program)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20