
com.liferay.commerce.internal.order.status.PendingCommerceOrderStatusImpl Maven / Gradle / Ivy
/**
* 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.commerce.internal.order.status;
import com.liferay.commerce.constants.CommerceOrderConstants;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.order.CommerceOrderValidatorRegistry;
import com.liferay.commerce.order.status.CommerceOrderStatus;
import com.liferay.commerce.service.CommerceOrderService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.model.WorkflowDefinitionLink;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.WorkflowDefinitionLinkLocalService;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
import java.util.HashMap;
import java.util.Locale;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
/**
* @author Alec Sloan
*/
@Component(
immediate = true,
property = {
"commerce.order.status.key=" + PendingCommerceOrderStatusImpl.KEY,
"commerce.order.status.priority:Integer=" + PendingCommerceOrderStatusImpl.PRIORITY
},
service = CommerceOrderStatus.class
)
public class PendingCommerceOrderStatusImpl implements CommerceOrderStatus {
public static final int KEY = CommerceOrderConstants.ORDER_STATUS_PENDING;
public static final int PRIORITY = 30;
@Override
public CommerceOrder doTransition(CommerceOrder commerceOrder, long userId)
throws PortalException {
if (isWorkflowEnabled(commerceOrder)) {
// Commerce order
commerceOrder.setStatus(WorkflowConstants.STATUS_PENDING);
// Workflow
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(commerceOrder.getGroupId());
serviceContext.setUserId(userId);
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
commerceOrder = WorkflowHandlerRegistryUtil.startWorkflowInstance(
commerceOrder.getCompanyId(), commerceOrder.getGroupId(),
userId, CommerceOrder.class.getName(),
commerceOrder.getCommerceOrderId(), commerceOrder,
serviceContext, new HashMap<>());
}
commerceOrder.setOrderStatus(KEY);
return _commerceOrderService.updateCommerceOrder(commerceOrder);
}
public int getKey() {
return KEY;
}
public String getLabel(Locale locale) {
return LanguageUtil.get(
locale, CommerceOrderConstants.getOrderStatusLabel(KEY));
}
public int getPriority() {
return PRIORITY;
}
@Override
public boolean isComplete(CommerceOrder commerceOrder) {
if (!commerceOrder.isOpen() && commerceOrder.isApproved()) {
return true;
}
return false;
}
@Override
public boolean isTransitionCriteriaMet(CommerceOrder commerceOrder)
throws PortalException {
if ((commerceOrder.getOrderStatus() ==
CommerceOrderConstants.ORDER_STATUS_IN_PROGRESS) &&
_commerceOrderValidatorRegistry.isValid(null, commerceOrder)) {
return true;
}
return false;
}
@Override
public boolean isWorkflowEnabled(CommerceOrder commerceOrder)
throws PortalException {
WorkflowDefinitionLink workflowDefinitionLink =
_workflowDefinitionLinkLocalService.fetchWorkflowDefinitionLink(
commerceOrder.getCompanyId(), commerceOrder.getGroupId(),
CommerceOrder.class.getName(), 0,
CommerceOrderConstants.TYPE_PK_FULFILLMENT, true);
if (workflowDefinitionLink != null) {
return true;
}
return false;
}
@Reference(
policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY
)
private volatile CommerceOrderService _commerceOrderService;
@Reference
private CommerceOrderValidatorRegistry _commerceOrderValidatorRegistry;
@Reference
private WorkflowDefinitionLinkLocalService
_workflowDefinitionLinkLocalService;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy