Search in sources :

Example 1 with UserQueryParams

use of org.hisp.dhis.user.UserQueryParams in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method findUser.

@Override
public Collection<org.hisp.dhis.api.mobile.model.User> findUser(String keyword) throws NotAllowedException {
    Collection<User> users = new HashSet<>();
    Collection<org.hisp.dhis.api.mobile.model.User> userList = new HashSet<>();
    if (keyword != null) {
        int index = keyword.indexOf(' ');
        if (index != -1 && index == keyword.lastIndexOf(' ')) {
            String[] keys = keyword.split(" ");
            keyword = keys[0] + "  " + keys[1];
        }
    }
    UserQueryParams params = new UserQueryParams();
    params.setQuery(keyword);
    users = userService.getUsers(params);
    for (User userCore : users) {
        org.hisp.dhis.api.mobile.model.User user = new org.hisp.dhis.api.mobile.model.User();
        user.setId(userCore.getId());
        user.setSurname(userCore.getSurname());
        user.setFirstName(userCore.getFirstName());
        userList.add(user);
    }
    return userList;
}
Also used : User(org.hisp.dhis.user.User) UserQueryParams(org.hisp.dhis.user.UserQueryParams) HashSet(java.util.HashSet)

Example 2 with UserQueryParams

use of org.hisp.dhis.user.UserQueryParams in project dhis2-core by dhis2.

the class GetUserListAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    UserQueryParams params = new UserQueryParams();
    params.setQuery(key);
    params.setInactiveMonths(months);
    params.setSelfRegistered(selfRegistered);
    params.setInvitationStatus(UserInvitationStatus.fromValue(invitationStatus));
    int count = userService.getUserCount(params);
    this.paging = createPaging(count);
    params.setFirst(paging.getStartPos());
    params.setMax(paging.getPageSize());
    users = userService.getUsers(params);
    return SUCCESS;
}
Also used : UserQueryParams(org.hisp.dhis.user.UserQueryParams)

Example 3 with UserQueryParams

use of org.hisp.dhis.user.UserQueryParams in project dhis2-core by dhis2.

the class MetadataOrgUnitMergeHandler method mergeUsers.

public void mergeUsers(OrgUnitMergeRequest request) {
    List<User> dataCaptureUsers = userService.getUsers(new UserQueryParams().setCanSeeOwnUserAuthorityGroups(true).setOrganisationUnits(request.getSources()));
    dataCaptureUsers.forEach(u -> {
        u.addOrganisationUnit(request.getTarget());
        u.removeOrganisationUnits(request.getSources());
    });
    List<User> dataViewUsers = userService.getUsers(new UserQueryParams().setCanSeeOwnUserAuthorityGroups(true).setDataViewOrganisationUnits(request.getSources()));
    dataViewUsers.forEach(u -> {
        u.getDataViewOrganisationUnits().add(request.getTarget());
        u.getDataViewOrganisationUnits().removeAll(request.getSources());
    });
    List<User> teiSearchOrgUnits = userService.getUsers(new UserQueryParams().setCanSeeOwnUserAuthorityGroups(true).setTeiSearchOrganisationUnits(request.getSources()));
    teiSearchOrgUnits.forEach(u -> {
        u.getTeiSearchOrganisationUnits().add(request.getTarget());
        u.getTeiSearchOrganisationUnits().removeAll(request.getSources());
    });
}
Also used : User(org.hisp.dhis.user.User) UserQueryParams(org.hisp.dhis.user.UserQueryParams)

Example 4 with UserQueryParams

use of org.hisp.dhis.user.UserQueryParams in project dhis2-core by dhis2.

the class DefaultDataStatisticsService method getSystemStatisticsSummary.

@Override
public DataSummary getSystemStatisticsSummary() {
    DataSummary statistics = new DataSummary();
    // Database objects
    Map<String, Long> objectCounts = new HashMap<>();
    statisticsProvider.getObjectCounts().forEach((object, count) -> objectCounts.put(object.getValue(), count));
    statistics.setObjectCounts(objectCounts);
    // Active users
    Date lastHour = new DateTime().minusHours(1).toDate();
    Map<Integer, Integer> activeUsers = new HashMap<>();
    activeUsers.put(0, userService.getActiveUsersCount(lastHour));
    activeUsers.put(1, userService.getActiveUsersCount(0));
    activeUsers.put(2, userService.getActiveUsersCount(1));
    activeUsers.put(7, userService.getActiveUsersCount(7));
    activeUsers.put(30, userService.getActiveUsersCount(30));
    statistics.setActiveUsers(activeUsers);
    // User invitations
    Map<String, Integer> userInvitations = new HashMap<>();
    UserQueryParams inviteAll = new UserQueryParams();
    inviteAll.setInvitationStatus(UserInvitationStatus.ALL);
    userInvitations.put(UserInvitationStatus.ALL.getValue(), userService.getUserCount(inviteAll));
    UserQueryParams inviteExpired = new UserQueryParams();
    inviteExpired.setInvitationStatus(UserInvitationStatus.EXPIRED);
    userInvitations.put(UserInvitationStatus.EXPIRED.getValue(), userService.getUserCount(inviteExpired));
    statistics.setUserInvitations(userInvitations);
    // Data values
    Map<Integer, Integer> dataValueCount = new HashMap<>();
    dataValueCount.put(0, dataValueService.getDataValueCount(0));
    dataValueCount.put(1, dataValueService.getDataValueCount(1));
    dataValueCount.put(7, dataValueService.getDataValueCount(7));
    dataValueCount.put(30, dataValueService.getDataValueCount(30));
    statistics.setDataValueCount(dataValueCount);
    // Events
    Map<Integer, Long> eventCount = new HashMap<>();
    eventCount.put(0, programStageInstanceService.getProgramStageInstanceCount(0));
    eventCount.put(1, programStageInstanceService.getProgramStageInstanceCount(1));
    eventCount.put(7, programStageInstanceService.getProgramStageInstanceCount(7));
    eventCount.put(30, programStageInstanceService.getProgramStageInstanceCount(30));
    statistics.setEventCount(eventCount);
    return statistics;
}
Also used : HashMap(java.util.HashMap) DataSummary(org.hisp.dhis.datasummary.DataSummary) Date(java.util.Date) DateTime(org.joda.time.DateTime) UserQueryParams(org.hisp.dhis.user.UserQueryParams)

Example 5 with UserQueryParams

use of org.hisp.dhis.user.UserQueryParams in project dhis2-core by dhis2.

the class UserController method getEntityList.

// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
protected List<User> getEntityList(WebMetadata metadata, WebOptions options, List<String> filters, List<Order> orders) throws QueryParserException {
    UserQueryParams params = makeUserQueryParams(options);
    String ou = options.get("ou");
    if (ou != null) {
        params.addOrganisationUnit(organisationUnitService.getOrganisationUnit(ou));
    }
    if (options.isManage()) {
        params.setCanManage(true);
        params.setAuthSubset(true);
    }
    boolean hasUserGroupFilter = filters.stream().anyMatch(f -> f.startsWith("userGroups."));
    params.setPrefetchUserGroups(hasUserGroupFilter);
    if (filters.isEmpty() && options.hasPaging()) {
        metadata.setPager(makePager(options, params));
    }
    Query query = makeQuery(options, filters, orders, params);
    return (List<User>) queryService.query(query);
}
Also used : Query(org.hisp.dhis.query.Query) List(java.util.List) UserQueryParams(org.hisp.dhis.user.UserQueryParams)

Aggregations

UserQueryParams (org.hisp.dhis.user.UserQueryParams)14 User (org.hisp.dhis.user.User)5 Date (java.util.Date)2 HashMap (java.util.HashMap)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 UserLookup (org.hisp.dhis.webapi.webdomain.user.UserLookup)2 UserLookups (org.hisp.dhis.webapi.webdomain.user.UserLookups)2 DateTime (org.joda.time.DateTime)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 Objects (org.hisp.dhis.common.Objects)1 DataSummary (org.hisp.dhis.datasummary.DataSummary)1 ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)1 Query (org.hisp.dhis.query.Query)1 IncomingSms (org.hisp.dhis.sms.incoming.IncomingSms)1 SmsMessageStatus (org.hisp.dhis.sms.incoming.SmsMessageStatus)1 UserGroup (org.hisp.dhis.user.UserGroup)1