001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.exportimport;
016    
017    import com.liferay.portal.model.User;
018    import com.liferay.registry.Registry;
019    import com.liferay.registry.RegistryUtil;
020    import com.liferay.registry.ServiceTracker;
021    
022    /**
023     * @author Edward Han
024     * @author Michael C. Han
025     * @author Brian Wing Shun Chan
026     * @author Raymond Aug??
027     */
028    public class UserImporterUtil {
029    
030            public static User importUser(
031                            long ldapServerId, long companyId, String emailAddress,
032                            String screenName)
033                    throws Exception {
034    
035                    return _getInstance().importUser(
036                            ldapServerId, companyId, emailAddress, screenName);
037            }
038    
039            public static User importUser(
040                            long companyId, String emailAddress, String screenName)
041                    throws Exception {
042    
043                    return _getInstance().importUser(companyId, emailAddress, screenName);
044            }
045    
046            public static User importUserByScreenName(long companyId, String screenName)
047                    throws Exception {
048    
049                    return _getInstance().importUserByScreenName(companyId, screenName);
050            }
051    
052            public static void importUsers() throws Exception {
053                    _getInstance().importUsers();
054            }
055    
056            public static void importUsers(long companyId) throws Exception {
057                    _getInstance().importUsers(companyId);
058            }
059    
060            public static void importUsers(long ldapServerId, long companyId)
061                    throws Exception {
062    
063                    _getInstance().importUsers(ldapServerId, companyId);
064            }
065    
066            private static UserImporter _getInstance() {
067                    return _instance._serviceTracker.getService();
068            }
069    
070            private UserImporterUtil() {
071                    Registry registry = RegistryUtil.getRegistry();
072    
073                    _serviceTracker = registry.trackServices(UserImporter.class);
074    
075                    _serviceTracker.open();
076            }
077    
078            private static final UserImporterUtil _instance = new UserImporterUtil();
079    
080            private final ServiceTracker<UserImporter, UserImporter> _serviceTracker;
081    
082    }