com.liferay.commerce.initializer.util.internal.osgi.commands.CommerceOSGiCommands Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.commerce.initializer.util Show documentation
Show all versions of com.liferay.commerce.initializer.util Show documentation
Liferay Commerce Initializer Utilities
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.commerce.initializer.util.internal.osgi.commands;
import com.liferay.commerce.initializer.util.CommerceOrderGenerator;
import com.liferay.commerce.initializer.util.CommerceShipmentGenerator;
import com.liferay.osgi.util.osgi.commands.OSGiCommands;
import com.liferay.portal.kernel.model.Company;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.PermissionCheckerFactory;
import com.liferay.portal.kernel.security.permission.PermissionThreadLocal;
import com.liferay.portal.kernel.service.CompanyLocalService;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.RoleLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.site.initializer.SiteInitializer;
import com.liferay.site.initializer.SiteInitializerRegistry;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Alessio Antonio Rendina
*/
@Component(
property = {
"osgi.command.function=generateOrders",
"osgi.command.function=generateShipments",
"osgi.command.function=initializeSite", "osgi.command.scope=commerce"
},
service = OSGiCommands.class
)
public class CommerceOSGiCommands implements OSGiCommands {
public void generateOrders(long groupId, int ordersCount) {
_commerceOrderGenerator.generate(groupId, ordersCount);
}
public void generateShipments(long groupId, int shipmentsCount)
throws Exception {
_commerceShipmentGenerator.generate(groupId, shipmentsCount);
}
public void initializeSite(long groupId, String key) throws Exception {
Group group = _groupLocalService.getGroup(groupId);
Company company = _companyLocalService.getCompanyById(
group.getCompanyId());
Role role = _roleLocalService.fetchRole(
company.getCompanyId(), RoleConstants.ADMINISTRATOR);
List roleUsers = _userLocalService.getRoleUsers(role.getRoleId());
User user = roleUsers.get(0);
PermissionChecker permissionChecker = _permissionCheckerFactory.create(
user);
PrincipalThreadLocal.setName(user.getUserId());
PermissionThreadLocal.setPermissionChecker(permissionChecker);
SiteInitializer siteInitializer =
_siteInitializerRegistry.getSiteInitializer(key);
siteInitializer.initialize(groupId);
}
@Reference
private CommerceOrderGenerator _commerceOrderGenerator;
@Reference
private CommerceShipmentGenerator _commerceShipmentGenerator;
@Reference
private CompanyLocalService _companyLocalService;
@Reference
private GroupLocalService _groupLocalService;
@Reference
private PermissionCheckerFactory _permissionCheckerFactory;
@Reference
private RoleLocalService _roleLocalService;
@Reference
private SiteInitializerRegistry _siteInitializerRegistry;
@Reference
private UserLocalService _userLocalService;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy