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