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 long getLastImportTime() throws Exception {
031                    return _getInstance().getLastImportTime();
032            }
033    
034            public static User importUser(
035                            long ldapServerId, long companyId, String emailAddress,
036                            String screenName)
037                    throws Exception {
038    
039                    return _getInstance().importUser(
040                            ldapServerId, companyId, emailAddress, screenName);
041            }
042    
043            public static User importUser(
044                            long companyId, String emailAddress, String screenName)
045                    throws Exception {
046    
047                    return _getInstance().importUser(companyId, emailAddress, screenName);
048            }
049    
050            public static User importUserByScreenName(long companyId, String screenName)
051                    throws Exception {
052    
053                    return _getInstance().importUserByScreenName(companyId, screenName);
054            }
055    
056            public static void importUsers() throws Exception {
057                    _getInstance().importUsers();
058            }
059    
060            public static void importUsers(long companyId) throws Exception {
061                    _getInstance().importUsers(companyId);
062            }
063    
064            public static void importUsers(long ldapServerId, long companyId)
065                    throws Exception {
066    
067                    _getInstance().importUsers(ldapServerId, companyId);
068            }
069    
070            private static UserImporter _getInstance() {
071                    return _instance._serviceTracker.getService();
072            }
073    
074            private UserImporterUtil() {
075                    Registry registry = RegistryUtil.getRegistry();
076    
077                    _serviceTracker = registry.trackServices(UserImporter.class);
078    
079                    _serviceTracker.open();
080            }
081    
082            private static final UserImporterUtil _instance = new UserImporterUtil();
083    
084            private final ServiceTracker<UserImporter, UserImporter> _serviceTracker;
085    
086    }