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