001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.tools.accounts;
029
030import org.opencms.file.CmsGroup;
031import org.opencms.jsp.CmsJspActionElement;
032import org.opencms.main.CmsException;
033import org.opencms.main.CmsRuntimeException;
034import org.opencms.main.OpenCms;
035import org.opencms.security.CmsOrganizationalUnit;
036import org.opencms.security.CmsPrincipal;
037import org.opencms.util.CmsUUID;
038import org.opencms.workplace.CmsDialog;
039import org.opencms.workplace.list.CmsListColumnDefinition;
040import org.opencms.workplace.list.CmsListDirectAction;
041import org.opencms.workplace.list.CmsListItem;
042import org.opencms.workplace.list.CmsListItemDetails;
043import org.opencms.workplace.list.CmsListItemDetailsFormatter;
044import org.opencms.workplace.list.CmsListMetadata;
045
046import java.io.IOException;
047import java.util.HashMap;
048import java.util.Iterator;
049import java.util.List;
050import java.util.Map;
051
052import javax.servlet.ServletException;
053import javax.servlet.http.HttpServletRequest;
054import javax.servlet.http.HttpServletResponse;
055import javax.servlet.jsp.PageContext;
056
057/**
058 * Group account view over all manageable organizational units.<p>
059 *
060 * @since 6.5.6
061 */
062public class CmsGroupsAllOrgUnitsList extends A_CmsGroupsList {
063
064    /** list action id constant. */
065    public static final String LIST_ACTION_OVERVIEW = "ao";
066
067    /** list column id constant. */
068    public static final String LIST_COLUMN_ORGUNIT = "co";
069
070    /** list item detail id constant. */
071    public static final String LIST_DETAIL_ORGUNIT_DESC = "dd";
072
073    /** list id constant. */
074    public static final String LIST_ID = "lgaou";
075
076    /**
077     * Public constructor.<p>
078     *
079     * @param jsp an initialized JSP action element
080     */
081    public CmsGroupsAllOrgUnitsList(CmsJspActionElement jsp) {
082
083        super(jsp, LIST_ID, Messages.get().container(Messages.GUI_GROUPS_LIST_NAME_0));
084    }
085
086    /**
087     * Public constructor with JSP variables.<p>
088     *
089     * @param context the JSP page context
090     * @param req the JSP request
091     * @param res the JSP response
092     */
093    public CmsGroupsAllOrgUnitsList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
094
095        this(new CmsJspActionElement(context, req, res));
096    }
097
098    /**
099     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#executeListSingleActions()
100     */
101    @Override
102    public void executeListSingleActions() throws IOException, ServletException, CmsRuntimeException {
103
104        String groupId = getSelectedItem().getId();
105        String groupName = getSelectedItem().get(LIST_COLUMN_NAME).toString();
106
107        Map<String, String[]> params = new HashMap<String, String[]>();
108        params.put(A_CmsEditGroupDialog.PARAM_GROUPID, new String[] {groupId});
109        params.put(A_CmsEditGroupDialog.PARAM_GROUPNAME, new String[] {groupName});
110        params.put(
111            A_CmsOrgUnitDialog.PARAM_OUFQN,
112            new String[] {getSelectedItem().get(LIST_COLUMN_ORGUNIT).toString().substring(1)});
113        // set action parameter to initial dialog call
114        params.put(CmsDialog.PARAM_ACTION, new String[] {CmsDialog.DIALOG_INITIAL});
115
116        if (getParamListAction().equals(LIST_ACTION_OVERVIEW)) {
117            // forward
118            getToolManager().jspForwardTool(this, "/accounts/orgunit/groups/edit", params);
119        } else if (getParamListAction().equals(LIST_DEFACTION_EDIT)) {
120            // forward to the edit user screen
121            getToolManager().jspForwardTool(this, "/accounts/orgunit/groups/edit", params);
122        } else {
123            super.executeListSingleActions();
124        }
125        listSave();
126    }
127
128    /**
129     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#fillDetails(java.lang.String)
130     */
131    @Override
132    protected void fillDetails(String detailId) {
133
134        super.fillDetails(detailId);
135
136        // get content
137        List<CmsListItem> groups = getList().getAllContent();
138        Iterator<CmsListItem> itGroups = groups.iterator();
139        while (itGroups.hasNext()) {
140            CmsListItem item = itGroups.next();
141            String groupName = item.get(LIST_COLUMN_NAME).toString();
142            StringBuffer html = new StringBuffer(512);
143            try {
144                if (detailId.equals(LIST_DETAIL_ORGUNIT_DESC)) {
145                    CmsGroup group = getCms().readGroup(groupName);
146                    html.append(
147                        OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), group.getOuFqn()).getDescription(
148                            getLocale()));
149                } else {
150                    continue;
151                }
152            } catch (Exception e) {
153                // ignore
154            }
155            item.set(detailId, html.toString());
156        }
157    }
158
159    /**
160     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#getGroups()
161     */
162    @Override
163    protected List<CmsGroup> getGroups() throws CmsException {
164
165        return CmsPrincipal.filterCoreGroups(OpenCms.getRoleManager().getManageableGroups(getCms(), "", true));
166    }
167
168    /**
169     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#getListItems()
170     */
171    @Override
172    protected List<CmsListItem> getListItems() throws CmsException {
173
174        List<CmsListItem> listItems = super.getListItems();
175        Iterator<CmsListItem> itListItems = listItems.iterator();
176        while (itListItems.hasNext()) {
177            CmsListItem item = itListItems.next();
178            CmsGroup group = getCms().readGroup(new CmsUUID(item.getId()));
179            item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + group.getOuFqn());
180        }
181
182        return listItems;
183    }
184
185    /**
186     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#setColumns(org.opencms.workplace.list.CmsListMetadata)
187     */
188    @Override
189    protected void setColumns(CmsListMetadata metadata) {
190
191        super.setColumns(metadata);
192
193        metadata.getColumnDefinition(LIST_COLUMN_USERS).setVisible(false);
194        metadata.getColumnDefinition(LIST_COLUMN_ACTIVATE).setVisible(false);
195        metadata.getColumnDefinition(LIST_COLUMN_DELETE).setVisible(false);
196
197        metadata.getColumnDefinition(LIST_COLUMN_DISPLAY).setWidth("25%");
198        metadata.getColumnDefinition(LIST_COLUMN_DESCRIPTION).setWidth("50%");
199
200        // add column for orgunit
201        CmsListColumnDefinition orgUnitCol = new CmsListColumnDefinition(LIST_COLUMN_ORGUNIT);
202        orgUnitCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_ORGUNIT_0));
203        orgUnitCol.setWidth("25%");
204        metadata.addColumn(
205            orgUnitCol,
206            metadata.getColumnDefinitions().indexOf(metadata.getColumnDefinition(LIST_COLUMN_DESCRIPTION)));
207
208    }
209
210    /**
211     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#setDeleteAction(org.opencms.workplace.list.CmsListColumnDefinition)
212     */
213    @Override
214    protected void setDeleteAction(CmsListColumnDefinition deleteCol) {
215
216        // noop
217    }
218
219    /**
220     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#setEditAction(org.opencms.workplace.list.CmsListColumnDefinition)
221     */
222    @Override
223    protected void setEditAction(CmsListColumnDefinition editCol) {
224
225        CmsListDirectAction editAction = new CmsListDirectAction(LIST_ACTION_OVERVIEW);
226        editAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_EDIT_NAME_0));
227        editAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_EDIT_HELP_0));
228        editAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group.png");
229        editCol.addDirectAction(editAction);
230    }
231
232    /**
233     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
234     */
235    @Override
236    protected void setIndependentActions(CmsListMetadata metadata) {
237
238        super.setIndependentActions(metadata);
239
240        // add orgunit description details
241        CmsListItemDetails orgUnitDescDetails = new CmsListItemDetails(LIST_DETAIL_ORGUNIT_DESC);
242        orgUnitDescDetails.setAtColumn(LIST_COLUMN_DISPLAY);
243        orgUnitDescDetails.setVisible(false);
244        orgUnitDescDetails.setShowActionName(
245            Messages.get().container(Messages.GUI_USERS_DETAIL_SHOW_ORGUNIT_DESC_NAME_0));
246        orgUnitDescDetails.setShowActionHelpText(
247            Messages.get().container(Messages.GUI_USERS_DETAIL_SHOW_ORGUNIT_DESC_HELP_0));
248        orgUnitDescDetails.setHideActionName(
249            Messages.get().container(Messages.GUI_USERS_DETAIL_HIDE_ORGUNIT_DESC_NAME_0));
250        orgUnitDescDetails.setHideActionHelpText(
251            Messages.get().container(Messages.GUI_USERS_DETAIL_HIDE_ORGUNIT_DESC_HELP_0));
252        orgUnitDescDetails.setName(Messages.get().container(Messages.GUI_USERS_DETAIL_ORGUNIT_DESC_NAME_0));
253        orgUnitDescDetails.setFormatter(
254            new CmsListItemDetailsFormatter(Messages.get().container(Messages.GUI_USERS_DETAIL_ORGUNIT_DESC_NAME_0)));
255        metadata.addItemDetails(orgUnitDescDetails);
256
257        metadata.getSearchAction().addColumn(metadata.getColumnDefinition(LIST_COLUMN_DESCRIPTION));
258        metadata.getSearchAction().addColumn(metadata.getColumnDefinition(LIST_COLUMN_ORGUNIT));
259    }
260
261    /**
262     * @see org.opencms.workplace.tools.accounts.A_CmsGroupsList#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
263     */
264    @Override
265    protected void setMultiActions(CmsListMetadata metadata) {
266
267        // noop
268    }
269
270    /**
271     * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
272     */
273    @Override
274    protected void validateParamaters() throws Exception {
275
276        // no param check needed
277    }
278}