use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class GetUserGroupListAction method populateMemberShipMap.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private Map<UserGroup, Boolean> populateMemberShipMap(List<UserGroup> userGroups) {
User currentUser = currentUserService.getCurrentUser();
Map<UserGroup, Boolean> map = new HashMap<>();
if (currentUser != null && currentUser.getGroups() != null) {
Set<UserGroup> members = currentUser.getGroups();
for (UserGroup ug : userGroups) {
map.put(ug, members.contains(ug));
}
}
return map;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class UpdateUserGroupAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
//TODO managed groups access control
UserGroup userGroup = userGroupService.getUserGroup(userGroupId);
Set<User> users = new HashSet<>();
for (String uid : usersSelected) {
users.add(userService.getUser(uid));
}
userGroup.setName(StringUtils.trimToNull(name));
userGroup.updateUsers(users);
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(userGroup, jsonAttributeValues);
}
Set<UserGroup> managedGroups = new HashSet<>();
for (String uid : userGroupsSelected) {
managedGroups.add(userGroupService.getUserGroup(uid));
}
userGroup.updateManagedGroups(managedGroups);
userGroupService.updateUserGroup(userGroup);
hibernateCacheManager.clearCache();
return SUCCESS;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class SendMessageAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
String metaData = MessageService.META_USER_AGENT + ServletActionContext.getRequest().getHeader(ContextUtils.HEADER_USER_AGENT);
Set<User> users = new HashSet<>();
if (!ignoreTree) {
for (OrganisationUnit unit : selectionTreeManager.getReloadedSelectedOrganisationUnits()) {
users.addAll(unit.getUsers());
}
}
String[] recipientsArray = recipients.split(",");
for (String recipient : recipientsArray) {
if (recipient.startsWith(PREFIX_USER)) {
User user = userService.getUser(recipient.substring(2));
if (user != null) {
users.add(user);
}
} else if (recipient.startsWith(PREFIX_USERGROUP)) {
UserGroup userGroup = userGroupService.getUserGroup(recipient.substring(3));
if (userGroup != null) {
users.addAll(userGroup.getMembers());
}
}
}
messageService.sendPrivateMessage(subject, text, metaData, users);
return SUCCESS;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ProcessingSendQuickSMSAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public String execute() throws Exception {
gatewayId = gatewayAdminService.getDefaultGateway().getName();
if (gatewayId == null || gatewayId.trim().length() == 0) {
message = i18n.getString("please_select_a_gateway_type_to_send_sms");
return ERROR;
}
if (text == null || text.trim().length() == 0) {
message = i18n.getString("no_message");
return ERROR;
}
User currentUser = currentUserService.getCurrentUser();
List<User> recipientsList = new ArrayList<>();
if ("phone".equals(sendTarget)) {
ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
recipients = mapper.readValue(recipients.iterator().next(), Set.class);
for (String each : recipients) {
if (!each.startsWith("+")) {
each = "+" + each;
}
User user = new User();
user.setPhoneNumber(each);
recipientsList.add(user);
}
// message = messageSender.sendMessage( smsSubject, smsMessage,
// currentUser, true, recipients, gatewayId );
} else if ("userGroup".equals(sendTarget)) {
UserGroup group = userGroupService.getUserGroup(userGroup);
if (group == null) {
message = i18n.getString("selected_user_group_is_unavailable");
return ERROR;
}
if (group.getMembers() == null || group.getMembers().isEmpty()) {
message = i18n.getString("selected_user_group_has_no_member");
return ERROR;
}
recipientsList = new ArrayList<>(group.getMembers());
} else if (sendTarget.equals("user")) {
Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits();
if (units != null && !units.isEmpty()) {
for (OrganisationUnit unit : units) {
recipientsList.addAll(unit.getUsers());
}
if (recipientsList.isEmpty()) {
message = i18n.getString("there_is_no_user_assigned_to_selected_units");
return ERROR;
}
// message = messageSender.sendMessage( smsSubject, smsMessage,
// currentUser, false, users, gatewayId );
}
} else if (sendTarget.equals("unit")) {
for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) {
if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) {
User user = new User();
user.setPhoneNumber(unit.getPhoneNumber());
recipientsList.add(user);
}
}
if (recipientsList.isEmpty()) {
message = i18n.getString("selected_units_have_no_phone_number");
return ERROR;
}
}
TaskId taskId = new TaskId(TaskCategory.SENDING_SMS, currentUser);
notifier.clear(taskId);
sendSmsTask.setTaskId(taskId);
sendSmsTask.setCurrentUser(currentUser);
sendSmsTask.setRecipientsList(recipientsList);
sendSmsTask.setSmsSubject(smsSubject);
sendSmsTask.setText(text);
scheduler.executeTask(sendSmsTask);
if (message != null && !message.equals("success")) {
message = i18n.getString(message);
return ERROR;
}
if (message == null) {
message = "An inter error occurs, please contact your administration";
return ERROR;
}
return SUCCESS;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class UnregisteredSMSListener method postProcess.
@Override
protected void postProcess(IncomingSms sms, SMSCommand smsCommand, Map<String, String> parsedMessage) {
UserGroup userGroup = smsCommand.getUserGroup();
String userName = sms.getOriginator();
if (userGroup != null) {
User anonymousUser = userService.getUserByUsername(userName);
if (anonymousUser == null) {
User user = new User();
user.setSurname(userName);
user.setFirstName("");
user.setAutoFields();
userService.addUser(user);
anonymousUser = userService.getUserByUsername(userName);
}
messageService.sendMessage(new MessageConversationParams.Builder(userGroup.getMembers(), anonymousUser, smsCommand.getName(), sms.getText(), MessageType.SYSTEM, null).build());
sendFeedback(smsCommand.getReceivedMessage(), sms.getOriginator(), INFO);
update(sms, SmsMessageStatus.PROCESSED, true);
}
}
Aggregations