Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lpd 34676 init #6067

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.liferay.commerce.product.service.CommerceChannelLocalService;
import com.liferay.frontend.data.set.resolver.FDSAPIURLResolver;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.util.Validator;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -42,29 +43,47 @@ public String resolve(String baseURL, HttpServletRequest httpServletRequest)
(CommerceContext)httpServletRequest.getAttribute(
CommerceWebKeys.COMMERCE_CONTEXT);

AccountEntry accountEntry = commerceContext.getAccountEntry();
CommerceChannel commerceChannel =
_commerceChannelLocalService.getCommerceChannel(
commerceContext.getCommerceChannelId());
CommerceOrder commerceOrder = commerceContext.getCommerceOrder();

return baseURL.replaceAll(
"\\{accountExternalReferenceCode\\}",
accountEntry.getExternalReferenceCode()
).replaceAll(
"\\{accountId\\}", String.valueOf(accountEntry.getAccountEntryId())
).replaceAll(
"\\{cartId\\}", String.valueOf(commerceOrder.getCommerceOrderId())
).replaceAll(
"\\{channelExternalReferenceCode\\}",
String.valueOf(commerceChannel.getExternalReferenceCode())
).replaceAll(
"\\{channelId\\}",
String.valueOf(commerceContext.getCommerceChannelId())
).replaceAll(
"\\{externalReferenceCode\\}",
commerceOrder.getExternalReferenceCode()
);
if (Validator.isNotNull(commerceContext)) {
AccountEntry accountEntry = commerceContext.getAccountEntry();

if (Validator.isNotNull(accountEntry)) {
baseURL = baseURL.replaceAll(
"\\{accountExternalReferenceCode\\}",
accountEntry.getExternalReferenceCode()
).replaceAll(
"\\{accountId\\}",
String.valueOf(accountEntry.getAccountEntryId())
);
}

CommerceChannel commerceChannel =
_commerceChannelLocalService.getCommerceChannel(
commerceContext.getCommerceChannelId());

if (Validator.isNotNull(commerceChannel)) {
baseURL = baseURL.replaceAll(
"\\{channelExternalReferenceCode\\}",
String.valueOf(commerceChannel.getExternalReferenceCode())
).replaceAll(
"\\{channelId\\}",
String.valueOf(commerceContext.getCommerceChannelId())
);
}

CommerceOrder commerceOrder = commerceContext.getCommerceOrder();

if (Validator.isNotNull(commerceOrder)) {
baseURL = baseURL.replaceAll(
"\\{cartId\\}",
String.valueOf(commerceOrder.getCommerceOrderId())
).replaceAll(
"\\{externalReferenceCode\\}",
commerceOrder.getExternalReferenceCode()
);
}
}

return baseURL;
}

@Reference
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* SPDX-FileCopyrightText: (c) 2024 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.order.content.web.internal.frontend.data.set.resolver;

import com.liferay.commerce.constants.CommerceWebKeys;
import com.liferay.commerce.context.CommerceContext;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.frontend.data.set.resolver.FDSAPIURLResolver;
import com.liferay.portal.kernel.util.Validator;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;

