Commit 90cb959d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Initial version. JM-816

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5137 b35dd754-fafc-0310-a699-88a17e54d16e
parent c9d04464
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupAlreadyExistsException;
import org.jivesoftware.wildfire.group.GroupManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* Command that allows to create and configure new goups.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class AddGroup extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Create new group");
form.addInstruction("Fill out this form to create a new group.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_multi);
field.setLabel("Description");
field.setVariable("desc");
field = form.addField();
field.setType(FormField.Type.jid_multi);
field.setLabel("Initial members");
field.setVariable("members");
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Shared group visibility");
field.setVariable("showInRoster");
field.addValue("nobody");
field.addOption("Disable sharing group in rosters", "nobody");
field.addOption("Show group in all users' rosters", "everybody");
field.addOption("Show group in group members' rosters", "onlyGroup");
field.addOption("Show group to members' rosters of these groups", "spefgroups");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.list_multi);
field.setVariable("groupList");
for (Group group : GroupManager.getInstance().getGroups()) {
field.addOption(group.getName(), group.getName());
}
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Display Name");
field.setVariable("displayName");
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().createGroup(data.getData().get("group").get(0));
} catch (GroupAlreadyExistsException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group already exists");
return;
}
List<String> desc = data.getData().get("desc");
if (desc != null && !desc.isEmpty()) {
group.setDescription(desc.get(0));
}
List<String> members = data.getData().get("members");
boolean withErrors = false;
if (members != null) {
Collection<JID> users = group.getMembers();
for (String user : members) {
try {
users.add(new JID(user));
} catch (Exception e) {
Log.warn("User not added to group", e);
withErrors = true;
}
}
}
String showInRoster = data.getData().get("showInRoster").get(0);
if ("nobody".equals(showInRoster)) {
// New group is not a shared group
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", " ");
group.getProperties().put("sharedRoster.groupList", " ");
}
else {
// New group is configured as a shared group
if ("spefgroups".equals(showInRoster)) {
// Show shared group to other groups
showInRoster = "onlyGroup";
}
List<String> displayName = data.getData().get("displayName");
List<String> groupList = data.getData().get("groupList");
if (displayName != null) {
group.getProperties().put("sharedRoster.showInRoster", showInRoster);
group.getProperties().put("sharedRoster.displayName", displayName.get(0));
if (groupList != null) {
StringBuilder buf = new StringBuilder();
String sep = "";
for (String groupName : groupList) {
buf.append(sep).append(groupName);
sep = ",";
}
group.getProperties().put("sharedRoster.groupList", buf.toString());
}
}
else {
withErrors = true;
}
}
note.addAttribute("type", "info");
note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
public String getCode() {
return "http://jabber.org/protocol/admin#add-group";
}
public String getDefaultLabel() {
return "Create new group";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* Command that allows to add members or admins to a given group.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class AddGroupUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Add members or admins to a group");
form.addInstruction("Fill out this form to add new members or admins to a group.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.boolean_type);
field.setLabel("Admin");
field.setVariable("admin");
field.addValue(false);
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.jid_multi);
field.setLabel("Users");
field.setVariable("users");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
String admin = data.getData().get("admin").get(0);
boolean isAdmin = "1".equals(admin) || "true".equals(admin);
Collection<JID> users = (isAdmin ? group.getAdmins() : group.getMembers());
boolean withErrors = false;
for (String user : data.getData().get("users")) {
try {
users.add(new JID(user));
} catch (Exception e) {
Log.warn("User not added to group", e);
withErrors = true;
}
}
note.addAttribute("type", "info");
note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
public String getCode() {
return "http://jabber.org/protocol/admin#add-group-members";
}
public String getDefaultLabel() {
return "Add members or admins to a group";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.Arrays;
import java.util.List;
/**
* Command that allows to delete existing groups.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class DeleteGroup extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Delete group");
form.addInstruction("Fill out this form to delete a group.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
GroupManager.getInstance().deleteGroup(group);
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
public String getCode() {
return "http://jabber.org/protocol/admin#delete-group";
}
public String getDefaultLabel() {
return "Delete group";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.List;
/**
* Command that allows to delete members or admins from a given group.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class DeleteGroupUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Delete members or admins from a group");
form.addInstruction("Fill out this form to delete members or admins from a group.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.jid_multi);
field.setLabel("Users");
field.setVariable("users");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
boolean withErrors = false;
for (String user : data.getData().get("users")) {
try {
group.getAdmins().remove(new JID(user));
group.getMembers().remove(new JID(user));
} catch (Exception e) {
Log.warn("User not deleted from group", e);
withErrors = true;
}
}
note.addAttribute("type", "info");
note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
public String getCode() {
return "http://jabber.org/protocol/admin#delete-group-members";
}
public String getDefaultLabel() {
return "Delete members or admins from a group";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Command that allows to retrieve list members of a given group.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class GetListGroupUsers extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Requesting List of Group Members");
form.addInstruction("Fill out this form to request list of group members and admins.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
DataForm form = new DataForm(DataForm.Type.result);
form.addReportedField("jid", "User", FormField.Type.jid_single);
form.addReportedField("admin", "Description", FormField.Type.boolean_type);
// Add group members the result
for (JID memberJID : group.getMembers()) {
Map<String,Object> fields = new HashMap<String,Object>();
fields.put("jid", memberJID.toString());
fields.put("admin", false);
form.addItemFields(fields);
}
// Add group admins the result
for (JID memberJID : group.getAdmins()) {
Map<String,Object> fields = new HashMap<String,Object>();
fields.put("jid", memberJID.toString());
fields.put("admin", true);
form.addItemFields(fields);
}
command.add(form.getElement());
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-group-members";
}
public String getDefaultLabel() {
return "Get List of Group Members";
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.roster.RosterManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Command that allows to retrieve a list of existing groups.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class GetListGroups extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Requesting List of Existing Groups");
form.addInstruction("Fill out this form to request list of groups.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Start from page number");
field.setVariable("start");
field.addValue("0");
field.addOption("0", "0");
field.addOption("25", "25");
field.addOption("50", "50");
field.addOption("75", "75");
field.addOption("100", "100");
field.addOption("150", "150");
field.addOption("200", "200");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Maximum number of items to show");
field.setVariable("max_items");
field.addValue("25");
field.addOption("25", "25");
field.addOption("50", "50");
field.addOption("75", "75");
field.addOption("100", "100");
field.addOption("150", "150");
field.addOption("200", "200");
field.addOption("None", "none");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
String start = data.getData().get("start").get(0);
String max_items = data.getData().get("max_items").get(0);
int nStart = 0;
if (start != null) {
try {
nStart = Integer.parseInt(start);
}
catch (NumberFormatException e) {
// Do nothing. Assume default value
}
}
int maxItems = 100000;
if (max_items != null && "none".equals(max_items)) {
try {
maxItems = Integer.parseInt(max_items);
}
catch (NumberFormatException e) {
// Do nothing. Assume that all users are being requested
}
}
DataForm form = new DataForm(DataForm.Type.result);
form.addReportedField("name", "Name", FormField.Type.text_single);
form.addReportedField("desc", "Description", FormField.Type.text_multi);
form.addReportedField("count", "User Count", FormField.Type.text_single);
form.addReportedField("shared", "Shared group?", FormField.Type.boolean_type);
form.addReportedField("display", "Display Name", FormField.Type.text_single);
form.addReportedField("visibility", "Visibility", FormField.Type.text_single);
form.addReportedField("groups", "Show group to members' rosters of these groups", FormField.Type.text_multi);
// Add groups to the result
for (Group group : GroupManager.getInstance().getGroups(nStart, maxItems)) {
boolean isSharedGroup = RosterManager.isSharedGroup(group);
Map<String, String> properties = group.getProperties();
Map<String,Object> fields = new HashMap<String,Object>();
fields.put("name", group.getName());
fields.put("desc", group.getDescription());
fields.put("count", group.getMembers().size() + group.getAdmins().size());
fields.put("shared", isSharedGroup);
fields.put("display",
(isSharedGroup ? properties.get("sharedRoster.displayName") : ""));
String showInRoster =
(isSharedGroup ? properties.get("sharedRoster.showInRoster") : "");
if ("onlyGroup".equals(showInRoster) &&
properties.get("sharedRoster.groupList").trim().length() > 0) {
// Show shared group to other groups
showInRoster = "spefgroups";
}
fields.put("visibility", showInRoster);
fields.put("groups", (isSharedGroup ? properties.get("sharedRoster.groupList") : ""));
form.addItemFields(fields);
}
command.add(form.getElement());
}
public String getCode() {
return "http://jabber.org/protocol/admin#get-groups";
}
public String getDefaultLabel() {
return "Get List of Existing Groups";
}
protected List<AdHocCommand.Action> getActions(SessionData data) {
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 1;
}
}
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.commands.admin.group;
import org.dom4j.Element;
import org.jivesoftware.wildfire.commands.AdHocCommand;
import org.jivesoftware.wildfire.commands.SessionData;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import java.util.*;
/**
* Command that allows to update a given group.
*
* @author Gaston Dombiak
*
* TODO Use i18n
*/
public class UpdateGroup extends AdHocCommand {
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
if (data.getStage() == 0) {
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form to specify the group to update.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
}
else {
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group not found");
return;
}
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form with the new group configuration.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_multi);
field.setLabel("Description");
field.setVariable("desc");
if (group.getDescription() != null) {
field.addValue(group.getDescription());
}
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Shared group visibility");
field.setVariable("showInRoster");
field.addValue("nobody");
field.addOption("Disable sharing group in rosters", "nobody");
field.addOption("Show group in all users' rosters", "everybody");
field.addOption("Show group in group members' rosters", "onlyGroup");
field.addOption("Show group to members' rosters of these groups", "spefgroups");
field.setRequired(true);
String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if (showInRoster != null) {
if ("onlyGroup".equals(showInRoster) &&
group.getProperties().get("sharedRoster.groupList").trim().length() > 0) {
// Show shared group to other groups
showInRoster = "spefgroups";
}
field.addValue(showInRoster);
}
field = form.addField();
field.setType(FormField.Type.list_multi);
field.setVariable("groupList");
for (Group otherGroup : GroupManager.getInstance().getGroups()) {
field.addOption(otherGroup.getName(), otherGroup.getName());
}
String groupList = group.getProperties().get("sharedRoster.groupList");
if (groupList != null) {
Collection<String> groups = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(groupList,",\t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken().trim();
groups.add(tok.trim());
}
for (String othergroup : groups) {
field.addValue(othergroup);
}
}
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Display Name");
field.setVariable("displayName");
String displayName = group.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
field.addValue(displayName);
}
}
// Add the form to the command
command.add(form.getElement());
}
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group not found");
return;
}
List<String> desc = data.getData().get("desc");
if (desc != null) {
group.setDescription(desc.get(0));
}
String showInRoster = data.getData().get("showInRoster").get(0);
if ("nobody".equals(showInRoster)) {
// New group is not a shared group
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", " ");
group.getProperties().put("sharedRoster.groupList", " ");
}
else {
// New group is configured as a shared group
if ("spefgroups".equals(showInRoster)) {
// Show shared group to other groups
showInRoster = "onlyGroup";
}
List<String> displayName = data.getData().get("displayName");
List<String> groupList = data.getData().get("groupList");
if (displayName != null) {
group.getProperties().put("sharedRoster.showInRoster", showInRoster);
group.getProperties().put("sharedRoster.displayName", displayName.get(0));
if (groupList != null) {
StringBuilder buf = new StringBuilder();
String sep = "";
for (String groupName : groupList) {
buf.append(sep).append(groupName);
sep = ",";
}
group.getProperties().put("sharedRoster.groupList", buf.toString());
}
}
}
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
public String getCode() {
return "http://jabber.org/protocol/admin#update-group";
}
public String getDefaultLabel() {
return "Update group configuration";
}
protected List<Action> getActions(SessionData data) {
if (data.getStage() == 0) {
return Arrays.asList(AdHocCommand.Action.next);
}
else if (data.getStage() == 1) {
return Arrays.asList(AdHocCommand.Action.next, AdHocCommand.Action.prev, AdHocCommand.Action.complete);
}
return Arrays.asList(AdHocCommand.Action.complete);
}
protected AdHocCommand.Action getExecuteAction(SessionData data) {
if (data.getStage() == 0) {
return AdHocCommand.Action.next;
}
return AdHocCommand.Action.complete;
}
public int getMaxStages(SessionData data) {
return 2;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment