Search in sources :

Example 1 with OrganisationUnitQueryParams

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

Example 2 with OrganisationUnitQueryParams

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Query(org.hisp.dhis.query.Query) ArrayList(java.util.ArrayList) OrganisationUnitQueryParams(org.hisp.dhis.organisationunit.OrganisationUnitQueryParams) ArrayList(java.util.ArrayList) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 3 with OrganisationUnitQueryParams

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

Aggregations

OrganisationUnitQueryParams (org.hisp.dhis.organisationunit.OrganisationUnitQueryParams)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 Query (org.hisp.dhis.query.Query)1