@Override
    public void execute(@Nonnull final SessionData data, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(data.getOwner());

        int nStart = 0;
        final List<String> start_data = data.getData().get("start");
        if (start_data != null && !start_data.isEmpty()) {
            String start = start_data.get(0);
            if (start != null && !"none".equals(start)) {
                try {
                    nStart = Integer.parseInt(start);
                } catch (NumberFormatException e) {
                    // Do nothing. Assume that all users are being requested
                }
            }
        }
        int maxItems = 100000;
        final List<String> max_items_data = data.getData().get("max_items");
        if (max_items_data != null && !max_items_data.isEmpty()) {
            String max_items = max_items_data.get(0);
            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", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.name.label", preferredLocale), FormField.Type.text_single);
        form.addReportedField("desc", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.desc.label", preferredLocale), FormField.Type.text_multi);
        form.addReportedField("count", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.count.label", preferredLocale), FormField.Type.text_single);
        form.addReportedField("shared", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.shared.label", preferredLocale), FormField.Type.boolean_type);
        form.addReportedField("display", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.display.label", preferredLocale), FormField.Type.text_single);
        form.addReportedField("visibility", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.visibility.label", preferredLocale), FormField.Type.text_single);
        form.addReportedField("groups", LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.groups.label", preferredLocale), 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<>();
            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 ? group.getSharedDisplayName() : ""));
            final String showInRoster;
            if (!isSharedGroup || group.getSharedWith() == null) {
                showInRoster = "";
            } else {
                switch (group.getSharedWith()) {
                    case nobody:
                        showInRoster = LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.visibility.nobody.label", preferredLocale);
                        break;
                    case everybody:
                        showInRoster = LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.visibility.everybody.label", preferredLocale);
                        break;
                    case usersOfGroups:
                        final List<String> sharedWith = group.getSharedWithUsersInGroupNames();
                        if (sharedWith.isEmpty() || (sharedWith.size() == 1 && sharedWith.contains(group.getName()))) {
                            showInRoster = LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.visibility.onlygroup.label", preferredLocale);
                        } else {
                            showInRoster = LocaleUtils.getLocalizedString("commands.admin.group.getlistgroups.form.reportedfield.visibility.spefgroups.label", preferredLocale);
                        }
                        break;
                    default:
                        showInRoster = group.getSharedWith().toString();
                        break;
                }
            }
            fields.put("visibility", showInRoster);
            fields.put("groups", (isSharedGroup ? String.join(",", group.getSharedWithUsersInGroupNames()) : ""));
            form.addItemFields(fields);
        }
        command.add(form.getElement());
    }
Command that allows to retrieve a list of existing groups.

@author Gaston Dombiak
xmppserver/src/main/java/org/jivesoftware/openfire/commands/admin/group/GetListGroups.java