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.portlet.usersadmin.lar;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.model.Group;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.GroupLocalServiceUtil;
021    import com.liferay.portal.service.UserLocalServiceUtil;
022    import com.liferay.portlet.exportimport.lar.BaseStagedModelDataHandler;
023    import com.liferay.portlet.exportimport.lar.PortletDataContext;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Daniel Kocsis
030     */
031    public class UserStagedModelDataHandler
032            extends BaseStagedModelDataHandler<User> {
033    
034            public static final String[] CLASS_NAMES = {User.class.getName()};
035    
036            @Override
037            public void deleteStagedModel(
038                            String uuid, long groupId, String className, String extraData)
039                    throws PortalException {
040    
041                    Group group = GroupLocalServiceUtil.getGroup(groupId);
042    
043                    User user = UserLocalServiceUtil.fetchUserByUuidAndCompanyId(
044                            uuid, group.getCompanyId());
045    
046                    if (user != null) {
047                            deleteStagedModel(user);
048                    }
049            }
050    
051            @Override
052            public void deleteStagedModel(User user) throws PortalException {
053                    UserLocalServiceUtil.deleteUser(user);
054            }
055    
056            @Override
057            public List<User> fetchStagedModelsByUuidAndCompanyId(
058                    String uuid, long companyId) {
059    
060                    List<User> users = new ArrayList<>();
061    
062                    users.add(
063                            UserLocalServiceUtil.fetchUserByUuidAndCompanyId(uuid, companyId));
064    
065                    return users;
066            }
067    
068            @Override
069            public String[] getClassNames() {
070                    return CLASS_NAMES;
071            }
072    
073            @Override
074            public String getDisplayName(User user) {
075                    return user.getFullName();
076            }
077    
078            @Override
079            protected void doExportStagedModel(
080                    PortletDataContext portletDataContext, User user) {
081            }
082    
083            @Override
084            protected void doImportStagedModel(
085                    PortletDataContext portletDataContext, User user) {
086            }
087    
088    }