com.liferay.commerce.internal.order.status.InProgressCommerceOrderStatusImpl 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.CommerceOrderActionKeys;
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.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.security.permission.PermissionThreadLocal;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Alec Sloan
*/
@Component(
enabled = false, immediate = true,
property = {
"commerce.order.status.key=" + InProgressCommerceOrderStatusImpl.KEY,
"commerce.order.status.priority:Integer=" + InProgressCommerceOrderStatusImpl.PRIORITY
},
service = CommerceOrderStatus.class
)
public class InProgressCommerceOrderStatusImpl implements CommerceOrderStatus {
public static final int KEY =
CommerceOrderConstants.ORDER_STATUS_IN_PROGRESS;
public static final int PRIORITY = 20;
@Override
public CommerceOrder doTransition(CommerceOrder commerceOrder, long userId)
throws PortalException {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(commerceOrder.getGroupId());
serviceContext.setUserId(userId);
long commerceOrderId = commerceOrder.getCommerceOrderId();
if (commerceOrder.isDraft()) {
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
commerceOrder = WorkflowHandlerRegistryUtil.startWorkflowInstance(
commerceOrder.getCompanyId(), commerceOrder.getScopeGroupId(),
commerceOrder.getUserId(), CommerceOrder.class.getName(),
commerceOrderId, commerceOrder, serviceContext,
new HashMap<>());
commerceOrder.setStatusByUserId(userId);
commerceOrder.setStatusByUserName(
_portal.getUserName(userId, StringPool.BLANK));
commerceOrder.setStatusDate(new Date());
return commerceOrder;
}
commerceOrder.setOrderDate(new Date());
commerceOrder.setOrderStatus(KEY);
return _commerceOrderService.updateCommerceOrder(commerceOrder);
}
@Override
public int getKey() {
return KEY;
}
@Override
public String getLabel(Locale locale) {
return LanguageUtil.get(
locale, CommerceOrderConstants.getOrderStatusLabel(KEY));
}
@Override
public int getPriority() {
return PRIORITY;
}
@Override
public boolean isComplete(CommerceOrder commerceOrder) {
if (commerceOrder.isOpen()) {
return false;
}
return true;
}
@Override
public boolean isTransitionCriteriaMet(CommerceOrder commerceOrder)
throws PortalException {
if (!commerceOrder.isPending() &&
_commerceOrderValidatorRegistry.isValid(null, commerceOrder) &&
_commerceOrderModelResourcePermission.contains(
PermissionThreadLocal.getPermissionChecker(), commerceOrder,
CommerceOrderActionKeys.CHECKOUT_COMMERCE_ORDER)) {
return true;
}
return false;
}
@Override
public boolean isWorkflowEnabled(CommerceOrder commerceOrder)
throws PortalException {
return false;
}
@Reference(
target = "(model.class.name=com.liferay.commerce.model.CommerceOrder)"
)
private ModelResourcePermission
_commerceOrderModelResourcePermission;
@Reference
private CommerceOrderService _commerceOrderService;
@Reference
private CommerceOrderValidatorRegistry _commerceOrderValidatorRegistry;
@Reference
private Portal _portal;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy