Search in sources :

Example 96 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class GetOrganisationUnitChildrenAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    OrganisationUnit unit = organisationUnitService.getOrganisationUnit(id);
    organisationUnits = new ArrayList<>(unit.getChildren());
    Collections.sort(organisationUnits);
    if (usePaging) {
        this.paging = createPaging(organisationUnits.size());
        organisationUnits = organisationUnits.subList(paging.getStartPos(), paging.getEndPos());
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 97 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class GetOrganisationUnitTreeAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    version = getVersionString();
    username = currentUserService.getCurrentUsername();
    User user = currentUserService.getCurrentUser();
    if (user != null && user.hasOrganisationUnit()) {
        rootOrganisationUnits = new ArrayList<>(user.getOrganisationUnits());
    } else if (currentUserService.currentUserIsSuper() || user == null) {
        rootOrganisationUnits = new ArrayList<>(organisationUnitService.getRootOrganisationUnits());
    }
    if (byName != null) {
        List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName(byName);
        if (!organisationUnitByName.isEmpty()) {
            OrganisationUnit child = organisationUnitByName.get(0);
            organisationUnits.add(child);
            OrganisationUnit parent = child.getParent();
            if (parent != null) {
                do {
                    organisationUnits.add(parent);
                    organisationUnits.addAll(parent.getChildren());
                } while ((parent = parent.getParent()) != null);
            }
            return "partial";
        }
    }
    if (leafId != null) {
        OrganisationUnit leaf = organisationUnitService.getOrganisationUnit(leafId);
        if (leaf != null) {
            organisationUnits.add(leaf);
            organisationUnits.addAll(leaf.getChildren());
            for (OrganisationUnit organisationUnit : leaf.getAncestors()) {
                organisationUnits.add(organisationUnit);
                organisationUnits.addAll(organisationUnit.getChildren());
            }
        }
        return "partial";
    }
    if (parentId != null) {
        OrganisationUnit parent = organisationUnitService.getOrganisationUnit(parentId);
        if (parent != null) {
            organisationUnits.addAll(parent.getChildren());
        }
        return "partial";
    }
    if (!versionOnly && !rootOrganisationUnits.isEmpty()) {
        Integer offlineLevels = getOfflineOrganisationUnitLevels();
        for (OrganisationUnit unit : rootOrganisationUnits) {
            organisationUnits.addAll(organisationUnitService.getOrganisationUnitWithChildren(unit.getId(), offlineLevels));
        }
    }
    Collection<?> intersection = org.apache.commons.collections.CollectionUtils.intersection(organisationUnitService.getRootOrganisationUnits(), rootOrganisationUnits);
    if (intersection.size() > 0) {
        realRoot = true;
    }
    Collections.sort(rootOrganisationUnits);
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList)

Example 98 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DefaultDataApprovalLevelService method getUserReadApprovalLevels.

@Override
public Map<OrganisationUnit, Integer> getUserReadApprovalLevels(DataApprovalLevel approvalLevel) {
    Map<OrganisationUnit, Integer> map = new HashMap<>();
    User user = currentUserService.getCurrentUser();
    Collection<OrganisationUnit> orgUnits = user.getDataViewOrganisationUnits();
    if (orgUnits == null || orgUnits.isEmpty()) {
        orgUnits = organisationUnitService.getRootOrganisationUnits();
    }
    for (OrganisationUnit orgUnit : orgUnits) {
        map.put(orgUnit, approvalLevel.getLevel());
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap)

Example 99 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DefaultDataApprovalLevelService method getCurrentUsersLowestNumberOrgUnitLevel.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Finds the lowest number (highest level) organisaiton unit level
     * from the organisations assigned to the current user.
     */
private int getCurrentUsersLowestNumberOrgUnitLevel() {
    int level = APPROVAL_LEVEL_UNAPPROVED;
    Set<OrganisationUnit> userOrgUnits = currentUserService.getCurrentUser().getOrganisationUnits();
    for (OrganisationUnit orgUnit : userOrgUnits) {
        if (orgUnit.getLevel() < level) {
            level = orgUnit.getLevel();
        }
    }
    return level;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit)

Example 100 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DefaultDataApprovalLevelService method getUserReadApprovalLevels.

@Override
public Map<OrganisationUnit, Integer> getUserReadApprovalLevels() {
    Map<OrganisationUnit, Integer> map = new HashMap<>();
    User user = currentUserService.getCurrentUser();
    List<DataApprovalLevel> approvalLevels = getAllDataApprovalLevels();
    if (user.getUserCredentials().isAuthorized(DataApproval.AUTH_APPROVE_LOWER_LEVELS)) {
        for (OrganisationUnit orgUnit : user.getOrganisationUnits()) {
            map.put(orgUnit, APPROVAL_LEVEL_UNAPPROVED);
        }
    } else {
        for (OrganisationUnit orgUnit : user.getOrganisationUnits()) {
            int level = requiredApprovalLevel(orgUnit, user, approvalLevels);
            map.put(orgUnit, level);
        }
    }
    // ---------------------------------------------------------------------
    // Add data view organisation units with approval levels
    // ---------------------------------------------------------------------
    Collection<OrganisationUnit> dataViewOrgUnits = user.getDataViewOrganisationUnits();
    if (dataViewOrgUnits == null || dataViewOrgUnits.isEmpty()) {
        dataViewOrgUnits = organisationUnitService.getRootOrganisationUnits();
    }
    for (OrganisationUnit orgUnit : dataViewOrgUnits) {
        if (!map.containsKey(orgUnit)) {
            int level = requiredApprovalLevel(orgUnit, user, approvalLevels);
            map.put(orgUnit, level);
        }
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap)

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