001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Vladimir Pasquier
018 */
019package org.nuxeo.ecm.platform.groups.audit.factory;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.apache.commons.logging.Log;
027import org.apache.commons.logging.LogFactory;
028import org.nuxeo.ecm.core.api.NuxeoGroup;
029import org.nuxeo.ecm.platform.groups.audit.service.ExcelExportFactory;
030import org.nuxeo.ecm.platform.usermanager.UserManager;
031import org.nuxeo.runtime.api.Framework;
032
033public class ExcelExportAllGroups implements ExcelExportFactory {
034
035    public static final Log log = LogFactory.getLog(ExcelExportAllGroups.class);
036
037    @Override
038    public Map<String, Object> getDataToInject() {
039        UserManager userManager = Framework.getLocalService(UserManager.class);
040        List<String> groupsId = new ArrayList<String>();
041        List<NuxeoGroup> groups = new ArrayList<NuxeoGroup>();
042        groupsId = userManager.getGroupIds();
043        for (String groupId : groupsId) {
044            NuxeoGroup group;
045            group = userManager.getGroup(groupId);
046            groups.add(group);
047        }
048        Map<String, Object> beans = new HashMap<String, Object>();
049        beans.put("groups", groups);
050        beans.put("userManager", userManager);
051        return beans;
052    }
053
054}