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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations