use of org.jivesoftware.openfire.group.GroupAlreadyExistsException in project Openfire by igniterealtime.
the class UserServicePluginNG method createGroup.
/**
* Creates the group.
*
* @param groupName
* the group name
* @return the group
* @throws ServiceException
* @throws GroupAlreadyExistsException
* the group already exists exception
*/
private Group createGroup(String groupName) throws ServiceException {
Group group = null;
try {
group = GroupManager.getInstance().createGroup(groupName);
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
group.getProperties().put("sharedRoster.displayName", groupName);
group.getProperties().put("sharedRoster.groupList", "");
} catch (GroupAlreadyExistsException e) {
throw new ServiceException("Could not create group", groupName, ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.BAD_REQUEST, e);
}
return group;
}
use of org.jivesoftware.openfire.group.GroupAlreadyExistsException in project Openfire by igniterealtime.
the class AddGroup method execute.
@Override
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"));
}
use of org.jivesoftware.openfire.group.GroupAlreadyExistsException in project Openfire by igniterealtime.
the class GroupController method createGroup.
/**
* Creates the group.
*
* @param groupEntity
* the group entity
* @return the group
* @throws ServiceException
* the service exception
*/
public Group createGroup(GroupEntity groupEntity) throws ServiceException {
Group group;
if (groupEntity != null && !groupEntity.getName().isEmpty()) {
try {
group = GroupManager.getInstance().createGroup(groupEntity.getName());
group.setDescription(groupEntity.getDescription());
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
group.getProperties().put("sharedRoster.displayName", groupEntity.getName());
group.getProperties().put("sharedRoster.groupList", "");
} catch (GroupAlreadyExistsException e) {
throw new ServiceException("Could not create a group", groupEntity.getName(), ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
} else {
throw new ServiceException("Could not create new group", "groups", ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
}
return group;
}
Aggregations