001/* 002 * (C) Copyright 2006-2012 Nuxeo SAS (http://nuxeo.com/) and contributors. 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.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 * tmartins 016 */ 017package org.nuxeo.ecm.platform.usermanager; 018 019import java.util.List; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.api.DataModel; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.impl.DataModelImpl; 026 027/** 028 * A class that exposes the fields from user schema 029 * 030 * @since 5.7 031 * @author <a href="mailto:tm@nuxeo.com">Thierry Martins</a> 032 */ 033public class UserAdapterImpl implements UserAdapter { 034 035 private static final Log log = LogFactory.getLog(UserAdapterImpl.class); 036 037 protected final DocumentModel doc; 038 039 protected final UserConfig userConfig; 040 041 private DataModel dataModel; 042 043 public UserAdapterImpl(DocumentModel doc, UserManager userManager) { 044 this.doc = doc; 045 if (userManager != null && userManager instanceof UserManagerImpl) { 046 userConfig = ((UserManagerImpl) userManager).userConfig; 047 } else { 048 userConfig = UserConfig.DEFAULT; 049 } 050 dataModel = doc.getDataModel(userConfig.schemaName); 051 } 052 053 @Override 054 public String getName() { 055 return (String) dataModel.getValue(userConfig.nameKey); 056 } 057 058 @Override 059 public String getFirstName() { 060 return (String) dataModel.getValue(userConfig.firstNameKey); 061 } 062 063 @Override 064 public String getLastName() { 065 return (String) dataModel.getValue(userConfig.lastNameKey); 066 } 067 068 @Override 069 public String getEmail() { 070 return (String) dataModel.getValue(userConfig.emailKey); 071 } 072 073 @Override 074 public String getCompany() { 075 return (String) dataModel.getValue(userConfig.companyKey); 076 } 077 078 @Override 079 @SuppressWarnings("unchecked") 080 public List<String> getGroups() { 081 return (List<String>) dataModel.getValue(userConfig.groupsKey); 082 } 083 084 @Override 085 public String getSchemaName() { 086 return userConfig.schemaName; 087 } 088}