@Component(
property = "fds.rest.application.key=/headless-commerce-delivery-cart/v1.0/CartItem",
service = FDSAPIURLResolver.class
)
public class PendingCommerceOrderItemFDSAPIURLResolver
implements FDSAPIURLResolver {

@Override
public String getSchema() {
return "CartItem";
}

@Override
public String resolve(
String baseURL, HttpServletRequest httpServletRequest) {

CommerceContext commerceContext =
(CommerceContext)httpServletRequest.getAttribute(
CommerceWebKeys.COMMERCE_CONTEXT);

if (Validator.isNotNull(commerceContext)) {
CommerceOrder commerceOrder = commerceContext.getCommerceOrder();

if (Validator.isNotNull(commerceOrder)) {
baseURL = baseURL.replaceAll(
"\\{cartId\\}",
String.valueOf(commerceOrder.getCommerceOrderId())
).replaceAll(
"\\{externalReferenceCode\\}",
commerceOrder.getExternalReferenceCode()
);
}
}

return baseURL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* SPDX-FileCopyrightText: (c) 2024 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.order.content.web.internal.frontend.data.set.resolver;

import com.liferay.account.model.AccountEntry;
import com.liferay.commerce.constants.CommerceWebKeys;
import com.liferay.commerce.context.CommerceContext;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.product.model.CommerceChannel;
import com.liferay.commerce.product.service.CommerceChannelLocalService;
import com.liferay.frontend.data.set.resolver.FDSAPIURLResolver;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.util.Validator;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Gianmarco Brunialti Masera
*/
@Component(
property = "fds.rest.application.key=/headless-commerce-delivery-order/v1.0/PlacedOrder",
service = FDSAPIURLResolver.class
)
public class PlacedCommerceOrderFDSAPIURLResolver implements FDSAPIURLResolver {

@Override
public String getSchema() {
return "PlacedOrder";
}

@Override
public String resolve(String baseURL, HttpServletRequest httpServletRequest)
throws PortalException {

CommerceContext commerceContext =
(CommerceContext)httpServletRequest.getAttribute(
CommerceWebKeys.COMMERCE_CONTEXT);

if (Validator.isNotNull(commerceContext)) {
AccountEntry accountEntry = commerceContext.getAccountEntry();

if (Validator.isNotNull(accountEntry)) {
baseURL = baseURL.replaceAll(
"\\{accountExternalReferenceCode\\}",
accountEntry.getExternalReferenceCode()
).replaceAll(
"\\{accountId\\}",
String.valueOf(accountEntry.getAccountEntryId())
);
}

CommerceChannel commerceChannel =
_commerceChannelLocalService.getCommerceChannel(
commerceContext.getCommerceChannelId());

if (Validator.isNotNull(commerceChannel)) {
baseURL = baseURL.replaceAll(
"\\{channelExternalReferenceCode\\}",
String.valueOf(commerceChannel.getExternalReferenceCode())
).replaceAll(
"\\{channelId\\}",
String.valueOf(commerceContext.getCommerceChannelId())
);
}

CommerceOrder commerceOrder = commerceContext.getCommerceOrder();

if (Validator.isNotNull(commerceOrder)) {
baseURL = baseURL.replaceAll(
"\\{placedOrderId\\}",
String.valueOf(commerceOrder.getCommerceOrderId())
).replaceAll(
"\\{externalReferenceCode\\}",
commerceOrder.getExternalReferenceCode()
);
}
}

return baseURL;
}

@Reference
private CommerceChannelLocalService _commerceChannelLocalService;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* SPDX-FileCopyrightText: (c) 2024 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.order.content.web.internal.frontend.data.set.resolver;

import com.liferay.commerce.constants.CommerceWebKeys;
import com.liferay.commerce.context.CommerceContext;
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.frontend.data.set.resolver.FDSAPIURLResolver;
import com.liferay.portal.kernel.util.Validator;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;

/**
* @author Gianmarco Brunialti Masera
*/
@Component(
property = "fds.rest.application.key=/headless-commerce-delivery-order/v1.0/PlacedOrderItem",
service = FDSAPIURLResolver.class
)
public class PlacedCommerceOrderItemFDSAPIURLResolver
implements FDSAPIURLResolver {

@Override
public String getSchema() {
return "PlacedOrderItem";
}

@Override
public String resolve(
String baseURL, HttpServletRequest httpServletRequest) {

CommerceContext commerceContext =
(CommerceContext)httpServletRequest.getAttribute(
CommerceWebKeys.COMMERCE_CONTEXT);

if (Validator.isNotNull(commerceContext)) {
CommerceOrder commerceOrder = commerceContext.getCommerceOrder();

if (Validator.isNotNull(commerceOrder)) {
baseURL = baseURL.replaceAll(
"\\{placedOrderId\\}",
String.valueOf(commerceOrder.getCommerceOrderId())
).replaceAll(
"\\{externalReferenceCode\\}",
commerceOrder.getExternalReferenceCode()
);
}
}

return baseURL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
compileOnly project(":apps:commerce:headless:headless-commerce:headless-commerce-admin-catalog-api")
compileOnly project(":apps:commerce:headless:headless-commerce:headless-commerce-admin-channel-api")
compileOnly project(":apps:commerce:headless:headless-commerce:headless-commerce-admin-order-api")
compileOnly project(":apps:object:object-api")
compileOnly project(":apps:object:object-rest-api")
compileOnly project(":apps:portal-configuration:portal-configuration-module-configuration-api")
compileOnly project(":apps:portal-vulcan:portal-vulcan-api")
compileOnly project(":apps:site-initializer:site-initializer-extender:site-initializer-extender-api")
Expand Down
Loading