/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.users.admin.internal.exportimport.data.handler;
import com.liferay.exportimport.data.handler.base.BaseStagedModelDataHandler;
import com.liferay.exportimport.kernel.lar.PortletDataContext;
import com.liferay.exportimport.kernel.lar.StagedModelDataHandler;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import java.util.ArrayList;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Daniel Kocsis
*/
@Component(immediate = true, service = StagedModelDataHandler.class)
public class UserStagedModelDataHandler
extends BaseStagedModelDataHandler<User> {
public static final String[] CLASS_NAMES = {User.class.getName()};
@Override
public void deleteStagedModel(
String uuid, long groupId, String className, String extraData)
throws PortalException {
Group group = _groupLocalService.getGroup(groupId);
User user = _userLocalService.fetchUserByUuidAndCompanyId(
uuid, group.getCompanyId());
if (user != null) {
deleteStagedModel(user);
}
}
@Override
public void deleteStagedModel(User user) throws PortalException {
_userLocalService.deleteUser(user);
}
@Override
public List<User> fetchStagedModelsByUuidAndCompanyId(
String uuid, long companyId) {
List<User> users = new ArrayList<>();
users.add(
_userLocalService.fetchUserByUuidAndCompanyId(uuid, companyId));
return users;
}
@Override
public String[] getClassNames() {
return CLASS_NAMES;
}
@Override
public String getDisplayName(User user) {
return user.getFullName();
}
@Override
protected void doExportStagedModel(
PortletDataContext portletDataContext, User user) {
}
@Override
protected void doImportStagedModel(
PortletDataContext portletDataContext, User user) {
}
@Reference(unbind = "-")
protected void setGroupLocalService(GroupLocalService groupLocalService) {
_groupLocalService = groupLocalService;
}
@Reference(unbind = "-")
protected void setUserLocalService(UserLocalService userLocalService) {
_userLocalService = userLocalService;
}
private GroupLocalService _groupLocalService;
private UserLocalService _userLocalService;
}