001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger 016 */ 017 018package org.nuxeo.ecm.platform.usermanager.providers; 019 020import java.util.ArrayList; 021import java.util.List; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.NuxeoPrincipal; 027import org.nuxeo.ecm.platform.usermanager.UserManager; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * * Page provider listing {@link NuxeoPrincipal}s. 032 * 033 * @since 5.8 034 */ 035public class NuxeoPrincipalsPageProvider extends AbstractUsersPageProvider<NuxeoPrincipal> { 036 037 private static final Log log = LogFactory.getLog(NuxeoPrincipalsPageProvider.class); 038 039 protected List<NuxeoPrincipal> pagePrincipals; 040 041 @Override 042 public List<NuxeoPrincipal> getCurrentPage() { 043 if (pagePrincipals == null) { 044 List<DocumentModel> users = computeCurrentPage(); 045 pagePrincipals = new ArrayList<>(); 046 UserManager userManager = Framework.getLocalService(UserManager.class); 047 for (DocumentModel user : users) { 048 NuxeoPrincipal principal = userManager.getPrincipal( 049 user.getProperty(userManager.getUserIdField()).getValue(String.class)); 050 pagePrincipals.add(principal); 051 } 052 } 053 054 return pagePrincipals; 055 } 056 057 @Override 058 protected void pageChanged() { 059 pagePrincipals = null; 060 super.pageChanged(); 061 } 062 063 @Override 064 public void refresh() { 065 pagePrincipals = null; 066 super.refresh(); 067 } 068}