-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LPD-34676 Added Commerce Order FDSAPIURLResolvers
- Loading branch information
1 parent
9e190c2
commit 6d0a45f
Showing
4 changed files
with
246 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...nt/web/internal/frontend/data/set/resolver/PendingCommerceOrderItemFDSAPIURLResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...content/web/internal/frontend/data/set/resolver/PlacedCommerceOrderFDSAPIURLResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...ent/web/internal/frontend/data/set/resolver/PlacedCommerceOrderItemFDSAPIURLResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |