use of org.hisp.dhis.organisationunit.OrganisationUnitQueryParams in project dhis2-core by dhis2.
the class DefaultProgramService method mergeWithCurrentUserOrganisationUnits.
@Override
public void mergeWithCurrentUserOrganisationUnits(Program program, Collection<OrganisationUnit> mergeOrganisationUnits) {
Set<OrganisationUnit> selectedOrgUnits = Sets.newHashSet(program.getOrganisationUnits());
OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
params.setParents(currentUserService.getCurrentUser().getOrganisationUnits());
Set<OrganisationUnit> userOrganisationUnits = Sets.newHashSet(organisationUnitService.getOrganisationUnitsByQuery(params));
selectedOrgUnits.removeAll(userOrganisationUnits);
selectedOrgUnits.addAll(mergeOrganisationUnits);
program.updateOrganisationUnits(selectedOrgUnits);
updateProgram(program);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitQueryParams in project dhis2-core by dhis2.
the class OrganisationUnitController method getEntityList.
@Override
@SuppressWarnings("unchecked")
protected List<OrganisationUnit> getEntityList(WebMetadata metadata, WebOptions options, List<String> filters, List<Order> orders) throws QueryParserException {
List<OrganisationUnit> objects = Lists.newArrayList();
User currentUser = currentUserService.getCurrentUser();
boolean anySpecialPropertySet = ObjectUtils.anyIsTrue(options.isTrue("userOnly"), options.isTrue("userDataViewOnly"), options.isTrue("userDataViewFallback"), options.isTrue("levelSorted"));
boolean anyQueryPropertySet = ObjectUtils.firstNonNull(options.get("query"), options.getInt("level"), options.getInt("maxLevel")) != null || options.isTrue("withinUserHierarchy");
String memberObject = options.get("memberObject");
String memberCollection = options.get("memberCollection");
if (options.isTrue("userOnly")) {
objects = new ArrayList<>(currentUser.getOrganisationUnits());
} else if (options.isTrue("userDataViewOnly")) {
objects = new ArrayList<>(currentUser.getDataViewOrganisationUnits());
} else if (options.isTrue("userDataViewFallback")) {
if (currentUser.hasDataViewOrganisationUnit()) {
objects = new ArrayList<>(currentUser.getDataViewOrganisationUnits());
} else {
objects = organisationUnitService.getOrganisationUnitsAtLevel(1);
}
} else if (options.isTrue("levelSorted")) {
objects = new ArrayList<>(manager.getAll(getEntityClass()));
Collections.sort(objects, OrganisationUnitByLevelComparator.INSTANCE);
} else if (anyQueryPropertySet) {
OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
params.setQuery(options.get("query"));
params.setLevel(options.getInt("level"));
params.setMaxLevels(options.getInt("maxLevel"));
params.setParents(options.isTrue("withinUserHierarchy") ? currentUser.getOrganisationUnits() : Sets.newHashSet());
objects = organisationUnitService.getOrganisationUnitsByQuery(params);
}
// ---------------------------------------------------------------------
// Standard Query handling
// ---------------------------------------------------------------------
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, orders, options.getRootJunction());
query.setUser(currentUser);
query.setDefaultOrder();
if (anySpecialPropertySet || anyQueryPropertySet) {
query.setObjects(objects);
}
List<OrganisationUnit> list = (List<OrganisationUnit>) queryService.query(query);
// ---------------------------------------------------------------------
// Collection member count in hierarchy handling
// ---------------------------------------------------------------------
IdentifiableObject member = null;
if (memberObject != null && memberCollection != null && (member = manager.get(memberObject)) != null) {
for (OrganisationUnit unit : list) {
Long count = organisationUnitService.getOrganisationUnitHierarchyMemberCount(unit, member, memberCollection);
unit.setMemberCount((count != null ? count.intValue() : 0));
}
}
return list;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitQueryParams in project dhis2-core by dhis2.
the class GetOrganisationUnitsByNameAction method execute.
// -------------------------------------------------------------------------
// Implementation Action
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
term = term.toLowerCase();
User user = currentUserService.getCurrentUser();
OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
if (user != null && user.hasOrganisationUnit()) {
params.setParents(user.getOrganisationUnits());
}
params.setQuery(term);
params.setMax(MAX);
organisationUnits = organisationUnitService.getOrganisationUnitsByQuery(params);
return SUCCESS;
}
Aggregations