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