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