use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class MobileClientController method getOrgUnitsForUser2_8.
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public OrgUnits getOrgUnitsForUser2_8(HttpServletRequest request) throws NotAllowedException {
User user = currentUserService.getCurrentUser();
if (user == null) {
throw NotAllowedException.NO_USER;
}
Collection<OrganisationUnit> units = user.getOrganisationUnits();
List<MobileOrgUnitLinks> unitList = new ArrayList<>();
for (OrganisationUnit unit : units) {
unitList.add(getOrgUnit(unit, request));
}
OrgUnits orgUnits = new OrgUnits(unitList);
orgUnits.setClientVersion(DataStreamSerializable.TWO_POINT_EIGHT);
return orgUnits;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class FormUtils method getCategoryCombo.
private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
if (dataset.hasCategoryCombo()) {
DataElementCategoryCombo categoryCombo = dataset.getCategoryCombo();
CategoryCombo catCombo = new CategoryCombo();
catCombo.setId(categoryCombo.getUid());
List<DataElementCategory> cats = categoryCombo.getCategories();
if (cats != null && cats.size() > 0) {
for (DataElementCategory cat : cats) {
if (cat.getAccess() != null && !cat.getAccess().isRead()) {
continue;
}
Category c = new Category();
c.setId(cat.getUid());
c.setLabel(cat.getName());
List<DataElementCategoryOption> options = cat.getCategoryOptions();
if (options != null && options.size() > 0) {
for (DataElementCategoryOption option : options) {
if (option.getAccess() != null && !option.getAccess().isRead()) {
continue;
}
Option o = new Option();
o.setId(option.getUid());
o.setLabel(option.getDisplayName());
o.setStartDate(option.getStartDate());
o.setEndDate(option.getEndDate());
Set<OrganisationUnit> catOptionOUs = option.getOrganisationUnits();
if (userOrganisationUnits == null || userOrganisationUnits.isEmpty() || catOptionOUs == null || catOptionOUs.isEmpty()) {
c.getOptions().add(o);
} else if (userOrganisationUnits != null && catOptionOUs != null && !Collections.disjoint(userOrganisationUnits, catOptionOUs)) {
HashSet<OrganisationUnit> organisationUnits = new HashSet<>();
catOptionOUs.stream().filter(ou -> userOrganisationUnits.contains(ou)).forEach(ou -> {
organisationUnits.add(ou);
organisationUnits.addAll(getChildren(ou, new HashSet<>()));
});
o.setOrganisationUnits(organisationUnits);
c.getOptions().add(o);
}
}
}
catCombo.getCategories().add(c);
}
}
return catCombo;
}
return null;
}
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 DataApproval method getLowestApproval.
// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
/**
* Finds the lowest level (if any) at which data would be approved.
*/
public static DataApproval getLowestApproval(DataApproval dataApproval) {
OrganisationUnit orgUnit = dataApproval.getOrganisationUnit();
List<DataApprovalLevel> approvalLevels = dataApproval.getWorkflow().getSortedLevels();
Collections.reverse(approvalLevels);
DataApproval da = null;
for (DataApprovalLevel approvalLevel : approvalLevels) {
int orgUnitLevel = orgUnit.getLevel();
if (approvalLevel.getOrgUnitLevel() <= orgUnitLevel) {
if (approvalLevel.getOrgUnitLevel() < orgUnitLevel) {
orgUnit = orgUnit.getAncestors().get(approvalLevel.getOrgUnitLevel() - 1);
}
da = new DataApproval(approvalLevel, dataApproval.getWorkflow(), dataApproval.getPeriod(), orgUnit, dataApproval.getAttributeOptionCombo());
break;
}
}
return da;
}
Aggregations